diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-01-19 07:47:34 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-01-19 07:47:34 +0000 |
commit | cdacab3d89cdbbd8fd7c20b3b340e27352e6737e (patch) | |
tree | ad1746cf51bdb56a1cdcabf0c38eb6a53244c431 /firmware/powermgmt.c | |
parent | 13414ae77a77d96ef2cb210d644880b847c9ca6f (diff) |
Charging state reporting on H3x0
Don't read the GPIO every refresh of statusbar or gwps for plugged state, use a
variable exported from powermgmt instead.
Allow Custom WPS to access %bc for battery charge state on targets that support
this.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8383 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 4b3999751c..7bf2d58284 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -145,33 +145,28 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = }; #ifdef HAVE_CHARGING +charger_input_state_type charger_input_state IDATA_ATTR; + /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ static const short percent_to_volt_charge[11] = { +#if CONFIG_BATTERY == BATT_LIPOL1300 + 340, 349, 358, 367, 376, 385, 394, 403, 408, 413, 418 /* Estimated */ +#else /* values guessed, see http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone measures voltages over a charging cycle */ 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */ +#endif }; #endif /* HAVE_CHARGING */ -#if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 +#if defined(HAVE_CHARGE_CTRL) || \ + CONFIG_BATTERY == BATT_LIION2200 || \ + defined(HAVE_CHARGE_STATE) charge_state_type charge_state; /* charging mode */ #endif -#ifdef HAVE_CHARGING -/* - * Flag that the charger has been plugged in/removed: this is set for exactly - * one time through the power loop when the charger has been plugged in. - */ -static enum { - NO_CHARGER, - CHARGER_UNPLUGGED, /* transient state */ - CHARGER_PLUGGED, /* transient state */ - CHARGER -} charger_input_state; -#endif - #ifdef HAVE_CHARGE_CTRL int long_delta; /* long term delta battery voltage */ int short_delta; /* short term delta battery voltage */ @@ -317,7 +312,7 @@ static void battery_status_update(void) { int level; -#ifdef HAVE_CHARGE_CTRL +#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE) if (charge_state == DISCHARGING) { level = voltage_to_percent(battery_centivolts, percent_to_volt_discharge[battery_type]); @@ -520,6 +515,23 @@ static void power_thread_sleep(int ticks) } } #endif +#ifdef HAVE_CHARGE_STATE + switch (charger_input_state) { + case CHARGER_UNPLUGGED: + charge_state = DISCHARGING; + case NO_CHARGER: + break; + case CHARGER_PLUGGED: + case CHARGER: + if (charging_state()) { + charge_state = CHARGING; + } else { + charge_state = DISCHARGING; + } + break; + } + +#endif /* HAVE_CHARGE_STATE */ small_ticks = MIN(HZ/2, ticks); sleep(small_ticks); @@ -551,6 +563,7 @@ static void power_thread_sleep(int ticks) battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; } + #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) /* * If we have a lot of pending writes or if the disk is spining, @@ -821,7 +834,7 @@ static void power_thread(void) snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge"); } -#endif /* HAVE_CHARGE_CTRL*/ +#endif /* end HAVE_CHARGE_CTRL */ /* sleep for a minute */ @@ -840,7 +853,7 @@ static void power_thread(void) #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) if(usb_inserted()) { if(fd >= 0) { - /* It is probably too late to close the file but we can try... */ + /* It is probably too late to close the file but we can try...*/ close(fd); fd = -1; } @@ -855,9 +868,11 @@ static void power_thread(void) } } if(fd >= 0) { - snprintf(debug_message, DEBUG_MESSAGE_LEN, "%d, %d, %d, %d, %d, %d, %d, %d\n", + snprintf(debug_message, DEBUG_MESSAGE_LEN, + "%d, %d, %d, %d, %d, %d, %d, %d\n", powermgmt_last_cycle_startstop_min, battery_centivolts, - battery_percent, charger_input_state, charge_state, pid_p, pid_i, trickle_sec); + battery_percent, charger_input_state, charge_state, + pid_p, pid_i, trickle_sec); write(fd, debug_message, strlen(debug_message)); wrcount++; } |