From 3655048e0f8238dc64425ff79d9cf951b9b1f340 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 17 Jul 2021 07:49:49 +0200 Subject: [PATCH] stm32/dma: add MuxChannel trait to distinguish DMAMUX1 and DMAMUX2 channels. --- embassy-stm32/src/dma/bdma.rs | 8 ++++---- embassy-stm32/src/dma/dma.rs | 8 ++++---- embassy-stm32/src/dma/dmamux.rs | 22 ++++++++++++++++++---- embassy-stm32/src/dma/mod.rs | 3 +++ embassy-stm32/src/usart/mod.rs | 10 ++++++++-- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 3d9ff9eb..4c26a950 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -175,9 +175,9 @@ pac::dma_channels! { buf.as_mut_ptr(), buf.len(), #[cfg(dmamux)] - ::DMAMUX_REGS, + ::DMAMUX_REGS, #[cfg(dmamux)] - ::DMAMUX_CH_NUM, + ::DMAMUX_CH_NUM, ) } } @@ -199,9 +199,9 @@ pac::dma_channels! { buf.as_ptr() as *mut u8, buf.len(), #[cfg(dmamux)] - ::DMAMUX_REGS, + ::DMAMUX_REGS, #[cfg(dmamux)] - ::DMAMUX_CH_NUM, + ::DMAMUX_CH_NUM, ) } } diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 9b1c1160..75fc1403 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -177,9 +177,9 @@ pac::dma_channels! { buf.as_mut_ptr(), buf.len(), #[cfg(dmamux)] - ::DMAMUX_REGS, + ::DMAMUX_REGS, #[cfg(dmamux)] - ::DMAMUX_CH_NUM, + ::DMAMUX_CH_NUM, ) } } @@ -201,9 +201,9 @@ pac::dma_channels! { buf.as_ptr() as *mut u8, buf.len(), #[cfg(dmamux)] - ::DMAMUX_REGS, + ::DMAMUX_REGS, #[cfg(dmamux)] - ::DMAMUX_CH_NUM, + ::DMAMUX_CH_NUM, ) } } diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs index 186ec247..718859a4 100644 --- a/embassy-stm32/src/dma/dmamux.rs +++ b/embassy-stm32/src/dma/dmamux.rs @@ -19,17 +19,31 @@ pub(crate) unsafe fn configure_dmamux( }); } -pub(crate) trait MuxChannel { - const DMAMUX_CH_NUM: u8; - const DMAMUX_REGS: pac::dmamux::Dmamux; +pub(crate) mod sealed { + use super::*; + pub trait MuxChannel { + const DMAMUX_CH_NUM: u8; + const DMAMUX_REGS: pac::dmamux::Dmamux; + } +} + +pub struct DMAMUX1; +#[cfg(rcc_h7)] +pub struct DMAMUX2; + +pub trait MuxChannel: sealed::MuxChannel + super::Channel { + type Mux; } pac::dma_channels! { ($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, {dmamux: $dmamux:ident, dmamux_channel: $dmamux_channel:expr}) => { - impl MuxChannel for peripherals::$channel_peri { + impl sealed::MuxChannel for peripherals::$channel_peri { const DMAMUX_CH_NUM: u8 = $dmamux_channel; const DMAMUX_REGS: pac::dmamux::Dmamux = pac::$dmamux; } + impl MuxChannel for peripherals::$channel_peri { + type Mux = $dmamux; + } }; } diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index ebad3d7b..fbf82b87 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -5,6 +5,9 @@ mod dma; #[cfg(dmamux)] mod dmamux; +#[cfg(dmamux)] +pub use dmamux::*; + use core::future::Future; use embassy::util::Unborrow; diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 92021d0a..9df00d3a 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -172,13 +172,19 @@ crate::pac::peripheral_pins!( macro_rules! impl_dma { ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { - impl sealed::$signal for T { + impl sealed::$signal for T + where + T: crate::dma::MuxChannel, + { fn request(&self) -> dma::Request { $request } } - impl $signal for T {} + impl $signal for T where + T: crate::dma::MuxChannel + { + } }; ($inst:ident, {channel: $channel:ident}, $signal:ident, $request:expr) => { impl sealed::$signal for peripherals::$channel {