26
26
//! - **Dynamic**: Pin mode is selected at runtime. See changing configurations for more details
27
27
//! - Input
28
28
//! - **PullUp**: Input connected to high with a weak pull-up resistor. Will be high when nothing
29
- //! is connected
29
+ //! is connected
30
30
//! - **PullDown**: Input connected to ground with a weak pull-down resistor. Will be low when nothing
31
- //! is connected
31
+ //! is connected
32
32
//! - **Floating**: Input not pulled to high or low. Will be undefined when nothing is connected
33
33
//! - Output
34
34
//! - **PushPull**: Output which either drives the pin high or low
35
35
//! - **OpenDrain**: Output which leaves the gate floating, or pulls it to ground in drain
36
- //! mode. Can be used as an input in the `open` configuration
36
+ //! mode. Can be used as an input in the `open` configuration
37
37
//! - **Debugger**: Some pins start out being used by the debugger. A pin in this mode can only be
38
- //! used if the [JTAG peripheral has been turned off](#accessing-pa15-pb3-and-pb14).
38
+ //! used if the [JTAG peripheral has been turned off](#accessing-pa15-pb3-and-pb14).
39
39
//!
40
40
//! ## Changing modes
41
41
//! The simplest way to change the pin mode is to use the `into_<mode>` functions. These return a
@@ -215,7 +215,7 @@ mod sealed {
215
215
}
216
216
217
217
use sealed:: Interruptable ;
218
- use sealed:: PinMode ;
218
+ pub ( crate ) use sealed:: PinMode ;
219
219
220
220
impl < MODE > Interruptable for Input < MODE > { }
221
221
impl Interruptable for Dynamic { }
@@ -639,43 +639,38 @@ where
639
639
/// pin.
640
640
#[ inline]
641
641
pub fn into_alternate_push_pull (
642
- mut self ,
642
+ self ,
643
643
cr : & mut <Self as HL >:: Cr ,
644
644
) -> Pin < P , N , Alternate < PushPull > > {
645
- self . mode :: < Alternate < PushPull > > ( cr) ;
646
- Pin :: new ( )
645
+ self . into_mode ( cr)
647
646
}
648
647
649
648
/// Configures the pin to operate as an alternate function open-drain output
650
649
/// pin.
651
650
#[ inline]
652
651
pub fn into_alternate_open_drain (
653
- mut self ,
652
+ self ,
654
653
cr : & mut <Self as HL >:: Cr ,
655
654
) -> Pin < P , N , Alternate < OpenDrain > > {
656
- self . mode :: < Alternate < OpenDrain > > ( cr) ;
657
- Pin :: new ( )
655
+ self . into_mode ( cr)
658
656
}
659
657
660
658
/// Configures the pin to operate as a floating input pin
661
659
#[ inline]
662
- pub fn into_floating_input ( mut self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Input < Floating > > {
663
- self . mode :: < Input < Floating > > ( cr) ;
664
- Pin :: new ( )
660
+ pub fn into_floating_input ( self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Input < Floating > > {
661
+ self . into_mode ( cr)
665
662
}
666
663
667
664
/// Configures the pin to operate as a pulled down input pin
668
665
#[ inline]
669
- pub fn into_pull_down_input ( mut self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Input < PullDown > > {
670
- self . mode :: < Input < PullDown > > ( cr) ;
671
- Pin :: new ( )
666
+ pub fn into_pull_down_input ( self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Input < PullDown > > {
667
+ self . into_mode ( cr)
672
668
}
673
669
674
670
/// Configures the pin to operate as a pulled up input pin
675
671
#[ inline]
676
- pub fn into_pull_up_input ( mut self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Input < PullUp > > {
677
- self . mode :: < Input < PullUp > > ( cr) ;
678
- Pin :: new ( )
672
+ pub fn into_pull_up_input ( self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Input < PullUp > > {
673
+ self . into_mode ( cr)
679
674
}
680
675
681
676
/// Configures the pin to operate as an open-drain output pin.
@@ -694,8 +689,7 @@ where
694
689
initial_state : PinState ,
695
690
) -> Pin < P , N , Output < OpenDrain > > {
696
691
self . _set_state ( initial_state) ;
697
- self . mode :: < Output < OpenDrain > > ( cr) ;
698
- Pin :: new ( )
692
+ self . into_mode ( cr)
699
693
}
700
694
701
695
/// Configures the pin to operate as an push-pull output pin.
@@ -714,26 +708,23 @@ where
714
708
initial_state : PinState ,
715
709
) -> Pin < P , N , Output < PushPull > > {
716
710
self . _set_state ( initial_state) ;
717
- self . mode :: < Output < PushPull > > ( cr) ;
718
- Pin :: new ( )
711
+ self . into_mode ( cr)
719
712
}
720
713
721
714
/// Configures the pin to operate as an push-pull output pin.
722
715
/// The state will not be changed.
723
716
#[ inline]
724
717
pub fn into_push_pull_output_with_current_state (
725
- mut self ,
718
+ self ,
726
719
cr : & mut <Self as HL >:: Cr ,
727
720
) -> Pin < P , N , Output < PushPull > > {
728
- self . mode :: < Output < PushPull > > ( cr) ;
729
- Pin :: new ( )
721
+ self . into_mode ( cr)
730
722
}
731
723
732
724
/// Configures the pin to operate as an analog input pin
733
725
#[ inline]
734
- pub fn into_analog ( mut self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Analog > {
735
- self . mode :: < Analog > ( cr) ;
736
- Pin :: new ( )
726
+ pub fn into_analog ( self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , Analog > {
727
+ self . into_mode ( cr)
737
728
}
738
729
739
730
/// Configures the pin as a pin that can change between input
@@ -977,6 +968,12 @@ where
977
968
( r_bits & !( 0b1111 << Self :: OFFSET ) ) | ( bits << Self :: OFFSET )
978
969
} ) ;
979
970
}
971
+
972
+ #[ inline]
973
+ pub ( crate ) fn into_mode < MODE : PinMode > ( mut self , cr : & mut <Self as HL >:: Cr ) -> Pin < P , N , MODE > {
974
+ self . mode :: < MODE > ( cr) ;
975
+ Pin :: new ( )
976
+ }
980
977
}
981
978
982
979
gpio ! ( GPIOA , gpioa, PAx , 'A' , [
0 commit comments