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/drivers/adc.c | 2 +- firmware/export/adc.h | 11 +--- firmware/target/arm/iriver/h10/adc-h10.c | 73 +++++++++++++++++++++++-- firmware/target/arm/iriver/h10/adc-target.h | 42 ++++++++++++++ firmware/target/arm/iriver/h10/button-h10.c | 2 +- firmware/target/coldfire/iaudio/x5/adc-target.h | 32 +++++++++++ 6 files changed, 147 insertions(+), 15 deletions(-) create mode 100644 firmware/target/arm/iriver/h10/adc-target.h create mode 100644 firmware/target/coldfire/iaudio/x5/adc-target.h (limited to 'firmware') diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index 436c71105a..1ebac066e7 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c @@ -283,7 +283,7 @@ void adc_init(void) sleep(2); /* Ensure valid readings when adc_init returns */ } -#elif (CONFIG_CPU == PP5020) || (CONFIG_CPU == PP5002) +#elif defined(IPOD_ARCH) struct adc_struct { long timeout; diff --git a/firmware/export/adc.h b/firmware/export/adc.h index 2f14e3cf48..3a438832d6 100644 --- a/firmware/export/adc.h +++ b/firmware/export/adc.h @@ -21,13 +21,8 @@ #include "config.h" -#ifdef IAUDIO_X5 -#define NUM_ADC_CHANNELS 3 - -#define ADC_BUTTONS 0 -#define ADC_REMOTE 1 -#define ADC_BATTERY 2 -#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ +#ifdef TARGET_TREE +#include "adc-target.h" #elif defined(IPOD_ARCH) #define NUM_ADC_CHANNELS 1 @@ -112,7 +107,7 @@ unsigned short adc_read(int channel); void adc_init(void); #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)\ - || defined(IAUDIO_X5) || defined(IPOD_ARCH) + || defined(IPOD_ARCH) /* Force a scan now */ unsigned short adc_scan(int channel); #endif 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); } diff --git a/firmware/target/arm/iriver/h10/adc-target.h b/firmware/target/arm/iriver/h10/adc-target.h new file mode 100644 index 0000000000..3aab373290 --- /dev/null +++ b/firmware/target/arm/iriver/h10/adc-target.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Barry Wardell + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define ADC_ENABLE_ADDR (*(volatile unsigned long*)(0x70000010)) +#define ADC_ENABLE 0x1100 + +#define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00)) +#define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04)) +#define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20)) +#define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24)) +#define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c)) + +#define NUM_ADC_CHANNELS 4 + +#define ADC_BATTERY 0 +#define ADC_UNKNOWN_1 1 +#define ADC_UNKNOWN_2 2 +#define ADC_SCROLLPAD 3 +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ + +/* Force a scan now */ +unsigned short adc_scan(int channel); + +#endif diff --git a/firmware/target/arm/iriver/h10/button-h10.c b/firmware/target/arm/iriver/h10/button-h10.c index 2a5983e97a..08fb808fcf 100644 --- a/firmware/target/arm/iriver/h10/button-h10.c +++ b/firmware/target/arm/iriver/h10/button-h10.c @@ -70,7 +70,7 @@ int button_read_device(void) if ((state & 0x80) == 0) btn |= BUTTON_LEFT; /* Read power button */ - if ((GPIOB_INPUT_VAL & 0x1) == 0) btn |= BUTTON_POWER; + if ((GPIOB_INPUT_VAL & 0x1) == 1) btn |= BUTTON_POWER; /* Read scroller */ if ( ((GPIOC_INPUT_VAL & 0x4)==1) && ((GPIOD_INPUT_VAL & 0x10)==1) ) diff --git a/firmware/target/coldfire/iaudio/x5/adc-target.h b/firmware/target/coldfire/iaudio/x5/adc-target.h new file mode 100644 index 0000000000..5d158056b9 --- /dev/null +++ b/firmware/target/coldfire/iaudio/x5/adc-target.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 3 + +#define ADC_BUTTONS 0 +#define ADC_REMOTE 1 +#define ADC_BATTERY 2 +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ + +/* Force a scan now */ +unsigned short adc_scan(int channel); + +#endif -- cgit v1.2.3