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
This commit is contained in:
parent
702b53dd2a
commit
453db42291
@ -66,7 +66,7 @@ static void
|
|||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-f ctldev] [-m method] [-s] [-n] [-S] [-u]"
|
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());
|
getprogname());
|
||||||
fprintf(stderr, " -d delay before each call to read/poll/select/etc\n");
|
fprintf(stderr, " -d delay before each call to read/poll/select/etc\n");
|
||||||
fprintf(stderr, " -n Non-blocking IO\n");
|
fprintf(stderr, " -n Non-blocking IO\n");
|
||||||
@ -85,7 +85,11 @@ usage()
|
|||||||
fprintf(stderr, " no\t no interrupt\n");
|
fprintf(stderr, " no\t no interrupt\n");
|
||||||
fprintf(stderr, " er\t edge rising\n");
|
fprintf(stderr, " er\t edge rising\n");
|
||||||
fprintf(stderr, " ef\t edge falling\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
|
static void
|
||||||
@ -539,8 +543,15 @@ main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc % 2 == 1) {
|
if (argc == 1) {
|
||||||
fprintf(stderr, "%s: Invalid number of pin intr-conf pairs.\n",
|
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());
|
getprogname());
|
||||||
usage();
|
usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -567,7 +578,7 @@ main(int argc, char *argv[])
|
|||||||
err(EXIT_FAILURE, "cannot set O_NONBLOCK on %s", file);
|
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;
|
errno = 0;
|
||||||
pin_config.g_pin = strtol(argv[i], NULL, 10);
|
pin_config.g_pin = strtol(argv[i], NULL, 10);
|
||||||
@ -604,7 +615,31 @@ main(int argc, char *argv[])
|
|||||||
return EXIT_FAILURE;
|
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);
|
res = gpio_pin_set_flags(handle, &pin_config);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user