rendered paste bodydiff --git a/firmware/target/arm/sandisk/sansa-e200/button-e200.c b/firmware/target/arm/sandisk/sansa-e200/button-e200.c
index 4498cc0..0e20610 100644
--- a/firmware/target/arm/sandisk/sansa-e200/button-e200.c
+++ b/firmware/target/arm/sandisk/sansa-e200/button-e200.c
@@ -33,6 +33,7 @@ void button_init_device(void)
{
/* Enable all buttons except the wheel */
GPIOF_ENABLE |= 0xff;
+ GPIOH_ENABLE |= (0x3 << 6);
}
bool button_hold(void)
@@ -40,6 +41,35 @@ bool button_hold(void)
return (GPIOF_INPUT_VAL & 0x80)?true:false;
}
+static int button_wheel(void)
+{
+ char state;
+ char val;
+ static char last_val = 0;
+
+ /* The wheel counts 0 -> 1 -> 3 -> 2 as it rotates clockwise
+ Convert this to 0 -> 1 -> 2 -> 3 */
+ state = ((GPIOH_INPUT_VAL & (0x3 << 6)) >> 6);
+ if(state == 2)
+ val = 3;
+ else if(state == 3)
+ val = 2;
+ else
+ val = state;
+
+ if ((val > last_val) || (val == 3 && last_val == 0))
+ {
+ last_val = val;
+ return BUTTON_SCROLL_UP;
+ } else if ((val < last_val) || (val == 0 && last_val == 3)) {
+ last_val = val;
+ return BUTTON_SCROLL_DOWN;
+ } else {
+ last_val = val;
+ return 0;
+ }
+}
+
/*
* Get button pressed from hardware
*/
@@ -76,6 +106,8 @@ #endif
if ((state & 0x10) == 0) btn |= BUTTON_SELECT; /* The centre button */
if ((state & 0x20) == 0) btn |= BUTTON_UP; /* The "play" button */
if ((state & 0x40) != 0) btn |= BUTTON_POWER;
+
+ btn |= button_wheel();
}
return btn;