stm32/dma: add MuxChannel trait to distinguish DMAMUX1 and DMAMUX2 channels.

This commit is contained in:
Dario Nieuwenhuis 2021-07-17 07:49:49 +02:00
parent 54b5012c56
commit 3655048e0f
5 changed files with 37 additions and 14 deletions

View File

@ -175,9 +175,9 @@ pac::dma_channels! {
buf.as_mut_ptr(), buf.as_mut_ptr(),
buf.len(), buf.len(),
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_REGS, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_REGS,
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_CH_NUM, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_CH_NUM,
) )
} }
} }
@ -199,9 +199,9 @@ pac::dma_channels! {
buf.as_ptr() as *mut u8, buf.as_ptr() as *mut u8,
buf.len(), buf.len(),
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_REGS, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_REGS,
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_CH_NUM, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_CH_NUM,
) )
} }
} }

View File

@ -177,9 +177,9 @@ pac::dma_channels! {
buf.as_mut_ptr(), buf.as_mut_ptr(),
buf.len(), buf.len(),
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_REGS, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_REGS,
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_CH_NUM, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_CH_NUM,
) )
} }
} }
@ -201,9 +201,9 @@ pac::dma_channels! {
buf.as_ptr() as *mut u8, buf.as_ptr() as *mut u8,
buf.len(), buf.len(),
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_REGS, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_REGS,
#[cfg(dmamux)] #[cfg(dmamux)]
<Self as super::dmamux::MuxChannel>::DMAMUX_CH_NUM, <Self as super::dmamux::sealed::MuxChannel>::DMAMUX_CH_NUM,
) )
} }
} }

View File

@ -19,17 +19,31 @@ pub(crate) unsafe fn configure_dmamux(
}); });
} }
pub(crate) trait MuxChannel { pub(crate) mod sealed {
use super::*;
pub trait MuxChannel {
const DMAMUX_CH_NUM: u8; const DMAMUX_CH_NUM: u8;
const DMAMUX_REGS: pac::dmamux::Dmamux; 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! { pac::dma_channels! {
($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, {dmamux: $dmamux:ident, dmamux_channel: $dmamux_channel:expr}) => { ($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_CH_NUM: u8 = $dmamux_channel;
const DMAMUX_REGS: pac::dmamux::Dmamux = pac::$dmamux; const DMAMUX_REGS: pac::dmamux::Dmamux = pac::$dmamux;
} }
impl MuxChannel for peripherals::$channel_peri {
type Mux = $dmamux;
}
}; };
} }

View File

@ -5,6 +5,9 @@ mod dma;
#[cfg(dmamux)] #[cfg(dmamux)]
mod dmamux; mod dmamux;
#[cfg(dmamux)]
pub use dmamux::*;
use core::future::Future; use core::future::Future;
use embassy::util::Unborrow; use embassy::util::Unborrow;

View File

@ -172,13 +172,19 @@ crate::pac::peripheral_pins!(
macro_rules! impl_dma { macro_rules! impl_dma {
($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => { ($inst:ident, {dmamux: $dmamux:ident}, $signal:ident, $request:expr) => {
impl<T: crate::dma::Channel> sealed::$signal<peripherals::$inst> for T { impl<T> sealed::$signal<peripherals::$inst> for T
where
T: crate::dma::MuxChannel<Mux = crate::dma::$dmamux>,
{
fn request(&self) -> dma::Request { fn request(&self) -> dma::Request {
$request $request
} }
} }
impl<T: crate::dma::Channel> $signal<peripherals::$inst> for T {} impl<T> $signal<peripherals::$inst> for T where
T: crate::dma::MuxChannel<Mux = crate::dma::$dmamux>
{
}
}; };
($inst:ident, {channel: $channel:ident}, $signal:ident, $request:expr) => { ($inst:ident, {channel: $channel:ident}, $signal:ident, $request:expr) => {
impl sealed::$signal<peripherals::$inst> for peripherals::$channel { impl sealed::$signal<peripherals::$inst> for peripherals::$channel {