aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/adc
diff options
context:
space:
mode:
authorxoviat <[email protected]>2025-11-13 14:42:14 -0600
committerxoviat <[email protected]>2025-11-13 14:42:14 -0600
commit64b9c28eca4822a3ba1bd07d20964c2291c01cf5 (patch)
tree2263e3e12375ce83b14bf4ca42ba62eec21c3b85 /embassy-stm32/src/adc
parent86fbcbdd7b9a5d37f6a7b1553e1ad0b5e5c8aa96 (diff)
stm32: extract block_for_us
remove from pub api
Diffstat (limited to 'embassy-stm32/src/adc')
-rw-r--r--embassy-stm32/src/adc/c0.rs2
-rw-r--r--embassy-stm32/src/adc/f1.rs4
-rw-r--r--embassy-stm32/src/adc/f3.rs2
-rw-r--r--embassy-stm32/src/adc/mod.rs20
4 files changed, 6 insertions, 22 deletions
diff --git a/embassy-stm32/src/adc/c0.rs b/embassy-stm32/src/adc/c0.rs
index 983e7c10d..3bdca7edb 100644
--- a/embassy-stm32/src/adc/c0.rs
+++ b/embassy-stm32/src/adc/c0.rs
@@ -223,7 +223,7 @@ impl<'d, T: AnyInstance> Adc<'d, T> {
223 223
224 // "The software must wait for the ADC voltage regulator startup time." 224 // "The software must wait for the ADC voltage regulator startup time."
225 // See datasheet for the value. 225 // See datasheet for the value.
226 blocking_delay_us(TIME_ADC_VOLTAGE_REGUALTOR_STARTUP_US + 1); 226 blocking_delay_us(TIME_ADC_VOLTAGE_REGUALTOR_STARTUP_US as u64 + 1);
227 227
228 T::regs().cfgr1().modify(|reg| reg.set_res(resolution)); 228 T::regs().cfgr1().modify(|reg| reg.set_res(resolution));
229 229
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs
index f6220de78..d6c6f480b 100644
--- a/embassy-stm32/src/adc/f1.rs
+++ b/embassy-stm32/src/adc/f1.rs
@@ -43,7 +43,7 @@ impl<'d, T: Instance> Adc<'d, T> {
43 43
44 // 11.4: Before starting a calibration, the ADC must have been in power-on state (ADON bit = ‘1’) 44 // 11.4: Before starting a calibration, the ADC must have been in power-on state (ADON bit = ‘1’)
45 // for at least two ADC clock cycles. 45 // for at least two ADC clock cycles.
46 blocking_delay_us((1_000_000 * 2) / Self::freq().0 + 1); 46 blocking_delay_us((1_000_000 * 2) / Self::freq().0 as u64 + 1);
47 47
48 // Reset calibration 48 // Reset calibration
49 T::regs().cr2().modify(|reg| reg.set_rstcal(true)); 49 T::regs().cr2().modify(|reg| reg.set_rstcal(true));
@@ -58,7 +58,7 @@ impl<'d, T: Instance> Adc<'d, T> {
58 } 58 }
59 59
60 // One cycle after calibration 60 // One cycle after calibration
61 blocking_delay_us((1_000_000 * 1) / Self::freq().0 + 1); 61 blocking_delay_us((1_000_000 * 1) / Self::freq().0 as u64 + 1);
62 62
63 T::Interrupt::unpend(); 63 T::Interrupt::unpend();
64 unsafe { T::Interrupt::enable() }; 64 unsafe { T::Interrupt::enable() };
diff --git a/embassy-stm32/src/adc/f3.rs b/embassy-stm32/src/adc/f3.rs
index 4a77f3c5b..29bfdac97 100644
--- a/embassy-stm32/src/adc/f3.rs
+++ b/embassy-stm32/src/adc/f3.rs
@@ -62,7 +62,7 @@ impl<'d, T: Instance> Adc<'d, T> {
62 while T::regs().cr().read().adcal() {} 62 while T::regs().cr().read().adcal() {}
63 63
64 // Wait more than 4 clock cycles after adcal is cleared (RM0364 p. 223). 64 // Wait more than 4 clock cycles after adcal is cleared (RM0364 p. 223).
65 blocking_delay_us((1_000_000 * 4) / Self::freq().0 + 1); 65 blocking_delay_us((1_000_000 * 4) / Self::freq().0 as u64 + 1);
66 66
67 // Enable the adc 67 // Enable the adc
68 T::regs().cr().modify(|w| w.set_aden(true)); 68 T::regs().cr().modify(|w| w.set_aden(true));
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs
index 549f2f5a5..5ec08a22d 100644
--- a/embassy-stm32/src/adc/mod.rs
+++ b/embassy-stm32/src/adc/mod.rs
@@ -35,6 +35,8 @@ pub use ringbuffered::RingBufferedAdc;
35#[path = "adc4.rs"] 35#[path = "adc4.rs"]
36pub mod adc4; 36pub mod adc4;
37 37
38#[allow(unused)]
39pub(self) use crate::block_for_us as blocking_delay_us;
38pub use crate::pac::adc::vals; 40pub use crate::pac::adc::vals;
39#[cfg(not(any(adc_f1, adc_f3v3)))] 41#[cfg(not(any(adc_f1, adc_f3v3)))]
40pub use crate::pac::adc::vals::Res as Resolution; 42pub use crate::pac::adc::vals::Res as Resolution;
@@ -140,24 +142,6 @@ impl<T: SealedAnyInstance + Instance> BasicAnyInstance for T {
140))] 142))]
141impl<T: SealedAnyInstance + Instance> AnyInstance for T {} 143impl<T: SealedAnyInstance + Instance> AnyInstance for T {}
142 144
143/// Performs a busy-wait delay for a specified number of microseconds.
144#[allow(unused)]
145pub(crate) fn blocking_delay_us(us: u32) {
146 cfg_if::cfg_if! {
147 // this does strange things on stm32wlx in low power mode depending on exactly when it's called
148 // as in sometimes 15 us (1 tick) would take > 20 seconds.
149 if #[cfg(all(feature = "time", all(not(feature = "low-power"), not(stm32wlex))))] {
150 let duration = embassy_time::Duration::from_micros(us as u64);
151 embassy_time::block_for(duration);
152 } else {
153 let freq = unsafe { crate::rcc::get_freqs() }.sys.to_hertz().unwrap().0 as u64;
154 let us = us as u64;
155 let cycles = freq * us / 1_000_000;
156 cortex_m::asm::delay(cycles as u32);
157 }
158 }
159}
160
161#[cfg(any(adc_c0, adc_v3, adc_g0, adc_h5, adc_h7rs, adc_u0, adc_v4, adc_u5))] 145#[cfg(any(adc_c0, adc_v3, adc_g0, adc_h5, adc_h7rs, adc_u0, adc_v4, adc_u5))]
162/// Number of samples used for averaging. 146/// Number of samples used for averaging.
163#[derive(Copy, Clone, Debug)] 147#[derive(Copy, Clone, Debug)]