Crate gpiochip[−][src]
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
EventRequestFlags |
bitflag describing the events, that should generate a |
Flags |
bitflag describing the current gpio mode |
GpioArrayHandle |
A GPIO array handle acquired from the gpiochip |
GpioChip |
Provide high-level access to Linux gpiochip Driver |
GpioEvent |
A GPIO event received from a |
GpioEventHandle |
A GPIO event handle acquired from the gpiochip |
GpioHandle |
A GPIO handle acquired from the gpiochip |
LineInfo |
Data returned by |
RequestFlags |
bitflag describing the gpio mode, that should be requested |
Enums
EventId |
Functions
wait_for_event |
Wait until at least one gpio event has been received or timeout occured. |