/gpiotools

Small library and tools for working with GPIO

Primary LanguageC

gpiotools

This is a collection of tools and a library for working with GPIO on Linux.

Rather than using a 3rd party library like wiringPi or RPi.GPIO or using the now depreciated sysfs interface, this directly manipulates the character devices “/dev/gpiochip*”.

As a small static library, it can be easily included into other projects.

This library is a work in progress, and will grow as I need it.

Features of libgpiotools

So far, libgpiotools provides wrappers for the ioctl() calls in linux/gpio.h. These are all declared inline, so there should be minimal performance cost.

In many cases, a struct must be provided with some members filled in. In most of those cases, this struct must be filled in my the user.

The user should examine linux/gpio.h for information on the structs that need to be filled in.

Further functionality is planned as needed.

Utilities

gpiolist - get information about system GPIO devices

This utility prints information about the GPIO devices on the system.

Arguments are as such:

  • -h

    Print help information

  • -c

    Print chip information

  • -l <number | all>

    Print information about a single line or all lines.

  • -d <number>

    Specify the GPIO device to use. Give it just a number, like ‘1’ or ‘32’.

Example output:

spauldo@raspberrypi:~/repos/gpiotools $ ./gpiolist -c -d2 -lall
GPIO gpiochip2
  Label: brcmvirt-gpio
  Lines: 2
Line  0
  Used by: led0
  Flags: INPUT OUTPUT
Line  1
  Not configured.
spauldo@raspberrypi:~/repos/gpiotools $

License

This code is all © 2018 by Jeff Spaulding and licensed under the ISC licence:

   
Copyright (c) 2018 Jeff Spaulding <sarnet@gmail.com>
  
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.