2021-05-16 00:57:46 +00:00
|
|
|
#![macro_use]
|
|
|
|
|
2021-05-17 00:04:51 +00:00
|
|
|
#[cfg_attr(feature = "_dma_v1", path = "v1.rs")]
|
|
|
|
#[cfg_attr(feature = "_dma_v2", path = "v2.rs")]
|
2021-05-16 00:57:46 +00:00
|
|
|
mod _version;
|
2021-05-20 08:54:10 +00:00
|
|
|
#[allow(unused)]
|
2021-05-16 00:57:46 +00:00
|
|
|
pub use _version::*;
|
|
|
|
|
|
|
|
use crate::pac;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
pac::DMA(self.num())
|
|
|
|
}
|
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-05-16 00:57:46 +00:00
|
|
|
impl crate::dma::Channel for peripherals::$type {}
|
|
|
|
impl crate::dma::sealed::Channel for peripherals::$type {
|
|
|
|
#[inline]
|
|
|
|
fn num(&self) -> u8 {
|
|
|
|
$dma_num * 8 + $ch_num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|