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

Generic AdcChannel as async task parameter #3817

Open
gustavowd opened this issue Jan 28, 2025 · 1 comment
Open

Generic AdcChannel as async task parameter #3817

gustavowd opened this issue Jan 28, 2025 · 1 comment

Comments

@gustavowd
Copy link

Hi guys.
I'm trying to write a async task that convert analog to digital from an adc channel, but i would like to make it generic for channels.
The code is like this:
`#[embassy_executor::task]
async fn adc_task(mut adc: adc::Adc<'static, ADC1>, mut adc_pin: embassy_stm32::peripherals::PA1) {

adc.set_sample_time(SampleTime::CYCLES47_5);

loop {
    let measured = adc.blocking_read(&mut adc_pin);
    info!("measured: {}", measured);
    Timer::after_millis(500).await;
}

}`

Is there any way to passing a generic adc channel instead of a speficic pin (peripherals::PA1)? Something similar to AnyPin.
Any thoughts about this?

Thanks in advance.

@gustavowd
Copy link
Author

I believe i found it:

async fn adc_task(mut adc: adc::Adc<'static, ADC1>, mut adc_pin: AnyAdcChannel) {}

and

spawner.spawn(adc_task(adc, p.PA1.degrade_adc())).unwrap();

Is that the way to do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant