summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-02-20 15:55:38 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-02-20 15:55:38 +0000
commite9a183573bd05e33261ff664648d23c026506323 (patch)
treeecde26de149903957c6998667ae02b3b550662e8
parentac6e19a90c247d0e4af2ad9ae739cc3d7710217c (diff)
downloadrockbox-e9a183573bd05e33261ff664648d23c026506323.zip
rockbox-e9a183573bd05e33261ff664648d23c026506323.tar.gz
rockbox-e9a183573bd05e33261ff664648d23c026506323.tar.bz2
rockbox-e9a183573bd05e33261ff664648d23c026506323.tar.xz
Battery reading support for Sansa. Still needs calibration of voltage->percent mappings and remaining time. Thanks to Rene Peinthor for doing most of the work.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12417 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/config-e200.h14
-rw-r--r--firmware/target/arm/sandisk/sansa-e200/adc-e200.c78
-rw-r--r--firmware/target/arm/sandisk/sansa-e200/adc-target.h21
3 files changed, 22 insertions, 91 deletions
diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h
index d6491b0..afe2ebe 100644
--- a/firmware/export/config-e200.h
+++ b/firmware/export/config-e200.h
@@ -71,9 +71,7 @@
#define CONFIG_BACKLIGHT BL_H10 /* TODO: figure this out, probably not necessary
because of 'target' stuff */
-#define BATTERY_CAPACITY_DEFAULT 700 /* default battery capacity
- TODO: check this, probably different
- for different models too */
+#define BATTERY_CAPACITY_DEFAULT 750 /* default battery capacity */
#ifndef SIMULATOR
@@ -85,11 +83,11 @@
/* Type of mobile power */
#define CONFIG_BATTERY BATT_LPCS355385
-#define BATTERY_CAPACITY_MIN 1500 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 1600 /* max. capacity selectable */
-#define BATTERY_CAPACITY_INC 10 /* capacity increment */
-#define BATTERY_TYPES_COUNT 1 /* only one type */
-#define BATTERY_SCALE_FACTOR 5865
+#define BATTERY_CAPACITY_MIN 750 /* min. capacity selectable */
+#define BATTERY_CAPACITY_MAX 750 /* max. capacity selectable */
+#define BATTERY_CAPACITY_INC 0 /* capacity increment */
+#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define BATTERY_SCALE_FACTOR 5054
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/target/arm/sandisk/sansa-e200/adc-e200.c b/firmware/target/arm/sandisk/sansa-e200/adc-e200.c
index e9a3da5..b3206d6 100644
--- a/firmware/target/arm/sandisk/sansa-e200/adc-e200.c
+++ b/firmware/target/arm/sandisk/sansa-e200/adc-e200.c
@@ -16,81 +16,29 @@
* KIND, either express or implied.
*
****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include "system.h"
-#include "kernel.h"
-#include "thread.h"
#include "adc.h"
-
-static unsigned short adcdata[NUM_ADC_CHANNELS];
-
-/* Scan ADC so that adcdata[channel] gets updated */
-unsigned short adc_scan(int channel)
-{
- unsigned int adc_data_1;
- unsigned int adc_data_2;
-
- /* Initialise */
- ADC_ADDR=0x130;
- ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is
- off, 0x40 if the channel is on */
-
- /* Enable Channel */
- ADC_ADDR |= (0x1000000<<channel);
-
- /* Start? */
- ADC_ADDR |= 0x20000000;
- ADC_ADDR |= 0x80000000;
-
- /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
- For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
- 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
- adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff);
- adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3);
-
- adcdata[channel] = (adc_data_1<<2 | adc_data_2);
-
- /* FIXME: Hardcode a value for ~82% charge in here until we figure out the
- ADC. This will avoid the low battery warning message. */
- adcdata[ADC_UNREG_POWER] = 0x2C0;
-
- return adcdata[channel];
-}
+#include "i2c-pp.h"
+#include "logf.h"
/* Read 10-bit channel data */
unsigned short adc_read(int channel)
{
- return adcdata[channel];
-}
+ unsigned char bat[2];
+ unsigned short data = 0;
-static int adc_counter;
-
-static void adc_tick(void)
-{
- if(++adc_counter == HZ)
+ switch( channel)
{
- adc_counter = 0;
- adc_scan(ADC_0);
- adc_scan(ADC_1);
- adc_scan(ADC_2);
- adc_scan(ADC_3);
+ case ADC_UNREG_POWER:
+ pp_i2c_send( 0x46, 0x2e, 0x0);
+ pp_i2c_send( 0x46, 0x27, 0x1);
+ i2c_readbytes( 0x46, 0x2e, 2, bat);
+ data = ((bat[0]<<8) | bat[1]);
+ break;
}
+ return data;
}
void adc_init(void)
{
- /* Enable ADC */
- ADC_ENABLE_ADDR |= ADC_ENABLE;
-
- /* Initialise */
- ADC_INIT=0;
-
- /* Force a scan of all channels to get initial values */
- adc_scan(ADC_0);
- adc_scan(ADC_1);
- adc_scan(ADC_2);
- adc_scan(ADC_3);
-
- tick_add_task(adc_tick);
+ /* FIXME: Add initialization of the ADC */
}
diff --git a/firmware/target/arm/sandisk/sansa-e200/adc-target.h b/firmware/target/arm/sandisk/sansa-e200/adc-target.h
index 526f99e..e9bff42 100644
--- a/firmware/target/arm/sandisk/sansa-e200/adc-target.h
+++ b/firmware/target/arm/sandisk/sansa-e200/adc-target.h
@@ -19,24 +19,9 @@
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
-#define ADC_ENABLE_ADDR (*(volatile unsigned long*)(0x70000010))
-#define ADC_ENABLE 0x1100
+#define NUM_ADC_CHANNELS 1
-#define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00))
-#define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04))
-#define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20))
-#define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24))
-#define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c))
-
-#define NUM_ADC_CHANNELS 4
-
-#define ADC_0 0
-#define ADC_1 1
-#define ADC_2 2
-#define ADC_3 3
-#define ADC_UNREG_POWER ADC_0 /* For compatibility */
-
-/* Force a scan now */
-unsigned short adc_scan(int channel);
+#define ADC_BATTERY 0
+#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
#endif