summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/drivers/adc.c47
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
217static int current_channel;
218static int current_channel_idx;
219static unsigned short adcdata[NUM_ADC_CHANNELS];
220
221#define CHANNEL_ORDER_SIZE 2
222static int channel_order[CHANNEL_ORDER_SIZE] = {6,7};
223
224static 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
238unsigned short adc_read(int channel)
239{
240 return adcdata[channel];
241}
242
243void 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