summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/button-e200v2-fuze.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/button-e200v2-fuze.c')
-rw-r--r--firmware/target/arm/as3525/button-e200v2-fuze.c108
1 files changed, 2 insertions, 106 deletions
diff --git a/firmware/target/arm/as3525/button-e200v2-fuze.c b/firmware/target/arm/as3525/button-e200v2-fuze.c
index 2a75fa1e6f..2cbdcf5130 100644
--- a/firmware/target/arm/as3525/button-e200v2-fuze.c
+++ b/firmware/target/arm/as3525/button-e200v2-fuze.c
@@ -27,21 +27,14 @@
27#include "backlight.h" 27#include "backlight.h"
28#include "dbop-as3525.h" 28#include "dbop-as3525.h"
29 29
30extern void scrollwheel(unsigned wheel_value);
30 31
31#if defined(SANSA_FUZE) || defined(SANSA_FUZEV2) 32#if defined(SANSA_FUZE)
32#define DBOP_BIT15_BUTTON BUTTON_HOME 33#define DBOP_BIT15_BUTTON BUTTON_HOME
33#define WHEEL_REPEAT_INTERVAL (HZ/5)
34#define WHEEL_COUNTER_DIV 4
35#define ACCEL_INCREMENT 2
36#define ACCEL_SHIFT 2
37#endif 34#endif
38 35
39#ifdef SANSA_E200V2 36#ifdef SANSA_E200V2
40#define DBOP_BIT15_BUTTON BUTTON_REC 37#define DBOP_BIT15_BUTTON BUTTON_REC
41#define WHEEL_REPEAT_INTERVAL (HZ/5)
42#define WHEEL_COUNTER_DIV 2
43#define ACCEL_INCREMENT 3
44#define ACCEL_SHIFT 1
45#endif 38#endif
46 39
47/* Buttons */ 40/* Buttons */
@@ -56,103 +49,6 @@ void button_init_device(void)
56 GPIOA_PIN(1) = (1<<1); 49 GPIOA_PIN(1) = (1<<1);
57} 50}
58 51
59#if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL)
60static void scrollwheel(unsigned int wheel_value)
61{
62 /* current wheel values, parsed from dbop and the resulting button */
63 unsigned btn = BUTTON_NONE;
64 /* old wheel values */
65 static unsigned old_wheel_value = 0;
66 static unsigned old_btn = BUTTON_NONE;
67
68 /*
69 * Getting BUTTON_REPEAT works like this: Remember when the btn value was
70 * posted to the button_queue last, and if it was recent enough, generate
71 * BUTTON_REPEAT
72 */
73 static long last_wheel_post = 0;
74
75 /*
76 * Providing wheel acceleration works as follows: We increment accel
77 * by 2 if the wheel was turned, and decrement it by 1 each tick
78 * (no matter if it was turned), that means: the longer and faster you turn,
79 * the higher accel will be. accel>>2 will actually posted to the button_queue
80 */
81 static int accel = 0;
82 /* We only post every 4th action, as this matches better with the physical
83 * clicks of the wheel */
84 static int counter = 0;
85 /* Read wheel
86 * Bits 13 and 14 of DBOP_DIN change as follows (Gray Code):
87 * Clockwise rotation 00 -> 01 -> 11 -> 10 -> 00
88 * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00
89 *
90 * For easy look-up, actual wheel values act as indicies also,
91 * which is why the table seems to be not ordered correctly
92 */
93 static const unsigned char wheel_tbl[2][4] =
94 {
95 { 2, 0, 3, 1 }, /* Clockwise rotation */
96 { 1, 3, 0, 2 }, /* Counter-clockwise */
97 };
98
99 if(hold_button)
100 {
101 accel = counter = 0;
102 return;
103 }
104
105 if (old_wheel_value == wheel_tbl[0][wheel_value])
106 btn = BUTTON_SCROLL_FWD;
107 else if (old_wheel_value == wheel_tbl[1][wheel_value])
108 btn = BUTTON_SCROLL_BACK;
109 else if (old_wheel_value != wheel_value && accel > ACCEL_INCREMENT)
110 { /* if no button is read and wheel_value changed, assume old_btn */
111 btn = old_btn;
112 }
113 /* else btn = BUTTON_NONE */
114
115 if (btn != BUTTON_NONE)
116 {
117 if (btn != old_btn)
118 {
119 /* direction reversals nullify acceleration and counters */
120 old_btn = btn;
121 accel = counter = 0;
122 }
123 /* wheel_delta will cause lists to jump over items,
124 * we want this for fast scrolling, but we must keep it accurate
125 * for slow scrolling */
126 int wheel_delta = 0;
127 /* generate BUTTON_REPEAT if quick enough, scroll slightly faster too*/
128 if (TIME_BEFORE(current_tick, last_wheel_post + WHEEL_REPEAT_INTERVAL))
129 {
130 btn |= BUTTON_REPEAT;
131 wheel_delta = accel>>ACCEL_SHIFT;
132 }
133
134 accel += ACCEL_INCREMENT;
135
136 /* the wheel is more reliable if we don't send every change,
137 * every WHEEL_COUNTER_DIVth is basically one "physical click"
138 * which should make up 1 item in lists */
139 if (++counter >= WHEEL_COUNTER_DIV && queue_empty(&button_queue))
140 {
141 buttonlight_on();
142 backlight_on();
143 queue_post(&button_queue, btn, ((wheel_delta+1)<<24));
144 /* message posted - reset count and remember post */
145 counter = 0;
146 last_wheel_post = current_tick;
147 }
148 }
149 if (accel > 0)
150 accel--;
151
152 old_wheel_value = wheel_value;
153}
154#endif /* !defined(BOOTLOADER) && defined(SCROLLWHEEL) */
155
156bool button_hold(void) 52bool button_hold(void)
157{ 53{
158 return hold_button; 54 return hold_button;