[PATCH] Add Linux gpio sysfs applets

Sascha Hauer s.hauer at pengutronix.de
Wed Apr 30 08:07:55 UTC 2014


On Tue, Apr 29, 2014 at 09:53:05PM +0200, Ralf Friedl wrote:
> Sascha Hauer wrote:
> >This adds applets for manipulating gpios under Linux via sysfs. It uses
> >the /sys/class/gpio API to set direction and value of gpios and to read
> >back the actual value. The applets work like the corresponding C functions
> >in the kernel:
> >
> >gpio_set_value <gpio> <value>
> >gpio_get_value <gpio>
> >gpio_direction_output <gpio> <value>
> >gpio_direction_input <gpio>
> >
> ><gpio> is the Linux gpio number and <value> is 0 for low and 1 for high.
> >gpio_get_value will report the value to stdout.
> >
> >If not already exported the applets export the gpio via
> >/sys/class/gpio/export. After usage the gpio is unexported again,
> >but only if it wasn't exported before calling the applet.
> What is the advantage of these applets compared to a direct echo to
> /sys/class/gpio/... ?

The applets are easier to use and provide better error handling. To
export a gpio and set its value it would require two operations:

echo 10 > /sys/class/gpio/export
echo high > /sys/class/gpio/gpio10/direction

Both operations can fail, so you need error checking for both. With the
applets you could write

gpio_direction_output 10 1 || exit 1

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


More information about the busybox mailing list