From nobody Thu Dec 22 09:14:43 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 4Nd4QC4GStz1Gly3; Thu, 22 Dec 2022 09:14:43 +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 4Nd4QC3cvnz41S9; Thu, 22 Dec 2022 09:14:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671700483; 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=0vZVQIU24j3jzUQOsaV2szewqIPulExeM81cu3ygA1k=; b=ifkk1ZyAPupere28X5tMmJseGDLptEUBOGowv5WoI8WJPH8uqzbSKyhFkfDZNXafbuwAnC IdymCWaBKYxbzN4L3MlYhTlZofQj9YcUj3pMgtFP/9w6yaWDvn6OnIixb7dOtL1mXd4aRG T3Xtb9UScmpzfchC1P7VEPLnBB74OlkaWvz+7H7kFXnfZDrAkM3Tcb/pMeXEoBbvBrQNYI jo3b4b36Gvqu9MqNg8SAKUZMRaoxxFfBCZoyKh9rYtSfwBeB2gUzoao+0VB9V/QnLVRgfo bSwJfIPwBSNA/YkZWPib/HKM5z5qwa4MGSCiTlzUOHfITcgmBkunMAGy3rTxoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671700483; 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=0vZVQIU24j3jzUQOsaV2szewqIPulExeM81cu3ygA1k=; b=tuzI38/QOyBKQIlwGA08iaMH19bMzM7gE8b23+0ZO/wh15J86MBsts/8dlGHEfyjzbXKQ3 9W3a7PADOzB87DrmQFs0tiD89pRmcpraqODXlewL7NOhTSy3XPQAsllVU6qAw3JRNT67hH cxUwGEJJP6lbeNkqQfINVXd4ulGJwGYXNsvRB0diDa9TO/E2xhKS9XrR72cwsAdarJQgSA tdEdI0y7puv//K4g87xNLq+nqsnEeMyxh77/6yvDjeWSNE7sR137HCEH5p/BIRjYFKW09L YSP1uai8vogGdRptkWxgqF6eoK8RckiVOg0uHYXgc+E5LbELsBlVxVz8YAMU3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671700483; a=rsa-sha256; cv=none; b=WzeYur9WDcLEIUW8t7e2DhbYnowgvU1f3ZxJeFiXi3InZUeHmnzQV9+vWR97bTvTm8FyPG XHj4dcF70T7OryDgxq5DD09GvBEGtczjbLXo20jasR7KIZ8fhENiin55bGdgCiwieDfy9C 0LCu0N4zIwu+IKy8Ned8viuGgIh/3431YxK7ilU8j9hhtvL4pOUHw7gFjgLgRHNuSdDhsM /hFnEHNvBrKvA73NixPi2CTgt4Urn4jIqIE8f48kRcumawvphWUXkvoGoIuZSV327Bd5fR 18ddvb5xv9mInAocGLJkX0q2hhk2l/2nQ0DuMZ7qzw6BGiwcbJwQaVBZegY8Xg== 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 4Nd4QC2YWJzpJ6; Thu, 22 Dec 2022 09:14:43 +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 2BM9EhWS025015; Thu, 22 Dec 2022 09:14:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BM9EhZa025014; Thu, 22 Dec 2022 09:14:43 GMT (envelope-from git) Date: Thu, 22 Dec 2022 09:14:43 GMT Message-Id: <202212220914.2BM9EhZa025014@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rene Ladan Subject: git: 453db42291a3 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 453db42291a3179a51b9bf41ca7dbc0a5298bffa Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rene (doc, ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=453db42291a3179a51b9bf41ca7dbc0a5298bffa commit 453db42291a3179a51b9bf41ca7dbc0a5298bffa Author: Rene Ladan AuthorDate: 2022-12-21 21:24:11 +0000 Commit: Rene Ladan CommitDate: 2022-12-22 09:13:59 +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 --- 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..00aff726388a 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)