Index: firmware/export/config/ipodnano2g.h =================================================================== --- firmware/export/config/ipodnano2g.h (revision 24279) +++ firmware/export/config/ipodnano2g.h (working copy) @@ -132,6 +132,10 @@ #define BATTERY_CAPACITY_INC 50 /* capacity increment */ #define BATTERY_TYPES_COUNT 1 /* only one type */ +/* define current usage levels */ +#define CURRENT_NORMAL 20 /* value taken for Debug Menu -> View battery */ +#define CURRENT_BACKLIGHT 10 /* value taken for Debug Menu -> View battery */ + /* Hardware controlled charging with monitoring */ #define CONFIG_CHARGING CHARGING_MONITOR Index: firmware/powermgmt.c =================================================================== --- firmware/powermgmt.c (revision 24279) +++ firmware/powermgmt.c (working copy) @@ -56,6 +56,10 @@ #include "pcf50606.h" #endif +#ifdef IPOD_NANO2G +#include "pmu-target.h" +#endif + /** Shared by sim **/ int last_sent_battery_level = 100; /* battery level (0-100%) */ @@ -283,9 +287,9 @@ #endif /* discharging: remaining running time */ if (battery_millivolts > percent_to_volt_discharge[0][0]) { - /* linear extrapolation */ + /* linear extrapolation. -1h to take into account fast drop below 3700 mV */ powermgmt_est_runningtime_min = (level + battery_percent)*60 - * battery_capacity / 200 / runcurrent(); + * battery_capacity / 200 / runcurrent() - 60; } if (0 > powermgmt_est_runningtime_min) { powermgmt_est_runningtime_min = 0; @@ -369,6 +373,8 @@ */ static int runcurrent(void) { +#if 0 + /* AB: old style */ int current; #if MEM == 8 && !(defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM)) @@ -413,6 +419,28 @@ #endif /* BOOTLOADER */ return current; +#else + /* dynamic current estimation */ + static int i32current = CURRENT_NORMAL * 1024; /* initialize with uA */ + int i32mA; + +#ifdef IPOD_VIDEO + /* in uA */ + i32mA = (adc_read(ADC_4066_ISTAT) * 2400) / +#if MEM == 64 + (2); +#else + (3); +#endif /* MEM */ +#endif /* IPOD_VIDEO */ +#ifdef IPOD_NANO2G + i32mA = pmu_read_battery_current() * 1000; +#endif + + i32current = (i32current * 1023 + i32mA) / 1024; + + return (i32current/1024); +#endif }