Remove some unused traits.

Move some fns to associated consts.
This commit is contained in:
Bob McWhirter 2021-07-13 09:50:42 -04:00
parent c39ac201ff
commit 92247369e7
3 changed files with 58 additions and 61 deletions

View file

@ -13,7 +13,7 @@ use crate::interrupt;
use crate::pac; use crate::pac;
use crate::pac::bdma::vals; use crate::pac::bdma::vals;
const CH_COUNT: usize = pac::peripheral_count!(DMA) * 8; const CH_COUNT: usize = pac::peripheral_count!(bdma) * 8;
const CH_STATUS_NONE: u8 = 0; const CH_STATUS_NONE: u8 = 0;
const CH_STATUS_COMPLETED: u8 = 1; const CH_STATUS_COMPLETED: u8 = 1;
const CH_STATUS_ERROR: u8 = 2; const CH_STATUS_ERROR: u8 = 2;
@ -271,11 +271,15 @@ macro_rules! impl_dma_channel {
let state_num = self.state_num(); let state_num = self.state_num();
let regs = self.regs(); let regs = self.regs();
use crate::dmamux::sealed::Channel as _MuxChannel; use crate::dmamux::sealed::Channel as MuxChannel;
use crate::dmamux::sealed::PeripheralChannel; use crate::dmamux::sealed::PeripheralChannel;
let dmamux_regs = self.dmamux_regs(); let dmamux_regs = <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_REGS;
let dmamux_ch_num = self.dmamux_ch_num(); let dmamux_ch_num =
let request = PeripheralChannel::<T, crate::dmamux::M2P>::request(self); <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_CH_NUM;
let request = <crate::peripherals::$channel_peri as PeripheralChannel<
T,
crate::dmamux::M2P,
>>::REQUEST;
unsafe { unsafe {
transfer_m2p( transfer_m2p(
regs, regs,
@ -316,7 +320,7 @@ macro_rules! impl_dma_channel {
#[cfg(dmamux)] #[cfg(dmamux)]
impl<T> ReadDma<T> for crate::peripherals::$channel_peri impl<T> ReadDma<T> for crate::peripherals::$channel_peri
where where
Self: crate::dmamux::sealed::PeripheralChannel<T, crate::dmamux::M2P>, Self: crate::dmamux::sealed::PeripheralChannel<T, crate::dmamux::P2M>,
T: 'static, T: 'static,
{ {
type ReadDmaFuture<'a> = impl Future<Output = ()>; type ReadDmaFuture<'a> = impl Future<Output = ()>;
@ -334,11 +338,15 @@ macro_rules! impl_dma_channel {
let state_num = self.state_num(); let state_num = self.state_num();
let regs = self.regs(); let regs = self.regs();
use crate::dmamux::sealed::Channel as _MuxChannel; use crate::dmamux::sealed::Channel as MuxChannel;
use crate::dmamux::sealed::PeripheralChannel; use crate::dmamux::sealed::PeripheralChannel;
let dmamux_regs = self.dmamux_regs(); let dmamux_regs = <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_REGS;
let dmamux_ch_num = self.dmamux_ch_num(); let dmamux_ch_num =
let request = PeripheralChannel::<T, crate::dmamux::M2P>::request(self); <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_CH_NUM;
let request = <crate::peripherals::$channel_peri as PeripheralChannel<
T,
crate::dmamux::P2M,
>>::REQUEST;
unsafe { unsafe {
transfer_p2m( transfer_p2m(
regs, regs,

View file

@ -25,79 +25,65 @@ pub(crate) unsafe fn configure_dmamux(
pub(crate) mod sealed { pub(crate) mod sealed {
use super::*; use super::*;
pub trait DmaMux {
fn regs() -> pac::dmamux::Dmamux;
}
pub trait Channel { pub trait Channel {
fn dmamux_regs(&self) -> pac::dmamux::Dmamux; const DMAMUX_CH_NUM: u8;
fn dmamux_ch_num(&self) -> u8; const DMAMUX_REGS: pac::dmamux::Dmamux;
} }
pub trait PeripheralChannel<PERI, OP>: Channel { pub trait PeripheralChannel<PERI, OP>: Channel {
fn request(&self) -> u8; const REQUEST: u8;
} }
} }
pub trait DmaMux: sealed::DmaMux {}
pub trait Channel: sealed::Channel {} pub trait Channel: sealed::Channel {}
pub trait PeripheralChannel<PERI, OP>: sealed::Channel {} pub trait PeripheralChannel<PERI, OP>: sealed::Channel {}
pub struct P2M; pub struct P2M;
pub struct M2P; pub struct M2P;
#[allow(unused)] macro_rules! dma_num {
macro_rules! impl_dma_channel { (DMA1) => {
($channel_peri:ident, $dmamux_peri:ident, $channel_num:expr, $dma_peri: ident, $dma_num:expr) => { 0
impl Channel for peripherals::$channel_peri {} };
impl sealed::Channel for peripherals::$channel_peri { (DMA2) => {
fn dmamux_regs(&self) -> pac::dmamux::Dmamux { 1
crate::pac::$dmamux_peri };
} (BDMA) => {
0
fn dmamux_ch_num(&self) -> u8 {
($dma_num * 8) + $channel_num
}
}
}; };
} }
macro_rules! impl_dmamux { macro_rules! dmamux_peri {
($peri:ident) => { (DMA1) => {
impl sealed::DmaMux for peripherals::$peri { crate::pac::DMAMUX1
fn regs() -> pac::dmamux::Dmamux { };
pac::$peri (DMA2) => {
} crate::pac::DMAMUX1
};
(BDMA) => {
crate::pac::DMAMUX1
};
}
#[allow(unused)]
macro_rules! impl_dma_channel {
($channel_peri:ident, $channel_num:expr, $dma_peri: ident) => {
impl Channel for peripherals::$channel_peri {}
impl sealed::Channel for peripherals::$channel_peri {
const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num;
const DMAMUX_REGS: pac::dmamux::Dmamux = dmamux_peri!($dma_peri);
} }
impl DmaMux for peripherals::$peri {}
}; };
} }
peripherals! { peripherals! {
(bdma, DMA1) => { (bdma, $peri:ident) => {
bdma_channels! { bdma_channels! {
($channel_peri:ident, DMA1, $channel_num:expr) => { ($channel_peri:ident, $peri, $channel_num:expr) => {
impl_dma_channel!($channel_peri, DMAMUX1, $channel_num, DMA1, 0); impl_dma_channel!($channel_peri, $channel_num, $peri);
}; };
} }
}; };
(bdma, DMA2) => {
bdma_channels! {
($channel_peri:ident, DMA2, $channel_num:expr) => {
impl_dma_channel!($channel_peri, DMAMUX1, $channel_num, DMA2, 1);
};
}
};
(bdma, BDMA) => {
bdma_channels! {
($channel_peri:ident, BDMA, $channel_num:expr) => {
impl_dma_channel!($channel_peri, DMAMUX1, $channel_num, DMA2, 1);
};
}
};
(dmamux, DMAMUX1) => {
impl_dmamux!(DMAMUX1);
};
} }
#[allow(unused)] #[allow(unused)]
@ -106,9 +92,7 @@ macro_rules! impl_peripheral_channel {
impl sealed::PeripheralChannel<peripherals::$peri, $direction> impl sealed::PeripheralChannel<peripherals::$peri, $direction>
for peripherals::$channel_peri for peripherals::$channel_peri
{ {
fn request(&self) -> u8 { const REQUEST: u8 = $request;
$request
}
} }
impl PeripheralChannel<peripherals::$peri, $direction> for peripherals::$channel_peri {} impl PeripheralChannel<peripherals::$peri, $direction> for peripherals::$channel_peri {}

View file

@ -304,6 +304,11 @@ pub fn gen(options: Options) {
if let Some(block) = &p.block { if let Some(block) = &p.block {
let bi = BlockInfo::parse(block); let bi = BlockInfo::parse(block);
peripheral_counts.insert(
bi.module.clone(),
peripheral_counts.get(&bi.module).map_or(1, |v| v + 1),
);
for pin in &p.pins { for pin in &p.pins {
let mut row = Vec::new(); let mut row = Vec::new();
row.push(name.clone()); row.push(name.clone());