@@ -133,9 +133,13 @@ impl<MODE> Pin<MODE> {
133
133
unsafe { & * ptr }
134
134
}
135
135
136
+ pub ( crate ) fn conf ( & self ) -> & gpio:: PIN_CNF {
137
+ & self . block ( ) . pin_cnf [ self . pin ( ) as usize ]
138
+ }
139
+
136
140
/// Convert the pin to be a floating input
137
141
pub fn into_floating_input ( self ) -> Pin < Input < Floating > > {
138
- self . block ( ) . pin_cnf [ self . pin ( ) as usize ] . write ( |w| {
142
+ self . conf ( ) . write ( |w| {
139
143
w. dir ( ) . input ( ) ;
140
144
w. input ( ) . connect ( ) ;
141
145
w. pull ( ) . disabled ( ) ;
@@ -150,7 +154,7 @@ impl<MODE> Pin<MODE> {
150
154
}
151
155
}
152
156
pub fn into_pullup_input ( self ) -> Pin < Input < PullUp > > {
153
- self . block ( ) . pin_cnf [ self . pin ( ) as usize ] . write ( |w| {
157
+ self . conf ( ) . write ( |w| {
154
158
w. dir ( ) . input ( ) ;
155
159
w. input ( ) . connect ( ) ;
156
160
w. pull ( ) . pullup ( ) ;
@@ -165,7 +169,7 @@ impl<MODE> Pin<MODE> {
165
169
}
166
170
}
167
171
pub fn into_pulldown_input ( self ) -> Pin < Input < PullDown > > {
168
- self . block ( ) . pin_cnf [ self . pin ( ) as usize ] . write ( |w| {
172
+ self . conf ( ) . write ( |w| {
169
173
w. dir ( ) . input ( ) ;
170
174
w. input ( ) . connect ( ) ;
171
175
w. pull ( ) . pulldown ( ) ;
@@ -192,7 +196,7 @@ impl<MODE> Pin<MODE> {
192
196
Level :: High => pin. set_high ( ) . unwrap ( ) ,
193
197
}
194
198
195
- self . block ( ) . pin_cnf [ self . pin ( ) as usize ] . write ( |w| {
199
+ self . conf ( ) . write ( |w| {
196
200
w. dir ( ) . output ( ) ;
197
201
w. input ( ) . connect ( ) ; // AJM - hack for SPI
198
202
w. pull ( ) . disabled ( ) ;
@@ -224,8 +228,7 @@ impl<MODE> Pin<MODE> {
224
228
}
225
229
226
230
// This is safe, as we restrict our access to the dedicated register for this pin.
227
- let pin_cnf = & self . block ( ) . pin_cnf [ self . pin ( ) as usize ] ;
228
- pin_cnf. write ( |w| {
231
+ self . conf ( ) . write ( |w| {
229
232
w. dir ( ) . output ( ) ;
230
233
w. input ( ) . disconnect ( ) ;
231
234
w. pull ( ) . disabled ( ) ;
@@ -243,7 +246,7 @@ impl<MODE> Pin<MODE> {
243
246
/// It is primarily useful to reduce power usage.
244
247
pub fn into_disconnected ( self ) -> Pin < Disconnected > {
245
248
// Reset value is disconnected.
246
- self . block ( ) . pin_cnf [ self . pin ( ) as usize ] . reset ( ) ;
249
+ self . conf ( ) . reset ( ) ;
247
250
248
251
Pin {
249
252
_mode : PhantomData ,
0 commit comments