Create DMA fn to select peripheral based on channel number

This commit is contained in:
Ulf Lilleengen
2021-05-20 11:15:27 +02:00
committed by Dario Nieuwenhuis
parent 32fbb32a84
commit 03bfbe51f5
2 changed files with 22 additions and 7 deletions

View File

@ -20,24 +20,22 @@ pub(crate) mod sealed {
fn ch_num(&self) -> u8 {
self.num() % 8
}
fn regs(&self) -> pac::dma::Dma;
fn regs(&self) -> pac::dma::Dma {
pac::DMA(self.num())
}
}
}
pub trait Channel: sealed::Channel + Sized {}
macro_rules! impl_dma_channel {
($name:ident, $type:ident, $dma_num:expr, $ch_num:expr) => {
($type:ident, $dma_num:expr, $ch_num:expr) => {
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
}
fn regs(&self) -> dma::Dma {
$name
}
}
};
}