@@ -81,6 +81,15 @@ pub struct PushPull;
81
81
/// Analog mode (type state)
82
82
pub struct Analog ;
83
83
84
+ /// Digital output pin state
85
+ #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
86
+ pub enum PinState {
87
+ /// Low pin state
88
+ Low ,
89
+ /// High pin state
90
+ High ,
91
+ }
92
+
84
93
/// GPIO Pin speed selection
85
94
pub enum Speed {
86
95
Low = 0 ,
@@ -240,6 +249,23 @@ impl<MODE, const P: char> PXx<Output<MODE>, P> {
240
249
}
241
250
}
242
251
252
+ #[ inline( always) ]
253
+ pub fn get_state ( & self ) -> PinState {
254
+ if self . is_set_low ( ) {
255
+ PinState :: Low
256
+ } else {
257
+ PinState :: High
258
+ }
259
+ }
260
+
261
+ #[ inline( always) ]
262
+ pub fn set_state ( & mut self , state : PinState ) {
263
+ match state {
264
+ PinState :: Low => self . set_low ( ) ,
265
+ PinState :: High => self . set_high ( ) ,
266
+ }
267
+ }
268
+
243
269
#[ inline( always) ]
244
270
pub fn is_set_high ( & self ) -> bool {
245
271
!self . is_set_low ( )
@@ -846,6 +872,23 @@ impl<MODE, const P: char, const N: u8> PX<Output<MODE>, P, N> {
846
872
}
847
873
}
848
874
875
+ #[ inline( always) ]
876
+ pub fn get_state ( & self ) -> PinState {
877
+ if self . is_set_low ( ) {
878
+ PinState :: Low
879
+ } else {
880
+ PinState :: High
881
+ }
882
+ }
883
+
884
+ #[ inline( always) ]
885
+ pub fn set_state ( & mut self , state : PinState ) {
886
+ match state {
887
+ PinState :: Low => self . set_low ( ) ,
888
+ PinState :: High => self . set_high ( ) ,
889
+ }
890
+ }
891
+
849
892
#[ inline( always) ]
850
893
pub fn is_set_high ( & self ) -> bool {
851
894
!self . is_set_low ( )
@@ -1286,6 +1329,23 @@ impl<MODE> Pin<Output<MODE>> {
1286
1329
} ;
1287
1330
}
1288
1331
1332
+ #[ inline( always) ]
1333
+ pub fn get_state ( & self ) -> PinState {
1334
+ if self . is_set_low ( ) {
1335
+ PinState :: Low
1336
+ } else {
1337
+ PinState :: High
1338
+ }
1339
+ }
1340
+
1341
+ #[ inline( always) ]
1342
+ pub fn set_state ( & mut self , state : PinState ) {
1343
+ match state {
1344
+ PinState :: Low => self . set_low ( ) ,
1345
+ PinState :: High => self . set_high ( ) ,
1346
+ }
1347
+ }
1348
+
1289
1349
#[ inline( always) ]
1290
1350
pub fn is_set_high ( & self ) -> bool {
1291
1351
!self . is_set_low ( )
0 commit comments