From ead0ccc4facf8ae6db14635a3b5a62284da85ccb Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Sat, 10 Jul 2021 06:15:10 +0300 Subject: [PATCH] rename Pxx to EPin, Generic to PEPin --- src/gpio.rs | 65 +++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/gpio.rs b/src/gpio.rs index 130be89a..b2b2a38d 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -342,7 +342,7 @@ macro_rules! gpio { use core::marker::PhantomData; use crate::pac::$GPIOX; use crate::rcc::{APB2, Enable, Reset}; - use super::{Active, Floating, GpioExt, Input, Generic, Pxx, Pin, CRL, CRH, Cr}; + use super::{Active, Floating, GpioExt, Input, PEPin, EPin, Pin, CRL, CRH, Cr}; #[allow(unused)] use super::Debugger; @@ -379,9 +379,9 @@ macro_rules! gpio { } } - impl Generic { - pub fn downgrade(self) -> Pxx { - Pxx::$PXx(self) + impl PEPin { + pub fn erase(self) -> EPin { + EPin::$PXx(self) } } @@ -393,8 +393,8 @@ macro_rules! gpio { /// /// This is useful when you want to collect the pins into an array where you /// need all the elements to have the same type - pub fn downgrade(self) -> Pxx { - self.into_generic().downgrade() + pub fn erase(self) -> EPin { + self.erase_number().erase() } } } @@ -402,12 +402,12 @@ macro_rules! gpio { } /// Partially erased pin. Only used in the Pxx enum -pub struct Generic { +pub struct PEPin { i: u8, _mode: PhantomData, } -impl PinExt for Generic { +impl PinExt for PEPin { type Mode = MODE; #[inline(always)] @@ -420,7 +420,7 @@ impl PinExt for Generic { } } -impl OutputPin for Generic, P> { +impl OutputPin for PEPin, P> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { // NOTE(unsafe) atomic write to a stateless register @@ -439,7 +439,7 @@ impl OutputPin for Generic, P> { } } -impl InputPin for Generic, P> { +impl InputPin for PEPin, P> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|b| !b) @@ -451,7 +451,7 @@ impl InputPin for Generic, P> { } } -impl StatefulOutputPin for Generic, P> { +impl StatefulOutputPin for PEPin, P> { fn is_set_high(&self) -> Result { self.is_set_low().map(|b| !b) } @@ -462,9 +462,9 @@ impl StatefulOutputPin for Generic, P> { } } -impl toggleable::Default for Generic, P> {} +impl toggleable::Default for PEPin, P> {} -impl InputPin for Generic, P> { +impl InputPin for PEPin, P> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|b| !b) @@ -585,8 +585,8 @@ where { /// Erases the pin number from the type #[inline] - fn into_generic(self) -> Generic { - Generic { + pub fn erase_number(self) -> PEPin { + PEPin { i: N, _mode: PhantomData, } @@ -1057,84 +1057,85 @@ cr!(CRL, crl); macro_rules! impl_pxx { ($(($port_id:literal :: $pin:ident)),*) => { - pub enum Pxx { + /// Erased pin + pub enum EPin { $( - $pin(Generic) + $pin(PEPin) ),* } - impl PinExt for Pxx { + impl PinExt for EPin { type Mode = MODE; #[inline(always)] fn pin_id(&self) -> u8 { match self { - $(Pxx::$pin(pin) => pin.pin_id()),* + $(Self::$pin(pin) => pin.pin_id()),* } } #[inline(always)] fn port_id(&self) -> u8 { match self { - $(Pxx::$pin(pin) => pin.port_id()),* + $(Self::$pin(pin) => pin.port_id()),* } } } - impl OutputPin for Pxx> { + impl OutputPin for EPin> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Infallible> { match self { - $(Pxx::$pin(pin) => pin.set_high()),* + $(Self::$pin(pin) => pin.set_high()),* } } fn set_low(&mut self) -> Result<(), Infallible> { match self { - $(Pxx::$pin(pin) => pin.set_low()),* + $(Self::$pin(pin) => pin.set_low()),* } } } - impl StatefulOutputPin for Pxx> { + impl StatefulOutputPin for EPin> { fn is_set_high(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_set_high()),* + $(Self::$pin(pin) => pin.is_set_high()),* } } fn is_set_low(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_set_low()),* + $(Self::$pin(pin) => pin.is_set_low()),* } } } - impl InputPin for Pxx> { + impl InputPin for EPin> { type Error = Infallible; fn is_high(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_high()),* + $(Self::$pin(pin) => pin.is_high()),* } } fn is_low(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_low()),* + $(Self::$pin(pin) => pin.is_low()),* } } } - impl InputPin for Pxx> { + impl InputPin for EPin> { type Error = Infallible; fn is_high(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_high()),* + $(Self::$pin(pin) => pin.is_high()),* } } fn is_low(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_low()),* + $(Self::$pin(pin) => pin.is_low()),* } } }