All of lore.kernel.org
 help / color / mirror / Atom feed
From: mchalain <marc.chalain@gmail.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 1/1] package/gpiod: add gpiod hardware handling daemon
Date: Tue, 16 Jun 2020 18:42:00 +0200	[thread overview]
Message-ID: <20200616164200.6399-1-marc.chalain@gmail.com> (raw)

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, during few months.

Signed-off-by: mchalain <marc.chalain@gmail.com>
---
 package/Config.in             |  1 +
 package/gpiod/Config.in       | 14 ++++++++++
 package/gpiod/S20gpiod        | 41 +++++++++++++++++++++++++++
 package/gpiod/gpiod.hash      |  1 +
 package/gpiod/gpiod.mk        | 52 +++++++++++++++++++++++++++++++++++
 package/gpiod/gpiod_defconfig |  0
 6 files changed, 109 insertions(+)
 create mode 100644 package/gpiod/Config.in
 create mode 100755 package/gpiod/S20gpiod
 create mode 100644 package/gpiod/gpiod.hash
 create mode 100644 package/gpiod/gpiod.mk
 create mode 100644 package/gpiod/gpiod_defconfig

diff --git a/package/Config.in b/package/Config.in
index d32eadab88..d529442fe7 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -457,6 +457,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"
diff --git a/package/gpiod/Config.in b/package/gpiod/Config.in
new file mode 100644
index 0000000000..e9d5dc47f9
--- /dev/null
+++ b/package/gpiod/Config.in
@@ -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
+	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/ support of MMU and headers > 4.8"
+	depends on !BR2_USE_MMU
+	depends on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_8
diff --git a/package/gpiod/S20gpiod b/package/gpiod/S20gpiod
new file mode 100755
index 0000000000..1a912c8e43
--- /dev/null
+++ b/package/gpiod/S20gpiod
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Starts gpiod.
+#
+
+RUNDIR=/var/run
+SBINDIR=/usr/sbin
+BINDIR=/usr/bin
+
+start() {
+	printf "Starting gpiod: "
+	start-stop-daemon -S -q --exec ${SBINDIR}/gpiod -- -D -p ${RUNDIR}/gpiod.pid
+	[ $? == 0 ] && echo "OK" || echo "FAILED"
+}
+stop() {
+	printf "Stopping gpiod: "
+	${SBINDIR}/gpiod -K -p ${RUNDIR}/gpiod.pid
+	echo "OK"
+}
+restart() {
+	stop
+	start
+}
+
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart|reload)
+	restart
+	;;
+  *)
+	echo "Usage: $0 {start|stop|restart}"
+	exit 1
+esac
+
+exit $?
+
diff --git a/package/gpiod/gpiod.hash b/package/gpiod/gpiod.hash
new file mode 100644
index 0000000000..4a9c10297c
--- /dev/null
+++ b/package/gpiod/gpiod.hash
@@ -0,0 +1 @@
+sha256 f7c12fafcfb02515ae34d9502b4121d7980606fb53b57bee35143bd985bfdddc  gpiod-1.0.tar.gz
diff --git a/package/gpiod/gpiod.mk b/package/gpiod/gpiod.mk
new file mode 100644
index 0000000000..ed99f1d3be
--- /dev/null
+++ b/package/gpiod/gpiod.mk
@@ -0,0 +1,52 @@
+################################################################################
+#
+# gpiod
+#
+################################################################################
+
+GPIOD_VERSION = 1.0
+GPIOD_SITE = $(call github,mchalain,gpiod,$(GPIOD_VERSION))
+
+GPIOD_MAKE_OPTS+=prefix=/usr
+GPIOD_MAKE_OPTS+=sysconfdir=/etc/gpiod
+#GPIOD_MAKE_OPTS+=DEBUG=y
+
+GPIOD_KCONFIG_FILE=$(GPIOD_PKGDIR)/gpiod_defconfig
+GPIOD_KCONFIG_EDITORS = config
+GPIOD_KCONFIG_OPTS = $(GPIOD_MAKE_OPTS)
+
+GPIOD_DEPENDENCIES += libgpiod
+GPIOD_DEPENDENCIES += libconfig
+
+define GPIOD_LIBCONFIG_OPTS
+	$(call KCONFIG_ENABLE_OPT,LIBCONFIG,$(@D)/.config)
+endef
+
+define GPIOD_KCONFIG_FIXUP_CMDS
+	$(GPIOD_LIBCONFIG_OPTS)
+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)/etc/gpiod/rules.d
+	$(MAKE) -C $(@D) $(GPIOD_MAKE_OPTS) \
+		DESTDIR="$(TARGET_DIR)" DEVINSTALL=n install
+endef
+
+define GPIOD_INSTALL_INIT_SYSTEMD
+	$(INSTALL) -D -m 644 $(GPIOD_PKGDIR)/gpiod.service \
+		$(TARGET_DIR)/usr/lib/systemd/system/gpiod.service
+	mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
+	ln -fs ../../../../usr/lib/systemd/system/gpiod.service \
+		$(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/gpiod.service
+endef
+define GPIOD_INSTALL_INIT_SYSV
+	$(INSTALL) -D -m 755 $(GPIOD_PKGDIR)/S20gpiod \
+		$(TARGET_DIR)/etc/init.d/S20gpiod
+endef
+
+$(eval $(kconfig-package))
diff --git a/package/gpiod/gpiod_defconfig b/package/gpiod/gpiod_defconfig
new file mode 100644
index 0000000000..e69de29bb2
-- 
2.17.1

             reply	other threads:[~2020-06-16 16:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16 16:42 mchalain [this message]
2020-06-17 20:38 ` [Buildroot] [PATCH 1/1] package/gpiod: add gpiod hardware handling daemon Thomas Petazzoni
2020-06-19 15:37   ` Marc Chalain
2020-06-19 19:39     ` Alexander Dahl
2020-06-19 20:25       ` Marc Chalain
2020-06-20 12:33         ` Alexander Dahl
2020-06-20 17:29           ` Marc Chalain
2020-06-26 11:29 Marc Chalain
2022-01-08 16:07 ` Romain Naour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200616164200.6399-1-marc.chalain@gmail.com \
    --to=marc.chalain@gmail.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.