#bindings #api-wrapper #raspberry-pi #pi #raspberry #wiring

wiringpi

An API wrapper for WiringPi, implementing the most important functions and provides a bit of type system convenience. See README.md for Raspberry Pi build instructions.

8 releases

Uses old Rust 2015

0.2.4 Mar 17, 2018
0.2.3 Mar 4, 2018
0.2.2 Feb 4, 2018
0.2.1 May 28, 2017
0.1.1 Apr 18, 2015

#45 in #raspberry

Download history 23/week @ 2024-07-21 27/week @ 2024-07-28 22/week @ 2024-08-04 31/week @ 2024-08-11 15/week @ 2024-08-18 22/week @ 2024-08-25 26/week @ 2024-09-01 30/week @ 2024-09-08 26/week @ 2024-09-15 59/week @ 2024-09-22 55/week @ 2024-09-29 4/week @ 2024-10-06 20/week @ 2024-10-13 23/week @ 2024-10-20 26/week @ 2024-10-27 34/week @ 2024-11-03

103 downloads per month
Used in 3 crates (2 directly)

MIT license

1MB
14K SLoC

C 13K SLoC // 0.3% comments Rust 556 SLoC // 0.0% comments Bazel 198 SLoC // 0.2% comments Shell 34 SLoC // 0.6% comments

Contains (static library, 130KB) wiringPi/wiringPi/libwiringPi.a, (static library, 91KB) WiringOP/wiringPi/libwiringPi.a, (ELF exe/lib, 19KB) wiringPi/wiringPiD/wiringpid

WiringPi Bindings for Rust

An API wrapper for WiringPi to make it accessible using Rust. It implements the most important functions and provides a bit of type system convenience.

Add the following lines to your Cargo.io to use rust-wiringpi:

[dependencies]
wiringpi = "0.2"

Online Documentation

Released

Master branch

Example: Flashing Light

extern crate wiringpi;

use wiringpi::pin::Value::{High, Low};
use std::{thread, time};

fn main() {
    //Setup WiringPi with its own pin numbering order
    let pi = wiringpi::setup();

    //Use WiringPi pin 0 as output
    let pin = pi.output_pin(0);

    let interval = time::Duration::from_millis(1000);

    loop {
        //Set pin 0 to high and wait one second
        pin.digital_write(High);
        thread::sleep(interval);

        //Set pin 0 to low and wait one second
        pin.digital_write(Low);
        thread::sleep(interval);
    }
}

Cross Compiling Using Cargo

Follow this guide.

cargo build --target=arm-unknown-linux-gnueabihf   # Older models
cargo build --target=armv7-unknown-linux-gnueabihf # Newer models

Orange Pi support

rust-wiringpi can also wrap the WiringOP library for the Orange Pi SBC boards. This can be enabled with the orangepi feature:

[dependencies.wiringpi]
verson = "0.2"
features = ["orangepi"]

Development Mode

In development mode, rust-wiringpi is compiled as a rust-native library excluding the original WiringPi. And binding functions are replaced by dummy functions that output simple logs to stdout. With this mode, you can build and debug your project on platforms that does not support WiringPi.

# build
$ cargo build --features wiringpi/development

# run
$ cargo run --features wiringpi/development

[wiringpi] `wiringPiSetup` called
[wiringpi] `pinMode` called with: 0, 1
[wiringpi] `digitalWrite` called with: 0, 1
[wiringpi] `digitalWrite` called with: 0, 0
...

Dependencies