diff options
Diffstat (limited to 'firmware/drivers/adc.c')
-rw-r--r-- | firmware/drivers/adc.c | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index 646509b8a8..388ff66d5f 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c | |||
@@ -108,135 +108,6 @@ void adc_init(void) | |||
108 | 108 | ||
109 | sleep(2); /* Ensure valid readings when adc_init returns */ | 109 | sleep(2); /* Ensure valid readings when adc_init returns */ |
110 | } | 110 | } |
111 | #elif CONFIG_CPU == MCF5249 | ||
112 | static unsigned char adcdata[NUM_ADC_CHANNELS]; | ||
113 | |||
114 | #ifdef IRIVER_H300_SERIES | ||
115 | static int adcc2_parms[] = | ||
116 | { | ||
117 | [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */ | ||
118 | [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */ | ||
119 | [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ | ||
120 | [ADC_REMOTEDETECT] = 0x80 | (2 << 1) | 1, /* ADCIN1, resistive divider */ | ||
121 | }; | ||
122 | |||
123 | unsigned short adc_scan(int channel) | ||
124 | { | ||
125 | int level = set_irq_level(HIGHEST_IRQ_LEVEL); | ||
126 | unsigned char data; | ||
127 | |||
128 | pcf50606_write(0x2f, adcc2_parms[channel]); | ||
129 | data = pcf50606_read(0x30); | ||
130 | |||
131 | adcdata[channel] = data; | ||
132 | |||
133 | set_irq_level(level); | ||
134 | return data; | ||
135 | } | ||
136 | #else | ||
137 | |||
138 | #define CS_LO and_l(~0x80, &GPIO_OUT) | ||
139 | #define CS_HI or_l(0x80, &GPIO_OUT) | ||
140 | #define CLK_LO and_l(~0x00400000, &GPIO_OUT) | ||
141 | #define CLK_HI or_l(0x00400000, &GPIO_OUT) | ||
142 | #define DO (GPIO_READ & 0x80000000) | ||
143 | #define DI_LO and_l(~0x00200000, &GPIO_OUT) | ||
144 | #define DI_HI or_l(0x00200000, &GPIO_OUT) | ||
145 | |||
146 | /* delay loop */ | ||
147 | #define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) | ||
148 | |||
149 | unsigned short adc_scan(int channel) | ||
150 | { | ||
151 | unsigned char data = 0; | ||
152 | int i; | ||
153 | |||
154 | CS_LO; | ||
155 | |||
156 | DI_HI; /* Start bit */ | ||
157 | DELAY; | ||
158 | CLK_HI; | ||
159 | DELAY; | ||
160 | CLK_LO; | ||
161 | |||
162 | DI_HI; /* Single channel */ | ||
163 | DELAY; | ||
164 | CLK_HI; | ||
165 | DELAY; | ||
166 | CLK_LO; | ||
167 | |||
168 | if(channel & 1) /* LSB of channel number */ | ||
169 | DI_HI; | ||
170 | else | ||
171 | DI_LO; | ||
172 | DELAY; | ||
173 | CLK_HI; | ||
174 | DELAY; | ||
175 | CLK_LO; | ||
176 | |||
177 | if(channel & 2) /* MSB of channel number */ | ||
178 | DI_HI; | ||
179 | else | ||
180 | DI_LO; | ||
181 | DELAY; | ||
182 | CLK_HI; | ||
183 | DELAY; | ||
184 | CLK_LO; | ||
185 | |||
186 | DELAY; | ||
187 | |||
188 | for(i = 0;i < 8;i++) /* 8 bits of data */ | ||
189 | { | ||
190 | CLK_HI; | ||
191 | DELAY; | ||
192 | CLK_LO; | ||
193 | DELAY; | ||
194 | data <<= 1; | ||
195 | data |= DO?1:0; | ||
196 | } | ||
197 | |||
198 | CS_HI; | ||
199 | |||
200 | adcdata[channel] = data; | ||
201 | |||
202 | return data; | ||
203 | } | ||
204 | #endif | ||
205 | |||
206 | unsigned short adc_read(int channel) | ||
207 | { | ||
208 | return adcdata[channel]; | ||
209 | } | ||
210 | |||
211 | static int adc_counter; | ||
212 | |||
213 | static void adc_tick(void) | ||
214 | { | ||
215 | if(++adc_counter == HZ) | ||
216 | { | ||
217 | adc_counter = 0; | ||
218 | adc_scan(ADC_BATTERY); | ||
219 | adc_scan(ADC_REMOTEDETECT); /* Temporary. Remove when the remote | ||
220 | detection feels stable. */ | ||
221 | } | ||
222 | } | ||
223 | |||
224 | void adc_init(void) | ||
225 | { | ||
226 | #ifndef IRIVER_H300_SERIES | ||
227 | or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS | ||
228 | GPIO21: Data In (to the ADC) | ||
229 | GPIO22: CLK | ||
230 | GPIO31: Data Out (from the ADC) */ | ||
231 | or_l(0x00600080, &GPIO_ENABLE); | ||
232 | or_l(0x80, &GPIO_OUT); /* CS high */ | ||
233 | and_l(~0x00400000, &GPIO_OUT); /* CLK low */ | ||
234 | #endif | ||
235 | |||
236 | adc_scan(ADC_BATTERY); | ||
237 | |||
238 | tick_add_task(adc_tick); | ||
239 | } | ||
240 | 111 | ||
241 | #elif CONFIG_CPU == TCC730 | 112 | #elif CONFIG_CPU == TCC730 |
242 | 113 | ||