mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-10 05:32:40 -05:00
add the ADC driver for the Gigabeat
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11089 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
ceac1733c5
commit
3496689c8e
2 changed files with 79 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
78
firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c
Normal file
78
firmware/target/arm/gigabeat/meg-fx/adc-meg-fx.c
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue