--- /home/nicolas/Desktop/button-x5.c	2007-03-05 21:15:36.000000000 +0100
+++ /home/nicolas/sources/rockbox-bleeding/firmware/target/coldfire/iaudio/x5/button-x5.c	2007-03-25 12:31:09.000000000 +0200
@@ -57,12 +57,18 @@
 
 int button_read_device(void)
 {
+    #define FILTER 3
+    #define DELTA 10
     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;
+    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,13 +83,22 @@
     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;
-        data = last_valid;
+        
+         /* 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 <= DELTA)
+            data = tab_min;
+        else
+            data = 0xFF;
         
         if (data < 0xf0)
         {
