Merge pull request #1909 from xoviat/adc
stm32: generate adc_common and misc.
This commit is contained in:
@ -50,7 +50,7 @@ impl<'d, T: Instance> Adc<'d, T> {
|
||||
while T::regs().cr().read().adcal() {}
|
||||
|
||||
// Wait more than 4 clock cycles after adcal is cleared (RM0364 p. 223)
|
||||
delay.delay_us(6 * 1_000_000 / Self::freq().0);
|
||||
delay.delay_us(1 + (6 * 1_000_000 / Self::freq().0));
|
||||
|
||||
// Enable the adc
|
||||
T::regs().cr().modify(|w| w.set_aden(true));
|
||||
|
@ -56,127 +56,21 @@ pub trait Instance: sealed::Instance + crate::Peripheral<P = Self> + crate::rcc:
|
||||
pub trait AdcPin<T: Instance>: sealed::AdcPin<T> {}
|
||||
pub trait InternalChannel<T>: sealed::InternalChannel<T> {}
|
||||
|
||||
#[cfg(not(any(stm32h7, adc_f3, adc_v4)))]
|
||||
foreach_peripheral!(
|
||||
(adc, $inst:ident) => {
|
||||
foreach_adc!(
|
||||
($inst:ident, $common_inst:ident, $clock:ident) => {
|
||||
impl crate::adc::sealed::Instance for peripherals::$inst {
|
||||
fn regs() -> crate::pac::adc::Adc {
|
||||
crate::pac::$inst
|
||||
}
|
||||
|
||||
#[cfg(not(any(adc_f1, adc_v1, adc_f3_v2, adc_g0)))]
|
||||
fn common_regs() -> crate::pac::adccommon::AdcCommon {
|
||||
foreach_peripheral!{
|
||||
(adccommon, $common_inst:ident) => {
|
||||
return crate::pac::$common_inst
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::adc::Instance for peripherals::$inst {}
|
||||
};
|
||||
);
|
||||
|
||||
#[cfg(any(stm32h7, adc_f3, adc_v4))]
|
||||
foreach_peripheral!(
|
||||
(adc, ADC3) => {
|
||||
impl crate::adc::sealed::Instance for peripherals::ADC3 {
|
||||
fn regs() -> crate::pac::adc::Adc {
|
||||
crate::pac::ADC3
|
||||
}
|
||||
#[cfg(all(not(adc_f1), not(adc_v1)))]
|
||||
#[allow(unreachable_code)]
|
||||
fn common_regs() -> crate::pac::adccommon::AdcCommon {
|
||||
foreach_peripheral!{
|
||||
(adccommon, ADC3_COMMON) => {
|
||||
return crate::pac::ADC3_COMMON
|
||||
};
|
||||
// Fall back to ADC_COMMON if ADC3_COMMON does not exist
|
||||
(adccommon, ADC_COMMON) => {
|
||||
return crate::pac::ADC_COMMON
|
||||
};
|
||||
}
|
||||
return crate::pac::$common_inst
|
||||
}
|
||||
|
||||
#[cfg(adc_f3)]
|
||||
fn frequency() -> crate::time::Hertz {
|
||||
unsafe { crate::rcc::get_freqs() }.adc34.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::adc::Instance for peripherals::ADC3 {}
|
||||
};
|
||||
(adc, ADC4) => {
|
||||
impl crate::adc::sealed::Instance for peripherals::ADC4 {
|
||||
fn regs() -> crate::pac::adc::Adc {
|
||||
crate::pac::ADC4
|
||||
}
|
||||
#[cfg(not(any(adc_f1, adc_v1)))]
|
||||
#[allow(unreachable_code)]
|
||||
fn common_regs() -> crate::pac::adccommon::AdcCommon {
|
||||
foreach_peripheral!{
|
||||
(adccommon, ADC3_COMMON) => {
|
||||
return crate::pac::ADC3_COMMON
|
||||
};
|
||||
// Fall back to ADC_COMMON if ADC3_COMMON does not exist
|
||||
(adccommon, ADC_COMMON) => {
|
||||
return crate::pac::ADC_COMMON
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(adc_f3)]
|
||||
fn frequency() -> crate::time::Hertz {
|
||||
unsafe { crate::rcc::get_freqs() }.adc34.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::adc::Instance for peripherals::ADC4 {}
|
||||
};
|
||||
(adc, ADC5) => {
|
||||
impl crate::adc::sealed::Instance for peripherals::ADC5 {
|
||||
fn regs() -> crate::pac::adc::Adc {
|
||||
crate::pac::ADC5
|
||||
}
|
||||
#[cfg(not(any(adc_f1, adc_v1)))]
|
||||
#[allow(unreachable_code)]
|
||||
fn common_regs() -> crate::pac::adccommon::AdcCommon {
|
||||
foreach_peripheral!{
|
||||
(adccommon, ADC3_COMMON) => {
|
||||
return crate::pac::ADC3_COMMON
|
||||
};
|
||||
// Fall back to ADC_COMMON if ADC3_COMMON does not exist
|
||||
(adccommon, ADC_COMMON) => {
|
||||
return crate::pac::ADC_COMMON
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(adc_f3)]
|
||||
fn frequency() -> crate::time::Hertz {
|
||||
unsafe { crate::rcc::get_freqs() }.adc34.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::adc::Instance for peripherals::ADC5 {}
|
||||
};
|
||||
(adc, $inst:ident) => {
|
||||
impl crate::adc::sealed::Instance for peripherals::$inst {
|
||||
fn regs() -> crate::pac::adc::Adc {
|
||||
crate::pac::$inst
|
||||
}
|
||||
#[cfg(not(any(adc_f1, adc_v1)))]
|
||||
fn common_regs() -> crate::pac::adccommon::AdcCommon {
|
||||
foreach_peripheral!{
|
||||
(adccommon, ADC_COMMON) => {
|
||||
return crate::pac::ADC_COMMON
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(adc_f3)]
|
||||
fn frequency() -> crate::time::Hertz {
|
||||
unsafe { crate::rcc::get_freqs() }.adc.unwrap()
|
||||
unsafe { crate::rcc::get_freqs() }.$clock.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
}
|
||||
});
|
||||
|
||||
#[cfg(rcc_f3)]
|
||||
#[cfg(all(rcc_f3, adc3_common))]
|
||||
let adc34 = config.adc.map(|adc| {
|
||||
if !adc.is_bus() {
|
||||
RCC.cfgr2().modify(|w| {
|
||||
@ -291,9 +291,13 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
Hertz(sysclk / adc as u32)
|
||||
})
|
||||
} else {
|
||||
// TODO: need to use only if adc32_common is present
|
||||
crate::pac::ADC3_COMMON.ccr().modify(|w| {
|
||||
assert!(!(adc.bus_div() == 1 && hpre_bits != Hpre::DIV1));
|
||||
|
||||
todo!()
|
||||
w.set_ckmode(adc.into());
|
||||
|
||||
Hertz(sysclk / adc.bus_div() as u32)
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
@ -323,8 +327,10 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
ahb1: Hertz(hclk),
|
||||
#[cfg(rcc_f3)]
|
||||
adc: adc,
|
||||
#[cfg(rcc_f3)]
|
||||
#[cfg(all(rcc_f3, adc3_common))]
|
||||
adc34: adc34,
|
||||
#[cfg(all(rcc_f3, not(adc3_common)))]
|
||||
adc34: None,
|
||||
#[cfg(stm32f334)]
|
||||
hrtim: hrtim,
|
||||
});
|
||||
|
Reference in New Issue
Block a user