diff --git a/embassy-stm32/src/adc/f3.rs b/embassy-stm32/src/adc/f3.rs index da185e875..f6a4e1209 100644 --- a/embassy-stm32/src/adc/f3.rs +++ b/embassy-stm32/src/adc/f3.rs @@ -33,13 +33,6 @@ impl super::VrefConverter for T { const CHANNEL: u8 = 18; } -impl super::VrefInt { - /// The value that vref would be if vdda was at 3300mv - pub fn value(&self) -> u16 { - crate::pac::VREFINTCAL.data().read() - } -} - impl super::TemperatureConverter for T { const CHANNEL: u8 = 16; } diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index a5ca6277f..3bf893a35 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs @@ -123,6 +123,14 @@ impl SealedAdcChannel for VrefInt { } } +impl VrefInt { + #[cfg(any(adc_f3v1, adc_f3v2))] + /// The value that vref would be if vdda was at 3300mv + pub fn calibrated_value(&self) -> u16 { + crate::pac::VREFINTCAL.data().read() + } +} + /// Internal temperature channel. pub struct Temperature; impl AdcChannel for Temperature {} diff --git a/examples/stm32f334/src/bin/adc.rs b/examples/stm32f334/src/bin/adc.rs index a420c8876..486f160ec 100644 --- a/examples/stm32f334/src/bin/adc.rs +++ b/examples/stm32f334/src/bin/adc.rs @@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) -> ! { loop { let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await; - info!("read vref: {} (should be {})", vref, vrefint.value()); + info!("read vref: {} (should be {})", vref, vrefint.calibrated_value()); let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await; info!("read temperature: {}", temp); @@ -55,7 +55,7 @@ async fn main(_spawner: Spawner) -> ! { let pin = adc.read(&mut p.PA0, SampleTime::CYCLES601_5).await; info!("read pin: {}", pin); - let pin_mv = (pin as u32 * vrefint.value() as u32 / vref as u32) * 3300 / 4095; + let pin_mv = (pin as u32 * vrefint.calibrated_value() as u32 / vref as u32) * 3300 / 4095; info!("computed pin mv: {}", pin_mv); Timer::after_millis(500).await; diff --git a/examples/stm32f334/src/bin/opamp.rs b/examples/stm32f334/src/bin/opamp.rs index ddefdd03d..9555fd35d 100644 --- a/examples/stm32f334/src/bin/opamp.rs +++ b/examples/stm32f334/src/bin/opamp.rs @@ -50,7 +50,7 @@ async fn main(_spawner: Spawner) -> ! { loop { let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await; - info!("read vref: {} (should be {})", vref, vrefint.value()); + info!("read vref: {} (should be {})", vref, vrefint.calibrated_value()); let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await; info!("read temperature: {}", temp); @@ -58,7 +58,7 @@ async fn main(_spawner: Spawner) -> ! { let buffer = adc.read(&mut buffer, SampleTime::CYCLES601_5).await; info!("read buffer: {}", buffer); - let pin_mv = (buffer as u32 * vrefint.value() as u32 / vref as u32) * 3300 / 4095; + let pin_mv = (buffer as u32 * vrefint.calibrated_value() as u32 / vref as u32) * 3300 / 4095; info!("computed pin mv: {}", pin_mv); Timer::after_millis(500).await;