--- Desktop/button-x5.c	2007-03-05 21:15:36.000000000 +0100
+++ sources/rockbox-bleeding/firmware/target/coldfire/iaudio/x5/button-x5.c	2007-03-21 20:56:29.000000000 +0100
@@ -57,12 +57,18 @@
 
 int button_read_device(void)
 {
+    #define FILTER 10
     int  btn = BUTTON_NONE;
     bool hold_button_old;
     bool remote_hold_button_old;
-    static int prev_data = 0xff;
+    int data;
     static int last_valid = 0xff;
-    int  data;
+    static int tab[FILTER] = {0xff};
+    static int cursor = 0;
+    int tab_size = FILTER;
+    int tab_max = 0x00;
+    int tab_min = 0xFF;
+    int i;
 
     /* normal buttons */
     hold_button_old = hold_button;
@@ -77,12 +83,20 @@
     if (button_scan_on && !hold_button)
     {
         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;
+        
+         /* ADC debouncing */
+        tab[cursor++] = data;
+        if (cursor >= tab_size)
+        	cursor = 0;
+        for (i = 0; i < tab_size; i++)
+        {
+            if ((unsigned) tab[i] < (unsigned) tab_min)
+              	tab_min = tab[i];
+            if ((unsigned) tab[i] > (unsigned) tab_max)
+              	tab_max = tab[i];
+        }
+        if ((unsigned) tab_max - (unsigned) tab_min < 2)
+            last_valid = tab_min;
         data = last_valid;
         
         if (data < 0xf0)
