GithubHelp home page GithubHelp logo

edsaleh / rust-sysfs-gpio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rust-embedded/rust-sysfs-gpio

0.0 2.0 0.0 7.88 MB

A Rust Interface to the Linux sysfs GPIO interface (https://www.kernel.org/doc/Documentation/gpio/sysfs.txt)

License: Apache License 2.0

Rust 100.00%

rust-sysfs-gpio's Introduction

rust-sysfs-gpio

Build Status Version License

rust-sysfs-gpio is a rust library/crate providing access to the Linux sysfs GPIO interface (https://www.kernel.org/doc/Documentation). It seeks to provide an API that is safe, convenient, and efficient.

Many devices such as the Raspberry Pi or Beaglebone Black provide userspace access to a number of GPIO peripherals. The standard kernel API for providing access to these GPIOs is via sysfs.

You might want to also check out the gpio-utils Project for a convenient way to associate names with pins and export them as part of system boot. That project uses this library.

Install/Use

To use sysfs_gpio, first add this to your Cargo.toml:

[dependencies]
sysfs_gpio = "0.5"

Then, add this to your crate root:

extern crate sysfs_gpio;

Example/API

Blinking an LED:

extern crate sysfs_gpio;

use sysfs_gpio::{Direction, Pin};
use std::thread::sleep;
use std::time::Duration;

fn main() {
    let my_led = Pin::new(127); // number depends on chip, etc.
    my_led.with_exported(|| {
        loop {
            my_led.set_value(0).unwrap();
            sleep(Duration::from_millis(200));
            my_led.set_value(1).unwrap();
            sleep(Duration::from_millis(200));
        }
    }).unwrap();
}

More Examples:

Features

The following features are planned for the library:

  • Support for exporting a GPIO
  • Support for unexporting a GPIO
  • Support for setting the direction of a GPIO (in/out)
  • Support for reading the value of a GPIO input
  • Support for writing the value of a GPIO output
  • Support for configuring whether a pin is active low/high
  • Support for configuring interrupts on GPIO
  • Support for polling on GPIO with configured interrupt
  • Support for asynchronous polling using mio or tokio-core (requires enabling the mio-evented or tokio crate features, respectively)

Cross Compiling

Most likely, the machine you are running on is not your development machine (although it could be). In those cases, you will need to cross-compile. The rust-cross guide provides excellent, detailed instructions for cross-compiling.

Running the Example

Cross-compiling can be done by specifying an appropriate target. You can then move that to your device by whatever means and run it.

$ cargo build --target=arm-unknown-linux-gnueabihf --example blinky
$ scp target/arm-unknown-linux-gnueabihf/debug/examples/blinky ...

License

Copyright (c) 2015, Paul Osborne <[email protected]>

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
http://www.apache.org/license/LICENSE-2.0> or the MIT license
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
option.  This file may not be copied, modified, or distributed
except according to those terms.

rust-sysfs-gpio's People

Contributors

emosenkis avatar jwilm avatar marjakm avatar martinsp avatar mlakewood avatar nastevens avatar posborne avatar razican avatar rumatoest avatar tpmanley avatar zaynetro avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.