esp-rs / esp-idf-hal

embedded-hal implementation for Rust on ESP32 and ESP-IDF
https://docs.esp-rs.org/esp-idf-hal/
Apache License 2.0
436 stars 168 forks source link

Cannot figure out how to use GPIO interrupts in std build on esp32 #268

Closed nmarks99 closed 1 year ago

nmarks99 commented 1 year ago

I've spent a while trying to figure out the easiest way to use interrupts in my esp-idf-hal project however I have not found a good solution and there are no examples on how to do this. I've seen #144 and #177 but neither of these arrive at a great solution. I'm about to do what was done in #177 and use the lower level esp_idf_sys calls to implement gpio interrupts however I would like to know is a better solution exists or what the idiomatic way to go about this would be.

The only example I have been able to find on using a gpio interrupt in a std environment is the button-interrupt example in the std-training repo, which builds when using a RISCV target, however for my esp32 (non-riscv) chip as target, I get the following linker error I have not been able to resolve dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Finally, one more semi related question I have is, is it possible to use esp32-hal as a dependency in a std build (with esp-idf-hal)? I was having a look at the gpio interrupt example for a no_std build and it seems very straightforward, however I tried (perhaps naively) to simply include the esp32-hal crate in my Cargo.toml and I get the following linker error: note: some 'extern' functions couldn't be found; some native libraries may need to be installed or have their path specified Any idea on how to fix this or if this is even a reasonable approach?

Any help/suggestions would be greatly appreciated.

ivmarkov commented 1 year ago

In backwards order:

nmarks99 commented 1 year ago

Thanks, I'll check those out. Is there an example anywhere on how to use the callbacks?

ivmarkov commented 1 year ago

Not really sure what exactly you anticipate from an example (calling subscribe should be pretty trivial), but here's one.

ivmarkov commented 1 year ago

What I would suggest (again) is to join the Matrix channel, and ask your questions there. GitHub issue tracker is not the most ergonomic medium for this type of interaction.

nmarks99 commented 1 year ago

will do thank you!