summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 d6491b089c..afe2ebec89 100644
--- a/firmware/export/config-e200.h
+++ b/firmware/export/config-e200.h
@@ -71,9 +71,7 @@
71#define CONFIG_BACKLIGHT BL_H10 /* TODO: figure this out, probably not necessary 71#define CONFIG_BACKLIGHT BL_H10 /* TODO: figure this out, probably not necessary
72 because of 'target' stuff */ 72 because of 'target' stuff */
73 73
74#define BATTERY_CAPACITY_DEFAULT 700 /* default battery capacity 74#define BATTERY_CAPACITY_DEFAULT 750 /* default battery capacity */
75 TODO: check this, probably different
76 for different models too */
77 75
78#ifndef SIMULATOR 76#ifndef SIMULATOR
79 77
@@ -85,11 +83,11 @@
85 83
86/* Type of mobile power */ 84/* Type of mobile power */
87#define CONFIG_BATTERY BATT_LPCS355385 85#define CONFIG_BATTERY BATT_LPCS355385
88#define BATTERY_CAPACITY_MIN 1500 /* min. capacity selectable */ 86#define BATTERY_CAPACITY_MIN 750 /* min. capacity selectable */
89#define BATTERY_CAPACITY_MAX 1600 /* max. capacity selectable */ 87#define BATTERY_CAPACITY_MAX 750 /* max. capacity selectable */
90#define BATTERY_CAPACITY_INC 10 /* capacity increment */ 88#define BATTERY_CAPACITY_INC 0 /* capacity increment */
91#define BATTERY_TYPES_COUNT 1 /* only one type */ 89#define BATTERY_TYPES_COUNT 1 /* only one type */
92#define BATTERY_SCALE_FACTOR 5865 90#define BATTERY_SCALE_FACTOR 5054
93 91
94/* Hardware controlled charging? FIXME */ 92/* Hardware controlled charging? FIXME */
95#define CONFIG_CHARGING CHARGING_SIMPLE 93#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 e9a3da5703..b3206d68d1 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 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#include "config.h"
20#include "cpu.h"
21#include "system.h"
22#include "kernel.h"
23#include "thread.h"
24#include "adc.h" 19#include "adc.h"
25 20#include "i2c-pp.h"
26static unsigned short adcdata[NUM_ADC_CHANNELS]; 21#include "logf.h"
27
28/* Scan ADC so that adcdata[channel] gets updated */
29unsigned short adc_scan(int channel)
30{
31 unsigned int adc_data_1;
32 unsigned int adc_data_2;
33
34 /* Initialise */
35 ADC_ADDR=0x130;
36 ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is
37 off, 0x40 if the channel is on */
38
39 /* Enable Channel */
40 ADC_ADDR |= (0x1000000<<channel);
41
42 /* Start? */
43 ADC_ADDR |= 0x20000000;
44 ADC_ADDR |= 0x80000000;
45
46 /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
47 For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
48 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
49 adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff);
50 adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3);
51
52 adcdata[channel] = (adc_data_1<<2 | adc_data_2);
53
54 /* FIXME: Hardcode a value for ~82% charge in here until we figure out the
55 ADC. This will avoid the low battery warning message. */
56 adcdata[ADC_UNREG_POWER] = 0x2C0;
57
58 return adcdata[channel];
59}
60 22
61/* Read 10-bit channel data */ 23/* Read 10-bit channel data */
62unsigned short adc_read(int channel) 24unsigned short adc_read(int channel)
63{ 25{
64 return adcdata[channel]; 26 unsigned char bat[2];
65} 27 unsigned short data = 0;
66 28
67static int adc_counter; 29 switch( channel)
68
69static void adc_tick(void)
70{
71 if(++adc_counter == HZ)
72 { 30 {
73 adc_counter = 0; 31 case ADC_UNREG_POWER:
74 adc_scan(ADC_0); 32 pp_i2c_send( 0x46, 0x2e, 0x0);
75 adc_scan(ADC_1); 33 pp_i2c_send( 0x46, 0x27, 0x1);
76 adc_scan(ADC_2); 34 i2c_readbytes( 0x46, 0x2e, 2, bat);
77 adc_scan(ADC_3); 35 data = ((bat[0]<<8) | bat[1]);
36 break;
78 } 37 }
38 return data;
79} 39}
80 40
81void adc_init(void) 41void adc_init(void)
82{ 42{
83 /* Enable ADC */ 43 /* FIXME: Add initialization of the ADC */
84 ADC_ENABLE_ADDR |= ADC_ENABLE;
85
86 /* Initialise */
87 ADC_INIT=0;
88
89 /* Force a scan of all channels to get initial values */
90 adc_scan(ADC_0);
91 adc_scan(ADC_1);
92 adc_scan(ADC_2);
93 adc_scan(ADC_3);
94
95 tick_add_task(adc_tick);
96} 44}
diff --git a/firmware/target/arm/sandisk/sansa-e200/adc-target.h b/firmware/target/arm/sandisk/sansa-e200/adc-target.h
index 526f99e43b..e9bff42a52 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 @@
19#ifndef _ADC_TARGET_H_ 19#ifndef _ADC_TARGET_H_
20#define _ADC_TARGET_H_ 20#define _ADC_TARGET_H_
21 21
22#define ADC_ENABLE_ADDR (*(volatile unsigned long*)(0x70000010)) 22#define NUM_ADC_CHANNELS 1
23#define ADC_ENABLE 0x1100
24 23
25#define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00)) 24#define ADC_BATTERY 0
26#define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04)) 25#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
27#define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20))
28#define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24))
29#define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c))
30
31#define NUM_ADC_CHANNELS 4
32
33#define ADC_0 0
34#define ADC_1 1
35#define ADC_2 2
36#define ADC_3 3
37#define ADC_UNREG_POWER ADC_0 /* For compatibility */
38
39/* Force a scan now */
40unsigned short adc_scan(int channel);
41 26
42#endif 27#endif