mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-03-19 05:24:11 +00:00
tools: gpio: add debounce support to gpio-event-mon
Add support for debouncing monitored lines to gpio-event-mon. Signed-off-by: Kent Gibson <warthog618@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
This commit is contained in:
parent
62757c32d5
commit
cf048e05b6
1 changed files with 17 additions and 3 deletions
|
@ -148,11 +148,12 @@ void print_usage(void)
|
||||||
" -s Set line as open source\n"
|
" -s Set line as open source\n"
|
||||||
" -r Listen for rising edges\n"
|
" -r Listen for rising edges\n"
|
||||||
" -f Listen for falling 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"
|
" [-c <n>] Do <n> loops (optional, infinite loop if not stated)\n"
|
||||||
" -? This helptext\n"
|
" -? This helptext\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Example:\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"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,11 +168,12 @@ int main(int argc, char **argv)
|
||||||
unsigned int num_lines = 0;
|
unsigned int num_lines = 0;
|
||||||
unsigned int loops = 0;
|
unsigned int loops = 0;
|
||||||
struct gpio_v2_line_config config;
|
struct gpio_v2_line_config config;
|
||||||
int c;
|
int c, attr, i;
|
||||||
|
unsigned long debounce_period_us = 0;
|
||||||
|
|
||||||
memset(&config, 0, sizeof(config));
|
memset(&config, 0, sizeof(config));
|
||||||
config.flags = GPIO_V2_LINE_FLAG_INPUT;
|
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) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
loops = strtoul(optarg, NULL, 10);
|
loops = strtoul(optarg, NULL, 10);
|
||||||
|
@ -187,6 +189,9 @@ int main(int argc, char **argv)
|
||||||
lines[num_lines] = strtoul(optarg, NULL, 10);
|
lines[num_lines] = strtoul(optarg, NULL, 10);
|
||||||
num_lines++;
|
num_lines++;
|
||||||
break;
|
break;
|
||||||
|
case 'b':
|
||||||
|
debounce_period_us = strtoul(optarg, NULL, 10);
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
config.flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN;
|
config.flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN;
|
||||||
break;
|
break;
|
||||||
|
@ -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) {
|
if (!device_name || num_lines == 0) {
|
||||||
print_usage();
|
print_usage();
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue