Skip to content

Feuerlabs/gpio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.