aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/adc/f3.rs7
-rw-r--r--embassy-stm32/src/adc/mod.rs8
-rw-r--r--examples/stm32f334/src/bin/adc.rs4
-rw-r--r--examples/stm32f334/src/bin/opamp.rs4
4 files changed, 12 insertions, 11 deletions
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<T: Instance> super::VrefConverter for T {
33 const CHANNEL: u8 = 18; 33 const CHANNEL: u8 = 18;
34} 34}
35 35
36impl super::VrefInt {
37 /// The value that vref would be if vdda was at 3300mv
38 pub fn value(&self) -> u16 {
39 crate::pac::VREFINTCAL.data().read()
40 }
41}
42
43impl<T: Instance> super::TemperatureConverter for T { 36impl<T: Instance> super::TemperatureConverter for T {
44 const CHANNEL: u8 = 16; 37 const CHANNEL: u8 = 16;
45} 38}
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<T: Instance + VrefConverter> SealedAdcChannel<T> for VrefInt {
123 } 123 }
124} 124}
125 125
126impl VrefInt {
127 #[cfg(any(adc_f3v1, adc_f3v2))]
128 /// The value that vref would be if vdda was at 3300mv
129 pub fn calibrated_value(&self) -> u16 {
130 crate::pac::VREFINTCAL.data().read()
131 }
132}
133
126/// Internal temperature channel. 134/// Internal temperature channel.
127pub struct Temperature; 135pub struct Temperature;
128impl<T: Instance + TemperatureConverter> AdcChannel<T> for Temperature {} 136impl<T: Instance + TemperatureConverter> AdcChannel<T> 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) -> ! {
47 47
48 loop { 48 loop {
49 let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await; 49 let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await;
50 info!("read vref: {} (should be {})", vref, vrefint.value()); 50 info!("read vref: {} (should be {})", vref, vrefint.calibrated_value());
51 51
52 let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await; 52 let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await;
53 info!("read temperature: {}", temp); 53 info!("read temperature: {}", temp);
@@ -55,7 +55,7 @@ async fn main(_spawner: Spawner) -> ! {
55 let pin = adc.read(&mut p.PA0, SampleTime::CYCLES601_5).await; 55 let pin = adc.read(&mut p.PA0, SampleTime::CYCLES601_5).await;
56 info!("read pin: {}", pin); 56 info!("read pin: {}", pin);
57 57
58 let pin_mv = (pin as u32 * vrefint.value() as u32 / vref as u32) * 3300 / 4095; 58 let pin_mv = (pin as u32 * vrefint.calibrated_value() as u32 / vref as u32) * 3300 / 4095;
59 info!("computed pin mv: {}", pin_mv); 59 info!("computed pin mv: {}", pin_mv);
60 60
61 Timer::after_millis(500).await; 61 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) -> ! {
50 50
51 loop { 51 loop {
52 let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await; 52 let vref = adc.read(&mut vrefint, SampleTime::CYCLES601_5).await;
53 info!("read vref: {} (should be {})", vref, vrefint.value()); 53 info!("read vref: {} (should be {})", vref, vrefint.calibrated_value());
54 54
55 let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await; 55 let temp = adc.read(&mut temperature, SampleTime::CYCLES601_5).await;
56 info!("read temperature: {}", temp); 56 info!("read temperature: {}", temp);
@@ -58,7 +58,7 @@ async fn main(_spawner: Spawner) -> ! {
58 let buffer = adc.read(&mut buffer, SampleTime::CYCLES601_5).await; 58 let buffer = adc.read(&mut buffer, SampleTime::CYCLES601_5).await;
59 info!("read buffer: {}", buffer); 59 info!("read buffer: {}", buffer);
60 60
61 let pin_mv = (buffer as u32 * vrefint.value() as u32 / vref as u32) * 3300 / 4095; 61 let pin_mv = (buffer as u32 * vrefint.calibrated_value() as u32 / vref as u32) * 3300 / 4095;
62 info!("computed pin mv: {}", pin_mv); 62 info!("computed pin mv: {}", pin_mv);
63 63
64 Timer::after_millis(500).await; 64 Timer::after_millis(500).await;