GithubHelp home page GithubHelp logo

isabella232 / gpio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from feuerlabs/gpio

0.0 0.0 0.0 355 KB

sysfs GPIO port driver and erlang module

License: Mozilla Public License 2.0

C 62.89% Erlang 37.11%

gpio's Introduction

gpio

gpio is a device driver application for GPIO (General Purpose IO) written in erlang and C.

IO-pins are accessed either in a generic, Linux-based, way using control files or by direct memory acces.
Direct memory acces is currently implemented for the following processors:

  • bcm 2835 (Raspberry Pi)

Dependencies

To build gpio you will need a working installation of Erlang R15B (or later).
Information on building and installing Erlang/OTP can be found here (more info).

gpio is built using rebar that can be found here, with building instructions here. rebar's dynamic configuration mechanism, described here, is used so the environment variable REBAR_DEPS should be set to the directory where your erlang applications are located.

Download

Clone the repository in a suitable location:

$ git clone git://github.com/Feuerlabs/gpio.git

Build

Rebar will compile all needed dependencies.
Compile:

$ cd gpio
$ rebar compile
...
==> gpio (compile)

Run

gpio is started in a standard erlang fashion:

$ erl
(node@host) 1> application:start(gpio).

API

The interface has the following functions for accessing a single pin:

  • init
  • init_direct
  • release
  • set
  • get
  • clr
  • input
  • output
  • set_direction
  • get_direction
  • set_interrupt
  • get_interrupt

The interface has the following functions for accessing several pins using a mask:

  • set_mask
  • get_mask
  • clr_mask

Example

An example on how to setup a gpio interrupt.

gpio:set_interrupt(25, falling),
receive 
    {gpio_interrupt, 0, 25, Value} ->
      io:format("pin 25, high to low\n")
end.

Given that the gpio application is started with the following config in environment (raspberry pi mode):

{gpio, [{options, [{chipset,bcm2835}]}]}

Then we can do some fast gpio access

gpio:init_direct(24),
gpio:set_direction(24, low),
gpio:set(24),
timer:sleep(1010),
gpio:clr(24),  
timer:sleep(2210),
ok.

This code will init pin 24 in direct access mode, using io registers instead of the normal linux /sys/class/gpio file interface. Then set pin 24 in output mode that default to a low output value. After that the pin is set to high for 1010 ms and then set to low again. (This is the power-on sequence for a SIM900 GPRS module).

For details see the generated documentation.

Documentation

gpio is documented using edoc. To generate the documentation do:

$ cd gpio
$ rebar doc

The result is a collection of html-documents under gpio/doc.

gpio's People

Contributors

tonyrog avatar malotte avatar magnusfeuer 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.