summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iaudio/x5/adc-x5.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iaudio/x5/adc-x5.c')
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/adc-x5.c44
1 files changed, 36 insertions, 8 deletions
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
27static unsigned short adcdata[NUM_ADC_CHANNELS]; 27static unsigned short adcdata[NUM_ADC_CHANNELS];
28 28
29static int channelnum[] = 29static 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 */
37static volatile bool button_scan_on = true;
38
39void adc_enable_button_scan(bool enable)
40{
41 button_scan_on = enable;
42}
43
44bool adc_get_button_scan_enabled(void)
45{
46 return button_scan_on;
47}
48
36unsigned short adc_scan(int channel) 49unsigned 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
57static void adc_tick(void) 85static 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);