summaryrefslogtreecommitdiff
path: root/firmware/target/arm/iriver/h10/adc-h10.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/iriver/h10/adc-h10.c')
-rwxr-xr-xfirmware/target/arm/iriver/h10/adc-h10.c73
1 files changed, 68 insertions, 5 deletions
diff --git a/firmware/target/arm/iriver/h10/adc-h10.c b/firmware/target/arm/iriver/h10/adc-h10.c
index 0e17ae4f91..b3a36e6b39 100755
--- a/firmware/target/arm/iriver/h10/adc-h10.c
+++ b/firmware/target/arm/iriver/h10/adc-h10.c
@@ -23,19 +23,82 @@
23#include "thread.h" 23#include "thread.h"
24#include "adc.h" 24#include "adc.h"
25 25
26/* TODO: implement adc functionality */ 26static unsigned short adcdata[NUM_ADC_CHANNELS];
27
28/* Scan ADC so that adcdata[channel] gets updated */
27unsigned short adc_scan(int channel) 29unsigned short adc_scan(int channel)
28{ 30{
29 (void)channel; 31 unsigned int adc_data_1;
30 return 0; 32 unsigned int adc_data_2;
33
34 /* Initialise */
35 ADC_ADDR=0x130;
36 ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is
37 off, 0x40 if the channel is on */
38
39 /* Enable Channel */
40 ADC_ADDR |= (0x1000000<<channel);
41
42 /* Start? */
43 ADC_ADDR |= 0x20000000;
44 ADC_ADDR |= 0x80000000;
45
46 /* Wait 50ms for things to settle */
47 sleep(HZ/20);
48
49 /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
50 For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
51 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
52 adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff);
53 adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3);
54
55 adcdata[channel] = (adc_data_1<<2 | adc_data_2);
56
57 return adcdata[channel];
31} 58}
32 59
60/* Read 10-bit channel data */
33unsigned short adc_read(int channel) 61unsigned short adc_read(int channel)
34{ 62{
35 (void)channel; 63 return adcdata[channel];
36 return 0; 64}
65
66static int adc_counter;
67
68static void adc_tick(void)
69{
70 if(++adc_counter == HZ)
71 {
72 adc_counter = 0;
73 adc_scan(ADC_BATTERY);
74 adc_scan(ADC_UNKNOWN_1);
75 adc_scan(ADC_UNKNOWN_2);
76 adc_scan(ADC_SCROLLPAD);
77 }
37} 78}
38 79
39void adc_init(void) 80void adc_init(void)
40{ 81{
82 /* Enable ADC */
83 ADC_ENABLE_ADDR |= ADC_ENABLE;
84
85 /* Initialise */
86 ADC_INIT=0;
87 ADC_ADDR=0x130;
88 ADC_STATUS=0;
89
90 /* Enable Channels 1-4 */
91 ADC_ADDR |= 0x1000000;
92 ADC_ADDR |= 0x2000000;
93 ADC_ADDR |= 0x4000000;
94 ADC_ADDR |= 0x8000000;
95
96 /* Start? */
97 ADC_ADDR |= 0x20000000;
98 ADC_ADDR |= 0x80000000;
99
100 /* Wait 50ms for things to settle */
101 sleep(HZ/20);
102
103 tick_add_task(adc_tick);
41} 104}