-
Notifications
You must be signed in to change notification settings - Fork 215
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
Can I redefine or extend the defined by HAL interrupt handler? #856
Comments
We currently don't support this and I can't see an easy/non-invasive way of doing it. Is there a particular reason why you don't want to use the async methods? |
I suspect that using futures may significantly slow down handling of the GPIO events like rising edges in my high-frequency application. Yet, I don't know if it will be a problem, just a precaution. Thank you for the response! |
I've actually hit this limitation for real, I'm writing an application on the esp32h2 that uses a KY-040 rotary encoder with interrupt based handling and the default GPIO interrupt handler drops/deduplicates interrupts which causes it to break without a way of redefining/extending the GPIO handler |
This would be a valid use case. Long term we need a solution for this. The embassy project treats interrupts as resources and requires that drivers "take" the interrupt in their constructors. I do like this idea generally, but I'm not a huge fan of the macros accompanying it. With all that said, you're in luck :). The esp32h2 has a PCNT peripheral, with the express purpose of being used with rotary encoders. We don't yet have an async driver for this peripheral yet, but if you can use it with manual interrupts for now. Checkout the example. |
Hello, I want to share an example I'm facing where multiple interrupts handlers are important. I'm using embassy to do some fancy async stuff, with async async fn wait_for_echo(&mut self) -> Duration {
let _ = self.pin_echo.wait_for_high().await;
let before = Instant::now();
let _ = self.pin_echo.wait_for_low().await;
Instant::now() - before
} The duration returned by this function will be used to compute the distance the sensors reports. This is very time sensitive. But by using awaits, the embassy overhead takes some times to give back the code to execution which causes from 35us to +200us of overhead delay, which really affect the sensor precision. (With only one async task running) The solution would be to stop using async awaits here and directly do the computations in the GPIO interrupt. But I get to the same problem you had. Also, I'm didn't find any other HAL implementation with multiple Interrupts handlers. Is there a reason why ? Thanks for all your work ! 💚 |
@matheo-lucak While it wouldn't solve the original problem of having your own interrupt handler and using async for other peripherals you could try to use the RMT peripheral in this case for more accurate measurements |
@Kixiron @matheo-lucak FYI I've created an issue to discuss potential solutions: #1063 |
Hello!
Thank you for this great project and for your work!
I am using async I2C in my project, so I add the
async
feature for theesp-hal
dependency.It seems like enabling the
async
feature aside from theI2C_EXT0
interrupt that is required for async I2C to work, also definesGPIO
interrupt that is used to detect GPIO events like rising edges.However, I want to detect rising edge on a pin and I would like to implement the GPIO handler myself rather than using a task and
pin.wait_for_rising_edge
async method.Can I somehow redefine or extend the already defined by the crate GPIO interrupt handler? Or can I prevent the crate from defining the GPIO interrupt (maybe disabling the
wait_for_rising_edge
functionality) while having theasync
feature enabled (for async I2C to work) ?Thanks!
The text was updated successfully, but these errors were encountered: