summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2004-02-05 13:44:04 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2004-02-05 13:44:04 +0000
commita258fe1887bf3213bffa07e96f1ec3871fbb9c31 (patch)
treede789c550e65cdcda9b90225f9394bd044734e04 /firmware
parent0579667f37bbf0acefe42c9a8fe70f2f555edce0 (diff)
downloadrockbox-a258fe1887bf3213bffa07e96f1ec3871fbb9c31.tar.gz
rockbox-a258fe1887bf3213bffa07e96f1ec3871fbb9c31.tar.bz2
rockbox-a258fe1887bf3213bffa07e96f1ec3871fbb9c31.zip
Better charging feedback for FM/V2 devices
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4296 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/power.c5
-rw-r--r--firmware/export/powermgmt.h5
-rw-r--r--firmware/powermgmt.c30
3 files changed, 34 insertions, 6 deletions
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c
index 83300fe1d4..563ff3e25c 100644
--- a/firmware/drivers/power.c
+++ b/firmware/drivers/power.c
@@ -45,8 +45,9 @@ bool charger_inserted(void)
return adc_read(ADC_EXT_POWER) > 0x100;
#else
#ifdef HAVE_FMADC
- /* FM */
- return adc_read(ADC_CHARGE_REGULATOR) < 0x1FF;
+ /* FM or V2, can also charge from the USB port */
+ return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF) ||
+ (adc_read(ADC_USB_POWER) < 0x1FF);
#else
/* Player */
return (PADR & 1) == 0;
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index f6b1a64b68..c772195d64 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -68,10 +68,13 @@ extern int powermgmt_last_cycle_level; /* which level had the batteries
extern int battery_lazyness[20]; /* how does the battery react when plugging in/out the charger */
void enable_trickle_charge(bool on);
extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
-extern int charge_state; /* tells what the charger is doing (for info display): 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */
#endif /* HAVE_CHARGE_CTRL */
+#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_LIION)
+extern int charge_state; /* tells what the charger is doing (for info display): 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */
+#endif
+
#define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */
#define CURRENT_USB 500 /* usual current in mA in USB mode */
#define CURRENT_BACKLIGHT 30 /* additional current when backlight is always on */
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 374f10c8f8..c7c299092c 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -105,6 +105,11 @@ void set_battery_capacity(int capacity)
battery_capacity = 1500;
}
+#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_LIION)
+int charge_state = 0; /* at the beginning, the
+ charger does nothing */
+#endif
+
#ifdef HAVE_CHARGE_CTRL
char power_message[POWER_MESSAGE_LEN] = ""; /* message that's shown in
@@ -121,9 +126,6 @@ int trickle_sec = 0; /* how many seconds should the
charger be enabled per
minute for trickle
charging? */
-int charge_state = 0; /* at the beginning, the
- charger does nothing */
-
static int percent_to_volt_charge[11] = /* voltages (centivolt) of 0%, 10%,
... 100% when charging enabled */
{
@@ -428,6 +430,9 @@ static void power_thread(void)
int i;
int avg, ok_samples, spin_samples;
int current = 0;
+#ifdef HAVE_LIION
+ int charging_current;
+#endif
#ifdef HAVE_CHARGE_CTRL
int delta;
int charged_time = 0;
@@ -517,6 +522,24 @@ static void power_thread(void)
#endif /* MEM == 8 */
#endif /* HAVE_CHARGE_CONTROL */
+#ifdef HAVE_LIION
+ /* We use the information from the ADC_EXT_POWER ADC channel, which
+ tells us the charging current from the LTC1734. When DC is
+ connected (either via the external adapter, or via USB), we try
+ to determine if it is actively charging or only maintaining the
+ charge. My tests show that ADC readings is below about 0x80 means
+ that the LTC1734 is only maintaining the charge. */
+ if(charger_inserted()) {
+ charging_current = adc_read(ADC_EXT_POWER);
+ if(charging_current < 0x80) {
+ charge_state = 2; /* Trickle */
+ } else {
+ charge_state = 1; /* Charging */
+ }
+ } else {
+ charge_state = 0; /* Not charging */
+ }
+#else
#ifdef HAVE_CHARGE_CTRL
if (charge_pause > 0)
@@ -754,6 +777,7 @@ static void power_thread(void)
powermgmt_last_cycle_startstop_min++;
#endif /* HAVE_CHARGE_CTRL*/
+#endif /* HAVE_LIION */
/* sleep for roughly a minute */
#ifdef HAVE_CHARGE_CTRL