diff options
| author | Linus Nielsen Feltzing <linus@haxx.se> | 2004-02-05 13:44:04 +0000 |
|---|---|---|
| committer | Linus Nielsen Feltzing <linus@haxx.se> | 2004-02-05 13:44:04 +0000 |
| commit | a258fe1887bf3213bffa07e96f1ec3871fbb9c31 (patch) | |
| tree | de789c550e65cdcda9b90225f9394bd044734e04 | |
| parent | 0579667f37bbf0acefe42c9a8fe70f2f555edce0 (diff) | |
| download | rockbox-a258fe1887bf3213bffa07e96f1ec3871fbb9c31.zip rockbox-a258fe1887bf3213bffa07e96f1ec3871fbb9c31.tar.gz rockbox-a258fe1887bf3213bffa07e96f1ec3871fbb9c31.tar.bz2 rockbox-a258fe1887bf3213bffa07e96f1ec3871fbb9c31.tar.xz | |
Better charging feedback for FM/V2 devices
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4296 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/status.c | 2 | ||||
| -rw-r--r-- | firmware/drivers/power.c | 5 | ||||
| -rw-r--r-- | firmware/export/powermgmt.h | 5 | ||||
| -rw-r--r-- | firmware/powermgmt.c | 30 |
4 files changed, 35 insertions, 7 deletions
diff --git a/apps/status.c b/apps/status.c index 65eff70..a7f37a9 100644 --- a/apps/status.c +++ b/apps/status.c @@ -137,7 +137,7 @@ void status_draw(bool force_redraw) if (info.inserted) { battery_state = true; plug_state = true; -#ifdef HAVE_CHARGE_CTRL +#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_LIION) /* zero battery run time if charging */ if (charge_state > 0) { global_settings.runtime = 0; diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c index 83300fe..563ff3e 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 f6b1a64..c772195 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 374f10c..c7c2990 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 |