Hardware Reference
In-Depth Information
export
The
export
pseudo file allows you to request a GPIO pin from the kernel. For example,
if you want to manipulate GPIO pin 17, you request it from the kernel by writing its pin
number to the pseudo file:
$ sudo -i
# echo 17 >/sys/class/gpio/export
After a successful run, list the directory
/sys/class/gpio
:
# ls
export gpio17 gpiochip0 unexport
#
A new subdirectory (a symlink to a directory, actually) named
gpio17
appears. This
tells you that the kernel has given up control of GPIO 17 and has provided you this file
system object to manipulate. At this point, you can consider the GPIO 17 as available.
unexport
Some applications may require a GPIO pin for only a short time. When the application is
finished with the pin, the application can release the pin back to the kernel. This is done
by writing to the
unexport
pseudo file:
$ sudo -i
# echo 17 >/sys/class/gpio/unexport
After this command completes, the pseudo object
gpio17
disappears from the
/sys/
class/gpio
directory. This confirms that the GPIO is now being managed by the driver
and makes it impossible for userspace programs to mess with it (except for direct register
access).
gpioX
Once you have a file system object like
/sys/class/gpio/gpio17
to work with, you can
configure it and perform I/O. The main objects that you'll see are outlined in Table
10-5
.
The ones normally used by shell programs are simply as follows:
direction
:
To set the I/O direction
value
:
To read or write the I/O bit
active_low
:
To alter the sense of logic