diff options
author | Jens Arnold <amiconn@rockbox.org> | 2007-07-30 20:12:03 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2007-07-30 20:12:03 +0000 |
commit | a4a3cd9d52b1969bf44315bdf4a229636ceb3f24 (patch) | |
tree | df1bb0f4c47c3c91998682d27b03747e8fcb79fb /firmware/target/arm/ipod/adc-ipod-pcf.c | |
parent | aaf92393b3b18dce26dde7a4f94a437cefdff684 (diff) | |
download | rockbox-a4a3cd9d52b1969bf44315bdf4a229636ceb3f24.tar.gz rockbox-a4a3cd9d52b1969bf44315bdf4a229636ceb3f24.zip |
First version of a 1st/2nd gen ADC driver. 1st gen is untested yet.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14082 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/ipod/adc-ipod-pcf.c')
-rw-r--r-- | firmware/target/arm/ipod/adc-ipod-pcf.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/firmware/target/arm/ipod/adc-ipod-pcf.c b/firmware/target/arm/ipod/adc-ipod-pcf.c new file mode 100644 index 0000000000..bc2524de5d --- /dev/null +++ b/firmware/target/arm/ipod/adc-ipod-pcf.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include "system.h" | ||
22 | #include "kernel.h" | ||
23 | #include "thread.h" | ||
24 | #include "string.h" | ||
25 | #include "adc.h" | ||
26 | #include "pcf50605.h" | ||
27 | |||
28 | struct adc_struct { | ||
29 | long timeout; | ||
30 | void (*conversion)(unsigned short *data); | ||
31 | short channelnum; | ||
32 | unsigned short data; | ||
33 | }; | ||
34 | |||
35 | static struct adc_struct adcdata[NUM_ADC_CHANNELS] IDATA_ATTR; | ||
36 | |||
37 | static unsigned short _adc_read(struct adc_struct *adc) | ||
38 | { | ||
39 | if (adc->timeout < current_tick) { | ||
40 | unsigned char data[2]; | ||
41 | unsigned short value; | ||
42 | /* 5x per 2 seconds */ | ||
43 | adc->timeout = current_tick + (HZ * 2 / 5); | ||
44 | |||
45 | /* ADCC1, 10 bit, start */ | ||
46 | pcf50605_write(0x2f, (adc->channelnum << 1) | 0x1); | ||
47 | pcf50605_read_multiple(0x30, data, 2); /* ADCS1, ADCS2 */ | ||
48 | value = data[0]; | ||
49 | value <<= 2; | ||
50 | value |= data[1] & 0x3; | ||
51 | |||
52 | if (adc->conversion) { | ||
53 | adc->conversion(&value); | ||
54 | } | ||
55 | adc->data = value; | ||
56 | return value; | ||
57 | } else | ||
58 | { | ||
59 | return adc->data; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | /* Force an ADC scan _now_ */ | ||
64 | unsigned short adc_scan(int channel) { | ||
65 | struct adc_struct *adc = &adcdata[channel]; | ||
66 | adc->timeout = 0; | ||
67 | return _adc_read(adc); | ||
68 | } | ||
69 | |||
70 | /* Retrieve the ADC value, only does a scan periodically */ | ||
71 | unsigned short adc_read(int channel) { | ||
72 | return _adc_read(&adcdata[channel]); | ||
73 | } | ||
74 | |||
75 | void adc_init(void) | ||
76 | { | ||
77 | struct adc_struct *adc_battery = &adcdata[ADC_BATTERY]; | ||
78 | adc_battery->channelnum = 0x2; /* ADCVIN1, resistive divider */ | ||
79 | adc_battery->timeout = 0; | ||
80 | _adc_read(adc_battery); | ||
81 | } | ||