5 unstable releases

Uses old Rust 2015

0.4.1 Mar 13, 2018
0.4.0 Mar 4, 2018
0.3.0 Jun 16, 2017
0.2.1 Jun 16, 2017
0.2.0 Jun 14, 2017

#1780 in Embedded development

Download history 150/week @ 2024-03-13 280/week @ 2024-03-20 318/week @ 2024-03-27 232/week @ 2024-04-03 187/week @ 2024-04-10 256/week @ 2024-04-17 278/week @ 2024-04-24 231/week @ 2024-05-01 214/week @ 2024-05-08 274/week @ 2024-05-15 412/week @ 2024-05-22 359/week @ 2024-05-29 620/week @ 2024-06-05 337/week @ 2024-06-12 217/week @ 2024-06-19 391/week @ 2024-06-26

1,671 downloads per month
Used in 6 crates

MIT license

13KB
233 lines

Rust GPIO

Deals with GPIO access on Linux and bare metal embedded systems, through sysfs and direct memory access. Works on stable Rust.

Roadmap

  • GPIO write support
  • Read support
  • Interrupt support

Other libraries

Other libraries can be found on crates.io. These include:

  • sysfs_gpio <https://github.com/rust-embedded/rust-sysfs-gpio>_ handles GPIO only via SysFS, but exposes all features. Slightly lower level.

  • cylus <https://github.com/Vikaton/cylus>_ Documentation is dead, does a few questionable things like unwrapping()

  • cupi <https://github.com/cuprumpi/cupi>_ Most comprehensive GPIO library, includes almost all features planned for gpio. Does not use volatile.

    TODO: Benchmark


lib.rs:

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

No runtime deps