gpio: add simple get/set helpers for GPIO lines
PATCH 1/1 gpio: add simple get/set helpers for GPIO lines
The Linux kernel GPIO api operates with chips, lines, handles, and events.
The chip and line structures represent info about gpio chips, and gpio lines, respectively. They are used to e.g. lookup a line with a certain name, and/or line flags.
The handle structure is used to "obtain" a handle to one or more gpio lines on a chip. Until the file descriptor in this handle is closed, the gpio lines cannot be used by others. The same file descriptor is used when setting or getting the line values (one can also set the initial value when obtaining handles for output lines).
The event structure is used to get a file descriptor that can be used with select/poll to wait for changes in line levels.
This commit add simple support for setting and getting the value for a single gpio line. It does so by obtaining a line handle to get/set the value, and then release the handle immediately again.
Functionality that could be implemented, but is postponed until the need arises includes:
* looking up a gpio line by its name
* setting/getting multiple gpio lines with a single function
* waiting for events
* holding on to handles
Some of the above probably require adding structures to represent gpio lines and events, while handles should be private to the class.
---
Changes since RFC:
* added gpio.h to ell.h
* changed copyright to Geanix
* open gpiochip in l_gpio_chip_new()
* open gpiochip read-only
* added input checks
* clear ioctl structs with memset instead of = {0}
* reorder error-paths
Makefile.am | 6 ++- ell/ell.h | 1 + ell/ell.sym | 5 ++ ell/gpio.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ell/gpio.h | 47 ++++++++++++++++++ 5 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 ell/gpio.c create mode 100644 ell/gpio.h
Makefile.am +4 -2
@@ -51,7 +51,8 @@ pkginclude_HEADERS = ell/ell.h \ ell/dhcp.h \ ell/cert.h \ ell/ecc.h \ - ell/ecdh.h + ell/ecdh.h \ + ell/gpio.h lib_LTLIBRARIES = ell/libell.la
@@ -119,7 +120,8 @@ ell_libell_la_SOURCES = $(linux_headers) \ ell/ecc.h \ ell/ecc-external.c \ ell/ecc.c \ - ell/ecdh.c + ell/ecdh.c \ + ell/gpio.c ell_libell_la_LDFLAGS = -no-undefined \ -Wl,--version-script=$(top_srcdir)/ell/ell.sym \
ell/ell.h +1 -0
@@ -59,3 +59,4 @@#include <ell/cert.h> #include <ell/ecc.h> #include <ell/ecdh.h> +#include <ell/gpio.h>
ell/ell.sym +5 -0
@@ -463,6 +463,11 @@ global: /* ecdh */ l_ecdh_generate_key_pair; l_ecdh_generate_shared_secret; + /* gpio */ + l_gpio_chip_new; + l_gpio_chip_free; + l_gpio_chip_get_line_value; + l_gpio_chip_set_line_value; local: *; };
ell/gpio.c new file +135 -0
135 lines not on this page · raw message
ell/gpio.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.20.0