-
-
Notifications
You must be signed in to change notification settings - Fork 111
Support extra parameter on `attachInterrupt() #44
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
Conversation
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 is a port of arduino/Arduino#4519, but for Arduino Due.
Just like the AVR implementation, on ARM the callback argument is sent on a register (r0). This means that we can safely pass arguments to a callback that doesn't expect any, and it will silently ignore them, allowing us to be backwards-compatible with no-argument interrupt callbacks with minimal overhead. How much overheader? Only 2 instructions. Let's look at the assembly of the assemly of ISR handler: Previous:
New:
|
To be honest, I don't think it ever will. The original PR on the AVR port has been pending for over 2 years without merge (despite apparent consensus that it would be useful and a pretty low performance overhead). If you know any way of getting their attention, please do / let me know. |
@paulo-raca we are definitely going to merge it (maybe slightly modified) but it's being delayed since it's part of Chainsaw project to unify APIs between platforms. I truly hope we'll be able to ship it before next month but we are severely outnumbered... Sorry again for the delay |
@facchinm thanks for the reply, I'm glad to hear it. Is there any way I can help? |
|
Closing by lack of interest |
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 mirrors the changes for AVR on arduino/Arduino#4519.