diff options
-rw-r--r-- | apps/debug_menu.c | 32 | ||||
-rw-r--r-- | firmware/export/adc.h | 5 | ||||
-rwxr-xr-x | firmware/target/coldfire/iaudio/x5/adc-x5.c | 44 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/x5/pcf50606-x5.c | 28 |
4 files changed, 85 insertions, 24 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 42c5776128..712a66cfa0 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -76,6 +76,10 @@ | |||
76 | #include "pcm_playback.h" | 76 | #include "pcm_playback.h" |
77 | #endif | 77 | #endif |
78 | 78 | ||
79 | #ifdef IAUDIO_X5 | ||
80 | #include "lcd-remote-target.h" | ||
81 | #endif | ||
82 | |||
79 | /*---------------------------------------------------*/ | 83 | /*---------------------------------------------------*/ |
80 | /* SPECIAL DEBUG STUFF */ | 84 | /* SPECIAL DEBUG STUFF */ |
81 | /*---------------------------------------------------*/ | 85 | /*---------------------------------------------------*/ |
@@ -92,7 +96,7 @@ char thread_status_char(int status) | |||
92 | case STATE_SLEEPING : return 'S'; | 96 | case STATE_SLEEPING : return 'S'; |
93 | case STATE_BLOCKED_W_TMO: return 'T'; | 97 | case STATE_BLOCKED_W_TMO: return 'T'; |
94 | } | 98 | } |
95 | 99 | ||
96 | return '?'; | 100 | return '?'; |
97 | } | 101 | } |
98 | #ifndef SIMULATOR | 102 | #ifndef SIMULATOR |
@@ -130,12 +134,12 @@ bool dbg_os(void) | |||
130 | thread = &cores[core].threads[i]; | 134 | thread = &cores[core].threads[i]; |
131 | if (thread->name == NULL) | 135 | if (thread->name == NULL) |
132 | continue; | 136 | continue; |
133 | 137 | ||
134 | usage = thread_stack_usage(thread); | 138 | usage = thread_stack_usage(thread); |
135 | status = thread_get_status(thread); | 139 | status = thread_get_status(thread); |
136 | 140 | ||
137 | snprintf(buf, 32, "(%d) %c%c %d %s: %d%%", core, | 141 | snprintf(buf, 32, "(%d) %c%c %d %s: %d%%", core, |
138 | (status == STATE_RUNNING) ? '*' : ' ', | 142 | (status == STATE_RUNNING) ? '*' : ' ', |
139 | thread_status_char(status), | 143 | thread_status_char(status), |
140 | cores[CURRENT_CORE].threads[i].priority, | 144 | cores[CURRENT_CORE].threads[i].priority, |
141 | cores[core].threads[i].name, usage); | 145 | cores[core].threads[i].name, usage); |
@@ -149,19 +153,19 @@ bool dbg_os(void) | |||
149 | thread = &cores[CURRENT_CORE].threads[i]; | 153 | thread = &cores[CURRENT_CORE].threads[i]; |
150 | if (thread->name == NULL) | 154 | if (thread->name == NULL) |
151 | continue; | 155 | continue; |
152 | 156 | ||
153 | usage = thread_stack_usage(thread); | 157 | usage = thread_stack_usage(thread); |
154 | status = thread_get_status(thread); | 158 | status = thread_get_status(thread); |
155 | # ifdef HAVE_PRIORITY_SCHEDULING | 159 | # ifdef HAVE_PRIORITY_SCHEDULING |
156 | snprintf(buf, 32, "%c%c %d %s: %d%%", | 160 | snprintf(buf, 32, "%c%c %d %s: %d%%", |
157 | (status == STATE_RUNNING) ? '*' : ' ', | 161 | (status == STATE_RUNNING) ? '*' : ' ', |
158 | thread_status_char(status), | 162 | thread_status_char(status), |
159 | cores[CURRENT_CORE].threads[i].priority, | 163 | cores[CURRENT_CORE].threads[i].priority, |
160 | cores[CURRENT_CORE].threads[i].name, usage); | 164 | cores[CURRENT_CORE].threads[i].name, usage); |
161 | # else | 165 | # else |
162 | snprintf(buf, 32, "%c%c %s: %d%%", | 166 | snprintf(buf, 32, "%c%c %s: %d%%", |
163 | (status == STATE_RUNNING) ? '*' : ' ', | 167 | (status == STATE_RUNNING) ? '*' : ' ', |
164 | (status == STATE_BLOCKED) ? 'B' : ' ', | 168 | (status == STATE_BLOCKED) ? 'B' : ' ', |
165 | cores[CURRENT_CORE].threads[i].name, usage); | 169 | cores[CURRENT_CORE].threads[i].name, usage); |
166 | # endif | 170 | # endif |
167 | lcd_puts(0, 1+i, buf); | 171 | lcd_puts(0, 1+i, buf); |
@@ -1066,9 +1070,17 @@ bool dbg_ports(void) | |||
1066 | adc_remotedetect = adc_read(ADC_REMOTEDETECT); | 1070 | adc_remotedetect = adc_read(ADC_REMOTEDETECT); |
1067 | #endif | 1071 | #endif |
1068 | 1072 | ||
1073 | #ifdef IAUDIO_X5 | ||
1074 | snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x", | ||
1075 | adc_get_button_scan_enabled() ? '+' : '-', adc_buttons); | ||
1076 | lcd_puts(0, line++, buf); | ||
1077 | snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x", | ||
1078 | remote_detect() ? '+' : '-', adc_remote); | ||
1079 | #else | ||
1069 | snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons); | 1080 | snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons); |
1070 | lcd_puts(0, line++, buf); | 1081 | lcd_puts(0, line++, buf); |
1071 | snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote); | 1082 | snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote); |
1083 | #endif | ||
1072 | lcd_puts(0, line++, buf); | 1084 | lcd_puts(0, line++, buf); |
1073 | snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery); | 1085 | snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery); |
1074 | lcd_puts(0, line++, buf); | 1086 | lcd_puts(0, line++, buf); |
@@ -1438,7 +1450,7 @@ bool view_battery(void) | |||
1438 | ext_pwr ? "present" : "absent"); | 1450 | ext_pwr ? "present" : "absent"); |
1439 | lcd_puts(0, 4, buf); | 1451 | lcd_puts(0, 4, buf); |
1440 | snprintf(buf, 30, "Battery: %s", | 1452 | snprintf(buf, 30, "Battery: %s", |
1441 | charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging"); | 1453 | charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging"); |
1442 | lcd_puts(0, 5, buf); | 1454 | lcd_puts(0, 5, buf); |
1443 | snprintf(buf, 30, "Dock mode: %s", | 1455 | snprintf(buf, 30, "Dock mode: %s", |
1444 | dock ? "enabled" : "disabled"); | 1456 | dock ? "enabled" : "disabled"); |
diff --git a/firmware/export/adc.h b/firmware/export/adc.h index 13d2617c00..487873dacc 100644 --- a/firmware/export/adc.h +++ b/firmware/export/adc.h | |||
@@ -105,4 +105,9 @@ void adc_init(void); | |||
105 | unsigned short adc_scan(int channel); | 105 | unsigned short adc_scan(int channel); |
106 | #endif | 106 | #endif |
107 | 107 | ||
108 | #if defined(IAUDIO_X5) | ||
109 | void adc_enable_button_scan(bool enable); | ||
110 | bool adc_get_button_scan_enabled(void); | ||
111 | #endif | ||
112 | |||
108 | #endif | 113 | #endif |
diff --git a/firmware/target/coldfire/iaudio/x5/adc-x5.c b/firmware/target/coldfire/iaudio/x5/adc-x5.c index fc45da8624..c923951e31 100755 --- a/firmware/target/coldfire/iaudio/x5/adc-x5.c +++ b/firmware/target/coldfire/iaudio/x5/adc-x5.c | |||
@@ -26,19 +26,47 @@ | |||
26 | 26 | ||
27 | static unsigned short adcdata[NUM_ADC_CHANNELS]; | 27 | static unsigned short adcdata[NUM_ADC_CHANNELS]; |
28 | 28 | ||
29 | static int channelnum[] = | 29 | static const int adcc2_parms[] = |
30 | { | 30 | { |
31 | 5, /* ADC_BUTTONS (ADCIN2) */ | 31 | [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */ |
32 | 6, /* ADC_REMOTE (ADCIN3) */ | 32 | [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */ |
33 | 0, /* ADC_BATTERY (BATVOLT, resistive divider) */ | 33 | [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ |
34 | }; | 34 | }; |
35 | 35 | ||
36 | /* have buttons scan by default */ | ||
37 | static volatile bool button_scan_on = true; | ||
38 | |||
39 | void adc_enable_button_scan(bool enable) | ||
40 | { | ||
41 | button_scan_on = enable; | ||
42 | } | ||
43 | |||
44 | bool adc_get_button_scan_enabled(void) | ||
45 | { | ||
46 | return button_scan_on; | ||
47 | } | ||
48 | |||
36 | unsigned short adc_scan(int channel) | 49 | unsigned short adc_scan(int channel) |
37 | { | 50 | { |
38 | int level = set_irq_level(HIGHEST_IRQ_LEVEL); | 51 | int level; |
39 | unsigned char data; | 52 | unsigned char data; |
40 | 53 | ||
41 | pcf50606_write(0x2f, 0x80 | (channelnum[channel] << 1) | 1); | 54 | if (channel == ADC_BUTTONS) |
55 | { | ||
56 | /* no button scan if nothing pushed */ | ||
57 | if (!button_scan_on) | ||
58 | return adcdata[channel] = 0xff; | ||
59 | } | ||
60 | else if (channel == ADC_REMOTE) | ||
61 | { | ||
62 | /* no remote scan if not plugged */ | ||
63 | if (GPIO_READ & 0x01000000) | ||
64 | return adcdata[channel] = 0xff; | ||
65 | } | ||
66 | |||
67 | level = set_irq_level(HIGHEST_IRQ_LEVEL); | ||
68 | |||
69 | pcf50606_write(0x2f, adcc2_parms[channel]); | ||
42 | data = pcf50606_read(0x30); | 70 | data = pcf50606_read(0x30); |
43 | 71 | ||
44 | adcdata[channel] = data; | 72 | adcdata[channel] = data; |
@@ -56,7 +84,7 @@ static int adc_counter; | |||
56 | 84 | ||
57 | static void adc_tick(void) | 85 | static void adc_tick(void) |
58 | { | 86 | { |
59 | if(++adc_counter == HZ) | 87 | if (++adc_counter == HZ) |
60 | { | 88 | { |
61 | adc_counter = 0; | 89 | adc_counter = 0; |
62 | adc_scan(ADC_BATTERY); | 90 | adc_scan(ADC_BATTERY); |
diff --git a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c index 58ff5d5cb0..8b3655c107 100644 --- a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c +++ b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.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 "adc.h" | ||
23 | #include "powermgmt.h" | 24 | #include "powermgmt.h" |
24 | 25 | ||
25 | /* These voltages were determined by measuring the output of the PCF50606 | 26 | /* These voltages were determined by measuring the output of the PCF50606 |
@@ -44,7 +45,7 @@ static void init_pmu_interrupts(void) | |||
44 | { | 45 | { |
45 | ~0x04, /* unmask ONKEY1S */ | 46 | ~0x04, /* unmask ONKEY1S */ |
46 | ~0x00, | 47 | ~0x00, |
47 | ~0x00 | 48 | ~0x06, /* unmask ACDREM, ACDINS */ |
48 | }; | 49 | }; |
49 | 50 | ||
50 | /* make sure GPI0 interrupt is off before unmasking anything */ | 51 | /* make sure GPI0 interrupt is off before unmasking anything */ |
@@ -63,6 +64,9 @@ static void init_pmu_interrupts(void) | |||
63 | 64 | ||
64 | static inline void enable_pmu_interrupts(void) | 65 | static inline void enable_pmu_interrupts(void) |
65 | { | 66 | { |
67 | /* clear pending GPI0 interrupts first or it may miss the first | ||
68 | H-L transition */ | ||
69 | or_l(0x00000100, &GPIO_INT_CLEAR); | ||
66 | or_l(0x3, &INTPRI5); /* INT32 - Priority 3 */ | 70 | or_l(0x3, &INTPRI5); /* INT32 - Priority 3 */ |
67 | } | 71 | } |
68 | 72 | ||
@@ -86,6 +90,9 @@ void pcf50606_init(void) | |||
86 | pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */ | 90 | pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */ |
87 | #endif | 91 | #endif |
88 | 92 | ||
93 | /* Accessory detect */ | ||
94 | pcf50606_write(0x33, 0x8e); /* ACDAPE=1, THRSHLD=2.40V */ | ||
95 | |||
89 | /* allow GPI0 interrupts from PMU now */ | 96 | /* allow GPI0 interrupts from PMU now */ |
90 | enable_pmu_interrupts(); | 97 | enable_pmu_interrupts(); |
91 | } | 98 | } |
@@ -101,12 +108,15 @@ void pcf50606_reset_timeout(void) | |||
101 | void GPI0(void) __attribute__ ((interrupt_handler, section(".text"))); | 108 | void GPI0(void) __attribute__ ((interrupt_handler, section(".text"))); |
102 | void GPI0(void) | 109 | void GPI0(void) |
103 | { | 110 | { |
104 | unsigned char read[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ | 111 | unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ |
112 | |||
113 | /* Clear pending GPI0 interrupts */ | ||
114 | or_l(0x00000100, &GPIO_INT_CLEAR); | ||
105 | 115 | ||
106 | /* clear pending interrupts from pcf50606 */ | 116 | /* clear pending interrupts from pcf50606 */ |
107 | pcf50606_read_multiple(0x02, read, 3); | 117 | pcf50606_read_multiple(0x02, data, 3); |
108 | 118 | ||
109 | if (read[0] & 0x04) | 119 | if (data[0] & 0x04) |
110 | { | 120 | { |
111 | /* ONKEY1S */ | 121 | /* ONKEY1S */ |
112 | if (GPIO_READ & 0x02000000) | 122 | if (GPIO_READ & 0x02000000) |
@@ -115,6 +125,12 @@ void GPI0(void) | |||
115 | pcf50606_reset_timeout(); /* remote ONKEY */ | 125 | pcf50606_reset_timeout(); /* remote ONKEY */ |
116 | } | 126 | } |
117 | 127 | ||
118 | /* Clear pending GPI0 interrupts */ | 128 | if (data[2] & 0x06) |
119 | or_l(0x00000100, &GPIO_INT_CLEAR); | 129 | { |
130 | /* ACDINS/ACDREM */ | ||
131 | /* Check if adc_scan should actually scan main buttons or not - | ||
132 | bias towards "yes" out of paranoia. */ | ||
133 | adc_enable_button_scan((data[2] & 0x02) != 0 || | ||
134 | (pcf50606_read(0x33) & 0x01) != 0); | ||
135 | } | ||
120 | } | 136 | } |