3434
3535use crate :: { iomuxc, ral} ;
3636
37+ pub use crate :: PinPortIncompatibleError ;
38+
3739/// Any GPIO instance.
3840type AnyInstance = crate :: AnyInstance < ral:: gpio:: RegisterBlock > ;
3941
40- /// Error returned when a pin is not compatible with a GPIO port.
41- #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
42- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
43- pub struct PinPortIncompatibleError ( ( ) ) ;
44-
4542/// GPIO ports.
4643pub struct Port {
4744 gpio : AnyInstance ,
@@ -68,12 +65,16 @@ impl Port {
6865 ///
6966 /// Returns an error if the pin is not compatible with this GPIO port
7067 /// (i.e., the pin's GPIO module number does not match the port's instance).
71- pub fn output < P , const N : u8 > ( & mut self , mut pin : P ) -> Result < Output , PinPortIncompatibleError >
68+ /// The pin is returned inside the error so you can recover it.
69+ pub fn output < P , const N : u8 > (
70+ & mut self ,
71+ mut pin : P ,
72+ ) -> Result < Output , PinPortIncompatibleError < P > >
7273 where
7374 P : iomuxc:: gpio:: Pin < N > ,
7475 {
7576 if N != self . instance ( ) {
76- return Err ( PinPortIncompatibleError ( ( ) ) ) ;
77+ return Err ( PinPortIncompatibleError ( pin ) ) ;
7778 }
7879 iomuxc:: gpio:: prepare ( & mut pin) ;
7980 Ok ( Output :: new ( self . duplicate_instance ( ) , P :: OFFSET ) )
@@ -83,12 +84,16 @@ impl Port {
8384 ///
8485 /// Returns an error if the pin is not compatible with this GPIO port
8586 /// (i.e., the pin's GPIO module number does not match the port's instance).
86- pub fn input < P , const N : u8 > ( & mut self , mut pin : P ) -> Result < Input , PinPortIncompatibleError >
87+ /// The pin is returned inside the error so you can recover it.
88+ pub fn input < P , const N : u8 > (
89+ & mut self ,
90+ mut pin : P ,
91+ ) -> Result < Input , PinPortIncompatibleError < P > >
8792 where
8893 P : iomuxc:: gpio:: Pin < N > ,
8994 {
9095 if N != self . instance ( ) {
91- return Err ( PinPortIncompatibleError ( ( ) ) ) ;
96+ return Err ( PinPortIncompatibleError ( pin ) ) ;
9297 }
9398 iomuxc:: gpio:: prepare ( & mut pin) ;
9499 Ok ( Input :: new ( self . duplicate_instance ( ) , P :: OFFSET ) )
@@ -107,7 +112,7 @@ impl Port {
107112 & mut self ,
108113 input : & Input ,
109114 trigger : Option < Trigger > ,
110- ) -> Result < ( ) , PinPortIncompatibleError > {
115+ ) -> Result < ( ) , PinPortIncompatibleError < ( ) > > {
111116 if !crate :: is_same_instance ( & self . gpio , & input. gpio ) {
112117 return Err ( PinPortIncompatibleError ( ( ) ) ) ;
113118 }
0 commit comments