summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2005-11-16 13:28:10 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2005-11-16 13:28:10 +0000
commit91c4873253bd7350e3430c455a7f58df576553de (patch)
tree595a5c3483c70780c8b21b86cb94ab0628253e39
parentffe0b23902ef8e92f60b7c15b53dfbb1f23fce8c (diff)
downloadrockbox-91c4873253bd7350e3430c455a7f58df576553de.zip
rockbox-91c4873253bd7350e3430c455a7f58df576553de.tar.gz
rockbox-91c4873253bd7350e3430c455a7f58df576553de.tar.bz2
rockbox-91c4873253bd7350e3430c455a7f58df576553de.tar.xz
H300: ADC driver
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7906 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/adc.c27
-rw-r--r--firmware/export/adc.h10
-rw-r--r--firmware/export/config-h300.h2
3 files changed, 28 insertions, 11 deletions
diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c
index c79c22c..c9ae2da 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 7a90afd..a5ba583 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 5343b65..a3d07a6 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