@@ -79,41 +79,82 @@ pub trait GpioErrorType {
7979 type Error : GpioError ;
8080}
8181
82+ /// Type used to represent pin masks
83+ pub trait PinMask : Copy + core:: fmt:: Debug {
84+ /// Create an empty mask (no pins selected)
85+ fn empty ( ) -> Self ;
86+
87+ /// Create a mask with all pins selected
88+ fn all ( ) -> Self ;
89+
90+ /// Check if the mask is empty
91+ fn is_empty ( & self ) -> bool ;
92+
93+ /// Check if the mask contains the specified pins
94+ fn contains ( & self , other : Self ) -> bool ;
95+
96+ /// Merge two masks
97+ fn union ( & self , other : Self ) -> Self ;
98+
99+ /// Get intersection of two masks
100+ fn intersection ( & self , other : Self ) -> Self ;
101+
102+ /// Toggle pins in mask
103+ fn toggle ( & self ) -> Self ;
104+ }
105+
82106/// Base trait for GPIO port operations with integrated error handling
83107pub trait GpioPort : GpioErrorType {
84108 /// Configuration type for GPIO pins
85109 type Config ;
86110
111+ /// Mask type for pin identification
112+ type Mask : PinMask ;
113+
87114 /// Configure GPIO pins with specified configuration
88- fn configure ( & mut self , pins : u32 , config : Self :: Config ) -> Result < ( ) , Self :: Error > ;
115+ fn configure ( & mut self , pins : Self :: Mask , config : Self :: Config ) -> Result < ( ) , Self :: Error > ;
89116
90117 /// Set and clear pins atomically using set and reset masks
91- fn set_reset ( & mut self , set_mask : u32 , reset_mask : u32 ) -> Result < ( ) , Self :: Error > ;
118+ fn set_reset (
119+ & mut self ,
120+ set_mask : Self :: Mask ,
121+ reset_mask : Self :: Mask ,
122+ ) -> Result < ( ) , Self :: Error > ;
92123
93124 /// Read current state of input pins
94- fn read_input ( & self ) -> Result < u32 , Self :: Error > ;
125+ fn read_input ( & self ) -> Result < Self :: Mask , Self :: Error > ;
95126
96127 /// Toggle specified output pins
97- fn toggle ( & mut self , pins : u32 ) -> Result < ( ) , Self :: Error > ;
128+ fn toggle ( & mut self , pins : Self :: Mask ) -> Result < ( ) , Self :: Error > ;
98129}
99130
100131/// Trait for GPIO interrupt capabilities with integrated error handling
101132pub trait GpioInterrupt : GpioErrorType {
133+ /// Mask type for pin identification
134+ type Mask : PinMask ;
135+
102136 /// Configure interrupt sensitivity for specified pins
103- fn irq_configure ( & mut self , mask : u32 , sensitivity : EdgeSensitivity )
104- -> Result < ( ) , Self :: Error > ;
137+ fn irq_configure (
138+ & mut self ,
139+ mask : Self :: Mask ,
140+ sensitivity : EdgeSensitivity ,
141+ ) -> Result < ( ) , Self :: Error > ;
105142
106143 /// Control interrupt operations (enable, disable, etc.)
107144 fn irq_control (
108145 & mut self ,
109- mask : u32 ,
146+ mask : Self :: Mask ,
110147 operation : InterruptOperation ,
111148 ) -> Result < bool , Self :: Error > ;
112149
113150 /// Register a callback for interrupt handling
114- fn register_interrupt_handler < F > ( & mut self , mask : u32 , handler : F ) -> Result < ( ) , Self :: Error >
151+ fn register_interrupt_handler < F > (
152+ & mut self ,
153+ mask : Self :: Mask ,
154+ handler : F ,
155+ ) -> Result < ( ) , Self :: Error >
115156 where
116- F : FnMut ( u32 ) + Send + ' static ;
157+ F : FnMut ( Self :: Mask ) + Send + ' static ;
117158}
118159
119160/// Trait for splitting a GPIO port into individual pins
0 commit comments