2021-06-10 15:33:43 -04:00
|
|
|
#![macro_use]
|
|
|
|
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(not(adc_f3_v2))]
|
2021-12-30 10:51:49 +01:00
|
|
|
#[cfg_attr(adc_f1, path = "f1.rs")]
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg_attr(adc_f3, path = "f3.rs")]
|
2022-03-19 11:05:00 +01:00
|
|
|
#[cfg_attr(adc_v1, path = "v1.rs")]
|
2022-10-26 18:04:52 -05:00
|
|
|
#[cfg_attr(adc_v2, path = "v2.rs")]
|
|
|
|
#[cfg_attr(any(adc_v3, adc_g0), path = "v3.rs")]
|
|
|
|
#[cfg_attr(adc_v4, path = "v4.rs")]
|
2021-06-10 15:33:43 -04:00
|
|
|
mod _version;
|
|
|
|
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(not(any(adc_f1, adc_f3_v2)))]
|
2022-10-26 02:04:52 -05:00
|
|
|
mod resolution;
|
2022-10-26 02:28:39 -05:00
|
|
|
mod sample_time;
|
2022-10-26 02:04:52 -05:00
|
|
|
|
2021-06-10 15:33:43 -04:00
|
|
|
#[allow(unused)]
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(not(adc_f3_v2))]
|
2021-06-10 15:33:43 -04:00
|
|
|
pub use _version::*;
|
2023-08-19 00:59:37 +02:00
|
|
|
#[cfg(not(any(adc_f1, adc_f3, adc_f3_v2)))]
|
2022-10-26 02:04:52 -05:00
|
|
|
pub use resolution::Resolution;
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(not(adc_f3_v2))]
|
2022-10-26 00:31:46 -05:00
|
|
|
pub use sample_time::SampleTime;
|
2021-06-10 15:33:43 -04:00
|
|
|
|
|
|
|
use crate::peripherals;
|
|
|
|
|
2022-10-26 17:51:12 -05:00
|
|
|
pub struct Adc<'d, T: Instance> {
|
2022-10-26 18:36:04 -05:00
|
|
|
#[allow(unused)]
|
|
|
|
adc: crate::PeripheralRef<'d, T>,
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(not(adc_f3_v2))]
|
2022-10-26 17:51:12 -05:00
|
|
|
sample_time: SampleTime,
|
|
|
|
}
|
|
|
|
|
2021-06-10 15:33:43 -04:00
|
|
|
pub(crate) mod sealed {
|
|
|
|
pub trait Instance {
|
2022-10-26 17:33:32 -05:00
|
|
|
fn regs() -> crate::pac::adc::Adc;
|
2023-09-05 12:10:31 +02:00
|
|
|
#[cfg(not(any(adc_f1, adc_v1, adc_f3_v2, adc_g0)))]
|
2022-10-26 17:33:32 -05:00
|
|
|
fn common_regs() -> crate::pac::adccommon::AdcCommon;
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(adc_f3)]
|
|
|
|
fn frequency() -> crate::time::Hertz;
|
2021-06-10 15:33:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait AdcPin<T: Instance> {
|
|
|
|
fn channel(&self) -> u8;
|
|
|
|
}
|
2022-10-07 14:31:55 +03:00
|
|
|
|
|
|
|
pub trait InternalChannel<T> {
|
|
|
|
fn channel(&self) -> u8;
|
|
|
|
}
|
2021-06-10 15:33:43 -04:00
|
|
|
}
|
|
|
|
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(not(any(adc_f1, adc_v1, adc_v2, adc_v4, adc_f3)))]
|
2022-10-26 18:36:04 -05:00
|
|
|
pub trait Instance: sealed::Instance + crate::Peripheral<P = Self> {}
|
2023-09-05 16:46:57 -05:00
|
|
|
#[cfg(any(adc_f1, adc_v1, adc_v2, adc_v4, adc_f3))]
|
2022-10-26 18:36:04 -05:00
|
|
|
pub trait Instance: sealed::Instance + crate::Peripheral<P = Self> + crate::rcc::RccPeripheral {}
|
2022-10-26 17:21:38 -05:00
|
|
|
|
2021-06-10 15:33:43 -04:00
|
|
|
pub trait AdcPin<T: Instance>: sealed::AdcPin<T> {}
|
2022-10-07 14:31:55 +03:00
|
|
|
pub trait InternalChannel<T>: sealed::InternalChannel<T> {}
|
2021-06-10 15:33:43 -04:00
|
|
|
|
2023-09-15 17:35:53 -05:00
|
|
|
foreach_adc!(
|
|
|
|
($inst:ident, $common_inst:ident, $clock:ident) => {
|
2021-06-10 15:33:43 -04:00
|
|
|
impl crate::adc::sealed::Instance for peripherals::$inst {
|
2022-10-26 17:33:32 -05:00
|
|
|
fn regs() -> crate::pac::adc::Adc {
|
|
|
|
crate::pac::$inst
|
2021-06-10 15:33:43 -04:00
|
|
|
}
|
2023-09-11 17:12:54 -05:00
|
|
|
|
2023-09-15 17:35:53 -05:00
|
|
|
#[cfg(not(any(adc_f1, adc_v1, adc_f3_v2, adc_g0)))]
|
2022-10-26 17:33:32 -05:00
|
|
|
fn common_regs() -> crate::pac::adccommon::AdcCommon {
|
2023-09-15 17:35:53 -05:00
|
|
|
return crate::pac::$common_inst
|
2022-03-19 11:05:00 +01:00
|
|
|
}
|
2023-09-05 16:46:57 -05:00
|
|
|
|
|
|
|
#[cfg(adc_f3)]
|
|
|
|
fn frequency() -> crate::time::Hertz {
|
2023-09-15 17:35:53 -05:00
|
|
|
unsafe { crate::rcc::get_freqs() }.$clock.unwrap()
|
2023-09-05 16:46:57 -05:00
|
|
|
}
|
2022-03-19 11:05:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl crate::adc::Instance for peripherals::$inst {}
|
|
|
|
};
|
|
|
|
);
|
|
|
|
|
2022-02-23 20:21:28 +01:00
|
|
|
macro_rules! impl_adc_pin {
|
2021-06-10 15:33:43 -04:00
|
|
|
($inst:ident, $pin:ident, $ch:expr) => {
|
2022-02-23 20:21:28 +01:00
|
|
|
impl crate::adc::AdcPin<peripherals::$inst> for crate::peripherals::$pin {}
|
2021-06-10 15:33:43 -04:00
|
|
|
|
2022-02-23 20:21:28 +01:00
|
|
|
impl crate::adc::sealed::AdcPin<peripherals::$inst> for crate::peripherals::$pin {
|
2021-06-10 15:33:43 -04:00
|
|
|
fn channel(&self) -> u8 {
|
|
|
|
$ch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|