diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/button.c | 124 |
1 files changed, 119 insertions, 5 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 0cfe1d1aa0..86d0b5d4e6 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -22,7 +22,7 @@ | |||
22 | 22 | ||
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include "config.h" | 24 | #include "config.h" |
25 | #include "sh7034.h" | 25 | #include "cpu.h" |
26 | #include "system.h" | 26 | #include "system.h" |
27 | #include "button.h" | 27 | #include "button.h" |
28 | #include "kernel.h" | 28 | #include "kernel.h" |
@@ -36,7 +36,7 @@ | |||
36 | struct event_queue button_queue; | 36 | struct event_queue button_queue; |
37 | 37 | ||
38 | static int lastbtn; /* Last valid button status */ | 38 | static int lastbtn; /* Last valid button status */ |
39 | #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD) | 39 | #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD) |
40 | static int last_read; /* Last button status, for debouncing/filtering */ | 40 | static int last_read; /* Last button status, for debouncing/filtering */ |
41 | static bool flipped; /* bottons can be flipped to match the LCD flip */ | 41 | static bool flipped; /* bottons can be flipped to match the LCD flip */ |
42 | #endif | 42 | #endif |
@@ -68,7 +68,7 @@ static void button_tick(void) | |||
68 | int diff; | 68 | int diff; |
69 | int btn; | 69 | int btn; |
70 | 70 | ||
71 | #ifndef HAVE_MMC | 71 | #if !defined(HAVE_MMC) && !defined(IRIVER_H100_PAD) |
72 | /* Post events for the remote control */ | 72 | /* Post events for the remote control */ |
73 | btn = remote_control_rx(); | 73 | btn = remote_control_rx(); |
74 | if(btn) | 74 | if(btn) |
@@ -180,7 +180,121 @@ int button_get_w_tmo(int ticks) | |||
180 | return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE; | 180 | return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE; |
181 | } | 181 | } |
182 | 182 | ||
183 | #if CONFIG_KEYPAD == RECORDER_PAD | 183 | #if CONFIG_KEYPAD == IRIVER_H100_PAD |
184 | void button_init() | ||
185 | { | ||
186 | #ifndef SIMULATOR | ||
187 | /* Set GPIO37 as general purpose input */ | ||
188 | GPIO1_FUNCTION |= 0x00000020; | ||
189 | GPIO1_ENABLE &= ~0x00000020; | ||
190 | #endif | ||
191 | queue_init(&button_queue); | ||
192 | lastbtn = 0; | ||
193 | tick_add_task(button_tick); | ||
194 | reset_poweroff_timer(); | ||
195 | flipped = false; | ||
196 | } | ||
197 | |||
198 | /* | ||
199 | * helper function to swap UP/DOWN, LEFT/RIGHT | ||
200 | */ | ||
201 | static int button_flip(int button) | ||
202 | { | ||
203 | int newbutton; | ||
204 | |||
205 | newbutton = button & | ||
206 | ~(BUTTON_UP | BUTTON_DOWN | ||
207 | | BUTTON_LEFT | BUTTON_RIGHT); | ||
208 | |||
209 | if (button & BUTTON_UP) | ||
210 | newbutton |= BUTTON_DOWN; | ||
211 | if (button & BUTTON_DOWN) | ||
212 | newbutton |= BUTTON_UP; | ||
213 | if (button & BUTTON_LEFT) | ||
214 | newbutton |= BUTTON_RIGHT; | ||
215 | if (button & BUTTON_RIGHT) | ||
216 | newbutton |= BUTTON_LEFT; | ||
217 | |||
218 | return newbutton; | ||
219 | } | ||
220 | |||
221 | /* | ||
222 | * set the flip attribute | ||
223 | * better only call this when the queue is empty | ||
224 | */ | ||
225 | void button_set_flip(bool flip) | ||
226 | { | ||
227 | if (flip != flipped) /* not the current setting */ | ||
228 | { | ||
229 | /* avoid race condition with the button_tick() */ | ||
230 | int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); | ||
231 | lastbtn = button_flip(lastbtn); | ||
232 | flipped = flip; | ||
233 | set_irq_level(oldlevel); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | /* | ||
238 | * Get button pressed from hardware | ||
239 | */ | ||
240 | static int button_read(void) | ||
241 | { | ||
242 | int btn = BUTTON_NONE; | ||
243 | int retval; | ||
244 | |||
245 | int data; | ||
246 | |||
247 | data = adc_scan(0); | ||
248 | |||
249 | if(data < 0x80) | ||
250 | if(data < 0x30) | ||
251 | if(data < 0x18) | ||
252 | btn = BUTTON_SELECT; | ||
253 | else | ||
254 | btn = BUTTON_UP; | ||
255 | else | ||
256 | if(data < 0x50) | ||
257 | btn = BUTTON_LEFT; | ||
258 | else | ||
259 | btn = BUTTON_DOWN; | ||
260 | else | ||
261 | if(data < 0xb0) | ||
262 | if(data < 0xa0) | ||
263 | btn = BUTTON_RIGHT; | ||
264 | else | ||
265 | btn = BUTTON_OFF; | ||
266 | else | ||
267 | if(data < 0xd0) | ||
268 | btn = BUTTON_MODE; | ||
269 | else | ||
270 | if(data < 0xf0) | ||
271 | btn = BUTTON_REC; | ||
272 | |||
273 | data = GPIO1_READ; | ||
274 | if ((data & 0x20) == 0) | ||
275 | btn |= BUTTON_ON; | ||
276 | |||
277 | |||
278 | if (btn && flipped) | ||
279 | btn = button_flip(btn); /* swap upside down */ | ||
280 | |||
281 | /* Filter the button status. It is only accepted if we get the same | ||
282 | status twice in a row. */ | ||
283 | if(btn != last_read) | ||
284 | retval = lastbtn; | ||
285 | else | ||
286 | retval = btn; | ||
287 | last_read = btn; | ||
288 | |||
289 | return retval; | ||
290 | } | ||
291 | |||
292 | bool button_hold(void) | ||
293 | { | ||
294 | return (GPIO1_READ & 0x00000002)?true:false; | ||
295 | } | ||
296 | |||
297 | #elif CONFIG_KEYPAD == RECORDER_PAD | ||
184 | 298 | ||
185 | /* AJBR buttons are connected to the CPU as follows: | 299 | /* AJBR buttons are connected to the CPU as follows: |
186 | * | 300 | * |
@@ -279,7 +393,6 @@ static int button_read(void) | |||
279 | int btn = BUTTON_NONE; | 393 | int btn = BUTTON_NONE; |
280 | int retval; | 394 | int retval; |
281 | 395 | ||
282 | /* Check port B pins for ON and OFF */ | ||
283 | int data; | 396 | int data; |
284 | 397 | ||
285 | #ifdef HAVE_FMADC | 398 | #ifdef HAVE_FMADC |
@@ -290,6 +403,7 @@ static int button_read(void) | |||
290 | if ( adc_read(2) > 512 ) | 403 | if ( adc_read(2) > 512 ) |
291 | btn |= BUTTON_OFF; | 404 | btn |= BUTTON_OFF; |
292 | #else | 405 | #else |
406 | /* Check port B pins for ON and OFF */ | ||
293 | data = PBDR; | 407 | data = PBDR; |
294 | if ((data & PBDR_BTN_ON) == 0) | 408 | if ((data & PBDR_BTN_ON) == 0) |
295 | btn |= BUTTON_ON; | 409 | btn |= BUTTON_ON; |