diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-04-29 23:56:15 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-04-29 23:56:15 +0200 |
| commit | 1ed2a0504aba38e4b404c776808ee5229cd72615 (patch) | |
| tree | 1d61f6d2e267ac3cbac9c3c5312284d7e6537b9d /embassy-stm32/src | |
| parent | 7fb74ff756a3f4b8f770df6d070ba152439a0c45 (diff) | |
stm32/dma: add support for same channel with different req in different DMAs/DMAMUXes.
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/dma/dmamux.rs | 24 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/macros.rs | 27 |
3 files changed, 2 insertions, 51 deletions
diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs index dc7cd3a66..1585b30d4 100644 --- a/embassy-stm32/src/dma/dmamux.rs +++ b/embassy-stm32/src/dma/dmamux.rs | |||
| @@ -19,30 +19,6 @@ pub(crate) fn configure_dmamux(info: &DmamuxInfo, request: u8) { | |||
| 19 | }); | 19 | }); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub(crate) trait SealedMuxChannel {} | ||
| 23 | |||
| 24 | /// DMAMUX1 instance. | ||
| 25 | pub struct DMAMUX1; | ||
| 26 | /// DMAMUX2 instance. | ||
| 27 | #[cfg(stm32h7)] | ||
| 28 | pub struct DMAMUX2; | ||
| 29 | |||
| 30 | /// DMAMUX channel trait. | ||
| 31 | #[allow(private_bounds)] | ||
| 32 | pub trait MuxChannel: SealedMuxChannel { | ||
| 33 | /// DMAMUX instance this channel is on. | ||
| 34 | type Mux; | ||
| 35 | } | ||
| 36 | |||
| 37 | macro_rules! dmamux_channel_impl { | ||
| 38 | ($channel_peri:ident, $dmamux:ident) => { | ||
| 39 | impl crate::dma::SealedMuxChannel for crate::peripherals::$channel_peri {} | ||
| 40 | impl crate::dma::MuxChannel for crate::peripherals::$channel_peri { | ||
| 41 | type Mux = crate::dma::$dmamux; | ||
| 42 | } | ||
| 43 | }; | ||
| 44 | } | ||
| 45 | |||
| 46 | /// safety: must be called only once | 22 | /// safety: must be called only once |
| 47 | pub(crate) unsafe fn init(_cs: critical_section::CriticalSection) { | 23 | pub(crate) unsafe fn init(_cs: critical_section::CriticalSection) { |
| 48 | crate::_generated::init_dmamux(); | 24 | crate::_generated::init_dmamux(); |
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 8766d0a60..3f5687a62 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -14,7 +14,7 @@ pub use gpdma::*; | |||
| 14 | #[cfg(dmamux)] | 14 | #[cfg(dmamux)] |
| 15 | mod dmamux; | 15 | mod dmamux; |
| 16 | #[cfg(dmamux)] | 16 | #[cfg(dmamux)] |
| 17 | pub use dmamux::*; | 17 | pub(crate) use dmamux::*; |
| 18 | 18 | ||
| 19 | mod util; | 19 | mod util; |
| 20 | pub(crate) use util::*; | 20 | pub(crate) use util::*; |
diff --git a/embassy-stm32/src/macros.rs b/embassy-stm32/src/macros.rs index 14137bc37..02dce1266 100644 --- a/embassy-stm32/src/macros.rs +++ b/embassy-stm32/src/macros.rs | |||
| @@ -36,32 +36,7 @@ macro_rules! dma_trait { | |||
| 36 | 36 | ||
| 37 | #[allow(unused)] | 37 | #[allow(unused)] |
| 38 | macro_rules! dma_trait_impl { | 38 | macro_rules! dma_trait_impl { |
| 39 | // DMAMUX | 39 | (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, $channel:ident, $request:expr) => { |
| 40 | (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {dmamux: $dmamux:ident}, $request:expr) => { | ||
| 41 | impl<T> crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for T | ||
| 42 | where | ||
| 43 | T: crate::dma::Channel + crate::dma::MuxChannel<Mux = crate::dma::$dmamux>, | ||
| 44 | { | ||
| 45 | fn request(&self) -> crate::dma::Request { | ||
| 46 | $request | ||
| 47 | } | ||
| 48 | } | ||
| 49 | }; | ||
| 50 | |||
| 51 | // DMAMUX | ||
| 52 | (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {dma: $dma:ident}, $request:expr) => { | ||
| 53 | impl<T> crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for T | ||
| 54 | where | ||
| 55 | T: crate::dma::Channel, | ||
| 56 | { | ||
| 57 | fn request(&self) -> crate::dma::Request { | ||
| 58 | $request | ||
| 59 | } | ||
| 60 | } | ||
| 61 | }; | ||
| 62 | |||
| 63 | // DMA/GPDMA, without DMAMUX | ||
| 64 | (crate::$mod:ident::$trait:ident$(<$mode:ident>)?, $instance:ident, {channel: $channel:ident}, $request:expr) => { | ||
| 65 | impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel { | 40 | impl crate::$mod::$trait<crate::peripherals::$instance $(, crate::$mod::$mode)?> for crate::peripherals::$channel { |
| 66 | fn request(&self) -> crate::dma::Request { | 41 | fn request(&self) -> crate::dma::Request { |
| 67 | $request | 42 | $request |
