esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
625 stars 168 forks source link

`async` ADC read #1643

Open jounathaen opened 1 month ago

jounathaen commented 1 month ago

Hi, I'm not so deep in the esp32's internals and also not in the code of the HAL, but I wondered if the ADC reading could be made async.

If I read the docs correctly, one basically has to use nb::block for a read, probably wasting a few hundred/thousand cycles in the process.

jessebraham commented 1 month ago

Based on a quick skimming of the TRM (for the C6, at least) it appears that this should be possible by configuring APB_SARADC_ADC_DONE_INT, which "triggers when the ADC completes one data conversion". As long as we have an interrupt we can create a future for it.

Also thank you for pointing this out, this is very valuable feedback! It's easy to overlook things like this :)