-
Notifications
You must be signed in to change notification settings - Fork 257
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
Bind "IRQ handlers" to GPIO pins #2146
Conversation
869c201
to
c2a1f99
Compare
cbb84c6
to
e26be16
Compare
esp-hal/src/gpio/mod.rs
Outdated
Self: GpioProperties, | ||
{ | ||
fn set_interrupt_handler(&mut self, handler: InterruptHandler) { | ||
raise_gpio_interrupt_priority(handler.priority()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I have a vauge feeling this won't play nicely with this idea. https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/intr_alloc.html#iram-safe-interrupt-handlers .
There should be some way to force users to choose a single priority from the start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly afraid "the priority you set here will be ignored" isn't what we are aiming for, but it's something to consider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps this shouldn't take InterruptHandler
as a parameter? Since this isn't a real interrupt and that way there's nothing to ignore here
858ec30
to
4fa457a
Compare
42b3ebf
to
b9b7c34
Compare
Sorry I haven't looked at this yet, I still need to think about this some more. Particularly, "The GPIO interrupts are handled at the maximum configured level" seems like a recipe for confusion, but I need to spend a bit more time thinking about what kind of footguns this may or may not cause in reality. |
I see how this can be convenient for the user - probably I'd prefer the user to not pass an InterruptHandler but a plain function and setting the priority separately However, I think we want the user to be able to register a custom global GPIO handler - especially via Mabe I'm missing something and it's possible but unfortunately this PR contains quite some "noise" so maybe I'm wrong |
Users can use |
As for "take a function pointer", there's #2110 (comment) . On one hand, there's API consistency (and convenience by doing things automagically). On the other, there's the need to not be confusing, but without some priority we can't late-bind the gpio handler like this PR tries to do. We can set the priority in the |
b9b7c34
to
5133906
Compare
Second attempt at this.
We now register interrupt handlers on-demand. Surprising behaviour may be:
async
functions overwrite any configured interrupt handlers. As an alternative, we could try restoring the handler, keeping both handlers in parallel and re-enabling the IRQ, or simply panicking if a user handler is set. I'm undecided, but "replace and keep working" is as equally valid a strategy as any.All documentation is missing because it wasn't necessary to demonstrate the idea.
cc #2009