Skip to content

Add new GPIO APIs for adding shared GPIO handlers, and improve docs #850

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 4 commits into from
Jun 8, 2022

Conversation

kilograham
Copy link
Contributor

Note this PR includes the get_core_num() change as they are dependent

@kilograham kilograham requested review from Wren6991 and liamfraser June 5, 2022 22:47
@kilograham kilograham self-assigned this Jun 5, 2022
@kilograham kilograham added this to the 1.3.2 milestone Jun 5, 2022
@kilograham kilograham force-pushed the gpio_irq_improvements branch from bd42d25 to 4cf55b4 Compare June 6, 2022 13:23
*
* This method adds such a explicit GPIO IRQ handler, and disables the "default" callback for the specified GPIOs.
*
* A raw handler should check for whichever GPIOs and events it handles, and acknowledge them itself; it might look something like:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably a dumb question, but if the user has to manually check for GPIO numbers inside their callback-function themselves, what's the advantage of using these "raw handlers" over the "shared handler"? From looking at the implementation of gpio_add_raw_irq_handler_with_order_priority_masked it seems like if you added multiple raw-handlers (each with a separate callback), then each of the callbacks would get called for every GPIO IRQ that's registered to be handled by a raw-handler?
So you could just do the same thing with the shared-handler, by calling a different function depending on the GPIO number that it was passed?
No doubt I'm missing something obvious / fundamental 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you can, but only one person can set the shared calback function. Therefore if you have two independent/unrelated bits of code that want to respond to GPIO IRQ they would stomp on each other if they used the old API. Most people will continue to use the existing API, but libraries that need to hook a GPIO should add their own handler.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh, "libraries that need to hook a GPIO should add their own handler" was the bit I was missing, thanks 😃
(is that worth clarifying in the doxygen?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think these comments are outdated as I don't see the text "libraries that need to"

Copy link
Contributor

@Wren6991 Wren6991 left a comment

Choose a reason for hiding this comment

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

Happy with this, other than discussion about whether to assert on double-hooking the same pin, and the comment nits.

At risk of bikeshedding, I'm not crazy about the name raw, as opposed to e.g. per_pin, but I don't feel strongly enough about this to not approve

@kilograham
Copy link
Contributor Author

Happy with this, other than discussion about whether to assert on double-hooking the same pin, and the comment nits.

At risk of bikeshedding, I'm not crazy about the name raw, as opposed to e.g. per_pin, but I don't feel strongly enough about this to not approve

note it isn't per pin anyway, as it can be more than one pin :-) sticking with raw for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants