daemon for controlling GPIOs
Subsystems (2)
Hi!
I wrote a simple daemon for controlling GPIOs via UNIX socket. Currently only the output set/unset works. The program read a config file and configuring the pins with libgpiod. The config file is in the tools directory. I don't really know where should I drop and how to configure libtool. The fork() is commented yet so the daemon writes info to the terminal. With the command for ex.
echo "gpiochip1:PD21 set=1" | socat - UNIX-
CONNECT:/var/run/gpiodaemon.sock
you can set a configured out to high. If it is useful for the project I can send more patch in the future with more feature. This is as you can see a demo only. I tested with an Allwinner H6 SoC (OrangePi Lite2). I am newbie in contributing so please fix me if required.
Regards,
André Kovács
From f18d2fbdff11798cd457ac75684f7dbff6812cad Mon Sep 17 00:00:00 2001
From: Andre Kovacs <[email protected]>
Date: Sat, 9 Nov 2019 19:14:13 +0100
Subject: [PATCH] gpiodaemon basics
The program read the config file and configure the IOs. Over a UNIX socket it is possible to set the configured output(s). Some little modifications was needed in the lib.
--- include/gpiod.h | 16 ++ lib/core.c | 5 + lib/iter.c | 5 + tools/Makefile.am | 4 +- tools/daemonconfig | 2 + tools/gpiodaemon.c | 466 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 497 insertions(+), 1 deletion(-) create mode 100644 tools/daemonconfig create mode 100644 tools/gpiodaemon.c
include/gpiod.h +16 -0
@@ -659,6 +659,13 @@ enum { };/** +* @brief Get the line's chip name. +* @param line GPIO line object. +* @return Chip name. +*/ +const char *gpiod_line_chip_name (struct gpiod_line *line)GPIOD_API ; + +/** * @brief Read the GPIO line offset. * @param line GPIO line object. * @return Line offset.
@@ -1321,6 +1328,15 @@ gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API;struct gpiod_chip *gpiod_chip_iter_next_noclose (struct gpiod_chip_iter *iter)GPIOD_API ; + +/** +* @brief Set offset to zero. +* @param iter The gpiochip iterator object. +*/ + + +void gpiod_chip_iter_reset_offset(struct gpiod_chip_iter *iter) GPIOD_API; +/** * @brief Iterate over all GPIO chips present in the system. * @param iter An initialized GPIO chip iterator.
lib/core.c +5 -0
@@ -334,6 +334,11 @@ struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line)return line->chip; } +const char *gpiod_line_chip_name (struct gpiod_line *line) +{ +return line->chip->name[0 ] =='\0' ?NULL : line->chip->name; +} +unsigned int gpiod_line_offset (struct gpiod_line *line) {return line->offset;
lib/iter.c +5 -0
@@ -169,3 +169,8 @@ struct gpiod_line *gpiod_line_iter_next(struct gpiod_line_iter *iter)return iter->offset < (iter->num_lines) ? iter->lines[iter->offset++] :NULL ; } + +void gpiod_chip_iter_reset_offset (struct gpiod_chip_iter *iter) +{ + iter->offset =0 ; +}
tools/Makefile.am +3 -1
@@ -14,7 +14,7 @@ libtools_common_la_SOURCES = tools-common.c tools-common.h LDADD = libtools-common.la $(top_builddir)/lib/libgpiod.la -bin_PROGRAMS = gpiodetect gpioinfo gpioget gpioset gpiomon gpiofind +bin_PROGRAMS = gpiodetect gpioinfo gpioget gpioset gpiomon gpiofind gpiodaemon gpiodetect_SOURCES = gpiodetect.c
@@ -28,6 +28,8 @@ gpiomon_SOURCES = gpiomon.c gpiofind_SOURCES = gpiofind.c +gpiodaemon_SOURCES = gpiodaemon.c + EXTRA_DIST = gpio-tools-test gpio-tools-test.bats if WITH_TESTS
tools/daemonconfig new file +2 -0
@@ -0,0 +1,2 @@ +gpiochip1:PD21 direction=out,defval=0,consumer=asd; +gpiochip1:118 direction=in,consumer=asd2;
tools/gpiodaemon.c new file +466 -0
466 lines not on this page · raw message
Signature · 1 line
2.11.0