User GPIO Driver

From Gumstix User Wiki
Jump to: navigation, search

This page documents the user GPIO driver, which is a reflection of the kernel's gpiolib API into user space.

Overview

The kernel provides an API, called gpiolib, which abstracts access to GPIO pins. It has a mechanism for exporting pins into userspace, and in general this is the preferred method of accessing gpio pins from userspace. This method works particularly well if it is setup for a given overo/daughtercard combination. However, since the kernel is often configured in a more generic manner, using the export method is inconvenient, so the user-gpio driver was created.

WARNING: It is possible to damage your overo chip if you do things incorrectly. This code has no way of knowing for example, if a pin is physically connected to an output or not. If, for example, a GPIO pin was connected to Vcc, and you choose to configure that pin as an output and drive it low, you've essentially created a short circuit, and this can stress or damagethe pin, possibly bricking your processor. You have been warned.

Driver Sources

The source code can be found here. The app directory contains the example user mode application. The lib directory contains the usermode library which translates the C API into the appropriate ioctl calls into the kernel driver, and the module directory contains the loadable kernel module. The Makefiles have been setup such that if you define the environment variable OVEROTOP then you should be able to just type make in top level directory and both the app and module will be built.

There are also some bitbake recipes in the gpio-app, gpio-lib and gpio-event-module directories.

Integrating/Building with Open Embedded

In order to build the driver under OE, you can do the following:

 cd to the directory containing org.embedded.dev
 svn co http://svn.hylands.org/linux/oe/user.collection user.collection
 bitbake task-gpio-all

This will build the following packages for the GPIO Event Driver:

./deploy/glibc/ipk/overo/gpio-event-module_svn20100218-r50.5_overo.ipk
./deploy/glibc/ipk/armv7a/gpio-event-app_svn20100218-r2.5_armv7a.ipk

and these packages for the user gpio driver:

./deploy/glibc/ipk/overo/gpio-module_svn20100218-r50.5_overo.ipk
./deploy/glibc/ipk/armv7a/gpio-app_svn20100218-r0.5_armv7a.ipk
./deploy/glibc/ipk/armv7a/gpio-lib_svn20100218-r0.5_armv7a.ipk

Note that the numeric portions of the pathnames will almost certainly be different.