From 91c4873253bd7350e3430c455a7f58df576553de Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Wed, 16 Nov 2005 13:28:10 +0000 Subject: H300: ADC driver git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7906 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/adc.c | 27 ++++++++++++++++++++++++++- firmware/export/adc.h | 10 +--------- firmware/export/config-h300.h | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index c79c22ce0f..c9ae2daca8 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c @@ -22,6 +22,7 @@ #include "kernel.h" #include "thread.h" #include "adc.h" +#include "pcf50606.h" #if CONFIG_CPU == SH7034 /************************************************************************** @@ -107,9 +108,29 @@ void adc_init(void) sleep(2); /* Ensure valid readings when adc_init returns */ } #elif CONFIG_CPU == MCF5249 - 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_HI or_l(0x80, &GPIO_OUT) #define CLK_LO and_l(~0x00400000, &GPIO_OUT) @@ -176,6 +197,7 @@ unsigned char adc_scan(int channel) return data; } +#endif unsigned short adc_read(int channel) { @@ -195,6 +217,8 @@ static void adc_tick(void) void adc_init(void) { +#ifdef IRIVER_H300_SERIES +#else or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS GPIO21: Data In (to the ADC) GPIO22: CLK @@ -202,6 +226,7 @@ void adc_init(void) or_l(0x00600080, &GPIO_ENABLE); or_l(0x80, &GPIO_OUT); /* CS high */ and_l(~0x00400000, &GPIO_OUT); /* CLK low */ +#endif adc_scan(ADC_BATTERY); diff --git a/firmware/export/adc.h b/firmware/export/adc.h index 7a90afd9b5..a5ba583c38 100644 --- a/firmware/export/adc.h +++ b/firmware/export/adc.h @@ -21,7 +21,7 @@ #include "config.h" -#ifdef IRIVER_H100_SERIES +#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) #define NUM_ADC_CHANNELS 4 #define ADC_BUTTONS 0 @@ -30,14 +30,6 @@ #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ #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 diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index 5343b657d9..a3d07a61bd 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h @@ -57,7 +57,7 @@ /* Type of mobile power */ #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 HAVE_CHARGING 1 -- cgit v1.2.3