aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/adc/mod.rs
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-09-27 20:58:46 -0500
committerxoviat <[email protected]>2023-09-27 20:58:46 -0500
commit79146c4bd5cdbd8337d0dbdfd93219b9cb330c47 (patch)
treee10d53df45b95db09e1d74d19a3abd269b736f69 /embassy-stm32/src/adc/mod.rs
parent20ea76c19c709abf652b9a044292eb26fd656223 (diff)
stm32/adc: cleanup f1, f3, v1, and v2
Diffstat (limited to 'embassy-stm32/src/adc/mod.rs')
-rw-r--r--embassy-stm32/src/adc/mod.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs
index 2f8f8f9e3..365738a31 100644
--- a/embassy-stm32/src/adc/mod.rs
+++ b/embassy-stm32/src/adc/mod.rs
@@ -31,15 +31,15 @@ pub struct Adc<'d, T: Instance> {
31} 31}
32 32
33pub(crate) mod sealed { 33pub(crate) mod sealed {
34 #[cfg(any(adc_f3, adc_v1))] 34 #[cfg(any(adc_f1, adc_f3, adc_v1))]
35 use embassy_sync::waitqueue::AtomicWaker; 35 use embassy_sync::waitqueue::AtomicWaker;
36 36
37 #[cfg(any(adc_f3, adc_v1))] 37 #[cfg(any(adc_f1, adc_f3, adc_v1))]
38 pub struct State { 38 pub struct State {
39 pub waker: AtomicWaker, 39 pub waker: AtomicWaker,
40 } 40 }
41 41
42 #[cfg(any(adc_f3, adc_v1))] 42 #[cfg(any(adc_f1, adc_f3, adc_v1))]
43 impl State { 43 impl State {
44 pub const fn new() -> Self { 44 pub const fn new() -> Self {
45 Self { 45 Self {
@@ -58,11 +58,14 @@ pub(crate) mod sealed {
58 fn common_regs() -> crate::pac::adccommon::AdcCommon; 58 fn common_regs() -> crate::pac::adccommon::AdcCommon;
59 #[cfg(adc_f3)] 59 #[cfg(adc_f3)]
60 fn frequency() -> crate::time::Hertz; 60 fn frequency() -> crate::time::Hertz;
61 #[cfg(any(adc_f3, adc_v1))] 61 #[cfg(any(adc_f1, adc_f3, adc_v1))]
62 fn state() -> &'static State; 62 fn state() -> &'static State;
63 } 63 }
64 64
65 pub trait AdcPin<T: Instance> { 65 pub trait AdcPin<T: Instance> {
66 #[cfg(any(adc_v1, adc_v2))]
67 fn set_as_analog(&mut self) {}
68
66 fn channel(&self) -> u8; 69 fn channel(&self) -> u8;
67 } 70 }
68 71
@@ -96,7 +99,7 @@ foreach_adc!(
96 unsafe { crate::rcc::get_freqs() }.$clock.unwrap() 99 unsafe { crate::rcc::get_freqs() }.$clock.unwrap()
97 } 100 }
98 101
99 #[cfg(any(adc_f3, adc_v1))] 102 #[cfg(any(adc_f1, adc_f3, adc_v1))]
100 fn state() -> &'static sealed::State { 103 fn state() -> &'static sealed::State {
101 static STATE: sealed::State = sealed::State::new(); 104 static STATE: sealed::State = sealed::State::new();
102 &STATE 105 &STATE
@@ -120,6 +123,11 @@ macro_rules! impl_adc_pin {
120 impl crate::adc::AdcPin<peripherals::$inst> for crate::peripherals::$pin {} 123 impl crate::adc::AdcPin<peripherals::$inst> for crate::peripherals::$pin {}
121 124
122 impl crate::adc::sealed::AdcPin<peripherals::$inst> for crate::peripherals::$pin { 125 impl crate::adc::sealed::AdcPin<peripherals::$inst> for crate::peripherals::$pin {
126 #[cfg(any(adc_v1, adc_v2))]
127 fn set_as_analog(&mut self) {
128 <Self as crate::gpio::sealed::Pin>::set_as_analog(self);
129 }
130
123 fn channel(&self) -> u8 { 131 fn channel(&self) -> u8 {
124 $ch 132 $ch
125 } 133 }