diff options
| -rw-r--r-- | embassy-stm32/src/adc/mod.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/adc/sample_time.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/can/fdcan.rs | 66 | ||||
| -rw-r--r-- | embassy-stm32/src/can/mod.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32/src/dac/mod.rs | 4 |
5 files changed, 78 insertions, 6 deletions
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index 56ecd63ca..94a8538bf 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | #[cfg(not(adc_f3))] | ||
| 3 | #[cfg_attr(adc_f1, path = "f1.rs")] | 4 | #[cfg_attr(adc_f1, path = "f1.rs")] |
| 4 | #[cfg_attr(adc_v1, path = "v1.rs")] | 5 | #[cfg_attr(adc_v1, path = "v1.rs")] |
| 5 | #[cfg_attr(adc_v2, path = "v2.rs")] | 6 | #[cfg_attr(adc_v2, path = "v2.rs")] |
| @@ -7,14 +8,16 @@ | |||
| 7 | #[cfg_attr(adc_v4, path = "v4.rs")] | 8 | #[cfg_attr(adc_v4, path = "v4.rs")] |
| 8 | mod _version; | 9 | mod _version; |
| 9 | 10 | ||
| 10 | #[cfg(not(adc_f1))] | 11 | #[cfg(not(any(adc_f1, adc_f3)))] |
| 11 | mod resolution; | 12 | mod resolution; |
| 12 | mod sample_time; | 13 | mod sample_time; |
| 13 | 14 | ||
| 15 | #[cfg(not(adc_f3))] | ||
| 14 | #[allow(unused)] | 16 | #[allow(unused)] |
| 15 | pub use _version::*; | 17 | pub use _version::*; |
| 16 | #[cfg(not(adc_f1))] | 18 | #[cfg(not(any(adc_f1, adc_f3)))] |
| 17 | pub use resolution::Resolution; | 19 | pub use resolution::Resolution; |
| 20 | #[cfg(not(adc_f3))] | ||
| 18 | pub use sample_time::SampleTime; | 21 | pub use sample_time::SampleTime; |
| 19 | 22 | ||
| 20 | use crate::peripherals; | 23 | use crate::peripherals; |
| @@ -22,13 +25,14 @@ use crate::peripherals; | |||
| 22 | pub struct Adc<'d, T: Instance> { | 25 | pub struct Adc<'d, T: Instance> { |
| 23 | #[allow(unused)] | 26 | #[allow(unused)] |
| 24 | adc: crate::PeripheralRef<'d, T>, | 27 | adc: crate::PeripheralRef<'d, T>, |
| 28 | #[cfg(not(adc_f3))] | ||
| 25 | sample_time: SampleTime, | 29 | sample_time: SampleTime, |
| 26 | } | 30 | } |
| 27 | 31 | ||
| 28 | pub(crate) mod sealed { | 32 | pub(crate) mod sealed { |
| 29 | pub trait Instance { | 33 | pub trait Instance { |
| 30 | fn regs() -> crate::pac::adc::Adc; | 34 | fn regs() -> crate::pac::adc::Adc; |
| 31 | #[cfg(all(not(adc_f1), not(adc_v1)))] | 35 | #[cfg(not(any(adc_f1, adc_v1, adc_f3)))] |
| 32 | fn common_regs() -> crate::pac::adccommon::AdcCommon; | 36 | fn common_regs() -> crate::pac::adccommon::AdcCommon; |
| 33 | } | 37 | } |
| 34 | 38 | ||
| @@ -56,7 +60,7 @@ foreach_peripheral!( | |||
| 56 | fn regs() -> crate::pac::adc::Adc { | 60 | fn regs() -> crate::pac::adc::Adc { |
| 57 | crate::pac::$inst | 61 | crate::pac::$inst |
| 58 | } | 62 | } |
| 59 | #[cfg(all(not(adc_f1), not(adc_v1)))] | 63 | #[cfg(not(any(adc_f1, adc_v1, adc_f3)))] |
| 60 | fn common_regs() -> crate::pac::adccommon::AdcCommon { | 64 | fn common_regs() -> crate::pac::adccommon::AdcCommon { |
| 61 | foreach_peripheral!{ | 65 | foreach_peripheral!{ |
| 62 | (adccommon, $common_inst:ident) => { | 66 | (adccommon, $common_inst:ident) => { |
diff --git a/embassy-stm32/src/adc/sample_time.rs b/embassy-stm32/src/adc/sample_time.rs index 0faa1e3c0..df0525560 100644 --- a/embassy-stm32/src/adc/sample_time.rs +++ b/embassy-stm32/src/adc/sample_time.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | #[cfg(not(adc_f3))] | ||
| 1 | macro_rules! impl_sample_time { | 2 | macro_rules! impl_sample_time { |
| 2 | ($default_doc:expr, $default:ident, ($(($doc:expr, $variant:ident, $pac_variant:ident)),*)) => { | 3 | ($default_doc:expr, $default:ident, ($(($doc:expr, $variant:ident, $pac_variant:ident)),*)) => { |
| 3 | #[doc = concat!("ADC sample time\n\nThe default setting is ", $default_doc, " ADC clock cycles.")] | 4 | #[doc = concat!("ADC sample time\n\nThe default setting is ", $default_doc, " ADC clock cycles.")] |
diff --git a/embassy-stm32/src/can/fdcan.rs b/embassy-stm32/src/can/fdcan.rs new file mode 100644 index 000000000..c31a7fc63 --- /dev/null +++ b/embassy-stm32/src/can/fdcan.rs | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | pub use bxcan; | ||
| 2 | use embassy_hal_common::PeripheralRef; | ||
| 3 | |||
| 4 | use crate::peripherals; | ||
| 5 | |||
| 6 | pub(crate) mod sealed { | ||
| 7 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 8 | use embassy_sync::channel::Channel; | ||
| 9 | use embassy_sync::waitqueue::AtomicWaker; | ||
| 10 | |||
| 11 | pub struct State { | ||
| 12 | pub tx_waker: AtomicWaker, | ||
| 13 | pub err_waker: AtomicWaker, | ||
| 14 | pub rx_queue: Channel<CriticalSectionRawMutex, (u16, bxcan::Frame), 32>, | ||
| 15 | } | ||
| 16 | |||
| 17 | impl State { | ||
| 18 | pub const fn new() -> Self { | ||
| 19 | Self { | ||
| 20 | tx_waker: AtomicWaker::new(), | ||
| 21 | err_waker: AtomicWaker::new(), | ||
| 22 | rx_queue: Channel::new(), | ||
| 23 | } | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | pub trait Instance { | ||
| 28 | const REGISTERS: *mut bxcan::RegisterBlock; | ||
| 29 | |||
| 30 | fn regs() -> &'static crate::pac::can::Fdcan; | ||
| 31 | fn state() -> &'static State; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | pub trait InterruptableInstance {} | ||
| 36 | pub trait Instance: sealed::Instance + InterruptableInstance + 'static {} | ||
| 37 | |||
| 38 | pub struct BxcanInstance<'a, T>(PeripheralRef<'a, T>); | ||
| 39 | |||
| 40 | unsafe impl<'d, T: Instance> bxcan::Instance for BxcanInstance<'d, T> { | ||
| 41 | const REGISTERS: *mut bxcan::RegisterBlock = T::REGISTERS; | ||
| 42 | } | ||
| 43 | |||
| 44 | foreach_peripheral!( | ||
| 45 | (can, $inst:ident) => { | ||
| 46 | impl sealed::Instance for peripherals::$inst { | ||
| 47 | const REGISTERS: *mut bxcan::RegisterBlock = crate::pac::$inst.as_ptr() as *mut _; | ||
| 48 | |||
| 49 | fn regs() -> &'static crate::pac::can::Fdcan { | ||
| 50 | &crate::pac::$inst | ||
| 51 | } | ||
| 52 | |||
| 53 | fn state() -> &'static sealed::State { | ||
| 54 | static STATE: sealed::State = sealed::State::new(); | ||
| 55 | &STATE | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | impl Instance for peripherals::$inst {} | ||
| 60 | |||
| 61 | impl InterruptableInstance for peripherals::$inst {} | ||
| 62 | }; | ||
| 63 | ); | ||
| 64 | |||
| 65 | pin_trait!(RxPin, Instance); | ||
| 66 | pin_trait!(TxPin, Instance); | ||
diff --git a/embassy-stm32/src/can/mod.rs b/embassy-stm32/src/can/mod.rs index c7e2e620a..4ff5aa0de 100644 --- a/embassy-stm32/src/can/mod.rs +++ b/embassy-stm32/src/can/mod.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | #[cfg_attr(can_bxcan, path = "bxcan.rs")] | 3 | #[cfg_attr(can_bxcan, path = "bxcan.rs")] |
| 4 | #[cfg_attr(can_fdcan, path = "fdcan.rs")] | ||
| 4 | mod _version; | 5 | mod _version; |
| 5 | pub use _version::*; | 6 | pub use _version::*; |
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 6712585cf..bf15eaac5 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -41,7 +41,7 @@ pub enum Ch1Trigger { | |||
| 41 | #[cfg(dac_v3)] | 41 | #[cfg(dac_v3)] |
| 42 | Tim1, | 42 | Tim1, |
| 43 | Tim2, | 43 | Tim2, |
| 44 | #[cfg(not(dac_v2))] | 44 | #[cfg(not(dac_v3))] |
| 45 | Tim3, | 45 | Tim3, |
| 46 | #[cfg(dac_v3)] | 46 | #[cfg(dac_v3)] |
| 47 | Tim4, | 47 | Tim4, |
| @@ -72,7 +72,7 @@ impl Ch1Trigger { | |||
| 72 | #[cfg(dac_v3)] | 72 | #[cfg(dac_v3)] |
| 73 | Ch1Trigger::Tim1 => dac::vals::Tsel1::TIM1_TRGO, | 73 | Ch1Trigger::Tim1 => dac::vals::Tsel1::TIM1_TRGO, |
| 74 | Ch1Trigger::Tim2 => dac::vals::Tsel1::TIM2_TRGO, | 74 | Ch1Trigger::Tim2 => dac::vals::Tsel1::TIM2_TRGO, |
| 75 | #[cfg(dac_v2)] | 75 | #[cfg(not(dac_v3))] |
| 76 | Ch1Trigger::Tim3 => dac::vals::Tsel1::TIM3_TRGO, | 76 | Ch1Trigger::Tim3 => dac::vals::Tsel1::TIM3_TRGO, |
| 77 | #[cfg(dac_v3)] | 77 | #[cfg(dac_v3)] |
| 78 | Ch1Trigger::Tim4 => dac::vals::Tsel1::TIM4_TRGO, | 78 | Ch1Trigger::Tim4 => dac::vals::Tsel1::TIM4_TRGO, |
