2021-07-15 05:42:06 +02:00
|
|
|
#![macro_use]
|
|
|
|
|
2022-06-12 22:15:44 +02:00
|
|
|
use crate::{pac, peripherals};
|
2021-07-15 05:42:06 +02:00
|
|
|
|
2023-06-19 03:07:26 +02:00
|
|
|
pub(crate) fn configure_dmamux<M: MuxChannel>(channel: &mut M, request: u8) {
|
2023-04-17 00:04:54 +02:00
|
|
|
let ch_mux_regs = channel.mux_regs().ccr(channel.mux_num());
|
2021-07-15 05:42:06 +02:00
|
|
|
ch_mux_regs.write(|reg| {
|
|
|
|
reg.set_nbreq(0);
|
|
|
|
reg.set_dmareq_id(request);
|
|
|
|
});
|
|
|
|
|
|
|
|
ch_mux_regs.modify(|reg| {
|
|
|
|
reg.set_ege(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-17 00:04:54 +02:00
|
|
|
pub(crate) mod dmamux_sealed {
|
2021-07-17 07:49:49 +02:00
|
|
|
use super::*;
|
|
|
|
pub trait MuxChannel {
|
2023-04-17 00:04:54 +02:00
|
|
|
fn mux_regs(&self) -> pac::dmamux::Dmamux;
|
|
|
|
fn mux_num(&self) -> usize;
|
2021-07-17 07:49:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DMAMUX1;
|
2022-02-24 05:59:42 +01:00
|
|
|
#[cfg(stm32h7)]
|
2021-07-17 07:49:49 +02:00
|
|
|
pub struct DMAMUX2;
|
|
|
|
|
2023-04-17 00:04:54 +02:00
|
|
|
pub trait MuxChannel: dmamux_sealed::MuxChannel {
|
2021-07-17 07:49:49 +02:00
|
|
|
type Mux;
|
2021-07-15 05:42:06 +02:00
|
|
|
}
|
|
|
|
|
2022-02-26 01:40:43 +01:00
|
|
|
foreach_dma_channel! {
|
|
|
|
($channel_peri:ident, $dma_peri:ident, $version:ident, $channel_num:expr, $index:expr, {dmamux: $dmamux:ident, dmamux_channel: $dmamux_channel:expr}) => {
|
2023-04-17 00:04:54 +02:00
|
|
|
impl dmamux_sealed::MuxChannel for peripherals::$channel_peri {
|
|
|
|
fn mux_regs(&self) -> pac::dmamux::Dmamux {
|
|
|
|
pac::$dmamux
|
|
|
|
}
|
|
|
|
fn mux_num(&self) -> usize {
|
|
|
|
$dmamux_channel
|
|
|
|
}
|
2021-07-15 05:42:06 +02:00
|
|
|
}
|
2021-07-17 07:49:49 +02:00
|
|
|
impl MuxChannel for peripherals::$channel_peri {
|
|
|
|
type Mux = $dmamux;
|
|
|
|
}
|
2021-07-15 05:42:06 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// safety: must be called only once
|
2023-10-12 00:34:47 +02:00
|
|
|
pub(crate) unsafe fn init(_cs: critical_section::CriticalSection) {
|
2022-03-04 17:42:38 +01:00
|
|
|
crate::_generated::init_dmamux();
|
2021-10-26 20:01:39 +02:00
|
|
|
}
|