Skip to contentSkip to conversation

package/gpiod: add gpiod hardware handling daemon

PATCH In review Marc Chalain 2 participants 2 messages Jun 26, 2020 – Jan 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/gpiod: add gpiod hardware handling daemon

Gpiod is a little daemon to trig gpio event and launch scripts on level changing events.
As udev or mdev, it reads rules files to attach scripts on events. and launch the scripts with environment variables to describe the event. It uses libgpiod to monitor the gpio and libconfig to read the rules. It is tested on Raspberry Pi (0,3,4) with success.

---
 package/Config.in              |  1 +
 package/gpiod/Config.in        | 14 +++++++++
 package/gpiod/S20gpiod.in      | 56 ++++++++++++++++++++++++++++++++++
 package/gpiod/gpiod.hash       |  2 ++
 package/gpiod/gpiod.mk         | 52 +++++++++++++++++++++++++++++++
 package/gpiod/gpiod.service.in | 11 +++++++
 6 files changed, 136 insertions(+)
 create mode 100644 package/gpiod/Config.in
 create mode 100755 package/gpiod/S20gpiod.in
 create mode 100644 package/gpiod/gpiod.hash
 create mode 100644 package/gpiod/gpiod.mk
 create mode 100644 package/gpiod/gpiod.service.in
package/Config.in +1 -0
index 6a34a895af..c86315630f 100644
@@ -458,6 +458,7 @@ endmenu
 	source "package/freescale-imx/Config.in"
 	source "package/fxload/Config.in"
 	source "package/gcnano-binaries/Config.in"
+	source "package/gpiod/Config.in"
 	source "package/gpm/Config.in"
 	source "package/gpsd/Config.in"
 	source "package/gptfdisk/Config.in"
package/gpiod/Config.in new file +14 -0
new file mode 100644
index 0000000000..e9ba5bdba3
@@ -0,0 +1,14 @@
+config BR2_PACKAGE_GPIOD
+	bool "gpiod: gpio monitor daemon"
+	depends on BR2_USE_MMU
+	depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_8 # libgpiod
+	select BR2_PACKAGE_LIBGPIOD
+	select BR2_PACKAGE_LIBCONFIG
+	help
+	  GPIOD monitors gpio events and start scripts.
+	  The daemon loads rules defining a gpio and
+	  the scripts to launch when the level of gpio changes.
+
+comment "gpiod needs a toolchain w/ kernel headers >= 4.8"
+	depends on !BR2_USE_MMU
+	depends on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_8
package/gpiod/S20gpiod.in new file +56 -0

56 lines not on this page · raw message

package/gpiod/gpiod.hash new file +2 -0
new file mode 100644
index 0000000000..af0486f792
@@ -0,0 +1,2 @@
+sha256 d042c0394071ea8fc7464f02c2e599021d15a9891bd378677b000aa373436c89  gpiod-1.1.tar.gz
+sha256 dfba39760e099e2a64567309f0c6ceacaf9e6473bf79835fe0f8a8580651ff49  LICENSE
package/gpiod/gpiod.mk new file +52 -0

52 lines not on this page · raw message

package/gpiod/gpiod.service.in new file +11 -0
new file mode 100644
index 0000000000..38a573ccf4
@@ -0,0 +1,11 @@
+[Unit]
+Description=GPIO event handler daemon
+
+[Service]
+Type=forking
+ExecStart=@PREFIX@/sbin/gpiod -D -p /var/run/gpiod.pid
+ExecStop=@PREFIX@/sbin/gpiod -K -p /var/run/gpiod.pid
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
Signature · 1 line
2.17.1
#1 lore raw

Hello Marc,

Le 26/06/2020 à 13:29, Marc Chalain a écrit :

Quoted 6 lines

Gpiod is a little daemon to trig gpio event and launch scripts on level changing events.
As udev or mdev, it reads rules files to attach scripts on events. and launch the scripts with environment variables to describe the event. It uses libgpiod to monitor the gpio and libconfig to read the rules. It is tested on Raspberry Pi (0,3,4) with success.

Did you had some feedback from libgpiod upstream project about merging your work ? [1]

Your gpiod daemon provided by libgpiod would be nice.

[1] http://lists.busybox.net/pipermail/buildroot/2020-June/587769.html

Quoted 34 lines
---
 package/Config.in              |  1 +
 package/gpiod/Config.in        | 14 +++++++++
 package/gpiod/S20gpiod.in      | 56 ++++++++++++++++++++++++++++++++++
 package/gpiod/gpiod.hash       |  2 ++
 package/gpiod/gpiod.mk         | 52 +++++++++++++++++++++++++++++++
 package/gpiod/gpiod.service.in | 11 +++++++
 6 files changed, 136 insertions(+)
 create mode 100644 package/gpiod/Config.in
 create mode 100755 package/gpiod/S20gpiod.in
 create mode 100644 package/gpiod/gpiod.hash
 create mode 100644 package/gpiod/gpiod.mk
 create mode 100644 package/gpiod/gpiod.service.in
package/Config.in +1 -0
index 6a34a895af..c86315630f 100644
@@ -458,6 +458,7 @@ endmenu
 	source "package/freescale-imx/Config.in"
 	source "package/fxload/Config.in"
 	source "package/gcnano-binaries/Config.in"
+	source "package/gpiod/Config.in"
 	source "package/gpm/Config.in"
 	source "package/gpsd/Config.in"
 	source "package/gptfdisk/Config.in"
package/gpiod/Config.in new file +0 -0
new file mode 100644
index 0000000000..e9ba5bdba3

