Index: apps/debug_menu.c =================================================================== --- apps/debug_menu.c (revision 25331) +++ apps/debug_menu.c (working copy) @@ -1556,16 +1556,11 @@ dock ? "enabled" : "disabled"); lcd_putsf(0, 7, "Headphone: %s", headphone ? "connected" : "disconnected"); -#ifdef IPOD_VIDEO - x = (adc_read(ADC_4066_ISTAT) * 2400) / -#if MEM == 64 - (1024 * 2); -#else - (1024 * 3); +#ifdef HAVE_DYNAMIC_RUNTIME_ESTIMATION + x = read_battery_current(); + lcd_putsf(0, 8, "I_bat: %d mA", x); + lcd_putsf(0, 9, "P_bat: %d mW", (x * y) / 1000); #endif - lcd_putsf(0, 8, "Ibat: %d mA", x); - lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000); -#endif #elif defined TOSHIBA_GIGABEAT_S int line = 3; unsigned int st; Index: firmware/export/powermgmt.h =================================================================== --- firmware/export/powermgmt.h (revision 25331) +++ firmware/export/powermgmt.h (working copy) @@ -177,5 +177,8 @@ #ifdef HAVE_LINEOUT_POWEROFF void lineout_set(bool); #endif +#ifdef HAVE_DYNAMIC_RUNTIME_ESTIMATION +unsigned int read_battery_current(void); +#endif #endif /* _POWERMGMT_H_ */ Index: firmware/export/config/ipodvideo.h =================================================================== --- firmware/export/config/ipodvideo.h (revision 25331) +++ firmware/export/config/ipodvideo.h (working copy) @@ -119,7 +119,6 @@ #define MAX_BRIGHTNESS_SETTING 32 #define DEFAULT_BRIGHTNESS_SETTING 16 - /* define this if the unit uses a scrollwheel for navigation */ #define HAVE_SCROLLWHEEL /* define to activate advanced wheel acceleration code */ @@ -151,12 +150,10 @@ /* define this if the unit can be powered or charged via USB */ #define HAVE_USB_POWER -/* define current usage levels */ -#define CURRENT_NORMAL 24 /* 30MHz clock, LCD off, accessory supply on */ -#define CURRENT_BACKLIGHT 20 /* FIXME: this needs adjusting */ -#if defined(HAVE_RECORDING) -#define CURRENT_RECORD 35 /* FIXME: this needs adjusting */ -#endif +/* Define this for using dynamic current/runtime estimation */ +#define HAVE_DYNAMIC_RUNTIME_ESTIMATION +/* Define standard current */ +#define CURRENT_NORMAL 24 /* 30MHz clock, LCD off, accessory supply on */ /* Define Apple remote tuner */ #define CONFIG_TUNER IPOD_REMOTE_TUNER Index: firmware/export/config/ipodnano2g.h =================================================================== --- firmware/export/config/ipodnano2g.h (revision 25331) +++ firmware/export/config/ipodnano2g.h (working copy) @@ -138,6 +138,11 @@ #define BATTERY_CAPACITY_INC 50 /* capacity increment */ #define BATTERY_TYPES_COUNT 1 /* only one type */ +/* Define this for using dynamic current/runtime estimation */ +#define HAVE_DYNAMIC_RUNTIME_ESTIMATION +/* Define standard current */ +#define CURRENT_NORMAL 20 /* value taken for Debug Menu -> View battery */ + /* Hardware controlled charging with monitoring */ #define CONFIG_CHARGING CHARGING_MONITOR Index: firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c =================================================================== --- firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c (revision 25331) +++ firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c (working copy) @@ -77,3 +77,11 @@ } } #endif + +#ifdef HAVE_DYNAMIC_RUNTIME_ESTIMATION +unsigned int read_battery_current(void) +{ + /* Return battery current in mA */ + return (pmu_read_battery_current()); +} +#endif Index: firmware/target/arm/ipod/powermgmt-ipod-pcf.c =================================================================== --- firmware/target/arm/ipod/powermgmt-ipod-pcf.c (revision 25331) +++ firmware/target/arm/ipod/powermgmt-ipod-pcf.c (working copy) @@ -138,3 +138,17 @@ audiohw_enable_lineout(enable); } #endif + +#ifdef HAVE_DYNAMIC_RUNTIME_ESTIMATION +unsigned int read_battery_current(void) +{ + /* Return battery current in mA */ +#if defined(IPOD_VIDEO) && (MEM==64) + return (adc_read(ADC_4066_ISTAT) * 2400) / (2 * 1024); +#elif defined(IPOD_VIDEO) && (MEM==32) + return (adc_read(ADC_4066_ISTAT) * 2400) / (3 * 1024); +#else + #error HAVE_DYNAMIC_RUNTIME_ESTIMATION defined without adc routine known. +#endif +} +#endif Index: firmware/powermgmt.c =================================================================== --- firmware/powermgmt.c (revision 25331) +++ firmware/powermgmt.c (working copy) @@ -380,6 +380,7 @@ */ static int runcurrent(void) { +#ifndef HAVE_DYNAMIC_RUNTIME_ESTIMATION int current = CURRENT_NORMAL; #ifndef BOOTLOADER @@ -417,6 +418,14 @@ #endif /* BOOTLOADER */ return current; +#else /* HAVE_DYNAMIC_RUNTIME_ESTIMATION */ + static int i32current = CURRENT_NORMAL << 10; /* initialize with ľA */ + + /* Low pass filtering of current measurement. Time constant = 1024 sec. */ + i32current = (i32current * 1023 + (read_battery_current()<<10)) >> 10; + + return (i32current >> 10); +#endif /* HAVE_DYNAMIC_RUNTIME_ESTIMATION */ } #endif /* CURRENT_NORMAL */ Index: uisimulator/common/powermgmt-sim.c =================================================================== --- uisimulator/common/powermgmt-sim.c (revision 25331) +++ uisimulator/common/powermgmt-sim.c (working copy) @@ -149,6 +149,13 @@ } #endif +#ifdef HAVE_DYNAMIC_RUNTIME_ESTIMATION +unsigned int read_battery_current(void) +{ + return (CURRENT_NORMAL * 1000); +} +#endif + void reset_poweroff_timer(void) { }