diff options
| author | Bob McWhirter <[email protected]> | 2021-07-13 09:50:42 -0400 |
|---|---|---|
| committer | Bob McWhirter <[email protected]> | 2021-07-13 10:09:35 -0400 |
| commit | 92247369e77bc55dd6247348a1f472cbe467d19f (patch) | |
| tree | aabef5c5fb298073aa8291cc13dfc0db3178aa6e | |
| parent | c39ac201ffad32a55d68dbe48de6185b91fc86af (diff) | |
Remove some unused traits.
Move some fns to associated consts.
| -rw-r--r-- | embassy-stm32/src/bdma/mod.rs | 28 | ||||
| -rw-r--r-- | embassy-stm32/src/dmamux/mod.rs | 84 | ||||
| -rw-r--r-- | stm32-metapac-gen/src/lib.rs | 5 |
3 files changed, 57 insertions, 60 deletions
diff --git a/embassy-stm32/src/bdma/mod.rs b/embassy-stm32/src/bdma/mod.rs index d62feb5b9..d36361e4c 100644 --- a/embassy-stm32/src/bdma/mod.rs +++ b/embassy-stm32/src/bdma/mod.rs | |||
| @@ -13,7 +13,7 @@ use crate::interrupt; | |||
| 13 | use crate::pac; | 13 | use crate::pac; |
| 14 | use crate::pac::bdma::vals; | 14 | use crate::pac::bdma::vals; |
| 15 | 15 | ||
| 16 | const CH_COUNT: usize = pac::peripheral_count!(DMA) * 8; | 16 | const CH_COUNT: usize = pac::peripheral_count!(bdma) * 8; |
| 17 | const CH_STATUS_NONE: u8 = 0; | 17 | const CH_STATUS_NONE: u8 = 0; |
| 18 | const CH_STATUS_COMPLETED: u8 = 1; | 18 | const CH_STATUS_COMPLETED: u8 = 1; |
| 19 | const CH_STATUS_ERROR: u8 = 2; | 19 | const CH_STATUS_ERROR: u8 = 2; |
| @@ -271,11 +271,15 @@ macro_rules! impl_dma_channel { | |||
| 271 | let state_num = self.state_num(); | 271 | let state_num = self.state_num(); |
| 272 | let regs = self.regs(); | 272 | let regs = self.regs(); |
| 273 | 273 | ||
| 274 | use crate::dmamux::sealed::Channel as _MuxChannel; | 274 | use crate::dmamux::sealed::Channel as MuxChannel; |
| 275 | use crate::dmamux::sealed::PeripheralChannel; | 275 | use crate::dmamux::sealed::PeripheralChannel; |
| 276 | let dmamux_regs = self.dmamux_regs(); | 276 | let dmamux_regs = <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_REGS; |
| 277 | let dmamux_ch_num = self.dmamux_ch_num(); | 277 | let dmamux_ch_num = |
| 278 | let request = PeripheralChannel::<T, crate::dmamux::M2P>::request(self); | 278 | <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_CH_NUM; |
| 279 | let request = <crate::peripherals::$channel_peri as PeripheralChannel< | ||
| 280 | T, | ||
| 281 | crate::dmamux::M2P, | ||
| 282 | >>::REQUEST; | ||
| 279 | unsafe { | 283 | unsafe { |
| 280 | transfer_m2p( | 284 | transfer_m2p( |
| 281 | regs, | 285 | regs, |
| @@ -316,7 +320,7 @@ macro_rules! impl_dma_channel { | |||
| 316 | #[cfg(dmamux)] | 320 | #[cfg(dmamux)] |
| 317 | impl<T> ReadDma<T> for crate::peripherals::$channel_peri | 321 | impl<T> ReadDma<T> for crate::peripherals::$channel_peri |
| 318 | where | 322 | where |
| 319 | Self: crate::dmamux::sealed::PeripheralChannel<T, crate::dmamux::M2P>, | 323 | Self: crate::dmamux::sealed::PeripheralChannel<T, crate::dmamux::P2M>, |
| 320 | T: 'static, | 324 | T: 'static, |
| 321 | { | 325 | { |
| 322 | type ReadDmaFuture<'a> = impl Future<Output = ()>; | 326 | type ReadDmaFuture<'a> = impl Future<Output = ()>; |
| @@ -334,11 +338,15 @@ macro_rules! impl_dma_channel { | |||
| 334 | let state_num = self.state_num(); | 338 | let state_num = self.state_num(); |
| 335 | let regs = self.regs(); | 339 | let regs = self.regs(); |
| 336 | 340 | ||
| 337 | use crate::dmamux::sealed::Channel as _MuxChannel; | 341 | use crate::dmamux::sealed::Channel as MuxChannel; |
| 338 | use crate::dmamux::sealed::PeripheralChannel; | 342 | use crate::dmamux::sealed::PeripheralChannel; |
| 339 | let dmamux_regs = self.dmamux_regs(); | 343 | let dmamux_regs = <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_REGS; |
| 340 | let dmamux_ch_num = self.dmamux_ch_num(); | 344 | let dmamux_ch_num = |
| 341 | let request = PeripheralChannel::<T, crate::dmamux::M2P>::request(self); | 345 | <crate::peripherals::$channel_peri as MuxChannel>::DMAMUX_CH_NUM; |
| 346 | let request = <crate::peripherals::$channel_peri as PeripheralChannel< | ||
| 347 | T, | ||
| 348 | crate::dmamux::P2M, | ||
| 349 | >>::REQUEST; | ||
| 342 | unsafe { | 350 | unsafe { |
| 343 | transfer_p2m( | 351 | transfer_p2m( |
| 344 | regs, | 352 | regs, |
diff --git a/embassy-stm32/src/dmamux/mod.rs b/embassy-stm32/src/dmamux/mod.rs index 564b8236a..ecea0b290 100644 --- a/embassy-stm32/src/dmamux/mod.rs +++ b/embassy-stm32/src/dmamux/mod.rs | |||
| @@ -25,79 +25,65 @@ pub(crate) unsafe fn configure_dmamux( | |||
| 25 | pub(crate) mod sealed { | 25 | pub(crate) mod sealed { |
| 26 | use super::*; | 26 | use super::*; |
| 27 | 27 | ||
| 28 | pub trait DmaMux { | ||
| 29 | fn regs() -> pac::dmamux::Dmamux; | ||
| 30 | } | ||
| 31 | |||
| 32 | pub trait Channel { | 28 | pub trait Channel { |
| 33 | fn dmamux_regs(&self) -> pac::dmamux::Dmamux; | 29 | const DMAMUX_CH_NUM: u8; |
| 34 | fn dmamux_ch_num(&self) -> u8; | 30 | const DMAMUX_REGS: pac::dmamux::Dmamux; |
| 35 | } | 31 | } |
| 36 | 32 | ||
| 37 | pub trait PeripheralChannel<PERI, OP>: Channel { | 33 | pub trait PeripheralChannel<PERI, OP>: Channel { |
| 38 | fn request(&self) -> u8; | 34 | const REQUEST: u8; |
| 39 | } | 35 | } |
| 40 | } | 36 | } |
| 41 | 37 | ||
| 42 | pub trait DmaMux: sealed::DmaMux {} | ||
| 43 | pub trait Channel: sealed::Channel {} | 38 | pub trait Channel: sealed::Channel {} |
| 44 | pub trait PeripheralChannel<PERI, OP>: sealed::Channel {} | 39 | pub trait PeripheralChannel<PERI, OP>: sealed::Channel {} |
| 45 | 40 | ||
| 46 | pub struct P2M; | 41 | pub struct P2M; |
| 47 | pub struct M2P; | 42 | pub struct M2P; |
| 48 | 43 | ||
| 49 | #[allow(unused)] | 44 | macro_rules! dma_num { |
| 50 | macro_rules! impl_dma_channel { | 45 | (DMA1) => { |
| 51 | ($channel_peri:ident, $dmamux_peri:ident, $channel_num:expr, $dma_peri: ident, $dma_num:expr) => { | 46 | 0 |
| 52 | impl Channel for peripherals::$channel_peri {} | 47 | }; |
| 53 | impl sealed::Channel for peripherals::$channel_peri { | 48 | (DMA2) => { |
| 54 | fn dmamux_regs(&self) -> pac::dmamux::Dmamux { | 49 | 1 |
| 55 | crate::pac::$dmamux_peri | 50 | }; |
| 56 | } | 51 | (BDMA) => { |
| 52 | 0 | ||
| 53 | }; | ||
| 54 | } | ||
| 57 | 55 | ||
| 58 | fn dmamux_ch_num(&self) -> u8 { | 56 | macro_rules! dmamux_peri { |
| 59 | ($dma_num * 8) + $channel_num | 57 | (DMA1) => { |
| 60 | } | 58 | crate::pac::DMAMUX1 |
| 61 | } | 59 | }; |
| 60 | (DMA2) => { | ||
| 61 | crate::pac::DMAMUX1 | ||
| 62 | }; | ||
| 63 | (BDMA) => { | ||
| 64 | crate::pac::DMAMUX1 | ||
| 62 | }; | 65 | }; |
| 63 | } | 66 | } |
| 64 | 67 | ||
| 65 | macro_rules! impl_dmamux { | 68 | #[allow(unused)] |
| 66 | ($peri:ident) => { | 69 | macro_rules! impl_dma_channel { |
| 67 | impl sealed::DmaMux for peripherals::$peri { | 70 | ($channel_peri:ident, $channel_num:expr, $dma_peri: ident) => { |
| 68 | fn regs() -> pac::dmamux::Dmamux { | 71 | impl Channel for peripherals::$channel_peri {} |
| 69 | pac::$peri | 72 | impl sealed::Channel for peripherals::$channel_peri { |
| 70 | } | 73 | const DMAMUX_CH_NUM: u8 = (dma_num!($dma_peri) * 8) + $channel_num; |
| 74 | const DMAMUX_REGS: pac::dmamux::Dmamux = dmamux_peri!($dma_peri); | ||
| 71 | } | 75 | } |
| 72 | impl DmaMux for peripherals::$peri {} | ||
| 73 | }; | 76 | }; |
| 74 | } | 77 | } |
| 75 | 78 | ||
| 76 | peripherals! { | 79 | peripherals! { |
| 77 | (bdma, DMA1) => { | 80 | (bdma, $peri:ident) => { |
| 78 | bdma_channels! { | 81 | bdma_channels! { |
| 79 | ($channel_peri:ident, DMA1, $channel_num:expr) => { | 82 | ($channel_peri:ident, $peri, $channel_num:expr) => { |
| 80 | impl_dma_channel!($channel_peri, DMAMUX1, $channel_num, DMA1, 0); | 83 | impl_dma_channel!($channel_peri, $channel_num, $peri); |
| 81 | }; | 84 | }; |
| 82 | } | 85 | } |
| 83 | }; | 86 | }; |
| 84 | (bdma, DMA2) => { | ||
| 85 | bdma_channels! { | ||
| 86 | ($channel_peri:ident, DMA2, $channel_num:expr) => { | ||
| 87 | impl_dma_channel!($channel_peri, DMAMUX1, $channel_num, DMA2, 1); | ||
| 88 | }; | ||
| 89 | } | ||
| 90 | }; | ||
| 91 | (bdma, BDMA) => { | ||
| 92 | bdma_channels! { | ||
| 93 | ($channel_peri:ident, BDMA, $channel_num:expr) => { | ||
| 94 | impl_dma_channel!($channel_peri, DMAMUX1, $channel_num, DMA2, 1); | ||
| 95 | }; | ||
| 96 | } | ||
| 97 | }; | ||
| 98 | (dmamux, DMAMUX1) => { | ||
| 99 | impl_dmamux!(DMAMUX1); | ||
| 100 | }; | ||
| 101 | } | 87 | } |
| 102 | 88 | ||
| 103 | #[allow(unused)] | 89 | #[allow(unused)] |
| @@ -106,9 +92,7 @@ macro_rules! impl_peripheral_channel { | |||
| 106 | impl sealed::PeripheralChannel<peripherals::$peri, $direction> | 92 | impl sealed::PeripheralChannel<peripherals::$peri, $direction> |
| 107 | for peripherals::$channel_peri | 93 | for peripherals::$channel_peri |
| 108 | { | 94 | { |
| 109 | fn request(&self) -> u8 { | 95 | const REQUEST: u8 = $request; |
| 110 | $request | ||
| 111 | } | ||
| 112 | } | 96 | } |
| 113 | 97 | ||
| 114 | impl PeripheralChannel<peripherals::$peri, $direction> for peripherals::$channel_peri {} | 98 | impl PeripheralChannel<peripherals::$peri, $direction> for peripherals::$channel_peri {} |
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index e7e3382f9..37254f6f0 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs | |||
| @@ -304,6 +304,11 @@ pub fn gen(options: Options) { | |||
| 304 | if let Some(block) = &p.block { | 304 | if let Some(block) = &p.block { |
| 305 | let bi = BlockInfo::parse(block); | 305 | let bi = BlockInfo::parse(block); |
| 306 | 306 | ||
| 307 | peripheral_counts.insert( | ||
| 308 | bi.module.clone(), | ||
| 309 | peripheral_counts.get(&bi.module).map_or(1, |v| v + 1), | ||
| 310 | ); | ||
| 311 | |||
| 307 | for pin in &p.pins { | 312 | for pin in &p.pins { |
| 308 | let mut row = Vec::new(); | 313 | let mut row = Vec::new(); |
| 309 | row.push(name.clone()); | 314 | row.push(name.clone()); |
