How to manage the GPIO with Sysfs interface

This document explains how to manage the GPIO pins on the FOX Board G20 using the Sysfs interface.

Sysfs is a virtual file system provided by Linux 2.6 that exports information about devices and drivers from the kernel device model to userspace, and is also used for configuration.

The FOX Board has 3 groups of 32 GPIO lines called PORT A, PORT B and PORT C.

Each line is identified with an index between 0 and 31 and a port offset as listed below:

Line→ 0 1 2 3 4 5 6 7 etc…
PORT A 32 31 32 33 34 35 36 37 etc…
PORT B 64 65 66 67 68 69 70 71 etc…
PORT C 96 97 98 99 100 101 102 103 etc…

Do a quick test using the on-board red led

The RED led mounted on the FOX Board G20 near USB client port is wired on the GPIO line PC7 (PORT C GPIO line 7). The GPIO id number to manage this led is 96 + 7 = 103.

To use a GPIO line you have to export it typing:

echo 103 > /sys/class/gpio/export

A new directory called /sys/class/gpio/gpio103 will be created with two new files inside: value and direction.

Set the PC7 line as output typing:

echo out > /sys/class/gpio/gpio103/direction

Now turn on and off the RED led typing:

echo 1 > /sys/class/gpio/gpio103/value
echo 0 > /sys/class/gpio/gpio103/value

Links

Contacts
powered by gentoo