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 <r...@freebsd.org>
AuthorDate: 2022-12-21 21:24:11 +0000
Commit:     Rene Ladan <r...@freebsd.org>
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)

Reply via email to