Expand description
Opening a GPIO line on a Linux board.
On a Raspberry Pi or any Linux board a pin is a line on a GPIO chip, a device file such as
/dev/gpiochip0, and a line’s number on that chip is the one a board’s pinout calls its
GPIO or BCM number. output and input open one through the GPIO character device
backend of pamoja-hal and hand it back as a Line, which a
Switch or a Contact sits over as
it would over any other pin. The language bindings open lines through the same two
functions, so a relay is driven the same way from Rust, TypeScript, Python, and C#.
A line is held by one process at a time, and the kernel names the holder, which
gpioinfo prints; a line held by another program or claimed by a kernel driver cannot be
opened until it is let go. On Raspberry Pi OS a user in the gpio group can open lines
without root.
Only Linux has the GPIO character device. Everywhere else this module still builds and
Line still names a type, but opening a line returns OpenError::Unsupported, so a
program and the bindings compile on any platform and say plainly where no line opens.
§Examples
use pamoja_gpio::linux;
use pamoja_gpio::pin::Level;
use pamoja_gpio::switch::{Contact, Switch};
// A relay board on GPIO17 that energizes on a low input, opened high so the pump stays
// off until it is asked to run, and a float switch to ground on GPIO27 with a pull-up.
let mut pump = Switch::active_low(linux::output("/dev/gpiochip0", 17, Level::High)?);
let mut float = Contact::active_low(linux::input("/dev/gpiochip0", 27)?);
pump.set(!float.is_asserted()?)?;Structs§
- Line
- A GPIO line opened on a Linux board, as an output or an input.
- Line
Error - Why an open line could not be driven or read.
Enums§
- Open
Error - Why a line could not be opened.
Constants§
- CONSUMER
- The name the kernel shows as holding a line opened here, which
gpioinfoprints.