mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-26 16:52:33 +00:00
stm32/adc: Ensure that clock is enabled
Sadly due to the inconsistency in clocking configuration across devices we cannot use RccPeripheral.
This commit is contained in:
parent
573e6ec373
commit
0b9961584b
@ -6,6 +6,17 @@ use embedded_hal::blocking::delay::DelayUs;
|
||||
|
||||
pub const VDDA_CALIB_MV: u32 = 3000;
|
||||
|
||||
/// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock
|
||||
/// configuration.
|
||||
unsafe fn enable() {
|
||||
#[cfg(rcc_h7)]
|
||||
crate::pac::RCC.apb2enr().modify(|w| w.set_adcen(true));
|
||||
#[cfg(rcc_g0)]
|
||||
crate::pac::RCC.apbenr2().modify(|w| w.set_adcen(true));
|
||||
#[cfg(rcc_l4)]
|
||||
crate::pac::RCC.ahb2enr().modify(|w| w.set_adcen(true));
|
||||
}
|
||||
|
||||
pub enum Resolution {
|
||||
TwelveBit,
|
||||
TenBit,
|
||||
@ -196,6 +207,7 @@ impl<'d, T: Instance> Adc<'d, T> {
|
||||
pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
|
||||
unborrow!(_peri);
|
||||
unsafe {
|
||||
enable();
|
||||
T::regs().cr().modify(|reg| {
|
||||
#[cfg(not(adc_g0))]
|
||||
reg.set_deeppwd(false);
|
||||
|
Loading…
Reference in New Issue
Block a user