1
1
use super :: * ;
2
2
3
- pub use ErasedPin as AnyPin ;
3
+ pub use AnyPin as ErasedPin ;
4
4
5
5
/// Fully erased pin
6
6
///
7
7
/// `MODE` is one of the pin modes (see [Modes](crate::gpio#modes) section).
8
- pub struct ErasedPin < MODE > {
8
+ pub struct AnyPin < MODE > {
9
9
// Bits 0-3: Pin, Bits 4-7: Port
10
10
pin_port : u8 ,
11
11
_mode : PhantomData < MODE > ,
12
12
}
13
13
14
- impl < MODE > fmt:: Debug for ErasedPin < MODE > {
14
+ impl < MODE > fmt:: Debug for AnyPin < MODE > {
15
15
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
16
16
formatter. write_fmt ( format_args ! (
17
17
"P({}{})<{}>" ,
@@ -23,7 +23,7 @@ impl<MODE> fmt::Debug for ErasedPin<MODE> {
23
23
}
24
24
25
25
#[ cfg( feature = "defmt" ) ]
26
- impl < MODE > defmt:: Format for ErasedPin < MODE > {
26
+ impl < MODE > defmt:: Format for AnyPin < MODE > {
27
27
fn format ( & self , f : defmt:: Formatter ) {
28
28
defmt:: write!(
29
29
f,
@@ -35,7 +35,7 @@ impl<MODE> defmt::Format for ErasedPin<MODE> {
35
35
}
36
36
}
37
37
38
- impl < MODE > PinExt for ErasedPin < MODE > {
38
+ impl < MODE > PinExt for AnyPin < MODE > {
39
39
type Mode = MODE ;
40
40
41
41
#[ inline( always) ]
@@ -48,7 +48,7 @@ impl<MODE> PinExt for ErasedPin<MODE> {
48
48
}
49
49
}
50
50
51
- impl < MODE > ErasedPin < MODE > {
51
+ impl < MODE > AnyPin < MODE > {
52
52
pub ( crate ) fn from_pin_port ( pin_port : u8 ) -> Self {
53
53
Self {
54
54
pin_port,
@@ -93,23 +93,17 @@ impl<MODE> ErasedPin<MODE> {
93
93
}
94
94
}
95
95
96
- impl < MODE > ErasedPin < Output < MODE > > {
96
+ impl < MODE > AnyPin < Output < MODE > > {
97
97
/// Drives the pin high
98
98
#[ inline( always) ]
99
99
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 ( ) ) ;
102
101
}
103
102
104
103
/// Drives the pin low
105
104
#[ inline( always) ]
106
105
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 ( ) ) ;
113
107
}
114
108
115
109
/// Is the pin in drive high or low mode?
@@ -140,7 +134,7 @@ impl<MODE> ErasedPin<Output<MODE>> {
140
134
/// Is the pin in drive low mode?
141
135
#[ inline( always) ]
142
136
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 ( )
144
138
}
145
139
146
140
/// Toggle pin output
@@ -154,7 +148,7 @@ impl<MODE> ErasedPin<Output<MODE>> {
154
148
}
155
149
}
156
150
157
- impl < MODE > ErasedPin < MODE >
151
+ impl < MODE > AnyPin < MODE >
158
152
where
159
153
MODE : marker:: Readable ,
160
154
{
@@ -167,6 +161,6 @@ where
167
161
/// Is the input pin low?
168
162
#[ inline( always) ]
169
163
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 ( )
171
165
}
172
166
}
0 commit comments