GPIO event

This page documents the gpio-event driver, which is similar to the driver on the Kernel programming page, but which allows multiple GPIO lines to be monitored.

Precompiled binaries
The following tarballs contain the source files, Makefile and prior to revision 1444, also contains the pre-built kernel module and user mode program:


 * gpio-event-2.6.18.tar.gz - For 2.6.18 kernels prior to SVN revision 1185
 * gpio-event-2.6.18-1185.tar.gz - For 2.6.18 kernels SVN revision 1185 thru 1238
 * gpio-event-2.6.18-1239.tar.gz - For 2.6.18 kernels SVN revision 1239 thru 1285
 * gpio-event-2.6.20-1286.tar.gz - For 2.6.20 kernels SVN revision 1286 thru 1443
 * gpio-event-2.6.21-1444.tar.gz - For 2.6.21 kernels SVN revision 1444 and newer
 * gpio-event-2.6.21-1444-select.tar.gz - For 2.6.21 kernels SVN revision 1444 and newer, with support for select

Building the driver
Create a directory parallel to the gumstix-buildroot. On my machine, my gumstix-builtroot is /home/dhylands/gumstix/gumstix-buildroot, so I created /home/dhylands/gumstix/gpio-event. Place the tarball in the gpio-event directory and expand it using: tar xzf gpio-event-2.6.18.tar.gz

If you're using a 2.6.18 kernel, then you should be able to use the prebuilt gpio-event-drv.ko file, and the gpio-event user mode program. I think that the sources should compile on the 2.6.15 or newer versions of the kernel. Typing "make" from wihin the gpio-event directory should build both the kernel module and the user-mode program.

Installing the kernel module
The kernel module can be installed by typing: insmod gpio-event-drv.ko

Adding pins to be monitored
The gpio-event program can be used to add gpio pins to be monitored. Simply run the gpio-event program, passing it a pin specification of the form: pin:edge:debounce. pin should be the GPIO number that you want to monitor. Edge should be r, f, or b to monitor rising, falling, or both edges, and debounce should be the number of milliseconds of debounce that you'd like. A debounce of 0 may be used for "clean" signals. For example: gpio-event 58:f:20 59:r:20 60:b:20

would cause gpio 58 to be monitored for falling edges, gpio 59 to be monitored for rising edges, and gpio 60 to be monitored for both rising and falling edges. Each pin will have a debounce of 20 milliseconds (which should be adequate for most pushbuttons).

You can pass as many pins to be monitored as you'd like on the command line. Each call is cumulative. If you specify the same pin, the new specification will override whatever is currently set. You can see the current pins being monitored by using: cat /proc/gpio-event/pins

Passing in a negative gpio number will cause the pin to stop being monitored (although I haven't actually tested this yet).

Detecting events
Once pins are setup to be monitored, any program can read /dev/gpio-event to get notified of the events. By default, an ASCII string of the form: "pin edge timestamp" followed by a newline will be delievered to /devb/gpio-event for each event that occurs. Running gpio-event with the -m or --monitor command line will cause the events to be monitored and printed. You could also use the command: cat /dev/gpio-event

to achieve a similar result. For C programs, you can opt to use a binary interface instead. The binary versus ASCII setting is maintained on a per-file basis, so each program could each open /dev/gpio-event with a different ASCII/binary setting.

The edge will be an R or an F depending on whether a rising or falling edge is being reported. The timestamp is a number with the integer portion being the current system time (as returned from the gettimeofday function) and the fractional portion reporting in microseconds.

Lauching a script
The gpio-event program can also be given the -e or --execute command line option, and the provided program or script will be launched with the same 3 paramters (gpio edge timestamp). For example: gpio-event --execute echo

will produce similar output to gpio-event --monitor