diff options
Diffstat (limited to 'firmware/drivers/adc.c')
-rw-r--r-- | firmware/drivers/adc.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index 6e1c57766a..1755fafb99 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "kernel.h" | 22 | #include "kernel.h" |
23 | #include "thread.h" | 23 | #include "thread.h" |
24 | #include "adc.h" | 24 | #include "adc.h" |
25 | #include "pcf50605.h" | ||
25 | #include "pcf50606.h" | 26 | #include "pcf50606.h" |
26 | 27 | ||
27 | #if CONFIG_CPU == SH7034 | 28 | #if CONFIG_CPU == SH7034 |
@@ -119,7 +120,7 @@ static int channelnum[] = | |||
119 | 2, /* ADC_REMOTEDETECT (ADCIN1, resistive divider) */ | 120 | 2, /* ADC_REMOTEDETECT (ADCIN1, resistive divider) */ |
120 | }; | 121 | }; |
121 | 122 | ||
122 | unsigned char adc_scan(int channel) | 123 | unsigned short adc_scan(int channel) |
123 | { | 124 | { |
124 | unsigned char data; | 125 | unsigned char data; |
125 | 126 | ||
@@ -143,7 +144,7 @@ unsigned char adc_scan(int channel) | |||
143 | /* delay loop */ | 144 | /* delay loop */ |
144 | #define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) | 145 | #define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) |
145 | 146 | ||
146 | unsigned char adc_scan(int channel) | 147 | unsigned short adc_scan(int channel) |
147 | { | 148 | { |
148 | unsigned char data = 0; | 149 | unsigned char data = 0; |
149 | int i; | 150 | int i; |
@@ -220,8 +221,7 @@ static void adc_tick(void) | |||
220 | 221 | ||
221 | void adc_init(void) | 222 | void adc_init(void) |
222 | { | 223 | { |
223 | #ifdef IRIVER_H300_SERIES | 224 | #ifndef IRIVER_H300_SERIES |
224 | #else | ||
225 | or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS | 225 | or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS |
226 | GPIO21: Data In (to the ADC) | 226 | GPIO21: Data In (to the ADC) |
227 | GPIO22: CLK | 227 | GPIO22: CLK |
@@ -284,17 +284,45 @@ void adc_init(void) | |||
284 | 284 | ||
285 | #elif CONFIG_CPU == PP5020 || (CONFIG_CPU == PP5002) | 285 | #elif CONFIG_CPU == PP5020 || (CONFIG_CPU == PP5002) |
286 | 286 | ||
287 | /* TODO: Implement adc.c */ | 287 | struct adc_struct { |
288 | long last_read; | ||
289 | int channelnum; | ||
290 | unsigned short data; | ||
291 | }; | ||
292 | |||
293 | static struct adc_struct adcdata[NUM_ADC_CHANNELS]; | ||
294 | |||
295 | static unsigned short adc_scan(struct adc_struct *adc) | ||
296 | { | ||
297 | /* Disable interrupts during the I2C transaction */ | ||
298 | int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); | ||
299 | unsigned short data = pcf50605_a2d_read(adc->channelnum); | ||
300 | set_irq_level(old_irq_level); | ||
301 | /* This gives us a 13 bit value corresponding to 0-5.4 volts | ||
302 | * The range of the value is 13FB-17FA */ | ||
303 | data = (data<<2)+0x13FB; | ||
304 | adc->data = data; | ||
305 | |||
306 | return data; | ||
307 | } | ||
288 | 308 | ||
289 | unsigned short adc_read(int channel) | 309 | unsigned short adc_read(int channel) |
290 | { | 310 | { |
291 | (void)channel; | 311 | struct adc_struct *adc = &adcdata[channel]; |
292 | return 0; | 312 | if (adc->last_read + HZ < current_tick) { |
313 | adc->last_read = current_tick; | ||
314 | return adc_scan(adc); | ||
315 | } else { | ||
316 | return adcdata[channel].data; | ||
317 | } | ||
293 | } | 318 | } |
294 | 319 | ||
295 | void adc_init(void) | 320 | void adc_init(void) |
296 | { | 321 | { |
322 | struct adc_struct *adc_battery = &adcdata[ADC_BATTERY]; | ||
323 | adc_battery->channelnum = 0x3; /* ADCVIN1, subtractor */ | ||
297 | 324 | ||
325 | adc_scan(adc_battery); | ||
298 | } | 326 | } |
299 | 327 | ||
300 | #elif CONFIG_CPU == PNX0101 | 328 | #elif CONFIG_CPU == PNX0101 |