stm32/dma: refactor.
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
|
||||
use crate::{pac, peripherals};
|
||||
|
||||
pub(crate) unsafe fn configure_dmamux(dmamux_regs: pac::dmamux::Dmamux, dmamux_ch_num: u8, request: u8) {
|
||||
let ch_mux_regs = dmamux_regs.ccr(dmamux_ch_num as _);
|
||||
pub(crate) unsafe fn configure_dmamux<M: MuxChannel>(channel: &mut M, request: u8) {
|
||||
let ch_mux_regs = channel.mux_regs().ccr(channel.mux_num());
|
||||
ch_mux_regs.write(|reg| {
|
||||
reg.set_nbreq(0);
|
||||
reg.set_dmareq_id(request);
|
||||
@ -14,11 +14,11 @@ pub(crate) unsafe fn configure_dmamux(dmamux_regs: pac::dmamux::Dmamux, dmamux_c
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
pub(crate) mod dmamux_sealed {
|
||||
use super::*;
|
||||
pub trait MuxChannel {
|
||||
const DMAMUX_CH_NUM: u8;
|
||||
const DMAMUX_REGS: pac::dmamux::Dmamux;
|
||||
fn mux_regs(&self) -> pac::dmamux::Dmamux;
|
||||
fn mux_num(&self) -> usize;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,15 +26,19 @@ pub struct DMAMUX1;
|
||||
#[cfg(stm32h7)]
|
||||
pub struct DMAMUX2;
|
||||
|
||||
pub trait MuxChannel: sealed::MuxChannel + super::Channel {
|
||||
pub trait MuxChannel: dmamux_sealed::MuxChannel {
|
||||
type Mux;
|
||||
}
|
||||
|
||||
foreach_dma_channel! {
|
||||
($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, $index:expr, {dmamux: $dmamux:ident, dmamux_channel: $dmamux_channel:expr}) => {
|
||||
impl sealed::MuxChannel for peripherals::$channel_peri {
|
||||
const DMAMUX_CH_NUM: u8 = $dmamux_channel;
|
||||
const DMAMUX_REGS: pac::dmamux::Dmamux = pac::$dmamux;
|
||||
impl dmamux_sealed::MuxChannel for peripherals::$channel_peri {
|
||||
fn mux_regs(&self) -> pac::dmamux::Dmamux {
|
||||
pac::$dmamux
|
||||
}
|
||||
fn mux_num(&self) -> usize {
|
||||
$dmamux_channel
|
||||
}
|
||||
}
|
||||
impl MuxChannel for peripherals::$channel_peri {
|
||||
type Mux = $dmamux;
|
||||
|
Reference in New Issue
Block a user