#rus-pi-ro #gpio #baremetal #raspberrypi

nightly no-std ruspiro-gpio

This crates provides a GPIO peripheral abstraction of the Raspberry Pi

7 releases (4 breaking)

new 0.4.2 May 1, 2021
0.4.1 Sep 12, 2020
0.4.0 Jan 3, 2020
0.3.0 Dec 11, 2019
0.0.2 Jul 29, 2019

#165 in No standard library

Download history 18/week @ 2021-01-13 13/week @ 2021-01-20 10/week @ 2021-01-27 5/week @ 2021-02-03 16/week @ 2021-02-10 29/week @ 2021-02-17 9/week @ 2021-02-24 10/week @ 2021-03-03 9/week @ 2021-03-10 4/week @ 2021-03-17 27/week @ 2021-03-24 17/week @ 2021-03-31 19/week @ 2021-04-07 25/week @ 2021-04-14 21/week @ 2021-04-21 32/week @ 2021-04-28

66 downloads per month
Used in 3 crates

Apache-2.0

37KB
614 lines

RusPiRo GPIO access abstraction for Raspberry Pi

This crate provide a simple to use and safe abstraction of the GPIO peripheral available on the Raspberry Pi 3. The GPIO configuration requires access to MMIO registers with a specific memory base address. As this might differ between different models the right address is choosen based on the given ruspiro_pi3 feature while compiling.

CI Latest Version Documentation License

Usage

To use the crate just add the following dependency to your Cargo.toml file:

[dependencies]
ruspiro-gpio = "0.4.2"

Once done the access to the GPIO abstraction is available in your rust files like so:

use ruspiro_gpio::GPIO;

fn demo() {
    // "grab" the GPIO in a safe way and use the provided closure to work with it
    // as long as the closure is executed, no other core can access the GPIO to configure pins etc.
    GPIO.with_mut(|gpio| {
        // retrieving a pin gives a Result<>. If the pin is not already taken it returns an Ok()
        // with the pin.
        if let Ok(pin) = gpio.get_pin(17) {
            // as we have now access to the pin, configure it as output and set it to high
            // to lit a connected LED
            pin.to_output().high();
        }
    })
}

Usage Hint

The GPIO crate provides access to the peripheral through a Singleton to ensure safe access from each core of the Raspberry Pi to it. This Singleton uses locks and atomic operations to safeguard the access. Those atomic operations does only work on the Raspberry Pi if the MMU is configured and active (with active caches). So to properly use this crate in your project please check the ruspiro-mmu crate as well and how to configure and activate the MMU.

License

Licensed under Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or MIT (LICENSE-MIT or http://opensource.org/licenses/MIT)) at your choice.

Dependencies

~0.6–1MB
~22K SLoC