@@ -401,6 +401,14 @@ pub enum LineDirection {
401
401
Out ,
402
402
}
403
403
404
+ /// How the line is biased
405
+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
406
+ pub enum LineBias {
407
+ PullUp ,
408
+ PullDown ,
409
+ Disabled ,
410
+ }
411
+
404
412
unsafe fn cstrbuf_to_string ( buf : & [ libc:: c_char ] ) -> Option < String > {
405
413
if buf[ 0 ] == 0 {
406
414
None
@@ -614,6 +622,23 @@ impl LineInfo {
614
622
}
615
623
}
616
624
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
+
617
642
/// True if the any flags for the device are set (input or output)
618
643
pub fn is_used ( & self ) -> bool {
619
644
!self . flags . is_empty ( )
@@ -643,6 +668,21 @@ impl LineInfo {
643
668
pub fn is_open_source ( & self ) -> bool {
644
669
self . flags . contains ( LineFlags :: OPEN_SOURCE )
645
670
}
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
+ }
646
686
}
647
687
648
688
/// Handle for interacting with a "requested" line
0 commit comments