summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/coldfire/iaudio/x5/adc-target.h5
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/adc-x5.c48
-rw-r--r--firmware/target/coldfire/iaudio/x5/pcf50606-x5.c4
3 files changed, 23 insertions, 34 deletions
diff --git a/firmware/target/coldfire/iaudio/x5/adc-target.h b/firmware/target/coldfire/iaudio/x5/adc-target.h
index 4081562fe5..28ba6225d1 100644
--- a/firmware/target/coldfire/iaudio/x5/adc-target.h
+++ b/firmware/target/coldfire/iaudio/x5/adc-target.h
@@ -28,5 +28,8 @@
28 28
29/* Force a scan now */ 29/* Force a scan now */
30unsigned short adc_scan(int channel); 30unsigned short adc_scan(int channel);
31 31static inline unsigned short adc_read(int channel)
32 { return adc_scan(channel); }
33static inline void adc_init(void)
34 {}
32#endif /* _ADC_TARGET_H_ */ 35#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/coldfire/iaudio/x5/adc-x5.c b/firmware/target/coldfire/iaudio/x5/adc-x5.c
index 72aec7d547..1895cacfe9 100755
--- a/firmware/target/coldfire/iaudio/x5/adc-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/adc-x5.c
@@ -24,49 +24,35 @@
24#include "adc.h" 24#include "adc.h"
25#include "pcf50606.h" 25#include "pcf50606.h"
26 26
27static unsigned short adcdata[NUM_ADC_CHANNELS]; 27/* get remaining 2 bits and return 10 bit value */
28 28static int get_10bit_voltage(int msbdata)
29static const int adcc2_parms[] =
30{ 29{
31 [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */ 30 int data = msbdata << 2;
32 [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */ 31 data |= pcf50606_read(0x31) & 0x3;
33 [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ 32 return data;
34}; 33}
35 34
36unsigned short adc_scan(int channel) 35unsigned short adc_scan(int channel)
37{ 36{
37 static const int adcc2_parms[] =
38 {
39 [ADC_BUTTONS] = 0x81 | (5 << 1), /* 8b - ADCIN2 */
40 [ADC_REMOTE] = 0x81 | (6 << 1), /* 8b - ADCIN3 */
41 [ADC_BATTERY] = 0x01 | (0 << 1), /* 10b - BATVOLT, resistive divider */
42 };
43
38 int level; 44 int level;
39 unsigned char data; 45 int data;
40 46
41 level = set_irq_level(HIGHEST_IRQ_LEVEL); 47 level = set_irq_level(HIGHEST_IRQ_LEVEL);
42 48
43 pcf50606_write(0x2f, adcc2_parms[channel]); 49 pcf50606_write(0x2f, adcc2_parms[channel]);
44 data = pcf50606_read(0x30); 50 data = pcf50606_read(0x30);
45 51
46 adcdata[channel] = data; 52 if (channel == ADC_BATTERY)
53 data = get_10bit_voltage(data);
47 54
48 set_irq_level(level); 55 set_irq_level(level);
49 return data;
50}
51
52unsigned short adc_read(int channel)
53{
54 return adcdata[channel];
55}
56
57static int adc_counter;
58
59static void adc_tick(void)
60{
61 if (++adc_counter == HZ)
62 {
63 adc_counter = 0;
64 adc_scan(ADC_BATTERY);
65 }
66}
67 56
68void adc_init(void) 57 return (unsigned short)data;
69{
70 adc_scan(ADC_BATTERY);
71 tick_add_task(adc_tick);
72} 58}
diff --git a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c
index 3443d1e567..59140667ef 100644
--- a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c
@@ -128,8 +128,8 @@ void GPI0(void)
128 if (data[2] & 0x06) 128 if (data[2] & 0x06)
129 { 129 {
130 /* ACDINS/ACDREM */ 130 /* ACDINS/ACDREM */
131 /* Check if adc_scan should actually scan main buttons or not - 131 /* Check if main buttons should be actually be scanned or not
132 bias towards "yes" out of paranoia. */ 132 - bias towards "yes" out of paranoia. */
133 button_enable_scan((data[2] & 0x02) != 0 || 133 button_enable_scan((data[2] & 0x02) != 0 ||
134 (pcf50606_read(0x33) & 0x01) != 0); 134 (pcf50606_read(0x33) & 0x01) != 0);
135 } 135 }