From e367b05fca08891b0ae47eab8b4a098253122633 Mon Sep 17 00:00:00 2001 From: Barry Wardell Date: Tue, 22 Aug 2006 20:17:09 +0000 Subject: Move X5 ADC code to target tree. Fix power button detection on H10. New ADC driver for H10. Thanks to Laurent Baum for all his help with this code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10701 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/iriver/h10/adc-h10.c | 73 +++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 5 deletions(-) (limited to 'firmware/target/arm/iriver/h10/adc-h10.c') 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 @@ #include "thread.h" #include "adc.h" -/* TODO: implement adc functionality */ +static unsigned short adcdata[NUM_ADC_CHANNELS]; + +/* Scan ADC so that adcdata[channel] gets updated */ unsigned short adc_scan(int channel) { - (void)channel; - return 0; + unsigned int adc_data_1; + unsigned int adc_data_2; + + /* Initialise */ + ADC_ADDR=0x130; + ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is + off, 0x40 if the channel is on */ + + /* Enable Channel */ + ADC_ADDR |= (0x1000000<> (8*channel)) & 0xff); + adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3); + + adcdata[channel] = (adc_data_1<<2 | adc_data_2); + + return adcdata[channel]; } +/* Read 10-bit channel data */ unsigned short adc_read(int channel) { - (void)channel; - return 0; + return adcdata[channel]; +} + +static int adc_counter; + +static void adc_tick(void) +{ + if(++adc_counter == HZ) + { + adc_counter = 0; + adc_scan(ADC_BATTERY); + adc_scan(ADC_UNKNOWN_1); + adc_scan(ADC_UNKNOWN_2); + adc_scan(ADC_SCROLLPAD); + } } void adc_init(void) { + /* Enable ADC */ + ADC_ENABLE_ADDR |= ADC_ENABLE; + + /* Initialise */ + ADC_INIT=0; + ADC_ADDR=0x130; + ADC_STATUS=0; + + /* Enable Channels 1-4 */ + ADC_ADDR |= 0x1000000; + ADC_ADDR |= 0x2000000; + ADC_ADDR |= 0x4000000; + ADC_ADDR |= 0x8000000; + + /* Start? */ + ADC_ADDR |= 0x20000000; + ADC_ADDR |= 0x80000000; + + /* Wait 50ms for things to settle */ + sleep(HZ/20); + + tick_add_task(adc_tick); } -- cgit v1.2.3