Git Product home page Git Product logo

libgpio's Introduction

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())

libgpio's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lhc180

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.