1
0
Fork 0
forked from len0rd/rockbox

H300: ADC driver

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7906 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2005-11-16 13:28:10 +00:00
parent ffe0b23902
commit 91c4873253
3 changed files with 28 additions and 11 deletions

View file

@ -22,6 +22,7 @@
#include "kernel.h" #include "kernel.h"
#include "thread.h" #include "thread.h"
#include "adc.h" #include "adc.h"
#include "pcf50606.h"
#if CONFIG_CPU == SH7034 #if CONFIG_CPU == SH7034
/************************************************************************** /**************************************************************************
@ -107,9 +108,29 @@ void adc_init(void)
sleep(2); /* Ensure valid readings when adc_init returns */ sleep(2); /* Ensure valid readings when adc_init returns */
} }
#elif CONFIG_CPU == MCF5249 #elif CONFIG_CPU == MCF5249
static unsigned char adcdata[NUM_ADC_CHANNELS]; static unsigned char adcdata[NUM_ADC_CHANNELS];
#ifdef IRIVER_H300_SERIES
static int channelnum[] =
{
5, /* ADC_BUTTONS */
6, /* ADC_REMOTE */
0, /* ADC_BATTERY */
};
unsigned char adc_scan(int channel)
{
unsigned char data;
pcf50606_write(0x2f, 0x80 | (channelnum[channel] << 1) | 1);
data = pcf50606_read(0x30);
adcdata[channel] = data;
return data;
}
#else
#define CS_LO and_l(~0x80, &GPIO_OUT) #define CS_LO and_l(~0x80, &GPIO_OUT)
#define CS_HI or_l(0x80, &GPIO_OUT) #define CS_HI or_l(0x80, &GPIO_OUT)
#define CLK_LO and_l(~0x00400000, &GPIO_OUT) #define CLK_LO and_l(~0x00400000, &GPIO_OUT)
@ -176,6 +197,7 @@ unsigned char adc_scan(int channel)
return data; return data;
} }
#endif
unsigned short adc_read(int channel) unsigned short adc_read(int channel)
{ {
@ -195,6 +217,8 @@ static void adc_tick(void)
void adc_init(void) void adc_init(void)
{ {
#ifdef IRIVER_H300_SERIES
#else
or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS
GPIO21: Data In (to the ADC) GPIO21: Data In (to the ADC)
GPIO22: CLK GPIO22: CLK
@ -202,6 +226,7 @@ void adc_init(void)
or_l(0x00600080, &GPIO_ENABLE); or_l(0x00600080, &GPIO_ENABLE);
or_l(0x80, &GPIO_OUT); /* CS high */ or_l(0x80, &GPIO_OUT); /* CS high */
and_l(~0x00400000, &GPIO_OUT); /* CLK low */ and_l(~0x00400000, &GPIO_OUT); /* CLK low */
#endif
adc_scan(ADC_BATTERY); adc_scan(ADC_BATTERY);

View file

@ -21,7 +21,7 @@
#include "config.h" #include "config.h"
#ifdef IRIVER_H100_SERIES #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
#define NUM_ADC_CHANNELS 4 #define NUM_ADC_CHANNELS 4
#define ADC_BUTTONS 0 #define ADC_BUTTONS 0
@ -30,14 +30,6 @@
#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
#else #else
#ifdef IRIVER_H300
/* TODO: we don't have enough info about the ADC for the H3x0 for now, so this
stuff is only added here for now to make things compile. */
#define ADC_BUTTONS -2
#define ADC_REMOTE -3
unsigned char adc_scan(int channel);
#endif
#define NUM_ADC_CHANNELS 8 #define NUM_ADC_CHANNELS 8

View file

@ -57,7 +57,7 @@
/* Type of mobile power */ /* Type of mobile power */
#define CONFIG_BATTERY BATT_LIPOL1300 #define CONFIG_BATTERY BATT_LIPOL1300
#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */ #define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */
/* Define this if the platform can charge batteries */ /* Define this if the platform can charge batteries */
#define HAVE_CHARGING 1 #define HAVE_CHARGING 1