diff options
author | Barry Wardell <rockbox@barrywardell.net> | 2006-10-05 10:58:51 +0000 |
---|---|---|
committer | Barry Wardell <rockbox@barrywardell.net> | 2006-10-05 10:58:51 +0000 |
commit | d4945dc0d07b23eced900075e8748ccc7fb3e424 (patch) | |
tree | 4d67d49b4c036a841fb1ffe2e5f3a267bb9309d0 /firmware/target/arm/ipod/adc-ipod.c | |
parent | 1d69db7355dc7e3cbabc3c1c949e5d6ba3863405 (diff) | |
download | rockbox-d4945dc0d07b23eced900075e8748ccc7fb3e424.tar.gz rockbox-d4945dc0d07b23eced900075e8748ccc7fb3e424.zip |
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
Diffstat (limited to 'firmware/target/arm/ipod/adc-ipod.c')
-rw-r--r-- | firmware/target/arm/ipod/adc-ipod.c | 80 |
1 files changed, 80 insertions, 0 deletions
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 @@ | |||
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 | return adc->data; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /* Force an ADC scan _now_ */ | ||
63 | unsigned short adc_scan(int channel) { | ||
64 | struct adc_struct *adc = &adcdata[channel]; | ||
65 | adc->timeout = 0; | ||
66 | return _adc_read(adc); | ||
67 | } | ||
68 | |||
69 | /* Retrieve the ADC value, only does a scan periodically */ | ||
70 | unsigned short adc_read(int channel) { | ||
71 | return _adc_read(&adcdata[channel]); | ||
72 | } | ||
73 | |||
74 | void adc_init(void) | ||
75 | { | ||
76 | struct adc_struct *adc_battery = &adcdata[ADC_BATTERY]; | ||
77 | adc_battery->channelnum = 0x2; /* ADCVIN1, resistive divider */ | ||
78 | adc_battery->timeout = 0; | ||
79 | _adc_read(adc_battery); | ||
80 | } | ||