From 3496689c8e1ff48453cb9f46f67b7e36ab9955fd Mon Sep 17 00:00:00 2001 From: Marcoen Hirschberg Date: Fri, 29 Sep 2006 10:52:34 +0000 Subject: [PATCH] add the ADC driver for the Gigabeat git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11089 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 1 + .../target/arm/gigabeat/meg-fx/adc-meg-fx.c | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c 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 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 0000000000..78b9dea5b2 --- /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); +}