Skip to content
/ libgpio Public

Bash library to manage Linux Kernel GPIO chips through a sysfs user interface

License

Notifications You must be signed in to change notification settings

Ventto/libgpio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libgpio

License Powered by Bash)

"libgpio is a Bash library to manage GPIO chips through the sysfs user interface"

For futher reading, take a look at Documentation/gpio/sysfs.txt (v4.4).

Compatibility

  • libgpio works for Linux kernels from v4.1.x to v4.7.x.
  • The kernel must be compiled with the CONFIG_GPIOLIB and CONFIG_GPIO_SYSFS option

Install

$ wget https://raw.githubusercontent.com/ventto/libgpio/master/libgpio.sh
$ . libgpio.sh

Usage

Manually

$ cd /sys/class/gpio
$ ls -l
gpiochip224/
[... truncated output...]

$ cat gpiochip224/ngpio   # print 32, so 32 GPIOS provided by the gpiochip
$ echo 230 > export       # export the GPIO n°6: 224 + 6
                          # make the GPIO n°6 ready to use
$ echo out > gpio230/direction   # set the direction
$ echo 1 > gpio230/value         # set the GPIO n°6 high
$ echo 230 > unexport            # release the GPIO

With libgpio

#!/bin/bash

. libgpio.sh

gpio_select_gpiochip 224   # select `/sys/class/gpio/gpiochip224`
gpio_count                 # print 32, so 32 GPIOs provided by the gpiochip
gpio_export '6'            # make the GPIO n°6 ready to use
gpio_direction_output '6'  # set the direction
gpio_set_value '6' '1'     # set the GPIO n°6 high
gpio_unexport '6'          # release the GPIO

Functions

    Name                |    Output                             |   Return
________________________|_______________________________________|_____________
gpio_select_gpiochip()  | -                                     |   0,1,2
gpio_gpiochip_isset()   | -                                     |   0,1
gpio_count()            | unsigned char: [0;254]                |   0,1,3
gpio_export()           | -                                     |   0,1,2,3
gpio_unexport()         | -                                     |   0,1,2,3
gpio_exported()         | -                                     |   0,1,2,3
gpio_unexported()       | -                                     |   0,1,2,3
gpio_export_all()       | -                                     |   0,1,3
gpio_unexport_all()     | -                                     |   0,1,3
gpio_get_edge()         | "none", "rising" or "falling"         |   0,1,2,3
gpio_get_active_low()   | "0" (active_low) or "1" (active_high) |   0,1,2,3
gpio_set_active_low()   | -                                     |   0,1,2,3
gpio_get_direction()    | "in" (input) or "out" (output)        |   0,1,2,3
gpio_direction_input()  | -                                     |   0,1,2,3
gpio_direction_output() | -                                     |   0,1,2,3
gpio_get_value()        | "0" (low) or "1" (high)               |   0,1,2,3
gpio_set_value()        | -                                     |   0,1,2,3
  • return 0: success
  • return 1: fail
  • return 2: bad args
  • return 3: GPIOCHIP_N variable not set (c.f: use gpio_select_gpiochip())

About

Bash library to manage Linux Kernel GPIO chips through a sysfs user interface

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages