From d4945dc0d07b23eced900075e8748ccc7fb3e424 Mon Sep 17 00:00:00 2001 From: Barry Wardell Date: Thu, 5 Oct 2006 10:58:51 +0000 Subject: Move all iPod targets into the target tree. FS#5890 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11129 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/ipod/adc-ipod.c | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 firmware/target/arm/ipod/adc-ipod.c (limited to 'firmware/target/arm/ipod/adc-ipod.c') diff --git a/firmware/target/arm/ipod/adc-ipod.c b/firmware/target/arm/ipod/adc-ipod.c new file mode 100644 index 0000000000..d351f0ee81 --- /dev/null +++ b/firmware/target/arm/ipod/adc-ipod.c @@ -0,0 +1,80 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "system.h" +#include "kernel.h" +#include "thread.h" +#include "string.h" +#include "adc.h" +#include "pcf50605.h" + +struct adc_struct { + long timeout; + void (*conversion)(unsigned short *data); + short channelnum; + unsigned short data; +}; + +static struct adc_struct adcdata[NUM_ADC_CHANNELS] IDATA_ATTR; + +static unsigned short _adc_read(struct adc_struct *adc) +{ + if (adc->timeout < current_tick) { + unsigned char data[2]; + unsigned short value; + /* 5x per 2 seconds */ + adc->timeout = current_tick + (HZ * 2 / 5); + + /* ADCC1, 10 bit, start */ + pcf50605_write(0x2f, (adc->channelnum << 1) | 0x1); + pcf50605_read_multiple(0x30, data, 2); /* ADCS1, ADCS2 */ + value = data[0]; + value <<= 2; + value |= data[1] & 0x3; + + if (adc->conversion) { + adc->conversion(&value); + } + adc->data = value; + return value; + } else { + return adc->data; + } +} + +/* Force an ADC scan _now_ */ +unsigned short adc_scan(int channel) { + struct adc_struct *adc = &adcdata[channel]; + adc->timeout = 0; + return _adc_read(adc); +} + +/* Retrieve the ADC value, only does a scan periodically */ +unsigned short adc_read(int channel) { + return _adc_read(&adcdata[channel]); +} + +void adc_init(void) +{ + struct adc_struct *adc_battery = &adcdata[ADC_BATTERY]; + adc_battery->channelnum = 0x2; /* ADCVIN1, resistive divider */ + adc_battery->timeout = 0; + _adc_read(adc_battery); +} -- cgit v1.2.3