Move regs trait implementation into generated pac
This allows handling devices that don't have DMA2
This commit is contained in:
parent
0cd3236fa3
commit
9fa5a2920f
@ -151,7 +151,7 @@ for chip in chips.values():
|
||||
for ch_num in range(8):
|
||||
channel = f'{name}_CH{ch_num}'
|
||||
peripheral_names.append(channel)
|
||||
f.write(f'impl_dma_channel!({channel}, {dma_num}, {ch_num});')
|
||||
f.write(f'impl_dma_channel!({name}, {channel}, {dma_num}, {ch_num});')
|
||||
|
||||
if peri['block'] == 'sdmmc_v2/SDMMC':
|
||||
f.write(f'impl_sdmmc!({name});')
|
||||
|
@ -20,26 +20,24 @@ pub(crate) mod sealed {
|
||||
fn ch_num(&self) -> u8 {
|
||||
self.num() % 8
|
||||
}
|
||||
|
||||
fn regs(&self) -> pac::dma::Dma {
|
||||
match self.dma_num() {
|
||||
0 => pac::DMA1,
|
||||
_ => pac::DMA2,
|
||||
}
|
||||
}
|
||||
fn regs(&self) -> pac::dma::Dma;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Channel: sealed::Channel + Sized {}
|
||||
|
||||
macro_rules! impl_dma_channel {
|
||||
($type:ident, $dma_num:expr, $ch_num:expr) => {
|
||||
($name:ident, $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
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user