summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchemicstry <chemicstry@gmail.com>2022-10-07 13:29:56 +0300
committerchemicstry <chemicstry@gmail.com>2022-10-07 13:29:56 +0300
commit9dca368c3dd1a8f00295b21c87d4fbb94afb60a5 (patch)
tree83c6a53e3e284da222105862237892aa106ec799
parentd49d1b6b1cf6de9577816397db3c41f6e93aa4e6 (diff)
downloadembassy-9dca368c3dd1a8f00295b21c87d4fbb94afb60a5.zip
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 8da13073..fba016a7 100644
--- a/embassy-stm32/src/adc/mod.rs
+++ b/embassy-stm32/src/adc/mod.rs
@@ -30,9 +30,9 @@ pub(crate) mod sealed {
}
}
-#[cfg(not(adc_f1))]
+#[cfg(not(any(adc_f1, adc_v2)))]
pub trait Instance: sealed::Instance + 'static {}
-#[cfg(adc_f1)]
+#[cfg(any(adc_f1, adc_v2))]
pub trait Instance: sealed::Instance + crate::rcc::RccPeripheral + 'static {}
#[cfg(all(not(adc_f1), not(adc_v1)))]
pub trait Common: sealed::Common + 'static {}
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs
index 25b7ba96..70e3b73b 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;
/// VREF voltage used for factory calibration of VREFINTCAL register.
pub const VREF_CALIB_MV: u32 = 3300;
-#[cfg(not(any(rcc_f4, rcc_f7)))]
-fn enable() {
- todo!()
-}
-
-#[cfg(any(rcc_f4, rcc_f7))]
-fn enable() {
- critical_section::with(|_| unsafe {
- // TODO do not enable all adc clocks if not needed
- crate::pac::RCC.apb2enr().modify(|w| w.set_adc1en(true));
- crate::pac::RCC.apb2enr().modify(|w| w.set_adc2en(true));
- crate::pac::RCC.apb2enr().modify(|w| w.set_adc3en(true));
- });
-}
-
pub enum Resolution {
TwelveBit,
TenBit,
@@ -164,9 +149,10 @@ where
{
pub fn new(_peri: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
into_ref!(_peri);
- enable();
+ T::enable();
+ T::reset();
- let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) };
+ let presc = unsafe { Prescaler::from_pclk2(T::frequency()) };
unsafe {
T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre()));
}
@@ -288,3 +274,9 @@ where
}
}
}
+
+impl<'d, T: Instance> Drop for Adc<'d, T> {
+ fn drop(&mut self) {
+ T::disable();
+ }
+}