summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-07-30 20:12:03 +0000
committerJens Arnold <amiconn@rockbox.org>2007-07-30 20:12:03 +0000
commita4a3cd9d52b1969bf44315bdf4a229636ceb3f24 (patch)
treedf1bb0f4c47c3c91998682d27b03747e8fcb79fb /firmware
parentaaf92393b3b18dce26dde7a4f94a437cefdff684 (diff)
downloadrockbox-a4a3cd9d52b1969bf44315bdf4a229636ceb3f24.tar.gz
rockbox-a4a3cd9d52b1969bf44315bdf4a229636ceb3f24.zip
First version of a 1st/2nd gen ADC driver. 1st gen is untested yet.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14082 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES16
-rw-r--r--firmware/export/config-ipod1g2g.h8
-rw-r--r--firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c100
-rw-r--r--firmware/target/arm/ipod/1g2g/adc-target.h34
-rw-r--r--firmware/target/arm/ipod/adc-ipod-pcf.c (renamed from firmware/target/arm/ipod/adc-ipod.c)10
5 files changed, 146 insertions, 22 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index b73a82a15c..91cead088d 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -562,7 +562,7 @@ target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-4g_color.c
target/arm/ipod/button-clickwheel.c
target/arm/ipod/lcd-gray.c
@@ -578,7 +578,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-4g_color.c
target/arm/ipod/button-clickwheel.c
target/arm/ipod/lcd-color_nano.c
@@ -594,7 +594,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-nano_video.c
target/arm/ipod/button-clickwheel.c
target/arm/ipod/lcd-color_nano.c
@@ -610,7 +610,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-nano_video.c
target/arm/ipod/button-clickwheel.c
target/arm/ipod/power-ipod.c
@@ -625,7 +625,7 @@ drivers/pcf50605.c
target/arm/ata-pp5002.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/3g/backlight-3g.c
target/arm/ipod/button-1g-3g.c
target/arm/ipod/lcd-gray.c
@@ -639,7 +639,7 @@ target/arm/usb-pp.c
target/arm/ata-pp5002.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/1g2g/adc-ipod-1g2g.c
target/arm/ipod/1g2g/backlight-1g2g.c
target/arm/ipod/button-1g-3g.c
target/arm/ipod/lcd-gray.c
@@ -654,7 +654,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-mini1g_mini2g.c
target/arm/ipod/button-mini1g.c
target/arm/ipod/lcd-gray.c
@@ -670,7 +670,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
-target/arm/ipod/adc-ipod.c
+target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-mini1g_mini2g.c
target/arm/ipod/button-clickwheel.c
target/arm/ipod/lcd-gray.c
diff --git a/firmware/export/config-ipod1g2g.h b/firmware/export/config-ipod1g2g.h
index b69d401f36..188c3930f6 100644
--- a/firmware/export/config-ipod1g2g.h
+++ b/firmware/export/config-ipod1g2g.h
@@ -81,11 +81,11 @@
/* Type of mobile power */
#define CONFIG_BATTERY BATT_LIPOL1300
-#define BATTERY_CAPACITY_MIN 630 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 1000 /* max. capacity selectable */
-#define BATTERY_CAPACITY_INC 10 /* capacity increment */
+#define BATTERY_CAPACITY_MIN 1200 /* min. capacity selectable */
+#define BATTERY_CAPACITY_MAX 1900 /* max. capacity selectable */
+#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
-#define BATTERY_SCALE_FACTOR 5865
+#define BATTERY_SCALE_FACTOR 25882
/* Hardware controlled charging? FIXME */
//#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c b/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c
new file mode 100644
index 0000000000..759b6fb592
--- /dev/null
+++ b/firmware/target/arm/ipod/1g2g/adc-ipod-1g2g.c
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2007 by Jens Arnold
+ *
+ * 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 "config.h"
+#include "cpu.h"
+#include "hwcompat.h"
+#include "kernel.h"
+
+static struct mutex adc_mutex NOCACHEBSS_ATTR;
+
+unsigned short adc_scan(int channel)
+{
+ int i, j;
+ unsigned short data = 0;
+ unsigned pval;
+
+ (void)channel; /* there is only one */
+ spinlock_lock(&adc_mutex);
+
+ if ((IPOD_HW_REVISION >> 16) == 1)
+ {
+ pval = GPIOB_OUTPUT_VAL;
+ GPIOB_OUTPUT_VAL = pval | 0x04; /* B2 -> high */
+ for (i = 32; i > 0; --i);
+
+ GPIOB_OUTPUT_VAL = pval; /* B2 -> low */
+ for (i = 200; i > 0; --i);
+
+ for (j = 0; j < 8; j++)
+ {
+ GPIOB_OUTPUT_VAL = pval | 0x02; /* B1 -> high */
+ for (i = 8; i > 0; --i);
+
+ data = (data << 1) | ((GPIOB_INPUT_VAL & 0x08) >> 3);
+
+ GPIOB_OUTPUT_VAL = pval; /* B1 -> low */
+ for (i = 320; i > 0; --i);
+ }
+ }
+ else if ((IPOD_HW_REVISION >> 16) == 2)
+ {
+ pval = GPIOB_OUTPUT_VAL;
+ GPIOB_OUTPUT_VAL = pval | 0x0a; /* B1, B3 -> high */
+ while (!(GPIOB_INPUT_VAL & 0x04)); /* wait for B2 == 1 */
+
+ GPIOB_OUTPUT_VAL = pval; /* B1, B3 -> low */
+ while (GPIOB_INPUT_VAL & 0x04); /* wait for B2 == 0 */
+
+ for (j = 0; j < 8; j++)
+ {
+ GPIOB_OUTPUT_VAL = pval | 0x02; /* B1 -> high */
+ while (!(GPIOB_INPUT_VAL & 0x04)); /* wait for B2 == 1 */
+
+ data = (data << 1) | ((GPIOB_INPUT_VAL & 0x10) >> 4);
+
+ GPIOB_OUTPUT_VAL = pval; /* B1 -> low */
+ while (GPIOB_INPUT_VAL & 0x04); /* wait for B2 == 0 */
+ }
+ }
+ spinlock_unlock(&adc_mutex);
+ return data;
+}
+
+void adc_init(void)
+{
+ spinlock_init(&adc_mutex);
+
+ GPIOB_ENABLE |= 0x1e; /* enable B1..B4 */
+
+ if ((IPOD_HW_REVISION >> 16) == 1)
+ {
+ GPIOB_OUTPUT_EN = (GPIOB_OUTPUT_EN & ~0x08) | 0x16;
+ /* B1, B2, B4 -> output, B3 -> input */
+ GPIOB_OUTPUT_VAL = (GPIOB_OUTPUT_VAL & ~0x06) | 0x10;
+ /* B1, B2 -> low, B4 -> high */
+ }
+ else if ((IPOD_HW_REVISION >> 16) == 2)
+ {
+ GPIOB_OUTPUT_EN = (GPIOB_OUTPUT_EN & ~0x14) | 0x0a;
+ /* B1, B3 -> output, B2, B4 -> input */
+ GPIOB_OUTPUT_VAL &= ~0x0a; /* B1, B3 -> low */
+ while (GPIOB_INPUT_VAL & 0x04); /* wait for B2 == 0 */
+ }
+}
diff --git a/firmware/target/arm/ipod/1g2g/adc-target.h b/firmware/target/arm/ipod/1g2g/adc-target.h
new file mode 100644
index 0000000000..b3f6cd6303
--- /dev/null
+++ b/firmware/target/arm/ipod/1g2g/adc-target.h
@@ -0,0 +1,34 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2007 by Jens Arnold
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef _ADC_TARGET_H_
+#define _ADC_TARGET_H_
+
+#define NUM_ADC_CHANNELS 1
+
+#define ADC_BATTERY 0
+#define ADC_UNREG_POWER ADC_BATTERY
+
+/* Force a scan now */
+unsigned short adc_scan(int channel);
+static inline unsigned short adc_read(int channel)
+{
+ return adc_scan(channel);
+}
+#endif
diff --git a/firmware/target/arm/ipod/adc-ipod.c b/firmware/target/arm/ipod/adc-ipod-pcf.c
index 39463af30b..bc2524de5d 100644
--- a/firmware/target/arm/ipod/adc-ipod.c
+++ b/firmware/target/arm/ipod/adc-ipod-pcf.c
@@ -36,7 +36,6 @@ static struct adc_struct adcdata[NUM_ADC_CHANNELS] IDATA_ATTR;
static unsigned short _adc_read(struct adc_struct *adc)
{
-#ifndef IPOD_1G2G
if (adc->timeout < current_tick) {
unsigned char data[2];
unsigned short value;
@@ -56,7 +55,6 @@ static unsigned short _adc_read(struct adc_struct *adc)
adc->data = value;
return value;
} else
-#endif
{
return adc->data;
}
@@ -66,19 +64,11 @@ static unsigned short _adc_read(struct adc_struct *adc)
unsigned short adc_scan(int channel) {
struct adc_struct *adc = &adcdata[channel];
adc->timeout = 0;
-#ifdef IPOD_1G2G
- if (channel == ADC_UNREG_POWER)
- return 681; /* FIXME fake 4.00V */
-#endif
return _adc_read(adc);
}
/* Retrieve the ADC value, only does a scan periodically */
unsigned short adc_read(int channel) {
-#ifdef IPOD_1G2G
- if (channel == ADC_UNREG_POWER)
- return 681; /* FIXME fake 4.00V */
-#endif
return _adc_read(&adcdata[channel]);
}