@@ -276,34 +276,29 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
276
276
}
277
277
278
278
/// Configures the pin to operate as a input pin
279
- pub fn into_input ( mut self ) -> Pin < P , N , Input > {
280
- self . mode :: < Input > ( ) ;
281
- Pin :: new ( )
279
+ pub fn into_input ( self ) -> Pin < P , N , Input > {
280
+ self . into_mode ( )
282
281
}
283
282
284
283
/// Configures the pin to operate as a floating input pin
285
- pub fn into_floating_input ( mut self ) -> Pin < P , N , Input > {
286
- self . mode :: < Input > ( ) ;
287
- Pin :: new ( ) . _internal_resistor ( Pull :: None )
284
+ pub fn into_floating_input ( self ) -> Pin < P , N , Input > {
285
+ self . into_mode ( ) . _internal_resistor ( Pull :: None )
288
286
}
289
287
290
288
/// Configures the pin to operate as a pulled down input pin
291
- pub fn into_pull_down_input ( mut self ) -> Pin < P , N , Input > {
292
- self . mode :: < Input > ( ) ;
293
- Pin :: new ( ) . _internal_resistor ( Pull :: Down )
289
+ pub fn into_pull_down_input ( self ) -> Pin < P , N , Input > {
290
+ self . into_mode ( ) . _internal_resistor ( Pull :: Down )
294
291
}
295
292
296
293
/// Configures the pin to operate as a pulled up input pin
297
- pub fn into_pull_up_input ( mut self ) -> Pin < P , N , Input > {
298
- self . mode :: < Input > ( ) ;
299
- Pin :: new ( ) . _internal_resistor ( Pull :: Up )
294
+ pub fn into_pull_up_input ( self ) -> Pin < P , N , Input > {
295
+ self . into_mode ( ) . _internal_resistor ( Pull :: Up )
300
296
}
301
297
302
298
/// Configures the pin to operate as an open drain output pin
303
299
/// Initial state will be low.
304
- pub fn into_open_drain_output ( mut self ) -> Pin < P , N , Output < OpenDrain > > {
305
- self . mode :: < Output < OpenDrain > > ( ) ;
306
- Pin :: new ( )
300
+ pub fn into_open_drain_output ( self ) -> Pin < P , N , Output < OpenDrain > > {
301
+ self . into_mode ( )
307
302
}
308
303
309
304
/// Configures the pin to operate as an open-drain output pin.
@@ -313,16 +308,14 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
313
308
initial_state : PinState ,
314
309
) -> Pin < P , N , Output < OpenDrain > > {
315
310
self . _set_state ( initial_state) ;
316
- self . mode :: < Output < OpenDrain > > ( ) ;
317
- Pin :: new ( )
311
+ self . into_mode ( )
318
312
}
319
313
320
314
/// Configures the pin to operate as an push pull output pin
321
315
/// Initial state will be low.
322
316
pub fn into_push_pull_output ( mut self ) -> Pin < P , N , Output < PushPull > > {
323
317
self . _set_low ( ) ;
324
- self . mode :: < Output < PushPull > > ( ) ;
325
- Pin :: new ( )
318
+ self . into_mode ( )
326
319
}
327
320
328
321
/// Configures the pin to operate as an push-pull output pin.
@@ -332,14 +325,12 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
332
325
initial_state : PinState ,
333
326
) -> Pin < P , N , Output < PushPull > > {
334
327
self . _set_state ( initial_state) ;
335
- self . mode :: < Output < PushPull > > ( ) ;
336
- Pin :: new ( )
328
+ self . into_mode ( )
337
329
}
338
330
339
331
/// Configures the pin to operate as an analog input pin
340
- pub fn into_analog ( mut self ) -> Pin < P , N , Analog > {
341
- self . mode :: < Analog > ( ) ;
342
- Pin :: new ( )
332
+ pub fn into_analog ( self ) -> Pin < P , N , Analog > {
333
+ self . into_mode ( )
343
334
}
344
335
345
336
/// Configures the pin as a pin that can change between input
@@ -375,6 +366,12 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
375
366
. modify ( |r, w| w. bits ( ( r. bits ( ) & !( 0b11 << offset) ) | ( M :: MODER << offset) ) ) ;
376
367
}
377
368
}
369
+
370
+ #[ inline( always) ]
371
+ pub ( super ) fn into_mode < M : PinMode > ( mut self ) -> Pin < P , N , M > {
372
+ self . mode :: < M > ( ) ;
373
+ Pin :: new ( )
374
+ }
378
375
}
379
376
380
377
impl < const P : char , const N : u8 , MODE > Pin < P , N , MODE >
@@ -401,7 +398,7 @@ where
401
398
///
402
399
/// The closure `f` is called with the reconfigured pin. After it returns,
403
400
/// the pin will be configured back.
404
- pub fn with_floating_input < R > ( & mut self , f : impl FnOnce ( & mut Pin < P , N , Input > ) -> R ) -> R {
401
+ pub fn with_input < R > ( & mut self , f : impl FnOnce ( & mut Pin < P , N , Input > ) -> R ) -> R {
405
402
self . with_mode ( f)
406
403
}
407
404
0 commit comments