summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-10-29 13:48:57 +0000
committerJens Arnold <amiconn@rockbox.org>2006-10-29 13:48:57 +0000
commit85c9a05c56a290a0dd1686808d5bdb966d72f9a5 (patch)
tree4c05a7348210ed469e7ee0104f782c5e27378979
parentc4c4709d82e91f21283721eefcebe18182d901be (diff)
downloadrockbox-85c9a05c56a290a0dd1686808d5bdb966d72f9a5.tar.gz
rockbox-85c9a05c56a290a0dd1686808d5bdb966d72f9a5.zip
H300: Don't read the button ADC as long as no button is pressed, utilising the PCF50606 accessory detect feature. Ported from X5.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11383 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/debug_menu.c10
-rw-r--r--firmware/target/coldfire/iriver/button-target.h4
-rw-r--r--firmware/target/coldfire/iriver/h300/button-h300.c19
-rw-r--r--firmware/target/coldfire/iriver/h300/pcf50606-h300.c61
4 files changed, 86 insertions, 8 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 251d3b35ae..9d721d02e0 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -318,7 +318,7 @@ bool dbg_audio_thread(void)
318 break; 318 break;
319 case ACTION_STD_CANCEL: 319 case ACTION_STD_CANCEL:
320 done = true; 320 done = true;
321 break; 321 break;
322 } 322 }
323 action_signalscreenchange(); 323 action_signalscreenchange();
324 line = 0; 324 line = 0;
@@ -1070,15 +1070,17 @@ bool dbg_ports(void)
1070 adc_remotedetect = adc_read(ADC_REMOTEDETECT); 1070 adc_remotedetect = adc_read(ADC_REMOTEDETECT);
1071#endif 1071#endif
1072 1072
1073#ifdef IAUDIO_X5 1073#if defined(IAUDIO_X5) || defined(IRIVER_H300_SERIES)
1074 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x", 1074 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1075 button_scan_enabled() ? '+' : '-', adc_buttons); 1075 button_scan_enabled() ? '+' : '-', adc_buttons);
1076#else
1077 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1078#endif
1076 lcd_puts(0, line++, buf); 1079 lcd_puts(0, line++, buf);
1080#ifdef IAUDIO_X5
1077 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x", 1081 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1078 remote_detect() ? '+' : '-', adc_remote); 1082 remote_detect() ? '+' : '-', adc_remote);
1079#else 1083#else
1080 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1081 lcd_puts(0, line++, buf);
1082 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote); 1084 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1083#endif 1085#endif
1084 lcd_puts(0, line++, buf); 1086 lcd_puts(0, line++, buf);
diff --git a/firmware/target/coldfire/iriver/button-target.h b/firmware/target/coldfire/iriver/button-target.h
index b89761b317..3d3247ab80 100644
--- a/firmware/target/coldfire/iriver/button-target.h
+++ b/firmware/target/coldfire/iriver/button-target.h
@@ -33,6 +33,10 @@ bool remote_button_hold(void);
33bool remote_button_hold_only(void); 33bool remote_button_hold_only(void);
34void button_init_device(void); 34void button_init_device(void);
35int button_read_device(void); 35int button_read_device(void);
36#ifdef IRIVER_H300_SERIES
37void button_enable_scan(bool enable);
38bool button_scan_enabled(void);
39#endif
36 40
37/* iRiver H100/H300 specific button codes */ 41/* iRiver H100/H300 specific button codes */
38 42
diff --git a/firmware/target/coldfire/iriver/h300/button-h300.c b/firmware/target/coldfire/iriver/h300/button-h300.c
index 80210b6c19..bcd954df8a 100644
--- a/firmware/target/coldfire/iriver/h300/button-h300.c
+++ b/firmware/target/coldfire/iriver/h300/button-h300.c
@@ -27,9 +27,10 @@
27#include "backlight.h" 27#include "backlight.h"
28#include "adc.h" 28#include "adc.h"
29#include "system.h" 29#include "system.h"
30#ifdef HAVE_REMOTE_LCD
31#include "lcd-remote.h" 30#include "lcd-remote.h"
32#endif 31
32/* have buttons scan by default */
33static bool button_scan_on = true;
33 34
34void button_init_device(void) 35void button_init_device(void)
35{ 36{
@@ -41,13 +42,23 @@ void button_init_device(void)
41 GPIO1_FUNCTION |= 0x00100062; 42 GPIO1_FUNCTION |= 0x00100062;
42} 43}
43 44
45void button_enable_scan(bool enable)
46{
47 button_scan_on = enable;
48}
49
50bool button_scan_enabled(void)
51{
52 return button_scan_on;
53}
54
44bool button_hold(void) 55bool button_hold(void)
45{ 56{
46 return (GPIO1_READ & 0x00000002)?true:false; 57 return (GPIO1_READ & 0x00000002)?true:false;
47} 58}
48 59
49bool remote_button_hold_only(void) 60bool remote_button_hold_only(void)
50{ 61{
51 if(remote_type() == REMOTETYPE_H300_NONLCD) 62 if(remote_type() == REMOTETYPE_H300_NONLCD)
52 return adc_scan(ADC_REMOTE)<0x0d; /* hold should be 0x00 */ 63 return adc_scan(ADC_REMOTE)<0x0d; /* hold should be 0x00 */
53 else 64 else
@@ -88,7 +99,7 @@ int button_read_device(void)
88 backlight_hold_changed(hold_button); 99 backlight_hold_changed(hold_button);
89#endif 100#endif
90 101
91 if (!hold_button) 102 if (button_scan_on && !hold_button)
92 { 103 {
93 data = adc_scan(ADC_BUTTONS); 104 data = adc_scan(ADC_BUTTONS);
94 105
diff --git a/firmware/target/coldfire/iriver/h300/pcf50606-h300.c b/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
index c990f5ddcb..3a67d541d3 100644
--- a/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
+++ b/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
@@ -20,6 +20,7 @@
20#include "system.h" 20#include "system.h"
21#include "kernel.h" 21#include "kernel.h"
22#include "pcf50606.h" 22#include "pcf50606.h"
23#include "button-target.h"
23 24
24/* These voltages were determined by measuring the output of the PCF50606 25/* These voltages were determined by measuring the output of the PCF50606
25 on a running H300, and verified by disassembling the original firmware */ 26 on a running H300, and verified by disassembling the original firmware */
@@ -37,10 +38,44 @@ static void set_voltages(void)
37 pcf50606_write_multiple(0x23, buf, 5); 38 pcf50606_write_multiple(0x23, buf, 5);
38} 39}
39 40
41static void init_pmu_interrupts(void)
42{
43 /* inital data is interrupt masks */
44 unsigned char data[3] =
45 {
46 ~0x00,
47 ~0x00,
48 ~0x06, /* unmask ACDREM, ACDINS */
49 };
50
51 /* make sure GPI6 interrupt is off before unmasking anything */
52 and_l(~0x0f000000, &INTPRI5); /* INT38 - Priority 0 (Off) */
53
54 /* unmask the PMU interrupts we want to service */
55 pcf50606_write_multiple(0x05, data, 3);
56 /* clear INT1-3 as these are left set after standby */
57 pcf50606_read_multiple(0x02, data, 3);
58
59 /* Set to read pcf50606 INT but keep GPI6 off until init completes */
60 and_l(~0x00000040, &GPIO_ENABLE);
61 or_l(0x00000040, &GPIO_FUNCTION);
62 or_l(0x00004000, &GPIO_INT_EN); /* GPI6 H-L */
63}
64
65static inline void enable_pmu_interrupts(void)
66{
67 /* clear pending GPI6 interrupts first or it may miss the first
68 H-L transition */
69 or_l(0x00004000, &GPIO_INT_CLEAR);
70 or_l(0x03000000, &INTPRI5); /* INT38 - Priority 3 */
71}
72
40void pcf50606_init(void) 73void pcf50606_init(void)
41{ 74{
42 pcf50606_i2c_init(); 75 pcf50606_i2c_init();
43 76
77 /* initialize pmu interrupts but don't service them yet */
78 init_pmu_interrupts();
44 set_voltages(); 79 set_voltages();
45 80
46 pcf50606_write(0x08, 0x60); /* Wake on USB and charger insertion */ 81 pcf50606_write(0x08, 0x60); /* Wake on USB and charger insertion */
@@ -49,4 +84,30 @@ void pcf50606_init(void)
49 84
50 pcf50606_write(0x35, 0x13); /* Backlight PWM = 512Hz 50/50 */ 85 pcf50606_write(0x35, 0x13); /* Backlight PWM = 512Hz 50/50 */
51 pcf50606_write(0x3a, 0x3b); /* PWM output on GPOOD1 */ 86 pcf50606_write(0x3a, 0x3b); /* PWM output on GPOOD1 */
87
88 pcf50606_write(0x33, 0x8c); /* Accessory detect: ACDAPE=1, THRSHLD=2.20V */
89
90 enable_pmu_interrupts(); /* allow GPI6 interrupts from PMU now */
91}
92
93/* PMU interrupt */
94void GPI6(void) __attribute__ ((interrupt_handler));
95void GPI6(void)
96{
97 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */
98
99 /* Clear pending GPI6 interrupts */
100 or_l(0x00004000, &GPIO_INT_CLEAR);
101
102 /* clear pending interrupts from pcf50606 */
103 pcf50606_read_multiple(0x02, data, 3);
104
105 if (data[2] & 0x06)
106 {
107 /* ACDINS/ACDREM */
108 /* Check if the button driver should actually scan main buttons or not
109 - bias towards "yes" out of paranoia. */
110 button_enable_scan((data[2] & 0x02) != 0 ||
111 (pcf50606_read(0x33) & 0x01) != 0);
112 }
52} 113}