diff options
author | Rene Ladan <rene@FreeBSD.org> | 2022-12-21 21:24:11 +0000 |
---|---|---|
committer | Rene Ladan <rene@FreeBSD.org> | 2022-12-22 09:13:59 +0000 |
commit | 453db42291a3179a51b9bf41ca7dbc0a5298bffa (patch) | |
tree | ce1e48439b8bfae0851c827a8f73170c10840002 | |
parent | 702b53dd2af4851f95c025a08a2029f9e67ba1bf (diff) | |
download | src-453db42291a3179a51b9bf41ca7dbc0a5298bffa.tar.gz src-453db42291a3179a51b9bf41ca7dbc0a5298bffa.zip |
-rw-r--r-- | tools/test/gpioevents/gpioevents.c | 47 |
1 files 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) |