Expand description
The gpiochip
crate provides access to Linux gpiochip devices
from rust. The interface is wrapped, so that rust types are being
used instead of C types.
§Examples
extern crate gpiochip as gpio;
/// Print information about first gpiochip
fn main() {
let chip = gpio::GpioChip::new("/dev/gpiochip0").unwrap();
println!("GPIOChip 0:");
println!(" Name: {:?}", chip.name);
println!(" Label: {:?}", chip.label);
println!(" Lines: {:?}", chip.lines);
println!("");
for i in 0..chip.lines {
let info = chip.info(i).unwrap();
println!(" GPIO {:?}: {:?}", info.gpio, info.name);
println!(" Consumer: {:?}", info.consumer);
println!(" Flags: {:?}", info.flags);
}
}
extern crate gpiochip as gpio;
/// Simple get/set example
fn main() {
let chip = gpio::GpioChip::new("/dev/gpiochip0").unwrap();
let gpio_a = chip.request("gpioA", gpio::RequestFlags::INPUT, 0, 0).unwrap();
let gpio_b = chip.request("gpioA", gpio::RequestFlags::OUTPUT | gpio::RequestFlags::ACTIVE_LOW, 1, 0).unwrap();
let val = gpio_a.get().unwrap();
gpio_b.set(val).unwrap();
}
extern crate gpiochip as gpio;
/// GPIO events
fn main() {
let chip = gpio::GpioChip::new("/dev/gpiochip0").unwrap();
let gpio_a = chip.request_event("gpioA", 0, gpio::RequestFlags::INPUT, gpio::EventRequestFlags::BOTH_EDGES).unwrap();
let gpio_b = chip.request_event("gpioB", 1, gpio::RequestFlags::INPUT, gpio::EventRequestFlags::BOTH_EDGES).unwrap();
let bitmap = gpio::wait_for_event(&[&gpio_a, &gpio_b], 1000).unwrap();
if bitmap & 0b01 == 0b01 {
let event = gpio_a.read().unwrap();
println!("gpioA: event @ {:?} - {:?}", event.timestamp, event.id);
}
if bitmap & 0b10 == 0b10 {
let event = gpio_b.read().unwrap();
println!("gpioB: event @ {:?} - {:?}", event.timestamp, event.id);
}
}
Structs§
- Event
Request Flags - bitflag describing the events, that should generate a
GpioEvent
theGpioEventHandle
- Flags
- bitflag describing the current gpio mode
- Gpio
Array Handle - A GPIO array handle acquired from the gpiochip
- Gpio
Chip - Provide high-level access to Linux gpiochip Driver
- Gpio
Event - A GPIO event received from a
GpioEventHandle
- Gpio
Event Handle - A GPIO event handle acquired from the gpiochip
- Gpio
Handle - A GPIO handle acquired from the gpiochip
- Line
Info - Data returned by
GpioChip::info()
- Request
Flags - bitflag describing the gpio mode, that should be requested
Enums§
Functions§
- wait_
for_ event - Wait until at least one gpio event has been received or timeout occured.