From d327eece0506e67692e7a5dcd21e3880494554b0 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Wed, 9 Oct 2024 19:12:40 +0300 Subject: [PATCH] Remap trait --- CHANGELOG.md | 3 +- src/afio.rs | 87 +++++++++++++++++++++++++++++++++++++++++- src/can.rs | 52 +++++++++++-------------- src/i2c.rs | 25 ++++++------- src/serial.rs | 102 +++++++++++++++++++++++++++----------------------- src/spi.rs | 67 +++++++++++++++------------------ 6 files changed, 209 insertions(+), 127 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 411cdfb2..5feee07a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Check "device selected" in `build.rs` [#502] - Use gpio field enums internally [#506] - Unmacro `dma.rs` [#505] -- Rework USART remap, +- Rework pin remaps, fix CAN1 remap [#511] ### Added @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). [#505]: https://github.com/stm32-rs/stm32f1xx-hal/pull/505 [#506]: https://github.com/stm32-rs/stm32f1xx-hal/pull/506 [#509]: https://github.com/stm32-rs/stm32f1xx-hal/pull/509 +[#511]: https://github.com/stm32-rs/stm32f1xx-hal/pull/511 ## [v0.10.0] - 2022-12-12 diff --git a/src/afio.rs b/src/afio.rs index 821fe0a4..d4e0b845 100644 --- a/src/afio.rs +++ b/src/afio.rs @@ -1,11 +1,12 @@ //! # Alternate Function I/Os -use crate::pac::{afio, AFIO, RCC}; +use crate::pac::{self, afio, AFIO, RCC}; use crate::rcc::{Enable, Reset}; use crate::gpio::{ Debugger, Floating, Input, PA15, {PB3, PB4}, }; +use crate::sealed::Sealed; pub trait AfioExt { fn constrain(self) -> Parts; @@ -150,4 +151,88 @@ impl MAPR2 { pub fn mapr2(&mut self) -> &afio::MAPR2 { unsafe { (*AFIO::ptr()).mapr2() } } + + pub fn modify_mapr(&mut self, mod_fn: F) + where + F: for<'w> FnOnce(&afio::mapr2::R, &'w mut afio::mapr2::W) -> &'w mut afio::mapr2::W, + { + self.mapr2().modify(|r, w| mod_fn(r, w)); + } +} + +pub trait Remap: Sealed { + type Mapr; + fn remap(mapr: &mut Self::Mapr, to: u8); +} + +macro_rules! remap { + ($( + $PER:ty: $MAPR:ident, $w:ident: $field:ident; + )+) => { + $( + remap!($PER: $MAPR, $w: $field); + )+ + }; + ($PER:ty: $MAPR:ident, bool: $field:ident) => { + impl Remap for $PER { + type Mapr = $MAPR; + fn remap(mapr: &mut Self::Mapr, to: u8) { + mapr.modify_mapr(|_, w| w.$field().bit(to != 0)); + } + } + }; + ($PER:ty: $MAPR:ident, u8: $field:ident) => { + impl Remap for $PER { + type Mapr = $MAPR; + fn remap(mapr: &mut Self::Mapr, to: u8) { + mapr.modify_mapr(|_, w| unsafe { w.$field().bits(to) }); + } + } + }; +} +use remap; + +remap! { + pac::SPI1: MAPR, bool: spi1_remap; + pac::I2C1: MAPR, bool: i2c1_remap; + pac::USART1: MAPR, bool: usart1_remap; + pac::USART2: MAPR, bool: usart2_remap; + pac::USART3: MAPR, u8: usart3_remap; + pac::TIM2: MAPR, u8: tim2_remap; + pac::TIM3: MAPR, u8: tim3_remap; +} + +#[cfg(feature = "medium")] +remap! { + pac::TIM4: MAPR, bool: tim4_remap; +} + +#[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity"))] +remap! { + pac::TIM1: MAPR, u8: tim1_remap; +} + +#[cfg(feature = "stm32f103")] +remap! { + pac::CAN1: MAPR, u8: can_remap; +} + +#[cfg(feature = "connectivity")] +remap! { + pac::CAN1: MAPR, u8: can1_remap; + //pac::ETHERNET_MAC: MAPR, bool: eth_remap; + pac::CAN2: MAPR, bool: can2_remap; + pac::SPI3: MAPR, bool: spi3_remap; +} + +#[cfg(feature = "xl")] +remap! { + pac::TIM9: MAPR2, bool: tim9_remap; + pac::TIM10: MAPR2, bool: tim10_remap; + pac::TIM11: MAPR2, bool: tim11_remap; +} +#[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high")))] +remap! { + pac::TIM13: MAPR2, bool: tim13_remap; + pac::TIM14: MAPR2, bool: tim14_remap; } diff --git a/src/can.rs b/src/can.rs index cf619424..1ddd5d9e 100644 --- a/src/can.rs +++ b/src/can.rs @@ -19,7 +19,7 @@ //! | TX | PB6 | PB13 | //! | RX | PB5 | PB12 | -use crate::afio::MAPR; +use crate::afio::Remap; use crate::gpio::{self, Alternate, Cr, Floating, Input, NoPin, PinMode, PullUp, PushPull}; use crate::pac::{self, RCC}; @@ -45,14 +45,10 @@ pub mod can1 { use super::*; remap! { - #[cfg(not(feature = "connectivity"))] - PA12, PA11 => { |_, w| unsafe { w.can_remap().bits(0) } }; - #[cfg(feature = "connectivity")] - PA12, PA11 => { |_, w| unsafe { w.can1_remap().bits(0) } }; - #[cfg(not(feature = "connectivity"))] - PB9, PB8 => { |_, w| unsafe { w.can_remap().bits(10) } }; - #[cfg(feature = "connectivity")] - PB9, PB8 => { |_, w| unsafe { w.can1_remap().bits(10) } }; + pac::CAN1: [ + PA12, PA11 => 0; + PB9, PB8 => 2; + ] } } @@ -61,70 +57,66 @@ pub mod can2 { use super::*; remap! { - PB6, PB5 => { |_, w| w.can2_remap().bit(false) }; - PB13, PB12 => { |_, w| w.can2_remap().bit(true) }; + pac::CAN2: [ + PB6, PB5 => 0; + PB13, PB12 => 1; + ] } } macro_rules! remap { - ($($(#[$attr:meta])* $TX:ident, $RX:ident => { $remapex:expr };)+) => { + ($PER:ty: [$($TX:ident, $RX:ident => $remap:literal;)+]) => { pub enum Tx { $( - $(#[$attr])* $TX(gpio::$TX), )+ None(NoPin), } pub enum Rx { $( - $(#[$attr])* $RX(gpio::$RX>), )+ None(NoPin), } $( - $(#[$attr])* - impl From<(gpio::$TX, gpio::$RX>, &mut MAPR)> for Pins> { - fn from(p: (gpio::$TX, gpio::$RX>, &mut MAPR)) -> Self { - p.2.modify_mapr($remapex); + impl From<(gpio::$TX, gpio::$RX>, &mut <$PER as Remap>::Mapr)> for Pins> { + fn from(p: (gpio::$TX, gpio::$RX>, &mut <$PER as Remap>::Mapr)) -> Self { + <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(p.0), rx: Rx::$RX(p.1) } } } - $(#[$attr])* - impl From<(gpio::$TX, gpio::$RX, &mut MAPR)> for Pins> + impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins> where Input: PinMode, PULL: InMode, { - fn from(p: (gpio::$TX, gpio::$RX, &mut MAPR)) -> Self { + fn from(p: (gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { let mut cr = Cr; let tx = p.0.into_mode(&mut cr); let rx = p.1.into_mode(&mut cr); - p.2.modify_mapr($remapex); + <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(tx), rx: Rx::$RX(rx) } } } - $(#[$attr])* - impl From<(gpio::$TX, &mut MAPR)> for Pins> { - fn from(p: (gpio::$TX, &mut MAPR)) -> Self { + impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins> { + fn from(p: (gpio::$TX, &mut <$PER as Remap>::Mapr)) -> Self { let tx = p.0.into_mode(&mut Cr); - p.1.modify_mapr($remapex); + <$PER>::remap(p.1, $remap); Self { tx: Tx::$TX(tx), rx: Rx::None(NoPin::new()) } } } - $(#[$attr])* - impl From<(gpio::$RX, &mut MAPR)> for Pins> + impl From<(gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins> where Input: PinMode, PULL: InMode, { - fn from(p: (gpio::$RX, &mut MAPR)) -> Self { + fn from(p: (gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { let rx = p.0.into_mode(&mut Cr); - p.1.modify_mapr($remapex); + <$PER>::remap(p.1, $remap); Self { tx: Tx::None(NoPin::new()), rx: Rx::$RX(rx) } } } diff --git a/src/i2c.rs b/src/i2c.rs index 4480241a..4ed73619 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -4,8 +4,9 @@ // parts of this code is based on // https://www.st.com/content/ccc/resource/technical/document/application_note/5d/ae/a3/6f/08/69/4e/9b/CD00209826.pdf/files/CD00209826.pdf/jcr:content/translations/en.CD00209826.pdf +use crate::afio::{Remap, MAPR}; use crate::gpio::{self, Alternate, Cr, OpenDrain}; -use crate::pac::{DWT, I2C1, I2C2, RCC}; +use crate::pac::{self, DWT, RCC}; use crate::rcc::{BusClock, Clocks, Enable, Reset}; use crate::time::{kHz, Hertz}; use core::ops::Deref; @@ -100,14 +101,12 @@ impl From<(SCL, SDA)> for Pins { } pub mod i2c1 { - use crate::afio::MAPR; - use super::*; remap! { - [ - PB6, PB7 => MAPR { |_, w| w.i2c1_remap().bit(false) }; - PB8, PB9 => MAPR { |_, w| w.i2c1_remap().bit(true) }; + pac::I2C1: [ + PB6, PB7 => MAPR: 0; + PB8, PB9 => MAPR: 1; ] } } @@ -115,15 +114,15 @@ pub mod i2c2 { use super::*; remap! { - [ + pac::I2C2: [ PB10, PB11; ] } } macro_rules! remap { - ([ - $($SCL:ident, $SDA:ident $( => $MAPR:ident { $remapex:expr })?;)+ + ($PER:ty: [ + $($SCL:ident, $SDA:ident $( => $MAPR:ident: $remap:literal)?;)+ ]) => { pub enum Scl { $( @@ -139,7 +138,7 @@ macro_rules! remap { $( impl From<(gpio::$SCL>, gpio::$SDA> $(, &mut $MAPR)?)> for Pins { fn from(p: (gpio::$SCL>, gpio::$SDA> $(, &mut $MAPR)?)) -> Self { - $(p.2.modify_mapr($remapex);)? + $(<$PER>::remap(p.2, $remap);)? Self { scl: Scl::$SCL(p.0), sda: Sda::$SDA(p.1) } } } @@ -149,7 +148,7 @@ macro_rules! remap { let mut cr = Cr; let scl = p.0.into_mode(&mut cr); let sda = p.1.into_mode(&mut cr); - $(p.2.modify_mapr($remapex);)? + $(<$PER>::remap(p.2, $remap);)? Self { scl: Scl::$SCL(scl), sda: Sda::$SDA(sda) } } } @@ -213,11 +212,11 @@ pub trait Instance: type Sda; } -impl Instance for I2C1 { +impl Instance for pac::I2C1 { type Scl = i2c1::Scl; type Sda = i2c1::Sda; } -impl Instance for I2C2 { +impl Instance for pac::I2C2 { type Scl = i2c2::Scl; type Sda = i2c2::Sda; } diff --git a/src/serial.rs b/src/serial.rs index 7cc5eaef..f1547787 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -66,10 +66,10 @@ use core::ops::Deref; use core::sync::atomic::{self, Ordering}; use embedded_dma::{ReadBuffer, WriteBuffer}; -use crate::afio::MAPR; +use crate::afio::Remap; use crate::dma::{dma1, CircBuffer, RxDma, Transfer, TxDma, R, W}; use crate::gpio::{self, Alternate, Cr, Floating, Input, NoPin, PinMode, PullUp, PushPull}; -use crate::pac::{RCC, USART1, USART2, USART3}; +use crate::pac::{self, RCC}; use crate::rcc::{BusClock, Clocks, Enable, Reset}; use crate::time::{Bps, U32Ext}; @@ -100,8 +100,10 @@ pub mod usart1 { use super::*; remap! { - PA9, PA10 => { |_, w| w.usart1_remap().bit(false) }; - PB6, PB7 => { |_, w| w.usart1_remap().bit(true) }; + pac::USART1: [ + PA9, PA10 => 0; + PB6, PB7 => 1; + ] } } @@ -109,8 +111,10 @@ pub mod usart2 { use super::*; remap! { - PA2, PA3 => { |_, w| w.usart2_remap().bit(false) }; - PD5, PD6 => { |_, w| w.usart2_remap().bit(true) }; + pac::USART2: [ + PA2, PA3 => 0; + PD5, PD6 => 1; + ] } } @@ -118,14 +122,16 @@ pub mod usart3 { use super::*; remap! { - PB10, PB11 => { |_, w| unsafe { w.usart3_remap().bits(0b00)} }; - PC10, PC11 => { |_, w| unsafe { w.usart3_remap().bits(0b01)} }; - PD8, PD9 => { |_, w| unsafe { w.usart3_remap().bits(0b11)} }; + pac::USART3: [ + PB10, PB11 => 0; + PC10, PC11 => 1; + PD8, PD9 => 3; + ] } } macro_rules! remap { - ($($TX:ident, $RX:ident => { $remapex:expr };)+) => { + ($PER:ty: [$($TX:ident, $RX:ident => $remap:literal;)+]) => { pub enum Tx { $( $TX(gpio::$TX>), @@ -140,52 +146,52 @@ macro_rules! remap { } $( - impl From<(gpio::$TX>, gpio::$RX>, &mut MAPR)> for Pins, Rx> { - fn from(p: (gpio::$TX>, gpio::$RX>, &mut MAPR)) -> Self { - p.2.modify_mapr($remapex); + impl From<(gpio::$TX>, gpio::$RX>, &mut <$PER as Remap>::Mapr)> for Pins, Rx> { + fn from(p: (gpio::$TX>, gpio::$RX>, &mut <$PER as Remap>::Mapr)) -> Self { + <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(p.0), rx: Rx::$RX(p.1) } } } - impl From<(gpio::$TX, gpio::$RX, &mut MAPR)> for Pins, Rx> + impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> where Alternate: PinMode, Input: PinMode, PULL: InMode, { - fn from(p: (gpio::$TX, gpio::$RX, &mut MAPR)) -> Self { + fn from(p: (gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { let mut cr = Cr; let tx = p.0.into_mode(&mut cr); let rx = p.1.into_mode(&mut cr); - p.2.modify_mapr($remapex); + <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(tx), rx: Rx::$RX(rx) } } } - impl From<(gpio::$TX>, &mut MAPR)> for Pins, Rx> { - fn from(p: (gpio::$TX>, &mut MAPR)) -> Self { - p.1.modify_mapr($remapex); + impl From<(gpio::$TX>, &mut <$PER as Remap>::Mapr)> for Pins, Rx> { + fn from(p: (gpio::$TX>, &mut <$PER as Remap>::Mapr)) -> Self { + <$PER>::remap(p.1, $remap); Self { tx: Tx::$TX(p.0), rx: Rx::None(NoPin::new()) } } } - impl From<(gpio::$TX, &mut MAPR)> for Pins, Rx> + impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> where Alternate: PinMode, { - fn from(p: (gpio::$TX, &mut MAPR)) -> Self { + fn from(p: (gpio::$TX, &mut <$PER as Remap>::Mapr)) -> Self { let tx = p.0.into_mode(&mut Cr); - p.1.modify_mapr($remapex); + <$PER>::remap(p.1, $remap); Self { tx: Tx::$TX(tx), rx: Rx::None(NoPin::new()) } } } - impl From<(gpio::$RX>, &mut MAPR)> for Pins, Rx> + impl From<(gpio::$RX>, &mut <$PER as Remap>::Mapr)> for Pins, Rx> where PULL: InMode, { - fn from(p: (gpio::$RX>, &mut MAPR)) -> Self { - p.1.modify_mapr($remapex); + fn from(p: (gpio::$RX>, &mut <$PER as Remap>::Mapr)) -> Self { + <$PER>::remap(p.1, $remap); Self { tx: Tx::None(NoPin::new()), rx: Rx::$RX(p.0) } } } @@ -243,7 +249,7 @@ pub trait Instance: } macro_rules! inst { - ($($USARTX:ident, $usart:ident;)+) => { + ($($USARTX:ty, $usart:ident;)+) => { $( impl Instance for $USARTX { type Tx = $usart::Tx; @@ -258,9 +264,9 @@ macro_rules! inst { } inst! { - USART1, usart1; - USART2, usart2; - USART3, usart3; + pac::USART1, usart1; + pac::USART2, usart2; + pac::USART3, usart3; } /// Serial error @@ -799,18 +805,18 @@ impl core::fmt::Write for Serial { } } -pub type Rx1 = Rx; -pub type Tx1 = Tx; -pub type Rx2 = Rx; -pub type Tx2 = Tx; -pub type Rx3 = Rx; -pub type Tx3 = Tx; +pub type Rx1 = Rx; +pub type Tx1 = Tx; +pub type Rx2 = Rx; +pub type Tx2 = Tx; +pub type Rx3 = Rx; +pub type Tx3 = Tx; use crate::dma::{Receive, TransferPayload, Transmit}; macro_rules! serialdma { ( - $USARTX:ident, + $USARTX:ty, $rxdma:ident, $txdma:ident, rx: $dmarxch:ty, @@ -850,7 +856,7 @@ macro_rules! serialdma { impl Rx<$USARTX> { pub fn with_dma(self, channel: $dmarxch) -> $rxdma { unsafe { - (*$USARTX::ptr()).cr3().modify(|_, w| w.dmar().set_bit()); + (*<$USARTX>::ptr()).cr3().modify(|_, w| w.dmar().set_bit()); } RxDma { payload: self, @@ -862,7 +868,7 @@ macro_rules! serialdma { impl Tx<$USARTX> { pub fn with_dma(self, channel: $dmatxch) -> $txdma { unsafe { - (*$USARTX::ptr()).cr3().modify(|_, w| w.dmat().set_bit()); + (*<$USARTX>::ptr()).cr3().modify(|_, w| w.dmat().set_bit()); } TxDma { payload: self, @@ -875,7 +881,9 @@ macro_rules! serialdma { pub fn release(mut self) -> (Rx<$USARTX>, $dmarxch) { self.stop(); unsafe { - (*$USARTX::ptr()).cr3().modify(|_, w| w.dmar().clear_bit()); + (*<$USARTX>::ptr()) + .cr3() + .modify(|_, w| w.dmar().clear_bit()); } let RxDma { payload, channel } = self; (payload, channel) @@ -886,7 +894,9 @@ macro_rules! serialdma { pub fn release(mut self) -> (Tx<$USARTX>, $dmatxch) { self.stop(); unsafe { - (*$USARTX::ptr()).cr3().modify(|_, w| w.dmat().clear_bit()); + (*<$USARTX>::ptr()) + .cr3() + .modify(|_, w| w.dmat().clear_bit()); } let TxDma { payload, channel } = self; (payload, channel) @@ -903,7 +913,7 @@ macro_rules! serialdma { // until the end of the transfer. let (ptr, len) = unsafe { buffer.write_buffer() }; self.channel.set_peripheral_address( - unsafe { (*$USARTX::ptr()).dr().as_ptr() as u32 }, + unsafe { (*<$USARTX>::ptr()).dr().as_ptr() as u32 }, false, ); self.channel.set_memory_address(ptr as u32, true); @@ -935,7 +945,7 @@ macro_rules! serialdma { // until the end of the transfer. let (ptr, len) = unsafe { buffer.write_buffer() }; self.channel.set_peripheral_address( - unsafe { (*$USARTX::ptr()).dr().as_ptr() as u32 }, + unsafe { (*<$USARTX>::ptr()).dr().as_ptr() as u32 }, false, ); self.channel.set_memory_address(ptr as u32, true); @@ -966,7 +976,7 @@ macro_rules! serialdma { let (ptr, len) = unsafe { buffer.read_buffer() }; self.channel.set_peripheral_address( - unsafe { (*$USARTX::ptr()).dr().as_ptr() as u32 }, + unsafe { (*<$USARTX>::ptr()).dr().as_ptr() as u32 }, false, ); @@ -992,21 +1002,21 @@ macro_rules! serialdma { } serialdma! { - USART1, + pac::USART1, RxDma1, TxDma1, rx: dma1::C5, tx: dma1::C4 } serialdma! { - USART2, + pac::USART2, RxDma2, TxDma2, rx: dma1::C6, tx: dma1::C7 } serialdma! { - USART3, + pac::USART3, RxDma3, TxDma3, rx: dma1::C3, diff --git a/src/spi.rs b/src/spi.rs index c585f5f0..67beaddc 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -41,7 +41,7 @@ use core::ptr; use crate::pac::{self, RCC}; -use crate::afio::MAPR; +use crate::afio::{Remap, MAPR}; use crate::dma::dma1; #[cfg(feature = "connectivity")] use crate::dma::dma2; @@ -123,8 +123,10 @@ pub mod spi1 { use super::*; remap! { - PA5, PA6, PA7 => MAPR { |_, w| w.spi1_remap().bit(false) }; - PB3, PB4, PB5 => MAPR { |_, w| w.spi1_remap().bit(true) }; + pac::SPI1: [ + PA5, PA6, PA7 => MAPR: 0; + PB3, PB4, PB5 => MAPR: 1; + ] } } @@ -132,30 +134,36 @@ pub mod spi2 { use super::*; remap! { - PB13, PB14, PB15; + pac::SPI2: [ + PB13, PB14, PB15; + ] } } #[cfg(any(feature = "high", feature = "connectivity"))] pub mod spi3 { use super::*; + #[cfg(not(feature = "connectivity"))] remap! { - #[cfg(not(feature = "connectivity"))] - PB3, PB4, PB5; - #[cfg(feature = "connectivity")] - PB3, PB4, PB5 => MAPR { |_, w| w.spi3_remap().bit(false) }; - #[cfg(feature = "connectivity")] - PC10, PC11, PC12 => MAPR { |_, w| w.spi3_remap().bit(true) }; + pac::SPI3: [ + PB3, PB4, PB5; + ] + } + #[cfg(feature = "connectivity")] + remap! { + pac::SPI3: [ + PB3, PB4, PB5 => MAPR: 0; + PC10, PC11, PC12 => MAPR: 1; + ] } } macro_rules! remap { - ( - $($(#[$attr:meta])* $SCK:ident, $MISO:ident, $MOSI:ident $( => $MAPR:ident { $remapex:expr })?;)+ - ) => { + ($PER:ty: [ + $($SCK:ident, $MISO:ident, $MOSI:ident $( => $MAPR:ident: $remap:literal)?;)+ + ]) => { pub enum Sck { $( - $(#[$attr])* $SCK(gpio::$SCK), )+ None(NoPin), @@ -163,7 +171,6 @@ macro_rules! remap { pub enum Mi { $( - $(#[$attr])* $MISO(gpio::$MISO>), )+ None(NoPin), @@ -171,7 +178,6 @@ macro_rules! remap { pub enum So { $( - $(#[$attr])* $MISO(gpio::$MISO>), )+ None(NoPin), @@ -179,7 +185,6 @@ macro_rules! remap { pub enum Mo { $( - $(#[$attr])* $MOSI(gpio::$MOSI), )+ None(NoPin), @@ -187,7 +192,6 @@ macro_rules! remap { pub enum Si { $( - $(#[$attr])* $MOSI(gpio::$MOSI>), )+ None(NoPin), @@ -195,15 +199,13 @@ macro_rules! remap { $( // For master mode - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MISO>, gpio::$MOSI $(, &mut $MAPR)?)> for MasterPins, Mo> { fn from(p: (gpio::$SCK, gpio::$MISO>, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { - $(p.3.modify_mapr($remapex);)? + $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(p.0), mi: Mi::$MISO(p.1), mo: Mo::$MOSI(p.2) } } } - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)> for MasterPins, Mo> where Input: PinMode, @@ -214,20 +216,18 @@ macro_rules! remap { let sck = p.0.into_mode(&mut cr); let miso = p.1.into_mode(&mut cr); let mosi = p.2.into_mode(&mut cr); - $(p.3.modify_mapr($remapex);)? + $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(sck), mi: Mi::$MISO(miso), mo: Mo::$MOSI(mosi) } } } - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MISO> $(, &mut $MAPR)?)> for MasterPins, Mo> { fn from(p: (gpio::$SCK, gpio::$MISO> $(, &mut $MAPR)?)) -> Self { - $(p.2.modify_mapr($remapex);)? + $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(p.0), mi: Mi::$MISO(p.1), mo: Mo::None(NoPin::new()) } } } - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)> for super::MasterPins, Mo> where Input: PinMode, @@ -237,33 +237,30 @@ macro_rules! remap { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); let miso = p.1.into_mode(&mut cr); - $(p.2.modify_mapr($remapex);)? + $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(sck), mi: Mi::$MISO(miso), mo: Mo::None(NoPin::new()) } } } - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)> for super::MasterPins, Mo> { fn from(p: (gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); let mosi = p.1.into_mode(&mut cr); - $(p.2.modify_mapr($remapex);)? + $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(sck), mi: Mi::None(NoPin::new()), mo: Mo::$MOSI(mosi) } } } // For slave mode - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MISO>, gpio::$MOSI> $(, &mut $MAPR)?)> for SlavePins, Si> { fn from(p: (gpio::$SCK, gpio::$MISO>, gpio::$MOSI> $(, &mut $MAPR)?)) -> Self { - $(p.3.modify_mapr($remapex);)? + $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(p.0), so: So::$MISO(p.1), si: Si::$MOSI(p.2) } } } - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)> for SlavePins, Si> where Alternate: PinMode, @@ -275,12 +272,11 @@ macro_rules! remap { let sck = p.0.into_mode(&mut cr); let miso = p.1.into_mode(&mut cr); let mosi = p.2.into_mode(&mut cr); - $(p.3.modify_mapr($remapex);)? + $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(sck), so: So::$MISO(miso), si: Si::$MOSI(mosi) } } } - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)> for SlavePins, Si> where Alternate: PinMode, @@ -289,12 +285,11 @@ macro_rules! remap { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); let miso = p.1.into_mode(&mut cr); - $(p.2.modify_mapr($remapex);)? + $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(sck), so: So::$MISO(miso), si: Si::None(NoPin::new()) } } } - $(#[$attr])* impl From<(gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)> for SlavePins, Si> where Input: PinMode, @@ -304,7 +299,7 @@ macro_rules! remap { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); let mosi = p.1.into_mode(&mut cr); - $(p.2.modify_mapr($remapex);)? + $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(sck), so: So::None(NoPin::new()), si: Si::$MOSI(mosi) } } }