Skip to content
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

async ADC read #1643

Open
jounathaen opened this issue May 30, 2024 · 4 comments
Open

async ADC read #1643

jounathaen opened this issue May 30, 2024 · 4 comments
Labels
help wanted Extra attention is needed peripheral:adc ADC peripheral

Comments

@jounathaen
Copy link
Contributor

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
Copy link
Member

jessebraham commented May 30, 2024

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 :)

@MabezDev MabezDev added enhancement help wanted Extra attention is needed labels Jun 5, 2024
@lu-zero
Copy link

lu-zero commented Jul 27, 2024

I just stumbled upon this problem. I wanted to have an embassy wifi example returning its battery status and nb::block does not look like it can be used.

@nan-mu
Copy link
Contributor

nan-mu commented Jul 28, 2024

I also don't know much about the specific operation of adc. I want to ask, can't we simply use the current read_oneshot to encapsulate a future? I will post an example later.

Update:
Failing that, it seems like nb is refactoring their future macros, and then, I can't wrap read_oneshot without using unsafe

@nan-mu
Copy link
Contributor

nan-mu commented Jul 29, 2024

I'm wondering if we could have the ADC own all the pins it needs? That might make it easier to do asynchronous stuff, but it might complicate the type declaration.

@tom-borcin tom-borcin removed the async label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed peripheral:adc ADC peripheral
Projects
Status: Todo
Development

No branches or pull requests

6 participants