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::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_COMPLETED: u8 = 1;
const CH_STATUS_ERROR: u8 = 2;
@ -271,11 +271,15 @@ macro_rules! impl_dma_channel {
let state_num = self.state_num();
let regs = self.regs();
use crate::dmamux::sealed::Channel as _MuxChannel;
use crate::dmamux::sealed::Channel as MuxChannel;
use crate::dmamux::sealed::PeripheralChannel;
let dmamux_regs = self.dmamux_regs();
let dmamux_ch_num = self.dmamux_ch_num();
let request = PeripheralChannel::<T, crate::dmamux::M2P>::request(self);
let dmamux_regs = <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_REGS;
let dmamux_ch_num =
<crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_CH_NUM;
let request = <crate::peripherals::$channel_peri as PeripheralChannel<
T,
crate::dmamux::M2P,
>>::REQUEST;
unsafe {
transfer_m2p(
regs,
@ -316,7 +320,7 @@ macro_rules! impl_dma_channel {
#[cfg(dmamux)]
impl<T> ReadDma<T> for crate::peripherals::$channel_peri
where
Self: crate::dmamux::sealed::PeripheralChannel<T, crate::dmamux::M2P>,
Self: crate::dmamux::sealed::PeripheralChannel<T, crate::dmamux::P2M>,
T: 'static,
{
type ReadDmaFuture<'a> = impl Future<Output = ()>;
@ -334,11 +338,15 @@ macro_rules! impl_dma_channel {
let state_num = self.state_num();
let regs = self.regs();
use crate::dmamux::sealed::Channel as _MuxChannel;
use crate::dmamux::sealed::Channel as MuxChannel;
use crate::dmamux::sealed::PeripheralChannel;
let dmamux_regs = self.dmamux_regs();
let dmamux_ch_num = self.dmamux_ch_num();
let request = PeripheralChannel::<T, crate::dmamux::M2P>::request(self);
let dmamux_regs = <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_REGS;
let dmamux_ch_num =
<crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_CH_NUM;
let request = <crate::peripherals::$channel_peri as PeripheralChannel<
T,
crate::dmamux::P2M,
>>::REQUEST;
unsafe {
transfer_p2m(
regs,

View file

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