Skip to content

Commit

Permalink
tools: gpio: add debounce support to gpio-event-mon
Browse files Browse the repository at this point in the history
Add support for debouncing monitored lines to gpio-event-mon.

Signed-off-by: Kent Gibson <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Signed-off-by: Bartosz Golaszewski <[email protected]>
  • Loading branch information
warthog618 authored and brgl committed Sep 30, 2020
1 parent 62757c3 commit cf048e0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tools/gpio/gpio-event-mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,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"
);
}

Expand All @@ -167,11 +168,12 @@ int main(int argc, char **argv)
unsigned int num_lines = 0;
unsigned int loops = 0;
struct gpio_v2_line_config config;
int c;
int c, attr, i;
unsigned long debounce_period_us = 0;

memset(&config, 0, sizeof(config));
config.flags = GPIO_V2_LINE_FLAG_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);
Expand All @@ -187,6 +189,9 @@ int main(int argc, char **argv)
lines[num_lines] = strtoul(optarg, NULL, 10);
num_lines++;
break;
case 'b':
debounce_period_us = strtoul(optarg, NULL, 10);
break;
case 'd':
config.flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN;
break;
Expand All @@ -205,6 +210,15 @@ int main(int argc, char **argv)
}
}

if (debounce_period_us) {
attr = config.num_attrs;
config.num_attrs++;
for (i = 0; i < num_lines; i++)
gpiotools_set_bit(&config.attrs[attr].mask, i);
config.attrs[attr].attr.id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE;
config.attrs[attr].attr.debounce_period_us = debounce_period_us;
}

if (!device_name || num_lines == 0) {
print_usage();
return -1;
Expand Down

0 comments on commit cf048e0

Please sign in to comment.