1

I am new to Arduino, and it's confusing to me how you can just write code in the IDE and use functions or macros such as #define ISR() in the avr-libc library without having to include the header file in the Arduino sketch.

I was trying to find where digitalPinToInterrupt() is defined, but had no luck. Any idea?

2

2 Answers 2

1

Generally, if you want to find identifiers in your Arduino board support, you can run the ctags program on the libc and Arduino core files. ctags is used as part of the build process in its effort to generate C++ declarations for you. So it is generally available to you as an Arduino user. You should find ctags or ctags.exe in:

/path/to/arduino15/builtin/tools/ctags/version-number/

This can be run against your board support in:

/path/to/arduino15/packages/vendor/hardware/architecture/version-number/

And your standard libraries found under directories in the form of:

/path/to/arduino15/packages/vendor/tools/compiler-tool/version-number/

If you're wondering what /path/to/arduino15/ would be on your system, it's documented here in terms of where the preferences file is stored. The relevant paths containing and version numbers and architecture names should show in the verify/compile output when verbose mode is turned on in preferences.

Specific example

On my linux system with reasonably current versions of UNO-related things, my command-line would look like:

~/.arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags \
    -f /tmp/output-file \
    -R \
     ~/.arduino15/packages/arduino/hardware/avr/1.8.3/ \
    ~/.arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/avr/include/

The resulting tag file can then greped or just opened and the following entries can be found, showing the filenames and line numbers to investigate:

DigitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/circuitplay32u4/pins_arduino.h   138;"   d
digitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/ethernet/pins_arduino.h  79;"    d
digitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/gemma/pins_arduino.h 64;"    d
digitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/leonardo/pins_arduino.h  160;"   d
digitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/mega/pins_arduino.h  110;"   d
digitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/robot_control/pins_arduino.h 120;"   d
digitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/robot_motor/pins_arduino.h   115;"   d
digitalPinToInterrupt   /home/user/.arduino15/packages/arduino/hardware/avr/1.8.3/variants/standard/pins_arduino.h  79;"    d

In the case of an UNO the standard variant is the significant declaration.


There are different implementations of ctags. The one used by the Arduino support files is Exuberant CTAGS and you may want to read its documentation, to learn how to control the program to display differently to only search for specific identifiers, etc. It is also typically used with editors that have some special support for the resulting tags file, to jump to definitions, like an IDE would.

1
  • By the way, I just noticed your atmega2560 tag. The generic instructions should cover this anyway, but: You'd be looking at the mega variant, which indicates this file and line.
    – timemage
    Commented Apr 5, 2021 at 16:26
0

If you like to tinker with the files. Than platformio is great option to go with. It provides auto completion and much more advance functionality.

You can easy see where some function/mecro is defined, by just right click on the function than click on the "Go to definition" option. Here is the picture

The file that contains the definition will be opened in the new tab. As for your current Macro check the image below digitalPinToInterrupt macro definition

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.