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;
|
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 {
|
pub enum Resolution {
|
||||||
TwelveBit,
|
TwelveBit,
|
||||||
TenBit,
|
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 {
|
pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
|
||||||
unborrow!(_peri);
|
unborrow!(_peri);
|
||||||
unsafe {
|
unsafe {
|
||||||
|
enable();
|
||||||
T::regs().cr().modify(|reg| {
|
T::regs().cr().modify(|reg| {
|
||||||
#[cfg(not(adc_g0))]
|
#[cfg(not(adc_g0))]
|
||||||
reg.set_deeppwd(false);
|
reg.set_deeppwd(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user