From f687c280a5c5adffc9846aa1ecf3973028c683e5 Mon Sep 17 00:00:00 2001 From: Jonathan Bastien-Filiatrault Date: Tue, 20 May 2025 21:10:18 -0400 Subject: [PATCH 1/3] Add the bias request and line flags. --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b8b6506..e746932 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -356,6 +356,9 @@ bitflags! { const ACTIVE_LOW = (1 << 2); const OPEN_DRAIN = (1 << 3); const OPEN_SOURCE = (1 << 4); + const BIAS_PULL_UP = (1 << 5); + const BIAS_PULL_DOWN = (1 << 6); + const BIAS_DISABLE = (1 << 7); } } @@ -385,6 +388,9 @@ bitflags! { const ACTIVE_LOW = (1 << 2); const OPEN_DRAIN = (1 << 3); const OPEN_SOURCE = (1 << 4); + const BIAS_PULL_UP = (1 << 5); + const BIAS_PULL_DOWN = (1 << 6); + const BIAS_DISABLE = (1 << 7); } } From f91852261319bbbdfb85e4800e26d3860b721bbf Mon Sep 17 00:00:00 2001 From: Jonathan Bastien-Filiatrault Date: Tue, 20 May 2025 21:25:52 -0400 Subject: [PATCH 2/3] Line bias accessors. --- src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e746932..b56ae09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -401,6 +401,14 @@ pub enum LineDirection { Out, } +/// How the line is biased +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum LineBias { + PullUp, + PullDown, + Disabled, +} + unsafe fn cstrbuf_to_string(buf: &[libc::c_char]) -> Option { if buf[0] == 0 { None @@ -614,6 +622,23 @@ impl LineInfo { } } + /// Get how this line is biased + /// + /// Some is returned when only one bias flag is present. + /// If more than one flag or no flags are specified, None is returned. + pub fn bias(&self) -> Option { + let up = self.flags.contains(LineFlags::BIAS_PULL_UP); + let down = self.flags.contains(LineFlags::BIAS_PULL_DOWN); + let disabled = self.flags.contains(LineFlags::BIAS_DISABLE); + + match (up, down, disabled) { + (true, false, false) => Some(LineBias::PullUp), + (false, true, false) => Some(LineBias::PullDown), + (false, false, true) => Some(LineBias::Disabled), + _ => None, + } + } + /// True if the any flags for the device are set (input or output) pub fn is_used(&self) -> bool { !self.flags.is_empty() @@ -643,6 +668,21 @@ impl LineInfo { pub fn is_open_source(&self) -> bool { self.flags.contains(LineFlags::OPEN_SOURCE) } + + // True if the line is marked as having a pull-up bias + pub fn is_bias_pull_up(&self) -> bool { + self.flags.contains(LineFlags::BIAS_PULL_UP) + } + + // True if the line is marked as having a pull-down bias + pub fn is_bias_pull_down(&self) -> bool { + self.flags.contains(LineFlags::BIAS_PULL_DOWN) + } + + // True if the line is marked as having a disabled bias + pub fn is_bias_disabled(&self) -> bool { + self.flags.contains(LineFlags::BIAS_DISABLE) + } } /// Handle for interacting with a "requested" line From adee757593d5b1d5b653e44f195250e704c49bf3 Mon Sep 17 00:00:00 2001 From: Jonathan Bastien-Filiatrault Date: Thu, 3 Jul 2025 20:48:33 -0400 Subject: [PATCH 3/3] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 135e768..6d10483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Versioning](https://semver.org/spec/v2.0.0.html). ### Changed - MSRV is now 1.82.0. +- Add accessors for line bias (pull-up, pull-down). ## [v0.6.0] - 2023-09-11