Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Kent Gibson and committed by
Bartosz Golaszewski
cf048e05 62757c32

+17 -3
+17 -3
tools/gpio/gpio-event-mon.c
··· 148 148 " -s Set line as open source\n" 149 149 " -r Listen for rising edges\n" 150 150 " -f Listen for falling edges\n" 151 + " -b <n> Debounce the line with period n microseconds\n" 151 152 " [-c <n>] Do <n> loops (optional, infinite loop if not stated)\n" 152 153 " -? This helptext\n" 153 154 "\n" 154 155 "Example:\n" 155 - "gpio-event-mon -n gpiochip0 -o 4 -r -f\n" 156 + "gpio-event-mon -n gpiochip0 -o 4 -r -f -b 10000\n" 156 157 ); 157 158 } 158 159 ··· 168 167 unsigned int num_lines = 0; 169 168 unsigned int loops = 0; 170 169 struct gpio_v2_line_config config; 171 - int c; 170 + int c, attr, i; 171 + unsigned long debounce_period_us = 0; 172 172 173 173 memset(&config, 0, sizeof(config)); 174 174 config.flags = GPIO_V2_LINE_FLAG_INPUT; 175 - while ((c = getopt(argc, argv, "c:n:o:dsrf?")) != -1) { 175 + while ((c = getopt(argc, argv, "c:n:o:b:dsrf?")) != -1) { 176 176 switch (c) { 177 177 case 'c': 178 178 loops = strtoul(optarg, NULL, 10); ··· 188 186 } 189 187 lines[num_lines] = strtoul(optarg, NULL, 10); 190 188 num_lines++; 189 + break; 190 + case 'b': 191 + debounce_period_us = strtoul(optarg, NULL, 10); 191 192 break; 192 193 case 'd': 193 194 config.flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN; ··· 208 203 print_usage(); 209 204 return -1; 210 205 } 206 + } 207 + 208 + if (debounce_period_us) { 209 + attr = config.num_attrs; 210 + config.num_attrs++; 211 + for (i = 0; i < num_lines; i++) 212 + gpiotools_set_bit(&config.attrs[attr].mask, i); 213 + config.attrs[attr].attr.id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE; 214 + config.attrs[attr].attr.debounce_period_us = debounce_period_us; 211 215 } 212 216 213 217 if (!device_name || num_lines == 0) {