package/gpiod/Config.in line 10

Quoted 10 lines
package/gpiod/Config.in new file +10 -0
@@ -0,0 +1,14 @@
+config BR2_PACKAGE_GPIOD
+	bool "gpiod: gpio monitor daemon"
+	depends on BR2_USE_MMU
+	depends on BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_8 # libgpiod
+	select BR2_PACKAGE_LIBGPIOD
+	select BR2_PACKAGE_LIBCONFIG
+	help
+	  GPIOD monitors gpio events and start scripts.
+	  The daemon loads rules defining a gpio and
+	  the scripts to launch when the level of gpio changes.

Add the url to the project:
https://github.com/mchalain/gpiod

Quoted 140 lines
package/gpiod/Config.in new file +4 -0
+
+comment "gpiod needs a toolchain w/ kernel headers >= 4.8"
+	depends on !BR2_USE_MMU
+	depends on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_8
package/gpiod/S20gpiod.in new file +56 -0
new file mode 100755
index 0000000000..2cc77af145
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# Starts gpiod.
+#
+
+DAEMON="gpiod"
+PIDFILE="/var/run/$DAEMON.pid"
+
+OPTIONS=""
+
+[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
+
+start() {
+	printf 'Starting %s: ' "$DAEMON"
+	OPTIONS="${OPTIONS} -p ${PIDFILE}"
+	OPTIONS="${OPTIONS} -D"
+	start-stop-daemon -S -q -x "@PREFIX@/sbin/$DAEMON" \
+		-- $OPTIONS
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+stop() {
+	printf 'Stopping %s: ' "$DAEMON"
+	start-stop-daemon -K -q -p "$PIDFILE"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		rm -f "$PIDFILE"
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+restart() {
+	stop
+	sleep 1
+	start
+}
+
+case "$1" in
+	start|stop|restart)
+		"$1";;
+	reload)
+		# Restart, since there is no true "reload" feature.
+		restart;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac
package/gpiod/gpiod.hash new file +2 -0
new file mode 100644
index 0000000000..af0486f792
@@ -0,0 +1,2 @@
+sha256 d042c0394071ea8fc7464f02c2e599021d15a9891bd378677b000aa373436c89  gpiod-1.1.tar.gz
+sha256 dfba39760e099e2a64567309f0c6ceacaf9e6473bf79835fe0f8a8580651ff49  LICENSE
package/gpiod/gpiod.mk new file +52 -0
new file mode 100644
index 0000000000..cef3a58fd5
@@ -0,0 +1,52 @@
+################################################################################
+#
+# gpiod
+#
+################################################################################
+
+GPIOD_VERSION = 1.1
+GPIOD_SITE = $(call github,mchalain,gpiod,$(GPIOD_VERSION))
+GPIOD_LICENSE = BSD
+GPIOD_LICENSE_FILES = LICENSE
+
+PREFIX=/usr
+SYSCONFDIR=/etc/gpiod
+
+GPIOD_MAKE_OPTS = \
+	prefix=$(PREFIX) \
+	sysconfdir=$(SYSCONFDIR)
+
+GPIOD_DEPENDENCIES = \
+	libgpiod \
+	libconfig
+
+define GPIOD_CONFIGURE_CMDS
+	$(TARGET_CONFIGURE_OPTS) $(TARGET_MAKE_ENV) \
+		$(MAKE1) -C $(@D) $(GPIOD_MAKE_OPTS) defconfig
+endef
+
+define GPIOD_BUILD_CMDS
+	$(TARGET_CONFIGURE_OPTS) $(TARGET_MAKE_ENV) \
+		$(MAKE1) -C $(@D) $(GPIOD_MAKE_OPTS)
+endef
+
+define GPIOD_INSTALL_TARGET_CMDS
+	$(INSTALL) -d -m 755 $(TARGET_DIR)$(SYSCONFDIR)/rules.d
+	$(MAKE) -C $(@D) $(GPIOD_MAKE_OPTS) \
+		DESTDIR="$(TARGET_DIR)" install
+endef
+
+define GPIOD_INSTALL_INIT_SYSTEMD
+	cp $(GPIOD_PKGDIR)/gpiod.service.in $(@D)/gpiod.service
+	$(SED) "s,@PREFIX@,$(PREFIX),g" $(@D)/gpiod.service
+	$(INSTALL) -D -m 644 $(@D)/gpiod.service \
+		$(TARGET_DIR)/usr/lib/systemd/system/gpiod.service
+endef
+define GPIOD_INSTALL_INIT_SYSV
+	cp $(GPIOD_PKGDIR)/S20gpiod.in $(@D)/S20gpiod
+	$(SED) "s,@PREFIX@,$(PREFIX),g" $(@D)/S20gpiod
+	$(INSTALL) -D -m 755 $(@D)/S20gpiod \
+		$(TARGET_DIR)/etc/init.d/S20gpiod
+endef
+
+$(eval $(generic-package))
package/gpiod/gpiod.service.in new file +1 -0
new file mode 100644
index 0000000000..38a573ccf4
@@ -0,0 +1,11 @@
+[Unit]

package/gpiod/gpiod.service.in line 11

Quoted 10 lines
package/gpiod/gpiod.service.in new file +10 -0
+Description=GPIO event handler daemon
+
+[Service]
+Type=forking
+ExecStart=@PREFIX@/sbin/gpiod -D -p /var/run/gpiod.pid
+ExecStop=@PREFIX@/sbin/gpiod -K -p /var/run/gpiod.pid
+Restart=always
+
+[Install]
+WantedBy=multi-user.target

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot