@@ -133,9 +133,13 @@ impl<MODE> Pin<MODE> {
133133 unsafe { & * ptr }
134134 }
135135
136+ pub ( crate ) fn conf ( & self ) -> & gpio:: PIN_CNF {
137+ & self . block ( ) . pin_cnf [ self . pin ( ) as usize ]
138+ }
139+
136140 /// Convert the pin to be a floating input
137141 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| {
139143 w. dir ( ) . input ( ) ;
140144 w. input ( ) . connect ( ) ;
141145 w. pull ( ) . disabled ( ) ;
@@ -150,7 +154,7 @@ impl<MODE> Pin<MODE> {
150154 }
151155 }
152156 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| {
154158 w. dir ( ) . input ( ) ;
155159 w. input ( ) . connect ( ) ;
156160 w. pull ( ) . pullup ( ) ;
@@ -165,7 +169,7 @@ impl<MODE> Pin<MODE> {
165169 }
166170 }
167171 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| {
169173 w. dir ( ) . input ( ) ;
170174 w. input ( ) . connect ( ) ;
171175 w. pull ( ) . pulldown ( ) ;
@@ -192,7 +196,7 @@ impl<MODE> Pin<MODE> {
192196 Level :: High => pin. set_high ( ) . unwrap ( ) ,
193197 }
194198
195- self . block ( ) . pin_cnf [ self . pin ( ) as usize ] . write ( |w| {
199+ self . conf ( ) . write ( |w| {
196200 w. dir ( ) . output ( ) ;
197201 w. input ( ) . connect ( ) ; // AJM - hack for SPI
198202 w. pull ( ) . disabled ( ) ;
@@ -224,8 +228,7 @@ impl<MODE> Pin<MODE> {
224228 }
225229
226230 // 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| {
229232 w. dir ( ) . output ( ) ;
230233 w. input ( ) . disconnect ( ) ;
231234 w. pull ( ) . disabled ( ) ;
@@ -236,6 +239,20 @@ impl<MODE> Pin<MODE> {
236239
237240 pin
238241 }
242+
243+ /// Disconnects the pin.
244+ ///
245+ /// In disconnected mode the pin cannot be used as input or output.
246+ /// It is primarily useful to reduce power usage.
247+ pub fn into_disconnected ( self ) -> Pin < Disconnected > {
248+ // Reset value is disconnected.
249+ self . conf ( ) . reset ( ) ;
250+
251+ Pin {
252+ _mode : PhantomData ,
253+ pin_port : self . pin_port ,
254+ }
255+ }
239256}
240257
241258impl < MODE > InputPin for Pin < Input < MODE > > {
@@ -489,6 +506,19 @@ macro_rules! gpio {
489506 pin
490507 }
491508
509+ /// Disconnects the pin.
510+ ///
511+ /// In disconnected mode the pin cannot be used as input or output.
512+ /// It is primarily useful to reduce power usage.
513+ pub fn into_disconnected( self ) -> $PXi<Disconnected > {
514+ // Reset value is disconnected.
515+ unsafe { & ( * $PX:: ptr( ) ) . pin_cnf[ $i] } . reset( ) ;
516+
517+ $PXi {
518+ _mode: PhantomData ,
519+ }
520+ }
521+
492522 /// Degrade to a generic pin struct, which can be used with peripherals
493523 pub fn degrade( self ) -> Pin <MODE > {
494524 Pin :: new( $port_value, $i)
@@ -552,58 +582,58 @@ macro_rules! gpio {
552582// 32-bit GPIO port (P0)
553583// ===========================================================================
554584gpio ! ( P0 , p0, p0, Port :: Port0 , [
555- P0_00 : ( p0_00, 0 , Input < Disconnected > ) ,
556- P0_01 : ( p0_01, 1 , Input < Disconnected > ) ,
557- P0_02 : ( p0_02, 2 , Input < Disconnected > ) ,
558- P0_03 : ( p0_03, 3 , Input < Disconnected > ) ,
559- P0_04 : ( p0_04, 4 , Input < Disconnected > ) ,
560- P0_05 : ( p0_05, 5 , Input < Disconnected > ) ,
561- P0_06 : ( p0_06, 6 , Input < Disconnected > ) ,
562- P0_07 : ( p0_07, 7 , Input < Disconnected > ) ,
563- P0_08 : ( p0_08, 8 , Input < Disconnected > ) ,
564- P0_09 : ( p0_09, 9 , Input < Disconnected > ) ,
565- P0_10 : ( p0_10, 10 , Input < Disconnected > ) ,
566- P0_11 : ( p0_11, 11 , Input < Disconnected > ) ,
567- P0_12 : ( p0_12, 12 , Input < Disconnected > ) ,
568- P0_13 : ( p0_13, 13 , Input < Disconnected > ) ,
569- P0_14 : ( p0_14, 14 , Input < Disconnected > ) ,
570- P0_15 : ( p0_15, 15 , Input < Disconnected > ) ,
571- P0_16 : ( p0_16, 16 , Input < Disconnected > ) ,
572- P0_17 : ( p0_17, 17 , Input < Disconnected > ) ,
573- P0_18 : ( p0_18, 18 , Input < Disconnected > ) ,
574- P0_19 : ( p0_19, 19 , Input < Disconnected > ) ,
575- P0_20 : ( p0_20, 20 , Input < Disconnected > ) ,
576- P0_21 : ( p0_21, 21 , Input < Disconnected > ) ,
577- P0_22 : ( p0_22, 22 , Input < Disconnected > ) ,
578- P0_23 : ( p0_23, 23 , Input < Disconnected > ) ,
579- P0_24 : ( p0_24, 24 , Input < Disconnected > ) ,
580- P0_25 : ( p0_25, 25 , Input < Disconnected > ) ,
581- P0_26 : ( p0_26, 26 , Input < Disconnected > ) ,
582- P0_27 : ( p0_27, 27 , Input < Disconnected > ) ,
583- P0_28 : ( p0_28, 28 , Input < Disconnected > ) ,
584- P0_29 : ( p0_29, 29 , Input < Disconnected > ) ,
585- P0_30 : ( p0_30, 30 , Input < Disconnected > ) ,
586- P0_31 : ( p0_31, 31 , Input < Disconnected > ) ,
585+ P0_00 : ( p0_00, 0 , Disconnected ) ,
586+ P0_01 : ( p0_01, 1 , Disconnected ) ,
587+ P0_02 : ( p0_02, 2 , Disconnected ) ,
588+ P0_03 : ( p0_03, 3 , Disconnected ) ,
589+ P0_04 : ( p0_04, 4 , Disconnected ) ,
590+ P0_05 : ( p0_05, 5 , Disconnected ) ,
591+ P0_06 : ( p0_06, 6 , Disconnected ) ,
592+ P0_07 : ( p0_07, 7 , Disconnected ) ,
593+ P0_08 : ( p0_08, 8 , Disconnected ) ,
594+ P0_09 : ( p0_09, 9 , Disconnected ) ,
595+ P0_10 : ( p0_10, 10 , Disconnected ) ,
596+ P0_11 : ( p0_11, 11 , Disconnected ) ,
597+ P0_12 : ( p0_12, 12 , Disconnected ) ,
598+ P0_13 : ( p0_13, 13 , Disconnected ) ,
599+ P0_14 : ( p0_14, 14 , Disconnected ) ,
600+ P0_15 : ( p0_15, 15 , Disconnected ) ,
601+ P0_16 : ( p0_16, 16 , Disconnected ) ,
602+ P0_17 : ( p0_17, 17 , Disconnected ) ,
603+ P0_18 : ( p0_18, 18 , Disconnected ) ,
604+ P0_19 : ( p0_19, 19 , Disconnected ) ,
605+ P0_20 : ( p0_20, 20 , Disconnected ) ,
606+ P0_21 : ( p0_21, 21 , Disconnected ) ,
607+ P0_22 : ( p0_22, 22 , Disconnected ) ,
608+ P0_23 : ( p0_23, 23 , Disconnected ) ,
609+ P0_24 : ( p0_24, 24 , Disconnected ) ,
610+ P0_25 : ( p0_25, 25 , Disconnected ) ,
611+ P0_26 : ( p0_26, 26 , Disconnected ) ,
612+ P0_27 : ( p0_27, 27 , Disconnected ) ,
613+ P0_28 : ( p0_28, 28 , Disconnected ) ,
614+ P0_29 : ( p0_29, 29 , Disconnected ) ,
615+ P0_30 : ( p0_30, 30 , Disconnected ) ,
616+ P0_31 : ( p0_31, 31 , Disconnected ) ,
587617] ) ;
588618
589619// The p1 types are present in the p0 module generated from the
590620// svd, but we want to export them in a p1 module from this crate.
591621#[ cfg( any( feature = "52833" , feature = "52840" ) ) ]
592622gpio ! ( P1 , p0, p1, Port :: Port1 , [
593- P1_00 : ( p1_00, 0 , Input < Disconnected > ) ,
594- P1_01 : ( p1_01, 1 , Input < Disconnected > ) ,
595- P1_02 : ( p1_02, 2 , Input < Disconnected > ) ,
596- P1_03 : ( p1_03, 3 , Input < Disconnected > ) ,
597- P1_04 : ( p1_04, 4 , Input < Disconnected > ) ,
598- P1_05 : ( p1_05, 5 , Input < Disconnected > ) ,
599- P1_06 : ( p1_06, 6 , Input < Disconnected > ) ,
600- P1_07 : ( p1_07, 7 , Input < Disconnected > ) ,
601- P1_08 : ( p1_08, 8 , Input < Disconnected > ) ,
602- P1_09 : ( p1_09, 9 , Input < Disconnected > ) ,
603- P1_10 : ( p1_10, 10 , Input < Disconnected > ) ,
604- P1_11 : ( p1_11, 11 , Input < Disconnected > ) ,
605- P1_12 : ( p1_12, 12 , Input < Disconnected > ) ,
606- P1_13 : ( p1_13, 13 , Input < Disconnected > ) ,
607- P1_14 : ( p1_14, 14 , Input < Disconnected > ) ,
608- P1_15 : ( p1_15, 15 , Input < Disconnected > ) ,
623+ P1_00 : ( p1_00, 0 , Disconnected ) ,
624+ P1_01 : ( p1_01, 1 , Disconnected ) ,
625+ P1_02 : ( p1_02, 2 , Disconnected ) ,
626+ P1_03 : ( p1_03, 3 , Disconnected ) ,
627+ P1_04 : ( p1_04, 4 , Disconnected ) ,
628+ P1_05 : ( p1_05, 5 , Disconnected ) ,
629+ P1_06 : ( p1_06, 6 , Disconnected ) ,
630+ P1_07 : ( p1_07, 7 , Disconnected ) ,
631+ P1_08 : ( p1_08, 8 , Disconnected ) ,
632+ P1_09 : ( p1_09, 9 , Disconnected ) ,
633+ P1_10 : ( p1_10, 10 , Disconnected ) ,
634+ P1_11 : ( p1_11, 11 , Disconnected ) ,
635+ P1_12 : ( p1_12, 12 , Disconnected ) ,
636+ P1_13 : ( p1_13, 13 , Disconnected ) ,
637+ P1_14 : ( p1_14, 14 , Disconnected ) ,
638+ P1_15 : ( p1_15, 15 , Disconnected ) ,
609639] ) ;
0 commit comments