summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoen Hirschberg <marcoen@gmail.com>2006-09-29 10:52:34 +0000
committerMarcoen Hirschberg <marcoen@gmail.com>2006-09-29 10:52:34 +0000
commit3496689c8e1ff48453cb9f46f67b7e36ab9955fd (patch)
tree9ccea8a955fcf744fa8ccd0c6631aeac533dab18
parentceac1733c5414528126fd0722cb45f449eb92ee2 (diff)
downloadrockbox-3496689c8e1ff48453cb9f46f67b7e36ab9955fd.zip
rockbox-3496689c8e1ff48453cb9f46f67b7e36ab9955fd.tar.gz
rockbox-3496689c8e1ff48453cb9f46f67b7e36ab9955fd.tar.bz2
rockbox-3496689c8e1ff48453cb9f46f67b7e36ab9955fd.tar.xz
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/SOURCES1
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c78
2 files changed, 79 insertions, 0 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index bc5eeed..423fe0e 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -301,6 +301,7 @@ target/arm/gigabeat/meg-fx/power-meg-fx.c
target/arm/gigabeat/meg-fx/usb-meg-fx.c
target/arm/gigabeat/meg-fx/lcd-meg-fx.c
target/arm/gigabeat/meg-fx/sc606-meg-fx.c
+target/arm/gigabeat/meg-fx/adc-meg-fx.c
#endif
#endif
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 0000000..78b9dea
--- /dev/null
+++ b/firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006 by Wade Brown
+ *
+ * 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 "cpu.h"
+#include "adc-target.h"
+
+
+void adc_init(void) {
+ /* Turn on the ADC PCLK */
+ CLKCON |= (1<<15);
+
+ /* Set channel 0, normal mode, disable "start by read" */
+ ADCCON &= ~(0x3F);
+
+ /* No start delay. Use nromal conversion mode. */
+ ADCDLY |= 0x1;
+
+ /* Set and enable the prescaler */
+ ADCCON = (ADCCON & ~(0xff<<6)) | (0x19<<6);
+ ADCCON |= (1<<14);
+}
+
+unsigned short adc_read(int channel) {
+ int i;
+
+ /* Set the channel */
+ ADCCON = (ADCCON & ~(0x7<<3)) | (channel<<3);
+
+ /* Start the conversion process */
+ ADCCON |= 0x1;
+
+ /* Wait for a low Enable_start */
+ i = 20000;
+ while(i > 0) {
+ if(ADCCON & 0x1) {
+ i--;
+ }
+ else {
+ break;
+ }
+ }
+ if(i == 0) {
+ /* Ran out of time */
+ return(0);
+ }
+
+ /* Wait for high End_of_Conversion */
+ i = 20000;
+ while(i > 0) {
+ if(ADCCON & (1<<15)) {
+ break;
+ }
+ else {
+ i--;
+ }
+ }
+ if(i == 0) {
+ /* Ran out of time */
+ return(0);
+ }
+
+ return(ADCDAT0 & 0x3ff);
+}