2021-05-16 00:57:46 +00:00
|
|
|
#![macro_use]
|
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
#[cfg_attr(dma_v1, path = "v1.rs")]
|
|
|
|
#[cfg_attr(dma_v2, path = "v2.rs")]
|
2021-05-16 00:57:46 +00:00
|
|
|
mod _version;
|
2021-05-25 02:17:24 +00:00
|
|
|
|
2021-05-20 08:54:10 +00:00
|
|
|
#[allow(unused)]
|
2021-05-16 00:57:46 +00:00
|
|
|
pub use _version::*;
|
|
|
|
|
|
|
|
use crate::pac;
|
2021-06-03 18:53:48 +00:00
|
|
|
use crate::peripherals;
|
2021-05-16 00:57:46 +00:00
|
|
|
|
|
|
|
pub(crate) mod sealed {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub trait Channel {
|
|
|
|
fn num(&self) -> u8;
|
|
|
|
|
|
|
|
fn dma_num(&self) -> u8 {
|
|
|
|
self.num() / 8
|
|
|
|
}
|
|
|
|
fn ch_num(&self) -> u8 {
|
|
|
|
self.num() % 8
|
|
|
|
}
|
2021-05-20 09:15:27 +00:00
|
|
|
fn regs(&self) -> pac::dma::Dma {
|
2021-05-25 02:17:24 +00:00
|
|
|
pac::DMA(self.num() as _)
|
2021-05-20 09:15:27 +00:00
|
|
|
}
|
2021-05-16 00:57:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Channel: sealed::Channel + Sized {}
|
|
|
|
|
|
|
|
macro_rules! impl_dma_channel {
|
2021-05-20 09:15:27 +00:00
|
|
|
($type:ident, $dma_num:expr, $ch_num:expr) => {
|
2021-06-03 18:53:48 +00:00
|
|
|
impl Channel for peripherals::$type {}
|
|
|
|
impl sealed::Channel for peripherals::$type {
|
2021-05-16 00:57:46 +00:00
|
|
|
#[inline]
|
|
|
|
fn num(&self) -> u8 {
|
|
|
|
$dma_num * 8 + $ch_num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-06-03 18:53:48 +00:00
|
|
|
|
|
|
|
crate::pac::peripherals!(
|
|
|
|
(dma,DMA1) => {
|
|
|
|
impl_dma_channel!(DMA1_CH0, 0, 0);
|
|
|
|
impl_dma_channel!(DMA1_CH1, 0, 1);
|
|
|
|
impl_dma_channel!(DMA1_CH2, 0, 2);
|
|
|
|
impl_dma_channel!(DMA1_CH3, 0, 3);
|
|
|
|
impl_dma_channel!(DMA1_CH4, 0, 4);
|
|
|
|
impl_dma_channel!(DMA1_CH5, 0, 5);
|
|
|
|
impl_dma_channel!(DMA1_CH6, 0, 6);
|
|
|
|
impl_dma_channel!(DMA1_CH7, 0, 7);
|
|
|
|
};
|
|
|
|
|
|
|
|
(dma,DMA2) => {
|
|
|
|
impl_dma_channel!(DMA2_CH0, 1, 0);
|
|
|
|
impl_dma_channel!(DMA2_CH1, 1, 1);
|
|
|
|
impl_dma_channel!(DMA2_CH2, 1, 2);
|
|
|
|
impl_dma_channel!(DMA2_CH3, 1, 3);
|
|
|
|
impl_dma_channel!(DMA2_CH4, 1, 4);
|
|
|
|
impl_dma_channel!(DMA2_CH5, 1, 5);
|
|
|
|
impl_dma_channel!(DMA2_CH6, 1, 6);
|
|
|
|
impl_dma_channel!(DMA2_CH7, 1, 7);
|
|
|
|
};
|
|
|
|
);
|