11use super :: * ;
22
3- pub use ErasedPin as AnyPin ;
3+ pub use AnyPin as ErasedPin ;
44
55/// Fully erased pin
66///
77/// `MODE` is one of the pin modes (see [Modes](crate::gpio#modes) section).
8- pub struct ErasedPin < MODE > {
8+ pub struct AnyPin < MODE > {
99 // Bits 0-3: Pin, Bits 4-7: Port
1010 pin_port : u8 ,
1111 _mode : PhantomData < MODE > ,
1212}
1313
14- impl < MODE > fmt:: Debug for ErasedPin < MODE > {
14+ impl < MODE > fmt:: Debug for AnyPin < MODE > {
1515 fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
1616 formatter. write_fmt ( format_args ! (
1717 "P({}{})<{}>" ,
@@ -23,7 +23,7 @@ impl<MODE> fmt::Debug for ErasedPin<MODE> {
2323}
2424
2525#[ cfg( feature = "defmt" ) ]
26- impl < MODE > defmt:: Format for ErasedPin < MODE > {
26+ impl < MODE > defmt:: Format for AnyPin < MODE > {
2727 fn format ( & self , f : defmt:: Formatter ) {
2828 defmt:: write!(
2929 f,
@@ -35,7 +35,7 @@ impl<MODE> defmt::Format for ErasedPin<MODE> {
3535 }
3636}
3737
38- impl < MODE > PinExt for ErasedPin < MODE > {
38+ impl < MODE > PinExt for AnyPin < MODE > {
3939 type Mode = MODE ;
4040
4141 #[ inline( always) ]
@@ -48,7 +48,7 @@ impl<MODE> PinExt for ErasedPin<MODE> {
4848 }
4949}
5050
51- impl < MODE > ErasedPin < MODE > {
51+ impl < MODE > AnyPin < MODE > {
5252 pub ( crate ) fn from_pin_port ( pin_port : u8 ) -> Self {
5353 Self {
5454 pin_port,
@@ -93,23 +93,17 @@ impl<MODE> ErasedPin<MODE> {
9393 }
9494}
9595
96- impl < MODE > ErasedPin < Output < MODE > > {
96+ impl < MODE > AnyPin < Output < MODE > > {
9797 /// Drives the pin high
9898 #[ inline( always) ]
9999 pub fn set_high ( & mut self ) {
100- // NOTE(unsafe) atomic write to a stateless register
101- unsafe { self . block ( ) . bsrr ( ) . write ( |w| w. bits ( 1 << self . pin_id ( ) ) ) } ;
100+ self . block ( ) . bsrr ( ) . write ( |w| w. bs ( self . pin_id ( ) ) . set_bit ( ) ) ;
102101 }
103102
104103 /// Drives the pin low
105104 #[ inline( always) ]
106105 pub fn set_low ( & mut self ) {
107- // NOTE(unsafe) atomic write to a stateless register
108- unsafe {
109- self . block ( )
110- . bsrr ( )
111- . write ( |w| w. bits ( 1 << ( self . pin_id ( ) + 16 ) ) )
112- } ;
106+ self . block ( ) . bsrr ( ) . write ( |w| w. br ( self . pin_id ( ) ) . set_bit ( ) ) ;
113107 }
114108
115109 /// Is the pin in drive high or low mode?
@@ -140,7 +134,7 @@ impl<MODE> ErasedPin<Output<MODE>> {
140134 /// Is the pin in drive low mode?
141135 #[ inline( always) ]
142136 pub fn is_set_low ( & self ) -> bool {
143- self . block ( ) . odr ( ) . read ( ) . bits ( ) & ( 1 << self . pin_id ( ) ) == 0
137+ self . block ( ) . odr ( ) . read ( ) . odr ( self . pin_id ( ) ) . bit_is_clear ( )
144138 }
145139
146140 /// Toggle pin output
@@ -154,7 +148,7 @@ impl<MODE> ErasedPin<Output<MODE>> {
154148 }
155149}
156150
157- impl < MODE > ErasedPin < MODE >
151+ impl < MODE > AnyPin < MODE >
158152where
159153 MODE : marker:: Readable ,
160154{
@@ -167,6 +161,6 @@ where
167161 /// Is the input pin low?
168162 #[ inline( always) ]
169163 pub fn is_low ( & self ) -> bool {
170- self . block ( ) . idr ( ) . read ( ) . bits ( ) & ( 1 << self . pin_id ( ) ) == 0
164+ self . block ( ) . idr ( ) . read ( ) . idr ( self . pin_id ( ) ) . bit_is_clear ( )
171165 }
172166}
0 commit comments