diff options
Diffstat (limited to 'firmware/drivers/button.c')
-rw-r--r-- | firmware/drivers/button.c | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 69849598c2..51fc3b5a1a 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -36,7 +36,7 @@ | |||
36 | struct event_queue button_queue; | 36 | struct event_queue button_queue; |
37 | 37 | ||
38 | static int lastbtn; | 38 | static int lastbtn; |
39 | #ifdef HAVE_RECORDER_KEYPAD | 39 | #if defined(HAVE_RECORDER_KEYPAD) || defined(HAVE_ONDIO_KEYPAD) |
40 | static bool flipped; /* bottons can be flipped to match the LCD flip */ | 40 | static bool flipped; /* bottons can be flipped to match the LCD flip */ |
41 | #endif | 41 | #endif |
42 | 42 | ||
@@ -337,7 +337,7 @@ static int button_read(void) | |||
337 | return btn; | 337 | return btn; |
338 | } | 338 | } |
339 | 339 | ||
340 | #elif HAVE_PLAYER_KEYPAD | 340 | #elif defined(HAVE_PLAYER_KEYPAD) |
341 | 341 | ||
342 | /* The player has two buttons on port pins: | 342 | /* The player has two buttons on port pins: |
343 | 343 | ||
@@ -386,7 +386,7 @@ static int button_read(void) | |||
386 | return btn; | 386 | return btn; |
387 | } | 387 | } |
388 | 388 | ||
389 | #elif HAVE_NEO_KEYPAD | 389 | #elif defined(HAVE_NEO_KEYPAD) |
390 | static bool mStation = false; | 390 | static bool mStation = false; |
391 | void button_init(void) | 391 | void button_init(void) |
392 | { | 392 | { |
@@ -421,6 +421,90 @@ int button_add(unsigned int button) | |||
421 | queue_post(&button_queue,button,NULL); | 421 | queue_post(&button_queue,button,NULL); |
422 | return 1; | 422 | return 1; |
423 | } | 423 | } |
424 | |||
425 | #elif defined HAVE_ONDIO_KEYPAD | ||
426 | |||
427 | /* | ||
428 | * helper function to swap UP/DOWN, LEFT/RIGHT | ||
429 | */ | ||
430 | static int button_flip(int button) | ||
431 | { | ||
432 | int newbutton; | ||
433 | |||
434 | newbutton = button & | ||
435 | ~(BUTTON_UP | BUTTON_DOWN | ||
436 | | BUTTON_LEFT | BUTTON_RIGHT); | ||
437 | |||
438 | if (button & BUTTON_UP) | ||
439 | newbutton |= BUTTON_DOWN; | ||
440 | if (button & BUTTON_DOWN) | ||
441 | newbutton |= BUTTON_UP; | ||
442 | if (button & BUTTON_LEFT) | ||
443 | newbutton |= BUTTON_RIGHT; | ||
444 | if (button & BUTTON_RIGHT) | ||
445 | newbutton |= BUTTON_LEFT; | ||
446 | |||
447 | return newbutton; | ||
448 | } | ||
449 | |||
450 | |||
451 | /* | ||
452 | * set the flip attribute | ||
453 | * better only call this when the queue is empty | ||
454 | */ | ||
455 | void button_set_flip(bool flip) | ||
456 | { | ||
457 | if (flip != flipped) /* not the current setting */ | ||
458 | { | ||
459 | /* avoid race condition with the button_tick() */ | ||
460 | int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); | ||
461 | lastbtn = button_flip(lastbtn); | ||
462 | flipped = flip; | ||
463 | set_irq_level(oldlevel); | ||
464 | } | ||
465 | } | ||
466 | |||
467 | |||
468 | /* The Ondio its 6 buttons on analog inputs: | ||
469 | OPTION: AN2 (used as MENU for now) | ||
470 | ON/OFF: AN3 | ||
471 | LEFT/RIGHT/UP/DOWN: AN4 | ||
472 | We map them like the player keys for now, although this is far from optimal. | ||
473 | */ | ||
474 | void button_init(void) | ||
475 | { | ||
476 | queue_init(&button_queue); | ||
477 | lastbtn = 0; | ||
478 | tick_add_task(button_tick); | ||
479 | |||
480 | reset_poweroff_timer(); | ||
481 | } | ||
482 | |||
483 | static int button_read(void) | ||
484 | { | ||
485 | int btn = BUTTON_NONE; | ||
486 | int data = adc_read(4); | ||
487 | |||
488 | if(adc_read(2) > 0x180) /* active high */ | ||
489 | btn |= BUTTON_MENU; | ||
490 | if(adc_read(3) < 0x180) /* active low */ | ||
491 | btn |= BUTTON_ON; | ||
492 | if(adc_read(3) < 0x180) | ||
493 | btn |= BUTTON_PLAY | BUTTON_UP; | ||
494 | |||
495 | /* Check the 4 direction keys, hard-coded analog limits for now */ | ||
496 | if (data >= 0x2E5) | ||
497 | btn |= BUTTON_LEFT; | ||
498 | else if (data >= 0x23F) | ||
499 | btn |= BUTTON_RIGHT; | ||
500 | else if (data >= 0x197) | ||
501 | btn |= BUTTON_PLAY | BUTTON_UP; | ||
502 | else if (data >= 0x0A1) | ||
503 | btn |= BUTTON_STOP | BUTTON_DOWN; | ||
504 | |||
505 | return btn; | ||
506 | } | ||
507 | |||
424 | #endif | 508 | #endif |
425 | 509 | ||
426 | int button_status(void) | 510 | int button_status(void) |