aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchemicstry <[email protected]>2022-10-07 13:29:56 +0300
committerchemicstry <[email protected]>2022-10-07 13:29:56 +0300
commit9dca368c3dd1a8f00295b21c87d4fbb94afb60a5 (patch)
tree83c6a53e3e284da222105862237892aa106ec799
parentd49d1b6b1cf6de9577816397db3c41f6e93aa4e6 (diff)
Use RccPeripheral for adc_v2
-rw-r--r--embassy-stm32/src/adc/mod.rs4
-rw-r--r--embassy-stm32/src/adc/v2.rs26
2 files changed, 11 insertions, 19 deletions
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs
index 8da13073e..fba016a77 100644
--- a/embassy-stm32/src/adc/mod.rs
+++ b/embassy-stm32/src/adc/mod.rs
@@ -30,9 +30,9 @@ pub(crate) mod sealed {
30 } 30 }
31} 31}
32 32
33#[cfg(not(adc_f1))] 33#[cfg(not(any(adc_f1, adc_v2)))]
34pub trait Instance: sealed::Instance + 'static {} 34pub trait Instance: sealed::Instance + 'static {}
35#[cfg(adc_f1)] 35#[cfg(any(adc_f1, adc_v2))]
36pub trait Instance: sealed::Instance + crate::rcc::RccPeripheral + 'static {} 36pub trait Instance: sealed::Instance + crate::rcc::RccPeripheral + 'static {}
37#[cfg(all(not(adc_f1), not(adc_v1)))] 37#[cfg(all(not(adc_f1), not(adc_v1)))]
38pub trait Common: sealed::Common + 'static {} 38pub trait Common: sealed::Common + 'static {}
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs
index 25b7ba967..70e3b73b3 100644
--- a/embassy-stm32/src/adc/v2.rs
+++ b/embassy-stm32/src/adc/v2.rs
@@ -12,21 +12,6 @@ pub const VREF_DEFAULT_MV: u32 = 3300;
12/// VREF voltage used for factory calibration of VREFINTCAL register. 12/// VREF voltage used for factory calibration of VREFINTCAL register.
13pub const VREF_CALIB_MV: u32 = 3300; 13pub const VREF_CALIB_MV: u32 = 3300;
14 14
15#[cfg(not(any(rcc_f4, rcc_f7)))]
16fn enable() {
17 todo!()
18}
19
20#[cfg(any(rcc_f4, rcc_f7))]
21fn enable() {
22 critical_section::with(|_| unsafe {
23 // TODO do not enable all adc clocks if not needed
24 crate::pac::RCC.apb2enr().modify(|w| w.set_adc1en(true));
25 crate::pac::RCC.apb2enr().modify(|w| w.set_adc2en(true));
26 crate::pac::RCC.apb2enr().modify(|w| w.set_adc3en(true));
27 });
28}
29
30pub enum Resolution { 15pub enum Resolution {
31 TwelveBit, 16 TwelveBit,
32 TenBit, 17 TenBit,
@@ -164,9 +149,10 @@ where
164{ 149{
165 pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { 150 pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
166 into_ref!(_peri); 151 into_ref!(_peri);
167 enable(); 152 T::enable();
153 T::reset();
168 154
169 let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; 155 let presc = unsafe { Prescaler::from_pclk2(T::frequency()) };
170 unsafe { 156 unsafe {
171 T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre())); 157 T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre()));
172 } 158 }
@@ -288,3 +274,9 @@ where
288 } 274 }
289 } 275 }
290} 276}
277
278impl<'d, T: Instance> Drop for Adc<'d, T> {
279 fn drop(&mut self) {
280 T::disable();
281 }
282}