Expand description
GPIO interface
The GPIO crate allows easy and fast access to GPIO pins. It aims to provide an ergonomic interface while being lower overhead, enabling high-frequency output without complicating simple tasks.
The core interface is defined using GpioValue
and the GpioOut
/GpioIn
traits. All backends implement at least some of these traits, making them
interchangeable, e.g. for testing.
The most commonly used implementation is based on the
Linux GPIO Sysfs
interface, found inside the sysfs
crate.
§Example
use gpio::{GpioIn, GpioOut};
use std::{thread, time};
// Let's open GPIO23 and -24, e.g. on a Raspberry Pi 2.
let mut gpio23 = gpio::sysfs::SysFsGpioInput::open(23).unwrap();
let mut gpio24 = gpio::sysfs::SysFsGpioOutput::open(24).unwrap();
// GPIO24 will be toggled every second in the background by a different thread
let mut value = false;
thread::spawn(move || loop {
gpio24.set_value(value).expect("could not set gpio24");
thread::sleep(time::Duration::from_millis(1000));
value = !value;
});
// The main thread will simply display the current value of GPIO23 every 100ms.
loop {
println!("GPIO23: {:?}", gpio23.read_value().unwrap());
thread::sleep(time::Duration::from_millis(100));
}
§TODO
/dev/mem
interface: Higher frequency port usage
Modules§
Enums§
- Gpio
Value - A value read from or written to a GPIO port