-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support extra parameter on attachInterrupt()
#58
Conversation
STM32 and ESP8266 are using C++ std::function to accomplish this. I am planning to do the same on Teensy in the near future. stm32duino/Arduino_Core_STM32#159 https://github.com/esp8266/Arduino/blob/master/cores/esp8266/FunctionalInterrupt.cpp |
Nice! If
(I haven't really tested it) |
There's been talk of upgrading to gcc 7. Any idea if newer AVR toolchains will someday support std::function? It'd really be a shame to do this another way if AVR will in the future have std::function... |
When writing an arduino library, it is difficult to connect interrupt handlers with the component instance that should be notified. In C, the common pattern to fix this is to specifying a `void*` parameter with the callback, where the listener can store any context necessary. This patch adds the new function `attachInterruptParam()` to implement this pattern.
932f1e6
to
3c6d386
Compare
I've just made a minor updated to this PR:
|
Any news on this one? |
Hi @Harvie , |
@facchinm cool! can't wait for this to be available on Arduino Nano/Uno. |
I think this PR can be closed, since this will be migrated from the ArduinoCore-API repo rather than implemented separately here in any case. In the meanwhile, we have #85 and arduino/ArduinoCore-API#95 to track this issue. @facchinm, @paulo-raca, agreed? |
Seems this is not really true: ArduinoCore-API has some code, but that is only for converting a reference argument to a pointer argument. And it specifies an For additional thoughts on the API and implementation, see arduino/ArduinoCore-API#99 |
|
It's been 5 years since I first sent this PR 😳 Time to give up |
@paulo-raca You can try https://github.com/neu-rah/PCINT |
When writing an arduino library, it is difficult to connect interrupt handlers with the component instance that should be notified.
In C, the common pattern to fix this is to specifying a
void*
parameter with the callback, where the listener can store any context necessary.This patch adds the new function
attachInterruptParam()
to implement this pattern.This PR was originally developed on arduino/Arduino#4519, and it's contains lengthy discussions about the implementation strategies and overhead.
A similar PR is available for SAM devices: arduino/ArduinoCore-sam#44
Overhead summary:
2*EXTERNAL_NUM_INTERRUPTS
extra bytes (10 bytes of RAM on Arduino Pro Micro)I do believe these are very acceptable values for a very useful feature.