GPIOlib

From ArmadeusWiki
Revision as of 14:05, 12 January 2011 by JulienB (Talk | contribs) (creation)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Page under construction... Construction.png Informations on this page are not guaranteed !!

With recent Linux kernel (> 2.6.3x), there is an abstraction layer meant to ease GPIO usage: gpiolib. We will explain here how to use it.

Installation

  • If not already done:
$ make linux26-menuconfig
Device Drivers  --->
    -*- GPIO Support  --->
        [*]   /sys/class/gpio/... (sysfs interface)
$ make
  • reflash your kernel (if needed)

Usage

  • Find your GPIO number, eg for PF14 -> PortF (n°6) pin 14 -> (6-1)*32 + 14 -> 174
  • Ask kernel to export the GPIO:
# echo 174 > /sys/class/gpio/export
  • Access functions are created:
# ls /sys/class/gpio/gpio174/
active_low  edge        subsystem   value
direction   power       uevent
  • Check GPIO direction and put in output:
# cat /sys/class/gpio/gpio174/direction
in
# echo out > /sys/class/gpio/gpio174/direction
# cat /sys/class/gpio/gpio174/direction
out
  • Play with GPIO value:
# echo 1 > /sys/class/gpio/gpio146/value
# echo 0 > /sys/class/gpio/gpio146/value

Links