arduino / ArduinoCore-megaavr

Arduino Core for the ATMEGA4809 CPU
103 stars 62 forks source link

Unable to use digitalPinToInterrupt with attachInterrupt and detachInterrupt #18

Closed per1234 closed 5 years ago

per1234 commented 5 years ago

We expect to be able to use the attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) syntax, even when the use of digitalPinToInterrupt is not absolutely necessary due to the interrupts having the same numbering as the pins (e.g. SAMD). This allows code to be written that is portable across architectures.

This is not currently possible with Arduino megaAVR Boards. Arduino megaAVR Boards' attachInterrupt was written to take a pin number as the first parameter, then convert the pin number to interrupt number inside attachInterrupt using digitalPinToInterrupt, breaking from the convention established in Arduino AVR Boards.

To make matters more confusing, the attachInterrupt documentation falsely claims:

For Uno WiFiRev.2, Due, Zero, MKR Family and 101 boards the interrupt number = pin number.

The attachInterrupt documentation also specifically says that the attachInterrupt(pin, ISR, mode) syntax is not recommended.


Originally reported at: http://forum.arduino.cc/index.php?topic=592249

facchinm commented 5 years ago

I totally agree with you, the right behaviour is the one you are describing, so the action must be:

This way both attachInterrupt(pin) and attachInterrupt(digitalPinToInterrupt(pin)) behaviours should be fine and consistent with SAMD core.