diff options
author | Daniel Stenberg <daniel@haxx.se> | 2005-01-09 23:26:39 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2005-01-09 23:26:39 +0000 |
commit | 00328982298d9f515257e412c740c61ea7315c92 (patch) | |
tree | d8dafe3f0afd92d0bdfa40349f4484b8865506bf /firmware/drivers | |
parent | 3fce85735ee8142268be5f8bdae994fa2caff86a (diff) | |
download | rockbox-00328982298d9f515257e412c740c61ea7315c92.tar.gz rockbox-00328982298d9f515257e412c740c61ea7315c92.zip |
Jean-Philippe Bernardy: ADC support for TCC730
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5547 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/adc.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index 46890badd4..5ef5f76a31 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c | |||
@@ -205,4 +205,51 @@ void adc_init(void) | |||
205 | adcdata[3] = adc_scan(3); | 205 | adcdata[3] = adc_scan(3); |
206 | } | 206 | } |
207 | 207 | ||
208 | #elif CONFIG_CPU == TCC730 | ||
209 | |||
210 | |||
211 | /************************************************************************** | ||
212 | ** | ||
213 | ** Each channel will be updated HZ/CHANNEL_ORDER_SIZE times per second. | ||
214 | ** | ||
215 | *************************************************************************/ | ||
216 | |||
217 | static int current_channel; | ||
218 | static int current_channel_idx; | ||
219 | static unsigned short adcdata[NUM_ADC_CHANNELS]; | ||
220 | |||
221 | #define CHANNEL_ORDER_SIZE 2 | ||
222 | static int channel_order[CHANNEL_ORDER_SIZE] = {6,7}; | ||
223 | |||
224 | static void adc_tick(void) | ||
225 | { | ||
226 | if (ADCON & (1 << 3)) { | ||
227 | /* previous conversion finished? */ | ||
228 | adcdata[current_channel] = ADDATA >> 6; | ||
229 | emu_debugf("ADC[%x] = %x", current_channel, adcdata[current_channel]); | ||
230 | if (++current_channel_idx >= CHANNEL_ORDER_SIZE) | ||
231 | current_channel_idx = 0; | ||
232 | current_channel = channel_order[current_channel_idx]; | ||
233 | int adcon = (current_channel << 4) | 1; | ||
234 | ADCON = adcon; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | unsigned short adc_read(int channel) | ||
239 | { | ||
240 | return adcdata[channel]; | ||
241 | } | ||
242 | |||
243 | void adc_init(void) | ||
244 | { | ||
245 | current_channel_idx = 0; | ||
246 | current_channel = channel_order[current_channel_idx]; | ||
247 | |||
248 | ADCON = (current_channel << 4) | 1; | ||
249 | |||
250 | tick_add_task(adc_tick); | ||
251 | |||
252 | sleep(2); /* Ensure valid readings when adc_init returns */ | ||
253 | } | ||
254 | |||
208 | #endif | 255 | #endif |