summaryrefslogtreecommitdiffstats
path: root/firmware/target
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-03-05 20:14:41 +0000
committerJens Arnold <amiconn@rockbox.org>2007-03-05 20:14:41 +0000
commit611737bde8674d9ad45fd15caa26e035a1c76802 (patch)
treee0bf42e53319bdfb47bc6ce2e7c96a4a95d4ca51 /firmware/target
parentfd4079ca1fdc0ae7b7ead700cf2f790c92fd60a8 (diff)
downloadrockbox-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
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/coldfire/iaudio/m5/button-m5.c9
-rw-r--r--firmware/target/coldfire/iaudio/x5/button-x5.c9
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)
int btn = BUTTON_NONE;
bool hold_button_old;
bool remote_hold_button_old;
+ static int prev_data = 0xff;
+ static int last_valid = 0xff;
int data;
/* normal buttons */
@@ -76,6 +78,13 @@ int button_read_device(void)
{
data = adc_scan(ADC_BUTTONS);
+ /* ADC debouncing: Only accept new reading if it's
+ * stable (+/-1). Use latest stable value otherwise. */
+ if ((unsigned)(data - prev_data + 1) <= 2)
+ last_valid = data;
+ prev_data = data;
+ data = last_valid;
+
if (data < 0xf0)
{
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)
int btn = BUTTON_NONE;
bool hold_button_old;
bool remote_hold_button_old;
+ static int prev_data = 0xff;
+ static int last_valid = 0xff;
int data;
/* normal buttons */
@@ -76,6 +78,13 @@ int button_read_device(void)
{
data = adc_scan(ADC_BUTTONS);
+ /* ADC debouncing: Only accept new reading if it's
+ * stable (+/-1). Use latest stable value otherwise. */
+ if ((unsigned)(data - prev_data + 1) <= 2)
+ last_valid = data;
+ prev_data = data;
+ data = last_valid;
+
if (data < 0xf0)
{
if(data < 0x7c)