diff options
author | Michael Giacomelli <giac2000@hotmail.com> | 2009-04-10 15:19:59 +0000 |
---|---|---|
committer | Michael Giacomelli <giac2000@hotmail.com> | 2009-04-10 15:19:59 +0000 |
commit | 30b888cb58507961c280640b257adbcfd5fcecbd (patch) | |
tree | 4a1a2ffaa269f139f70a2b369067c851e89c8f1c /firmware/target/arm | |
parent | a137733d1069129766ef72b487899ac906729e3b (diff) | |
download | rockbox-30b888cb58507961c280640b257adbcfd5fcecbd.tar.gz rockbox-30b888cb58507961c280640b257adbcfd5fcecbd.zip |
Commit fs#9959 by Jack Halpin. Removes delays from the Sansa e200v2 button driver and cleans up the code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20676 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c b/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c index 5edb31bc45..54e46f4a12 100644 --- a/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c +++ b/firmware/target/arm/as3525/sansa-e200v2/button-e200v2.c | |||
@@ -44,7 +44,7 @@ static long last_wheel_post = 0; | |||
44 | static long next_backlight_on = 0; | 44 | static long next_backlight_on = 0; |
45 | /* Buttons */ | 45 | /* Buttons */ |
46 | static bool hold_button = false; | 46 | static bool hold_button = false; |
47 | #ifndef BOOTLOADER | 47 | #ifndef BOOTLOADER |
48 | static bool hold_button_old = false; | 48 | static bool hold_button_old = false; |
49 | #endif | 49 | #endif |
50 | 50 | ||
@@ -73,7 +73,7 @@ void clickwheel(unsigned int wheel_value) | |||
73 | * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00 | 73 | * Counter-clockwise 00 -> 10 -> 11 -> 01 -> 00 |
74 | */ | 74 | */ |
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 | if (old_wheel_value == wheel_tbl[0][wheel_value]) | 78 | if (old_wheel_value == wheel_tbl[0][wheel_value]) |
79 | btn = BUTTON_SCROLL_FWD; | 79 | btn = BUTTON_SCROLL_FWD; |
@@ -83,7 +83,7 @@ void clickwheel(unsigned int wheel_value) | |||
83 | if (btn != BUTTON_NONE) | 83 | if (btn != BUTTON_NONE) |
84 | { | 84 | { |
85 | int repeat = 1; /* assume repeat */ | 85 | int repeat = 1; /* assume repeat */ |
86 | unsigned long usec = TIMER1_VALUE; /* WAG!!! and it works!!*/ | 86 | unsigned long usec = TIMER1_VALUE; |
87 | unsigned v = (usec - last_wheel_usec) & 0x7fffffff; | 87 | unsigned v = (usec - last_wheel_usec) & 0x7fffffff; |
88 | 88 | ||
89 | v = (v>0) ? 1000000 / v : 0; /* clicks/sec = 1000000 * +clicks/usec */ | 89 | v = (v>0) ? 1000000 / v : 0; /* clicks/sec = 1000000 * +clicks/usec */ |
@@ -162,7 +162,7 @@ void clickwheel(unsigned int wheel_value) | |||
162 | { | 162 | { |
163 | queue_post(&button_queue, btn, wheel_fast_mode | | 163 | queue_post(&button_queue, btn, wheel_fast_mode | |
164 | (wheel_delta << 24) | | 164 | (wheel_delta << 24) | |
165 | wheel_velocity*360/WHEELCLICKS_PER_ROTATION); | 165 | wheel_velocity*360/WHEELCLICKS_PER_ROTATION); |
166 | /* message posted - reset delta */ | 166 | /* message posted - reset delta */ |
167 | wheel_delta = 1; | 167 | wheel_delta = 1; |
168 | } | 168 | } |
@@ -173,7 +173,6 @@ void clickwheel(unsigned int wheel_value) | |||
173 | wheel_delta = 0x7f; | 173 | wheel_delta = 0x7f; |
174 | } | 174 | } |
175 | } | 175 | } |
176 | |||
177 | last_wheel_usec = usec; | 176 | last_wheel_usec = usec; |
178 | } | 177 | } |
179 | old_wheel_value = wheel_value; | 178 | old_wheel_value = wheel_value; |
@@ -183,26 +182,24 @@ static short read_dbop(void) | |||
183 | { | 182 | { |
184 | /*write a red pixel */ | 183 | /*write a red pixel */ |
185 | if (!lcd_button_support()) | 184 | if (!lcd_button_support()) |
186 | return _dbop_din; | 185 | return _dbop_din; |
187 | 186 | ||
188 | /* Set up dbop for input */ | 187 | /* Set up dbop for input */ |
189 | while (!(DBOP_STAT & (1<<10))); /* Wait for fifo to empty */ | 188 | while (!(DBOP_STAT & (1<<10))); /* Wait for fifo to empty */ |
190 | DBOP_CTRL |= (1<<19); | 189 | DBOP_CTRL |= (1<<19); |
191 | DBOP_CTRL &= ~(1<<16); /* disable output */ | 190 | DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */ |
192 | 191 | DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ | |
193 | DBOP_TIMPOL_01 = 0xe167e167; //11100001011001111110000101100111 | 192 | DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ |
194 | DBOP_TIMPOL_23 = 0xe167006e; //11100001011001110000000001101110 | 193 | |
195 | 194 | DBOP_CTRL |= (1<<15); /* start read */ | |
196 | DBOP_CTRL |= (1<<15); /* start read */ | 195 | while (!(DBOP_STAT & (1<<16))); /* wait for valid data */ |
197 | while (!(DBOP_STAT & (1<<16))); /* wait for valid data */ | 196 | |
198 | int delay = 50; | 197 | _dbop_din = DBOP_DIN; /* Read dbop data*/ |
199 | while(delay--); /* small delay to set up read */ | 198 | |
200 | 199 | /* Reset dbop for output */ | |
201 | _dbop_din = DBOP_DIN; /* now read dbop & store info*/ | 200 | DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */ |
202 | 201 | DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */ | |
203 | DBOP_TIMPOL_01 = 0x6e167; | 202 | DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */ |
204 | DBOP_TIMPOL_23 = 0xa167e06f; | ||
205 | DBOP_CTRL |= (1<<16); | ||
206 | DBOP_CTRL &= ~(1<<19); | 203 | DBOP_CTRL &= ~(1<<19); |
207 | 204 | ||
208 | return _dbop_din; | 205 | return _dbop_din; |
@@ -221,7 +218,7 @@ int button_read_device(void) | |||
221 | int btn = BUTTON_NONE; | 218 | int btn = BUTTON_NONE; |
222 | /* read buttons from dbop */ | 219 | /* read buttons from dbop */ |
223 | short dbop = read_dbop(); | 220 | short dbop = read_dbop(); |
224 | 221 | ||
225 | /* hold button */ | 222 | /* hold button */ |
226 | if(dbop & (1<<12)) | 223 | if(dbop & (1<<12)) |
227 | { | 224 | { |
@@ -232,17 +229,18 @@ int button_read_device(void) | |||
232 | { | 229 | { |
233 | hold_button = false; | 230 | hold_button = false; |
234 | } | 231 | } |
235 | 232 | ||
236 | if (dbop & (1<<8)) | 233 | if (dbop & (1<<8)) |
237 | btn |= BUTTON_POWER; | 234 | btn |= BUTTON_POWER; |
238 | if (!(dbop & (1<<15))) | 235 | |
239 | btn |= BUTTON_REC; | 236 | if (!(dbop & (1<<15))) |
237 | btn |= BUTTON_REC; | ||
240 | 238 | ||
241 | /* handle wheel */ | 239 | /* handle wheel */ |
242 | int wheel_value = dbop & (1<<13|1<<14); | 240 | int wheel_value = dbop & (1<<13|1<<14); |
243 | wheel_value >>= 13; | 241 | wheel_value >>= 13; |
244 | clickwheel(wheel_value); | 242 | clickwheel(wheel_value); |
245 | 243 | ||
246 | /* Set afsel, so that we can read our buttons */ | 244 | /* Set afsel, so that we can read our buttons */ |
247 | GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); | 245 | GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); |
248 | /* set dir so we can read our buttons (but reset the C pins first) */ | 246 | /* set dir so we can read our buttons (but reset the C pins first) */ |
@@ -256,7 +254,7 @@ int button_read_device(void) | |||
256 | 254 | ||
257 | GPIOC_DIR &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); | 255 | GPIOC_DIR &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); |
258 | 256 | ||
259 | int delay = 50; /* small delay needed to read buttons correctly */ | 257 | int delay = 2; /* small delay needed to read buttons correctly */ |
260 | while(delay--); | 258 | while(delay--); |
261 | 259 | ||
262 | /* direct GPIO connections */ | 260 | /* direct GPIO connections */ |
@@ -268,14 +266,14 @@ int button_read_device(void) | |||
268 | btn |= BUTTON_SELECT; | 266 | btn |= BUTTON_SELECT; |
269 | if (!GPIOC_PIN(5)) | 267 | if (!GPIOC_PIN(5)) |
270 | btn |= BUTTON_RIGHT; | 268 | btn |= BUTTON_RIGHT; |
271 | if (!GPIOC_PIN(6)) | 269 | if (!GPIOC_PIN(6)) |
272 | btn |= BUTTON_DOWN; | 270 | btn |= BUTTON_DOWN; |
273 | 271 | ||
274 | /* return to settings needed for lcd */ | 272 | /* return to settings needed for lcd */ |
275 | GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6); | 273 | GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6); |
276 | GPIOC_AFSEL |= (1<<2|1<<3|1<<4|1<<5|1<<6); | 274 | GPIOC_AFSEL |= (1<<2|1<<3|1<<4|1<<5|1<<6); |
277 | 275 | ||
278 | #ifndef BOOTLOADER | 276 | #ifndef BOOTLOADER |
279 | /* light handling */ | 277 | /* light handling */ |
280 | if (hold_button != hold_button_old) | 278 | if (hold_button != hold_button_old) |
281 | { | 279 | { |