-
Notifications
You must be signed in to change notification settings - Fork 14
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 port expander interrupts #21
Comments
Hi @t-moe, I also thought about how to support pin change interrupts in So an API for pin change interrupts always needs to query all pins of the expander at once. Or possibly mirror the flags locally such that we can track what pins fetched their flag already. But this quickly runs the risk of desynchronizing between the real flag and the locally cached one. Not really sure what kind of solution works best here... Beyond these specifics, I would not design the API using a |
Hi @Rahix, Currently I mainly need the "wait for pin changed" interrupt, on all pins of the PI4OE5V6408 at once. But someone else might have a different requirement. Which methods should I add to
or ( |
I think it's easier to talk about code so I created #28 as an idea. Please take a look and let me know your thoughts. The idea is that you get a Similarly, a What I'm unsure about is whether this is really a usable API for downstream applications. I very much dislike the fact that interrupt status needs to be queried in a central place with this API. You can't really handle the indivudual pins in isolation with this interface... |
Alright, because it's so much fun, here is a second alternative in #29. This one is better at decoupling the individual pins. The downside is that an explicit |
I really depends a bit on the usecase. In my case, I use the port-expander to wake the chip from deepsleep. Upon power-up I decode the interrupt status in a central place and map it to an enum Additionally:
What if we combine #28 + #29 and offer both APIs to the user ? We could use the same traits under the hood. The user can either call |
I also wanted to add a
PortDriverInterruptChange
trait that would allow the user to wait on one or multiple pins changing state.My approach:
(API is based on what the PI4IOE5V6408 offers. We could add other traits for edge detection later)
My idea was to make this accessible via:
wait_for_change_to
method for each pinwait_change_multiple
method (similar toread_multiple
)Problem: We can not keep the driver locked, while awaiting an async function.
This would require an extension of the shared-bus crate to either allow passing an async closure to the lock method, or have a lock method that returns a guard.
Before I do this, I wanted to ask you, if I'm on the right track here, or whether you have a different solution in mind regarding interrupts.
Originally posted by @t-moe in #17 (comment)
The text was updated successfully, but these errors were encountered: