From nobody Thu Dec 29 17:03:06 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NjZTQ5YXhz2kfgk; Thu, 29 Dec 2022 17:03:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NjZTQ4zjzz4NCq; Thu, 29 Dec 2022 17:03:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672333386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EaDkdtDOrZhkcejLvQaHh6qOGrulzy60vzmYqQwTOVM=; b=hKxtU06Mb7iigPVel+mk+iKwFQtnCTvak1eemgH5449U8DQbrPuafQpIaDIkBOXu+zJBpw KeY8hfwcJiyfheuhF/6ckZFXqj75ifHTtP/SasPLN0qwHhZWKA29+6ZPqQnk9zcH4XTcL/ ysM5gY6hCpPAK+fio+SatHqRFBhrU1EHb09jWcVS0lrcoAdvEk+oBM0CKq6zQaeY1C1vKM W9JKu4tIDbF925JrYSnFC7CtcQ0IS8r4S9pzBUHRfCYWMeWZrqbvWxEHPozudeCHAnrBR/ ajy730pId+gcdPZFTUw/Qh8yijEA7TMxg+Jae+MzOriyofQQGn1dXZ2nNXQusA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672333386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EaDkdtDOrZhkcejLvQaHh6qOGrulzy60vzmYqQwTOVM=; b=RmUr5L9L1ZGoVQE0Wg13ktyt3OIPgNak5WeBr1/VXgP5TybqxCyl7y+9mBBBAkyJhFLea4 zyBQ6TrWOzVm82XYXBeHYC+Elq8w8sIAbLsOJhuWsP6ba4MxgbKjSjdy2a6hS7ZjlhpBMK hoxlKD6aJVQlnHtW76X+0vodmsGbX8R4vyeOmreaIl1fsXR0jLshCh+d5cFtp/KTJt8lKC rUSYSdFENDvJJX0JL0kbBncl1Z/3TAPV+TaD1N49OjIag15lIPQ9CwzRNhUegk6Gw9gMQ/ w+md4H8UWAerBwJBiIeiLBOzFWUn3s73HK/HRrCT8Hu7VHkNcOnoVFF/SWGl6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1672333386; a=rsa-sha256; cv=none; b=L43v3kEMQwyZqfS49nY/cC/5jbBTrlPhrLhDwWjcMdAKjKZGwKyitQKXdxyaV+6QbKK4nu tTmi6dvfeb/YuZntN020r5vfBvFui4jbfhZD5oSrdpKwmbHNYztbiFN33CEGK6Rn3VJwrb GiYW4g0p1vq04O9kq84Hf5TGVpsZEoxBKubM3Zjj5ICtCt55/MkinYZAF7yh993UCSbt27 q+owmGGVE5Ds1fg6RLfGB+gkdvRSCa3xv+hc5dDuLGuPxfRQRpHBMTd7r+xANYQm6L4ted cJhdOQLJkLI9/MbAdH7X2T9u2zRytw9VTgCWgPiFVpmUe0O1NnePfZPfVSd4xg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NjZTQ42MnzcQj; Thu, 29 Dec 2022 17:03:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BTH36JP019278; Thu, 29 Dec 2022 17:03:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BTH36pM019277; Thu, 29 Dec 2022 17:03:06 GMT (envelope-from git) Date: Thu, 29 Dec 2022 17:03:06 GMT Message-Id: <202212291703.2BTH36pM019277@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rene Ladan Subject: git: 534470090d98 - stable/13 - gpioevents: add support for pull-down and floating input pins. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rene X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 534470090d987118b9728deda1b28f96ae5d1cec Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by rene (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=534470090d987118b9728deda1b28f96ae5d1cec commit 534470090d987118b9728deda1b28f96ae5d1cec Author: Rene Ladan AuthorDate: 2022-12-21 21:24:11 +0000 Commit: Rene Ladan CommitDate: 2022-12-29 17:02:37 +0000 gpioevents: add support for pull-down and floating input pins. The pin-mode (ft, pd, pu for floating, pull-down, pull-up) is specified after the intr-config (no, eb, ef, er) for each pin. Tested on my Raspberry Pi 1B. PR: 268504 Approved by: manu MFC after: 1 week (cherry picked from commit 453db42291a3179a51b9bf41ca7dbc0a5298bffa) gpioevents: fix some white-space errors Fixes: 453db42291a3 - gpioevents: add support for pull-down and floating input pins. Approved by: manu (implicit) MFC after: 1 week (cherry picked from commit e2f3742ab8b10ba5ec4dc190c5b64e9151bb0d57) --- tools/test/gpioevents/gpioevents.c | 47 +++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/tools/test/gpioevents/gpioevents.c b/tools/test/gpioevents/gpioevents.c index 20d18257f4a8..9beffa740875 100644 --- a/tools/test/gpioevents/gpioevents.c +++ b/tools/test/gpioevents/gpioevents.c @@ -66,7 +66,7 @@ static void usage() { fprintf(stderr, "usage: %s [-f ctldev] [-m method] [-s] [-n] [-S] [-u]" - "[-t timeout] [-d delay-usec] pin intr-config [pin intr-config ...]\n\n", + "[-t timeout] [-d delay-usec] pin intr-config pin-mode [pin intr-config pin-mode ...]\n\n", getprogname()); fprintf(stderr, " -d delay before each call to read/poll/select/etc\n"); fprintf(stderr, " -n Non-blocking IO\n"); @@ -85,7 +85,11 @@ usage() fprintf(stderr, " no\t no interrupt\n"); fprintf(stderr, " er\t edge rising\n"); fprintf(stderr, " ef\t edge falling\n"); - fprintf(stderr, " eb\t edge both\n"); + fprintf(stderr, " eb\t edge both\n\n"); + fprintf(stderr, "Possible options for pin-mode:\n\n"); + fprintf(stderr, " ft\t floating\n"); + fprintf(stderr, " pd\t pull-down\n"); + fprintf(stderr, " pu\t pull-up\n"); } static void @@ -539,8 +543,15 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - if (argc % 2 == 1) { - fprintf(stderr, "%s: Invalid number of pin intr-conf pairs.\n", + if (argc == 1) { + fprintf(stderr, "%s: No trigger type specified.\n", + getprogname()); + usage(); + return EXIT_FAILURE; + } + + if (argc % 3 != 0) { + fprintf(stderr, "%s: Invalid number of (pin intr-conf mode) triplets.\n", getprogname()); usage(); return EXIT_FAILURE; @@ -567,7 +578,7 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "cannot set O_NONBLOCK on %s", file); } - for (int i = 0; i <= argc - 2; i += 2) { + for (int i = 0; i <= argc - 3; i += 3) { errno = 0; pin_config.g_pin = strtol(argv[i], NULL, 10); @@ -604,7 +615,31 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - pin_config.g_flags |= GPIO_PIN_INPUT | GPIO_PIN_PULLUP; + if (strnlen(argv[i + 2], 2) < 2) { + fprintf(stderr, "%s: Invalid pin mode (argument " + "too short).\n", getprogname()); + usage(); + return EXIT_FAILURE; + } + + switch((argv[i + 2][0] << 8) + argv[i + 2][1]) { + case ('f' << 8) + 't': + /* no changes to pin_config */ + break; + case ('p' << 8) + 'd': + pin_config.g_flags |= GPIO_PIN_PULLDOWN; + break; + case ('p' << 8) + 'u': + pin_config.g_flags |= GPIO_PIN_PULLUP; + break; + default: + fprintf(stderr, "%s: Invalid pin mode.\n", + getprogname()); + usage(); + return EXIT_FAILURE; + } + + pin_config.g_flags |= GPIO_PIN_INPUT; res = gpio_pin_set_flags(handle, &pin_config); if (res < 0)