[PATCH v2 17/18] tools: gpio: add debounce support to gpio-event-mon

From: Kent Gibson
Date: Sat Jul 25 2020 - 00:22:51 EST


Add support for debouncing monitored lines to gpio-event-mon.

Signed-off-by: Kent Gibson <warthog618@xxxxxxxxx>
---
tools/gpio/gpio-event-mon.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c
index 5da980f78881..b64427d78942 100644
--- a/tools/gpio/gpio-event-mon.c
+++ b/tools/gpio/gpio-event-mon.c
@@ -129,11 +129,12 @@ void print_usage(void)
" -s Set line as open source\n"
" -r Listen for rising edges\n"
" -f Listen for falling edges\n"
+ " -b <n> Debounce the line with period n microseconds\n"
" [-c <n>] Do <n> loops (optional, infinite loop if not stated)\n"
" -? This helptext\n"
"\n"
"Example:\n"
- "gpio-event-mon -n gpiochip0 -o 4 -r -f\n"
+ "gpio-event-mon -n gpiochip0 -o 4 -r -f -b 10000\n"
);
}

@@ -147,11 +148,11 @@ int main(int argc, char **argv)
unsigned int line = -1;
unsigned int loops = 0;
struct gpioline_config config;
- int c;
+ int c, attr;

memset(&config, 0, sizeof(config));
config.flags = GPIOLINE_FLAG_V2_INPUT;
- while ((c = getopt(argc, argv, "c:n:o:dsrf?")) != -1) {
+ while ((c = getopt(argc, argv, "c:n:o:b:dsrf?")) != -1) {
switch (c) {
case 'c':
loops = strtoul(optarg, NULL, 10);
@@ -162,6 +163,14 @@ int main(int argc, char **argv)
case 'o':
line = strtoul(optarg, NULL, 10);
break;
+ case 'b':
+ attr = config.num_attrs;
+ config.num_attrs++;
+ gpiotools_set_bit(config.attrs[attr].mask, 0);
+ config.attrs[attr].attr.id = GPIOLINE_ATTR_ID_DEBOUNCE;
+ config.attrs[attr].attr.debounce_period =
+ strtoul(optarg, NULL, 10);
+ break;
case 'd':
config.flags |= GPIOLINE_FLAG_V2_OPEN_DRAIN;
break;
--
2.27.0