From a258fe1887bf3213bffa07e96f1ec3871fbb9c31 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 5 Feb 2004 13:44:04 +0000 Subject: Better charging feedback for FM/V2 devices git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4296 a1c6a512-1295-4272-9138-f99709370657 --- firmware/powermgmt.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'firmware/powermgmt.c') 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 -- cgit v1.2.3