summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/as3525/kernel-as3525.c22
-rw-r--r--firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c16
-rw-r--r--firmware/target/arm/as3525/sansa-fuze/button-fuze.c49
3 files changed, 55 insertions, 32 deletions
diff --git a/firmware/target/arm/as3525/kernel-as3525.c b/firmware/target/arm/as3525/kernel-as3525.c
index 3252e5abd1..986ceb3189 100644
--- a/firmware/target/arm/as3525/kernel-as3525.c
+++ b/firmware/target/arm/as3525/kernel-as3525.c
@@ -24,12 +24,29 @@
24#include "panic.h" 24#include "panic.h"
25#include "timer-target.h" 25#include "timer-target.h"
26 26
27#ifdef HAVE_SCROLLWHEEL
28/* The scrollwheel is polled every 5 ms (the tick tasks only every 10) */
29extern void button_read_dbop(void);
30static volatile int poll_scrollwheel = 0;
31
32void INT_TIMER2(void)
33{
34 if (!poll_scrollwheel)
35 call_tick_tasks(); /* Run through the list of tick tasks */
36 else
37 button_read_dbop();
38
39 poll_scrollwheel ^= 1;
40 TIMER2_INTCLR = 0; /* clear interrupt */
41}
42#else
27void INT_TIMER2(void) 43void INT_TIMER2(void)
28{ 44{
29 call_tick_tasks(); /* Run through the list of tick tasks */ 45 call_tick_tasks(); /* Run through the list of tick tasks */
30 46
31 TIMER2_INTCLR = 0; /* clear interrupt */ 47 TIMER2_INTCLR = 0; /* clear interrupt */
32} 48}
49#endif
33 50
34void tick_start(unsigned int interval_in_ms) 51void tick_start(unsigned int interval_in_ms)
35{ 52{
@@ -37,6 +54,11 @@ void tick_start(unsigned int interval_in_ms)
37 int prescale = 1; 54 int prescale = 1;
38 int cycles = TIMER_FREQ / 1000 * interval_in_ms; 55 int cycles = TIMER_FREQ / 1000 * interval_in_ms;
39 56
57#ifdef HAVE_SCROLLWHEEL
58 /* let the timer interrupt twice as often for the scrollwheel polling */
59 cycles >>= 1;
60#endif
61
40 while(cycles > 0x10000) 62 while(cycles > 0x10000)
41 { 63 {
42 phi++; 64 phi++;
diff --git a/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c b/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c
index 54e46f4a12..85288d2cc1 100644
--- a/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c
+++ b/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c
@@ -60,7 +60,7 @@ bool button_hold(void)
60 return hold_button; 60 return hold_button;
61} 61}
62 62
63void clickwheel(unsigned int wheel_value) 63static void scrollwheel(short dbop_din)
64{ 64{
65 static const unsigned char wheel_tbl[2][4] = 65 static const unsigned char wheel_tbl[2][4] =
66 { 66 {
@@ -75,6 +75,10 @@ void clickwheel(unsigned int wheel_value)
75 75
76 /* did the wheel value change? */ 76 /* did the wheel value change? */
77 unsigned int btn = BUTTON_NONE; 77 unsigned int btn = BUTTON_NONE;
78
79 unsigned wheel_value = dbop_din & (1<<13|1<<14);
80 wheel_value >>= 13;
81
78 if (old_wheel_value == wheel_tbl[0][wheel_value]) 82 if (old_wheel_value == wheel_tbl[0][wheel_value])
79 btn = BUTTON_SCROLL_FWD; 83 btn = BUTTON_SCROLL_FWD;
80 else if (old_wheel_value == wheel_tbl[1][wheel_value]) 84 else if (old_wheel_value == wheel_tbl[1][wheel_value])
@@ -178,7 +182,7 @@ void clickwheel(unsigned int wheel_value)
178 old_wheel_value = wheel_value; 182 old_wheel_value = wheel_value;
179} 183}
180 184
181static short read_dbop(void) 185short button_read_dbop(void)
182{ 186{
183 /*write a red pixel */ 187 /*write a red pixel */
184 if (!lcd_button_support()) 188 if (!lcd_button_support())
@@ -186,7 +190,7 @@ static short read_dbop(void)
186 190
187 /* Set up dbop for input */ 191 /* Set up dbop for input */
188 while (!(DBOP_STAT & (1<<10))); /* Wait for fifo to empty */ 192 while (!(DBOP_STAT & (1<<10))); /* Wait for fifo to empty */
189 DBOP_CTRL |= (1<<19); 193 DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */
190 DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */ 194 DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */
191 DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ 195 DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */
192 DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ 196 DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */
@@ -200,8 +204,9 @@ static short read_dbop(void)
200 DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */ 204 DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */
201 DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */ 205 DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */
202 DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */ 206 DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */
203 DBOP_CTRL &= ~(1<<19); 207 DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */
204 208
209 scrollwheel(_dbop_din);
205 return _dbop_din; 210 return _dbop_din;
206} 211}
207 212
@@ -217,7 +222,7 @@ int button_read_device(void)
217{ 222{
218 int btn = BUTTON_NONE; 223 int btn = BUTTON_NONE;
219 /* read buttons from dbop */ 224 /* read buttons from dbop */
220 short dbop = read_dbop(); 225 short dbop = button_read_dbop();
221 226
222 /* hold button */ 227 /* hold button */
223 if(dbop & (1<<12)) 228 if(dbop & (1<<12))
@@ -239,7 +244,6 @@ int button_read_device(void)
239 /* handle wheel */ 244 /* handle wheel */
240 int wheel_value = dbop & (1<<13|1<<14); 245 int wheel_value = dbop & (1<<13|1<<14);
241 wheel_value >>= 13; 246 wheel_value >>= 13;
242 clickwheel(wheel_value);
243 247
244 /* Set afsel, so that we can read our buttons */ 248 /* Set afsel, so that we can read our buttons */
245 GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); 249 GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6);
diff --git a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c
index f32776f6eb..f532a96431 100644
--- a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c
+++ b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c
@@ -49,7 +49,7 @@ void button_init_device(void)
49} 49}
50 50
51#if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL) 51#if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL)
52static void scrollwheel(short dbop) 52static void scrollwheel(short dbop_din)
53{ 53{
54 /* current wheel values, parsed from dbop and the resulting button */ 54 /* current wheel values, parsed from dbop and the resulting button */
55 unsigned wheel_value = 0; 55 unsigned wheel_value = 0;
@@ -76,7 +76,7 @@ static void scrollwheel(short dbop)
76 { 2, 0, 3, 1 }, /* Clockwise rotation */ 76 { 2, 0, 3, 1 }, /* Clockwise rotation */
77 { 1, 3, 0, 2 }, /* Counter-clockwise */ 77 { 1, 3, 0, 2 }, /* Counter-clockwise */
78 }; 78 };
79 wheel_value = dbop & (1<<13|1<<14); 79 wheel_value = dbop_din & (1<<13|1<<14);
80 wheel_value >>= 13; 80 wheel_value >>= 13;
81 81
82 if (old_wheel_value == wheel_tbl[0][wheel_value]) 82 if (old_wheel_value == wheel_tbl[0][wheel_value])
@@ -90,7 +90,7 @@ static void scrollwheel(short dbop)
90 { 90 {
91 /* direction reversals nullify repeats */ 91 /* direction reversals nullify repeats */
92 wheel_repeat = btn; 92 wheel_repeat = btn;
93 repeat = 0; 93 repeat = counter = 0;
94 } 94 }
95 if (btn != BUTTON_NONE) 95 if (btn != BUTTON_NONE)
96 { 96 {
@@ -139,7 +139,7 @@ static void button_delay(void)
139 while(i--); 139 while(i--);
140} 140}
141 141
142static short button_dbop(void) 142short button_read_dbop(void)
143{ 143{
144 /* skip home and power reading if lcd_button_support was blocked, 144 /* skip home and power reading if lcd_button_support was blocked,
145 * since the dbop bit 15 is invalid then, and use the old value instead */ 145 * since the dbop bit 15 is invalid then, and use the old value instead */
@@ -150,27 +150,24 @@ static short button_dbop(void)
150 old_home_power = (_dbop_din & (1<<15|1<<8)); 150 old_home_power = (_dbop_din & (1<<15|1<<8));
151 } 151 }
152 152
153 /* Wait for fifo to empty */ 153 /* Set up dbop for input */
154 while ((DBOP_STAT & (1<<10)) == 0); 154 while (!(DBOP_STAT & (1<<10))); /* Wait for fifo to empty */
155 155 DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */
156 DBOP_CTRL |= (1<<19); 156 DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */
157 DBOP_CTRL &= ~(1<<16); /* disable output */ 157 DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */
158 158 DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */
159 DBOP_TIMPOL_01 = 0xe167e167;
160 DBOP_TIMPOL_23 = 0xe167006e;
161 159
162 button_delay(); 160 button_delay();
161 DBOP_CTRL |= (1<<15); /* start read */
162 while (!(DBOP_STAT & (1<<16))); /* wait for valid data */
163 163
164 DBOP_CTRL |= (1<<15); /* start read */ 164 _dbop_din = DBOP_DIN; /* Read dbop data*/
165 while((DBOP_STAT & (1<<16)) == 0); /* wait for valid data */
166
167 _dbop_din = DBOP_DIN; /* now read */
168 165
169 DBOP_TIMPOL_01 = 0x6e167; 166 /* Reset dbop for output */
170 DBOP_TIMPOL_23 = 0xa167e06f; 167 DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */
171 168 DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */
172 DBOP_CTRL |= (1<<16); 169 DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */
173 DBOP_CTRL &= ~(1<<19); 170 DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */
174 171
175 /* write back old values if blocked */ 172 /* write back old values if blocked */
176 if (old_home_power != -20) 173 if (old_home_power != -20)
@@ -178,6 +175,10 @@ static short button_dbop(void)
178 _dbop_din |= old_home_power & 1<<15; 175 _dbop_din |= old_home_power & 1<<15;
179 _dbop_din &= 0xfeff|(old_home_power & 1<<8); 176 _dbop_din &= 0xfeff|(old_home_power & 1<<8);
180 } 177 }
178#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
179 /* read wheel on bit 13 & 14, but sent to the button queue seperately */
180 scrollwheel(_dbop_din);
181#endif
181 return _dbop_din; 182 return _dbop_din;
182} 183}
183 184
@@ -233,7 +234,7 @@ static int button_gpio(void)
233int button_read_device(void) 234int button_read_device(void)
234{ 235{
235 int btn = BUTTON_NONE; 236 int btn = BUTTON_NONE;
236 short dbop = button_dbop(); 237 short dbop = button_read_dbop();
237 static unsigned power_counter = 0; 238 static unsigned power_counter = 0;
238 /* hold button */ 239 /* hold button */
239 if(dbop & (1<<12)) 240 if(dbop & (1<<12))
@@ -244,10 +245,6 @@ int button_read_device(void)
244 else 245 else
245 { 246 {
246 hold_button = false; 247 hold_button = false;
247#if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
248 /* read wheel on bit 13 & 14, but sent to the button queue seperately */
249 scrollwheel(dbop);
250#endif
251 /* read power on bit 8, but not if hold button was just released, since 248 /* read power on bit 8, but not if hold button was just released, since
252 * you basically always hit power due to the slider mechanism after releasing 249 * you basically always hit power due to the slider mechanism after releasing
253 * hold (wait ~1 sec) */ 250 * hold (wait ~1 sec) */