deactivate debounce when delay is 0
authorMichael Gernoth <michael@gernoth.net>
Sun, 3 Jul 2011 10:50:28 +0000 (12:50 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sun, 3 Jul 2011 10:50:28 +0000 (12:50 +0200)
debounce.c

index 4006cd2..852118f 100644 (file)
@@ -5,13 +5,14 @@
 
 #define PREFIX "debounce: "
 
 
 #define PREFIX "debounce: "
 
-static int debounce_delay = 10;
+static int debounce_delay = 15;
 
 static int old_delay = 0;
 
 static int old_delay = 0;
+static unsigned old_flags = 0;
 static struct gpio_event_matrix_info *gpio_evmi = NULL;
 
 module_param(debounce_delay, int, S_IRUSR | S_IRGRP | S_IROTH);
 static struct gpio_event_matrix_info *gpio_evmi = NULL;
 
 module_param(debounce_delay, int, S_IRUSR | S_IRGRP | S_IROTH);
-MODULE_PARM_DESC(debounce_delay, "debouncing delay (ms), default: 10");
+MODULE_PARM_DESC(debounce_delay, "debouncing delay (ms), default: 15");
 
 static int find_ms2_dev(struct device *dev, void *data)
 {
 
 static int find_ms2_dev(struct device *dev, void *data)
 {
@@ -48,13 +49,6 @@ static int __init debounce_init(void)
        printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
 
        printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
 
-       /* GPIOKPF_DEBOUNCE should already be set by GPIOKPF_REMOVE_PHANTOM_KEYS */
-       if (!(gpio_evmi->flags & GPIOKPF_DEBOUNCE)) {
-               printk(KERN_INFO PREFIX "Activating debounce\n");
-               gpio_evmi->flags |= GPIOKPF_DEBOUNCE;
-               printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
-       }
-
        old_delay = gpio_evmi->debounce_delay.tv.nsec;
 
        if (gpio_evmi->debounce_delay.tv.nsec != debounce_delay * NSEC_PER_MSEC) {
        old_delay = gpio_evmi->debounce_delay.tv.nsec;
 
        if (gpio_evmi->debounce_delay.tv.nsec != debounce_delay * NSEC_PER_MSEC) {
@@ -63,6 +57,21 @@ static int __init debounce_init(void)
                printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        }
 
                printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
        }
 
+       old_flags = gpio_evmi->flags;
+
+       if (gpio_evmi->debounce_delay.tv.nsec != 0) {
+               /* GPIOKPF_DEBOUNCE should already be set by GPIOKPF_REMOVE_PHANTOM_KEYS */
+               if (!(gpio_evmi->flags & GPIOKPF_DEBOUNCE)) {
+                       printk(KERN_INFO PREFIX "Activating debounce\n");
+                       gpio_evmi->flags |= GPIOKPF_DEBOUNCE;
+               }
+       } else {
+               /* Deactivating GPIOKPF_DEBOUNCE */
+               printk(KERN_INFO PREFIX "Deactivating debounce\n");
+               gpio_evmi->flags &= ~GPIOKPF_DEBOUNCE;
+       }
+       printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
+
        return 0;
 }
 
        return 0;
 }
 
@@ -74,6 +83,11 @@ static void __exit debounce_exit(void)
                        gpio_evmi->debounce_delay.tv.nsec = old_delay;
                        printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
                }
                        gpio_evmi->debounce_delay.tv.nsec = old_delay;
                        printk(KERN_INFO PREFIX "debounce_delay: %u\n", gpio_evmi->debounce_delay.tv.nsec);
                }
+               if (gpio_evmi->flags != old_flags) {
+                       printk(KERN_INFO PREFIX "Restoring flags\n");
+                       gpio_evmi->flags = old_flags;
+                       printk(KERN_INFO PREFIX "flags: 0x%x\n", gpio_evmi->flags);
+               }
        }
 }
 
        }
 }
 
Impressum, Datenschutz