Use RccPeripheral for adc_v2
This commit is contained in:
parent
d49d1b6b1c
commit
9dca368c3d
@ -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 {}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user