embassy/embassy-stm32/src/adc/mod.rs

124 lines
3.5 KiB
Rust
Raw Normal View History

2021-06-10 21:33:43 +02:00
#![macro_use]
2022-03-19 11:05:00 +01:00
#[cfg_attr(adc_v4, path = "v4.rs")]
2021-06-10 21:33:43 +02:00
#[cfg_attr(adc_v3, path = "v3.rs")]
2021-10-19 15:36:41 +02:00
#[cfg_attr(adc_v2, path = "v2.rs")]
2021-08-30 21:34:37 +02:00
#[cfg_attr(adc_g0, path = "v3.rs")]
#[cfg_attr(adc_f1, path = "f1.rs")]
2022-03-19 11:05:00 +01:00
#[cfg_attr(adc_v1, path = "v1.rs")]
2021-06-10 21:33:43 +02:00
mod _version;
#[allow(unused)]
pub use _version::*;
use crate::peripherals;
pub(crate) mod sealed {
pub trait Instance {
fn regs() -> &'static crate::pac::adc::Adc;
2022-03-19 11:05:00 +01:00
#[cfg(all(not(adc_f1), not(adc_v1)))]
2021-06-10 21:33:43 +02:00
fn common_regs() -> &'static crate::pac::adccommon::AdcCommon;
}
2022-03-19 11:05:00 +01:00
#[cfg(all(not(adc_f1), not(adc_v1)))]
2021-06-10 21:33:43 +02:00
pub trait Common {
fn regs() -> &'static crate::pac::adccommon::AdcCommon;
}
pub trait AdcPin<T: Instance> {
fn channel(&self) -> u8;
}
}
#[cfg(not(adc_f1))]
2021-06-10 21:33:43 +02:00
pub trait Instance: sealed::Instance + 'static {}
#[cfg(adc_f1)]
pub trait Instance: sealed::Instance + crate::rcc::RccPeripheral + 'static {}
2022-03-19 11:05:00 +01:00
#[cfg(all(not(adc_f1), not(adc_v1)))]
2021-06-10 21:33:43 +02:00
pub trait Common: sealed::Common + 'static {}
pub trait AdcPin<T: Instance>: sealed::AdcPin<T> {}
2022-03-19 11:05:00 +01:00
#[cfg(not(stm32h7))]
foreach_peripheral!(
2021-06-10 21:33:43 +02:00
(adc, $inst:ident) => {
impl crate::adc::sealed::Instance for peripherals::$inst {
fn regs() -> &'static crate::pac::adc::Adc {
&crate::pac::$inst
}
2022-03-19 11:05:00 +01:00
#[cfg(all(not(adc_f1), not(adc_v1)))]
2021-06-10 21:33:43 +02:00
fn common_regs() -> &'static crate::pac::adccommon::AdcCommon {
foreach_peripheral!{
2021-06-10 21:33:43 +02:00
(adccommon, $common_inst:ident) => {
return &crate::pac::$common_inst
};
}
}
}
impl crate::adc::Instance for peripherals::$inst {}
};
);
2022-03-19 11:05:00 +01:00
#[cfg(stm32h7)]
foreach_peripheral!(
(adc, ADC3) => {
impl crate::adc::sealed::Instance for peripherals::ADC3 {
fn regs() -> &'static crate::pac::adc::Adc {
&crate::pac::ADC3
}
#[cfg(all(not(adc_f1), not(adc_v1)))]
fn common_regs() -> &'static crate::pac::adccommon::AdcCommon {
foreach_peripheral!{
(adccommon, ADC3_COMMON) => {
return &crate::pac::ADC3_COMMON
};
}
}
}
impl crate::adc::Instance for peripherals::ADC3 {}
};
(adc, $inst:ident) => {
impl crate::adc::sealed::Instance for peripherals::$inst {
fn regs() -> &'static crate::pac::adc::Adc {
&crate::pac::$inst
}
#[cfg(all(not(adc_f1), not(adc_v1)))]
fn common_regs() -> &'static crate::pac::adccommon::AdcCommon {
foreach_peripheral!{
(adccommon, ADC_COMMON) => {
return &crate::pac::ADC_COMMON
};
}
}
}
impl crate::adc::Instance for peripherals::$inst {}
};
);
#[cfg(all(not(adc_f1), not(adc_v1)))]
foreach_peripheral!(
2021-06-10 21:33:43 +02:00
(adccommon, $inst:ident) => {
impl sealed::Common for peripherals::$inst {
fn regs() -> &'static crate::pac::adccommon::AdcCommon {
&crate::pac::$inst
}
}
impl crate::adc::Common for peripherals::$inst {}
};
);
macro_rules! impl_adc_pin {
2021-06-10 21:33:43 +02:00
($inst:ident, $pin:ident, $ch:expr) => {
impl crate::adc::AdcPin<peripherals::$inst> for crate::peripherals::$pin {}
2021-06-10 21:33:43 +02:00
impl crate::adc::sealed::AdcPin<peripherals::$inst> for crate::peripherals::$pin {
2021-06-10 21:33:43 +02:00
fn channel(&self) -> u8 {
$ch
}
}
};
}