@@ -401,6 +401,14 @@ pub enum LineDirection {
401401 Out ,
402402}
403403
404+ /// How the line is biased
405+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
406+ pub enum LineBias {
407+ PullUp ,
408+ PullDown ,
409+ Disabled ,
410+ }
411+
404412unsafe fn cstrbuf_to_string ( buf : & [ libc:: c_char ] ) -> Option < String > {
405413 if buf[ 0 ] == 0 {
406414 None
@@ -614,6 +622,23 @@ impl LineInfo {
614622 }
615623 }
616624
625+ /// Get how this line is biased
626+ ///
627+ /// Some is returned when only one bias flag is present.
628+ /// If more than one flag or no flags are specified, None is returned.
629+ pub fn bias ( & self ) -> Option < LineBias > {
630+ let up = self . flags . contains ( LineFlags :: BIAS_PULL_UP ) ;
631+ let down = self . flags . contains ( LineFlags :: BIAS_PULL_DOWN ) ;
632+ let disabled = self . flags . contains ( LineFlags :: BIAS_DISABLE ) ;
633+
634+ match ( up, down, disabled) {
635+ ( true , false , false ) => Some ( LineBias :: PullUp ) ,
636+ ( false , true , false ) => Some ( LineBias :: PullDown ) ,
637+ ( false , false , true ) => Some ( LineBias :: Disabled ) ,
638+ _ => None ,
639+ }
640+ }
641+
617642 /// True if the any flags for the device are set (input or output)
618643 pub fn is_used ( & self ) -> bool {
619644 !self . flags . is_empty ( )
@@ -643,6 +668,21 @@ impl LineInfo {
643668 pub fn is_open_source ( & self ) -> bool {
644669 self . flags . contains ( LineFlags :: OPEN_SOURCE )
645670 }
671+
672+ // True if the line is marked as having a pull-up bias
673+ pub fn is_bias_pull_up ( & self ) -> bool {
674+ self . flags . contains ( LineFlags :: BIAS_PULL_UP )
675+ }
676+
677+ // True if the line is marked as having a pull-down bias
678+ pub fn is_bias_pull_down ( & self ) -> bool {
679+ self . flags . contains ( LineFlags :: BIAS_PULL_DOWN )
680+ }
681+
682+ // True if the line is marked as having a disabled bias
683+ pub fn is_bias_disabled ( & self ) -> bool {
684+ self . flags . contains ( LineFlags :: BIAS_DISABLE )
685+ }
646686}
647687
648688/// Handle for interacting with a "requested" line
0 commit comments