summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2005-01-09 23:26:39 +0000
committerDaniel Stenberg <daniel@haxx.se>2005-01-09 23:26:39 +0000
commit00328982298d9f515257e412c740c61ea7315c92 (patch)
treed8dafe3f0afd92d0bdfa40349f4484b8865506bf /firmware
parent3fce85735ee8142268be5f8bdae994fa2caff86a (diff)
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')
-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)
adcdata[3] = adc_scan(3);
}
+#elif CONFIG_CPU == TCC730
+
+
+/**************************************************************************
+ **
+ ** Each channel will be updated HZ/CHANNEL_ORDER_SIZE times per second.
+ **
+ *************************************************************************/
+
+static int current_channel;
+static int current_channel_idx;
+static unsigned short adcdata[NUM_ADC_CHANNELS];
+
+#define CHANNEL_ORDER_SIZE 2
+static int channel_order[CHANNEL_ORDER_SIZE] = {6,7};
+
+static void adc_tick(void)
+{
+ if (ADCON & (1 << 3)) {
+ /* previous conversion finished? */
+ adcdata[current_channel] = ADDATA >> 6;
+ emu_debugf("ADC[%x] = %x", current_channel, adcdata[current_channel]);
+ if (++current_channel_idx >= CHANNEL_ORDER_SIZE)
+ current_channel_idx = 0;
+ current_channel = channel_order[current_channel_idx];
+ int adcon = (current_channel << 4) | 1;
+ ADCON = adcon;
+ }
+}
+
+unsigned short adc_read(int channel)
+{
+ return adcdata[channel];
+}
+
+void adc_init(void)
+{
+ current_channel_idx = 0;
+ current_channel = channel_order[current_channel_idx];
+
+ ADCON = (current_channel << 4) | 1;
+
+ tick_add_task(adc_tick);
+
+ sleep(2); /* Ensure valid readings when adc_init returns */
+}
+
#endif