Skip to content

Added ability to bind std:function on interrupts #159

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

Merged
merged 5 commits into from
Nov 29, 2017

Conversation

straccio
Copy link
Contributor

The function attachInterrupt now also accept std:function<void(void)> in order to bind object method to an interrupt.

The function attachInterrupt now also accept std:function<void(void)> in order to bind object method to an interrupt.
Copy link
Member

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks interesting, can you provide a usage example in the commit message or in the comment above new attachInterrupt function ?

considering code: please consider removing the // and simply remove the lines ?

@LMESTM
Copy link
Member

LMESTM commented Nov 28, 2017

@straccio thanks for submitting the PR :-) !
Few further questions:
Could you provide a usage example (also part of my review comments) ?
Can you confirm that this change is backward compatible - I think this is the case from reviewing the code, just would like your confirmation on this.

@straccio
Copy link
Contributor Author

straccio commented Nov 28, 2017

Sure!

#define USER_BUTTON_PIN D75
volatile int state = HIGH;
void bt_handler(void) {
  state = !state;
}

std::function<void(void)> bt_handler_f = bt;
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  attachInterrupt(USER_BUTTON_PIN, bt_handler_f, FALLING);
}

void loop() {
  digitalWrite(LED_BUILTIN, state);
}

@straccio
Copy link
Contributor Author

Is backward compatible. I currently use something like this in Arduino Due.
I have only tested on STM32F429ZI

Copy link
Member

@LMESTM LMESTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (1 comment remains ..)

@fpistm fpistm added the enhancement New feature or request label Nov 29, 2017
@straccio
Copy link
Contributor Author

Good!
I like to add this enhancement also to wire library in order to give the ability to bind member function to wire callbacks.

If you remember others sources that use callbacks please tell me, i can do these changes also to them.

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some comment to remove.
Please, when done squash all commit in one.

You could also add your Signed-off-by: in the commit message.

Note:
Build for all variants with success (with c call and C++)

And thanks for this PR ;)

@fpistm fpistm merged commit baa22b0 into stm32duino:master Nov 29, 2017
@straccio
Copy link
Contributor Author

Thank you very much!

benwaffle pushed a commit to benwaffle/Arduino_Core_STM32 that referenced this pull request Apr 10, 2019
* Added ability to bind std:function on interrupts

The function attachInterrupt now also accept std:function<void(void)> in order to bind object method to an interrupt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants