summaryrefslogtreecommitdiff
path: root/firmware/drivers/button.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/button.c')
-rw-r--r--firmware/drivers/button.c253
1 files changed, 12 insertions, 241 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index cc9f0fa18d..c4e013afdc 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -46,6 +46,9 @@
46 46
47#ifdef TARGET_TREE 47#ifdef TARGET_TREE
48#include "button-target.h" 48#include "button-target.h"
49#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
50 || (CONFIG_KEYPAD == IRIVER_H300_PAD)
51#include "button-target.h"
49#endif 52#endif
50 53
51struct event_queue button_queue; 54struct event_queue button_queue;
@@ -82,10 +85,6 @@ static bool remote_filter_first_keypress;
82 85
83static int button_read(void); 86static int button_read(void);
84 87
85#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
86static bool remote_button_hold_only(void);
87#endif
88
89#ifdef HAVE_HEADPHONE_DETECTION 88#ifdef HAVE_HEADPHONE_DETECTION
90bool phones_present = false; 89bool phones_present = false;
91#endif 90#endif
@@ -309,17 +308,9 @@ void button_init(void)
309#ifdef TARGET_TREE 308#ifdef TARGET_TREE
310 button_init_device(); 309 button_init_device();
311 310
312#elif CONFIG_KEYPAD == IRIVER_H100_PAD 311#elif CONFIG_KEYPAD == IRIVER_H100_PAD \
313 /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs */ 312 || CONFIG_KEYPAD == IRIVER_H300_PAD
314 GPIO1_FUNCTION |= 0x00100062; 313 button_init_device(); /* temp untill TARGET_TREE is defined */
315 GPIO1_ENABLE &= ~0x00100060;
316#elif CONFIG_KEYPAD == IRIVER_H300_PAD
317 /* Set GPIO9 and GPIO15 as general purpose inputs */
318 GPIO_ENABLE &= ~0x00008200;
319 GPIO_FUNCTION |= 0x00008200;
320 /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs */
321 GPIO1_ENABLE &= ~0x00100060;
322 GPIO1_FUNCTION |= 0x00100062;
323#elif CONFIG_KEYPAD == RECORDER_PAD 314#elif CONFIG_KEYPAD == RECORDER_PAD
324 /* Set PB4 and PB8 as input pins */ 315 /* Set PB4 and PB8 as input pins */
325 PBCR1 &= 0xfffc; /* PB8MD = 00 */ 316 PBCR1 &= 0xfffc; /* PB8MD = 00 */
@@ -505,214 +496,19 @@ static int button_read(void)
505 int btn = BUTTON_NONE; 496 int btn = BUTTON_NONE;
506 int retval; 497 int retval;
507#ifndef TARGET_TREE 498#ifndef TARGET_TREE
499#if (CONFIG_KEYPAD != IRIVER_H100_PAD) \
500 && (CONFIG_KEYPAD != IRIVER_H300_PAD)
508 int data; 501 int data;
509#endif 502#endif
503#endif
510 504
511#ifdef TARGET_TREE 505#ifdef TARGET_TREE
512 btn = button_read_device(); 506 btn = button_read_device();
513 507
514#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) 508#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
515 static bool hold_button = false; 509 || (CONFIG_KEYPAD == IRIVER_H300_PAD)
516 static bool remote_hold_button = false; 510 btn = button_read_device(); /* temp untill TARGET_TREE is defined */
517 static int prev_data = 0xff;
518 static int last_valid = 0xff;
519 bool hold_button_old;
520 bool remote_hold_button_old;
521
522 /* normal buttons */
523 hold_button_old = hold_button;
524 hold_button = button_hold();
525
526#ifndef BOOTLOADER
527 if (hold_button != hold_button_old)
528 backlight_hold_changed(hold_button);
529#endif
530
531 if (!hold_button)
532 {
533 data = adc_scan(ADC_BUTTONS);
534
535 /* ADC debouncing: Only accept new reading if it's
536 * stable (+/-1). Use latest stable value otherwise. */
537 if ((unsigned)(data - prev_data + 1) <= 2)
538 last_valid = data;
539 prev_data = data;
540 data = last_valid;
541
542#if CONFIG_KEYPAD == IRIVER_H100_PAD
543 if (data < 0xf0)
544 {
545 if (data < 0x80)
546 if (data < 0x30)
547 if (data < 0x18)
548 btn = BUTTON_SELECT;
549 else
550 btn = BUTTON_UP;
551 else
552 if (data < 0x50)
553 btn = BUTTON_LEFT;
554 else
555 btn = BUTTON_DOWN;
556 else
557 if (data < 0xb0)
558 if (data < 0xa0)
559 btn = BUTTON_RIGHT;
560 else
561 btn = BUTTON_OFF;
562 else
563 if (data < 0xd0)
564 btn = BUTTON_MODE;
565 else
566 btn = BUTTON_REC;
567 }
568#else /* H300 */
569 if (data < 0xba)
570 {
571 if (data < 0x54)
572 if (data < 0x30)
573 if (data < 0x10)
574 btn = BUTTON_SELECT;
575 else
576 btn = BUTTON_UP;
577 else
578 btn = BUTTON_LEFT;
579 else
580 if (data < 0x98)
581 if (data < 0x76)
582 btn = BUTTON_DOWN;
583 else
584 btn = BUTTON_RIGHT;
585 else
586 btn = BUTTON_OFF;
587 }
588#endif
589 }
590
591 /* remote buttons */
592 remote_hold_button_old = remote_hold_button;
593 remote_hold_button = remote_button_hold_only();
594
595#ifndef BOOTLOADER
596 if (remote_hold_button != remote_hold_button_old)
597 remote_backlight_hold_changed(remote_hold_button);
598#endif
599 511
600 if (!remote_hold_button)
601 {
602 data = adc_scan(ADC_REMOTE);
603 switch (remote_type())
604 {
605 case REMOTETYPE_H100_LCD:
606 if (data < 0xf5)
607 {
608 if (data < 0x73)
609 if (data < 0x3f)
610 if (data < 0x25)
611 if(data < 0x0c)
612 btn |= BUTTON_RC_STOP;
613 else
614 btn |= BUTTON_RC_VOL_DOWN;
615 else
616 btn |= BUTTON_RC_MODE;
617 else
618 if (data < 0x5a)
619 btn |= BUTTON_RC_VOL_UP;
620 else
621 btn |= BUTTON_RC_BITRATE;
622 else
623 if (data < 0xa8)
624 if (data < 0x8c)
625 btn |= BUTTON_RC_REC;
626 else
627 btn |= BUTTON_RC_SOURCE;
628 else
629 if (data < 0xdf)
630 if(data < 0xc5)
631 btn |= BUTTON_RC_FF;
632 else
633 btn |= BUTTON_RC_MENU;
634 else
635 btn |= BUTTON_RC_REW;
636 }
637 break;
638 case REMOTETYPE_H300_LCD:
639 if (data < 0xf5)
640 {
641 if (data < 0x73)
642 if (data < 0x42)
643 if (data < 0x27)
644 if(data < 0x0c)
645 btn |= BUTTON_RC_VOL_DOWN;
646 else
647 btn |= BUTTON_RC_FF;
648 else
649 btn |= BUTTON_RC_STOP;
650 else
651 if (data < 0x5b)
652 btn |= BUTTON_RC_MODE;
653 else
654 btn |= BUTTON_RC_REC;
655 else
656 if (data < 0xab)
657 if (data < 0x8e)
658 btn |= BUTTON_RC_ON;
659 else
660 btn |= BUTTON_RC_BITRATE;
661 else
662 if (data < 0xde)
663 if(data < 0xc5)
664 btn |= BUTTON_RC_SOURCE;
665 else
666 btn |= BUTTON_RC_VOL_UP;
667 else
668 btn |= BUTTON_RC_REW;
669 }
670 break;
671 case REMOTETYPE_H300_NONLCD:
672 if (data < 0xf1)
673 {
674 if (data < 0x7d)
675 if (data < 0x25)
676 btn |= BUTTON_RC_FF;
677 else
678 btn |= BUTTON_RC_REW;
679 else
680 if (data < 0xd5)
681 btn |= BUTTON_RC_VOL_DOWN;
682 else
683 btn |= BUTTON_RC_VOL_UP;
684 }
685 break;
686 }
687 }
688
689 /* special buttons */
690#if CONFIG_KEYPAD == IRIVER_H300_PAD
691 if (!hold_button)
692 {
693 data = GPIO_READ;
694 if ((data & 0x0200) == 0)
695 btn |= BUTTON_MODE;
696 if ((data & 0x8000) == 0)
697 btn |= BUTTON_REC;
698 }
699#endif
700
701 data = GPIO1_READ;
702 if (!hold_button && ((data & 0x20) == 0))
703 btn |= BUTTON_ON;
704 if (!remote_hold_button && ((data & 0x40) == 0))
705 switch(remote_type())
706 {
707 case REMOTETYPE_H100_LCD:
708 case REMOTETYPE_H300_NONLCD:
709 btn |= BUTTON_RC_ON;
710 break;
711 case REMOTETYPE_H300_LCD:
712 btn |= BUTTON_RC_MENU;
713 break;
714 }
715
716#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD 512#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
717 static bool hold_button = false; 513 static bool hold_button = false;
718 bool hold_button_old; 514 bool hold_button_old;
@@ -910,31 +706,6 @@ static int button_read(void)
910 return retval; 706 return retval;
911} 707}
912 708
913#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
914bool button_hold(void)
915{
916 return (GPIO1_READ & 0x00000002)?true:false;
917}
918
919static bool remote_button_hold_only(void)
920{
921 if(remote_type() == REMOTETYPE_H300_NONLCD)
922 return adc_scan(ADC_REMOTE)<0x0d; /* hold should be 0x00 */
923 else
924 return (GPIO1_READ & 0x00100000)?true:false;
925}
926
927/* returns true only if there is remote present */
928bool remote_button_hold(void)
929{
930 /* H300's NON-LCD remote doesn't set the "remote present" bit */
931 if(remote_type() == REMOTETYPE_H300_NONLCD)
932 return remote_button_hold_only();
933 else
934 return ((GPIO_READ & 0x40000000) == 0)?remote_button_hold_only():false;
935}
936#endif
937
938#if CONFIG_KEYPAD == IRIVER_IFP7XX_PAD 709#if CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
939bool button_hold(void) 710bool button_hold(void)
940{ 711{