diff options
author | Daniel Ankers <dan@weirdo.org.uk> | 2006-10-16 17:21:36 +0000 |
---|---|---|
committer | Daniel Ankers <dan@weirdo.org.uk> | 2006-10-16 17:21:36 +0000 |
commit | d8ef7c58d83591bb0660fc4965cf2319fb5a4718 (patch) | |
tree | a71d3d9909cec32d3a8d22b10017a1e8959cfc16 /firmware/target/arm/sandisk/sansa-e200/adc-e200.c | |
parent | 55d1675ada5273a815966057b811605462e1f7bd (diff) | |
download | rockbox-d8ef7c58d83591bb0660fc4965cf2319fb5a4718.tar.gz rockbox-d8ef7c58d83591bb0660fc4965cf2319fb5a4718.zip |
Big Sansa update: Go back to using the common crt0-pp.S. Add LCD driver. Add ADC driver (may not be needed). Fix a bug in the button driver.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11237 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/sandisk/sansa-e200/adc-e200.c')
-rw-r--r-- | firmware/target/arm/sandisk/sansa-e200/adc-e200.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/firmware/target/arm/sandisk/sansa-e200/adc-e200.c b/firmware/target/arm/sandisk/sansa-e200/adc-e200.c new file mode 100644 index 0000000000..fbfa7d698a --- /dev/null +++ b/firmware/target/arm/sandisk/sansa-e200/adc-e200.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Barry Wardell | ||
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 "adc.h" | ||
25 | |||
26 | static unsigned short adcdata[NUM_ADC_CHANNELS]; | ||
27 | |||
28 | /* Scan ADC so that adcdata[channel] gets updated */ | ||
29 | unsigned short adc_scan(int channel) | ||
30 | { | ||
31 | unsigned int adc_data_1; | ||
32 | unsigned int adc_data_2; | ||
33 | |||
34 | /* Initialise */ | ||
35 | ADC_ADDR=0x130; | ||
36 | ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is | ||
37 | off, 0x40 if the channel is on */ | ||
38 | |||
39 | /* Enable Channel */ | ||
40 | ADC_ADDR |= (0x1000000<<channel); | ||
41 | |||
42 | /* Start? */ | ||
43 | ADC_ADDR |= 0x20000000; | ||
44 | ADC_ADDR |= 0x80000000; | ||
45 | |||
46 | /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel. | ||
47 | For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the | ||
48 | 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */ | ||
49 | adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff); | ||
50 | adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3); | ||
51 | |||
52 | adcdata[channel] = (adc_data_1<<2 | adc_data_2); | ||
53 | |||
54 | return adcdata[channel]; | ||
55 | } | ||
56 | |||
57 | /* Read 10-bit channel data */ | ||
58 | unsigned short adc_read(int channel) | ||
59 | { | ||
60 | return adcdata[channel]; | ||
61 | } | ||
62 | |||
63 | static int adc_counter; | ||
64 | |||
65 | static void adc_tick(void) | ||
66 | { | ||
67 | if(++adc_counter == HZ) | ||
68 | { | ||
69 | adc_counter = 0; | ||
70 | adc_scan(ADC_0); | ||
71 | adc_scan(ADC_1); | ||
72 | adc_scan(ADC_2); | ||
73 | adc_scan(ADC_3); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | void adc_init(void) | ||
78 | { | ||
79 | /* Enable ADC */ | ||
80 | ADC_ENABLE_ADDR |= ADC_ENABLE; | ||
81 | |||
82 | /* Initialise */ | ||
83 | ADC_INIT=0; | ||
84 | |||
85 | /* Force a scan of all channels to get initial values */ | ||
86 | adc_scan(ADC_0); | ||
87 | adc_scan(ADC_1); | ||
88 | adc_scan(ADC_2); | ||
89 | adc_scan(ADC_3); | ||
90 | |||
91 | tick_add_task(adc_tick); | ||
92 | } | ||