diff options
author | Jens Arnold <amiconn@rockbox.org> | 2007-03-05 20:14:41 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2007-03-05 20:14:41 +0000 |
commit | 611737bde8674d9ad45fd15caa26e035a1c76802 (patch) | |
tree | e0bf42e53319bdfb47bc6ce2e7c96a4a95d4ca51 | |
parent | fd4079ca1fdc0ae7b7ead700cf2f790c92fd60a8 (diff) | |
download | rockbox-611737bde8674d9ad45fd15caa26e035a1c76802.tar.gz rockbox-611737bde8674d9ad45fd15caa26e035a1c76802.zip |
Add extra filtering to the X5 and M5 button drivers to prevent erratic button events (ported from H300).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12627 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/target/coldfire/iaudio/m5/button-m5.c | 9 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/x5/button-x5.c | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iaudio/m5/button-m5.c b/firmware/target/coldfire/iaudio/m5/button-m5.c index a5fdd79fde..5d49bf1e35 100644 --- a/firmware/target/coldfire/iaudio/m5/button-m5.c +++ b/firmware/target/coldfire/iaudio/m5/button-m5.c | |||
@@ -60,6 +60,8 @@ int button_read_device(void) | |||
60 | int btn = BUTTON_NONE; | 60 | int btn = BUTTON_NONE; |
61 | bool hold_button_old; | 61 | bool hold_button_old; |
62 | bool remote_hold_button_old; | 62 | bool remote_hold_button_old; |
63 | static int prev_data = 0xff; | ||
64 | static int last_valid = 0xff; | ||
63 | int data; | 65 | int data; |
64 | 66 | ||
65 | /* normal buttons */ | 67 | /* normal buttons */ |
@@ -76,6 +78,13 @@ int button_read_device(void) | |||
76 | { | 78 | { |
77 | data = adc_scan(ADC_BUTTONS); | 79 | data = adc_scan(ADC_BUTTONS); |
78 | 80 | ||
81 | /* ADC debouncing: Only accept new reading if it's | ||
82 | * stable (+/-1). Use latest stable value otherwise. */ | ||
83 | if ((unsigned)(data - prev_data + 1) <= 2) | ||
84 | last_valid = data; | ||
85 | prev_data = data; | ||
86 | data = last_valid; | ||
87 | |||
79 | if (data < 0xf0) | 88 | if (data < 0xf0) |
80 | { | 89 | { |
81 | if(data < 0x7c) | 90 | if(data < 0x7c) |
diff --git a/firmware/target/coldfire/iaudio/x5/button-x5.c b/firmware/target/coldfire/iaudio/x5/button-x5.c index 7cb86ff930..6182262b61 100644 --- a/firmware/target/coldfire/iaudio/x5/button-x5.c +++ b/firmware/target/coldfire/iaudio/x5/button-x5.c | |||
@@ -60,6 +60,8 @@ int button_read_device(void) | |||
60 | int btn = BUTTON_NONE; | 60 | int btn = BUTTON_NONE; |
61 | bool hold_button_old; | 61 | bool hold_button_old; |
62 | bool remote_hold_button_old; | 62 | bool remote_hold_button_old; |
63 | static int prev_data = 0xff; | ||
64 | static int last_valid = 0xff; | ||
63 | int data; | 65 | int data; |
64 | 66 | ||
65 | /* normal buttons */ | 67 | /* normal buttons */ |
@@ -76,6 +78,13 @@ int button_read_device(void) | |||
76 | { | 78 | { |
77 | data = adc_scan(ADC_BUTTONS); | 79 | data = adc_scan(ADC_BUTTONS); |
78 | 80 | ||
81 | /* ADC debouncing: Only accept new reading if it's | ||
82 | * stable (+/-1). Use latest stable value otherwise. */ | ||
83 | if ((unsigned)(data - prev_data + 1) <= 2) | ||
84 | last_valid = data; | ||
85 | prev_data = data; | ||
86 | data = last_valid; | ||
87 | |||
79 | if (data < 0xf0) | 88 | if (data < 0xf0) |
80 | { | 89 | { |
81 | if(data < 0x7c) | 90 | if(data < 0x7c) |