diff options
author | Marcoen Hirschberg <marcoen@gmail.com> | 2006-09-29 10:52:34 +0000 |
---|---|---|
committer | Marcoen Hirschberg <marcoen@gmail.com> | 2006-09-29 10:52:34 +0000 |
commit | 3496689c8e1ff48453cb9f46f67b7e36ab9955fd (patch) | |
tree | 9ccea8a955fcf744fa8ccd0c6631aeac533dab18 | |
parent | ceac1733c5414528126fd0722cb45f449eb92ee2 (diff) | |
download | rockbox-3496689c8e1ff48453cb9f46f67b7e36ab9955fd.tar.gz rockbox-3496689c8e1ff48453cb9f46f67b7e36ab9955fd.zip |
add the ADC driver for the Gigabeat
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11089 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/SOURCES | 1 | ||||
-rw-r--r-- | firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c | 78 |
2 files changed, 79 insertions, 0 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index bc5eeedeef..423fe0ee38 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -301,6 +301,7 @@ target/arm/gigabeat/meg-fx/power-meg-fx.c | |||
301 | target/arm/gigabeat/meg-fx/usb-meg-fx.c | 301 | target/arm/gigabeat/meg-fx/usb-meg-fx.c |
302 | target/arm/gigabeat/meg-fx/lcd-meg-fx.c | 302 | target/arm/gigabeat/meg-fx/lcd-meg-fx.c |
303 | target/arm/gigabeat/meg-fx/sc606-meg-fx.c | 303 | target/arm/gigabeat/meg-fx/sc606-meg-fx.c |
304 | target/arm/gigabeat/meg-fx/adc-meg-fx.c | ||
304 | #endif | 305 | #endif |
305 | #endif | 306 | #endif |
306 | 307 | ||
diff --git a/firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c new file mode 100644 index 0000000000..78b9dea5b2 --- /dev/null +++ b/firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Wade Brown | ||
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 "cpu.h" | ||
20 | #include "adc-target.h" | ||
21 | |||
22 | |||
23 | void adc_init(void) { | ||
24 | /* Turn on the ADC PCLK */ | ||
25 | CLKCON |= (1<<15); | ||
26 | |||
27 | /* Set channel 0, normal mode, disable "start by read" */ | ||
28 | ADCCON &= ~(0x3F); | ||
29 | |||
30 | /* No start delay. Use nromal conversion mode. */ | ||
31 | ADCDLY |= 0x1; | ||
32 | |||
33 | /* Set and enable the prescaler */ | ||
34 | ADCCON = (ADCCON & ~(0xff<<6)) | (0x19<<6); | ||
35 | ADCCON |= (1<<14); | ||
36 | } | ||
37 | |||
38 | unsigned short adc_read(int channel) { | ||
39 | int i; | ||
40 | |||
41 | /* Set the channel */ | ||
42 | ADCCON = (ADCCON & ~(0x7<<3)) | (channel<<3); | ||
43 | |||
44 | /* Start the conversion process */ | ||
45 | ADCCON |= 0x1; | ||
46 | |||
47 | /* Wait for a low Enable_start */ | ||
48 | i = 20000; | ||
49 | while(i > 0) { | ||
50 | if(ADCCON & 0x1) { | ||
51 | i--; | ||
52 | } | ||
53 | else { | ||
54 | break; | ||
55 | } | ||
56 | } | ||
57 | if(i == 0) { | ||
58 | /* Ran out of time */ | ||
59 | return(0); | ||
60 | } | ||
61 | |||
62 | /* Wait for high End_of_Conversion */ | ||
63 | i = 20000; | ||
64 | while(i > 0) { | ||
65 | if(ADCCON & (1<<15)) { | ||
66 | break; | ||
67 | } | ||
68 | else { | ||
69 | i--; | ||
70 | } | ||
71 | } | ||
72 | if(i == 0) { | ||
73 | /* Ran out of time */ | ||
74 | return(0); | ||
75 | } | ||
76 | |||
77 | return(ADCDAT0 & 0x3ff); | ||
78 | } | ||