Crate gpiocdev

Source
Expand description

A library for accessing GPIO lines on Linux platforms using the GPIO character device.

Lines are requested and manipulated using the request module.

The lines available on specific chips can be discovered using the chip module.

The lines available on the system can be discovered by name using the find_named_line and find_named_lines functions, or using the iterator returned by lines.

§Example Usage

Request an input line and output line, and read from the input and change the output to that value:

use gpiocdev::line::{Bias, Value};

let req = gpiocdev::Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_line(3)
    .as_input()
    .with_bias(Bias::PullUp)
    .with_line(4)
    .as_output(Value::Inactive)
    .request()?;
let value = req.value(3)?;
req.set_value(4, value)?;

Monitor a line for debounced edges:

let req = gpiocdev::Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_line(5)
    .with_edge_detection(gpiocdev::line::EdgeDetection::BothEdges)
    .with_debounce_period(std::time::Duration::from_millis(5))
    .request()?;
for edge in req.edge_events() {
    println!("{edge:?}");
}

Re-exports§

pub use chip::Chip;
pub use request::Request;

Modules§

async_io
Asynchronous wrappers for the async-io reactor.
chip
Types and functions specific to chips.
line
Types specific to lines.
request
Types and functions related to requesting lines.
tokio
Asynchronous wrappers for the Tokio reactor.

Structs§

FoundLine
The info for a line discovered in the system.
LineIterator
An iterator for all lines in the system available to the caller.

Enums§

AbiVersion
The uAPI ABI versions available to interact with the kernel.
Error
Errors returned by gpiocdev functions.

Functions§

detect_abi_version
Detect the most recent uAPI ABI supported by the platform.
find_named_line
Find the chip hosting a named line, and the line offset on that chip.
find_named_lines
Find a collection of named lines.
lines
An iterator over all the GPIO lines visible to the caller.
supports_abi_version
Check if the platform and library support a specific ABI version.

Type Aliases§

Result
The result for gpiocdev functions.