Index: apps/debug_menu.c =================================================================== --- apps/debug_menu.c (revision 29321) +++ apps/debug_menu.c (working copy) @@ -1240,13 +1240,10 @@ dock ? "enabled" : "disabled"); lcd_putsf(0, 7, "Headphone: %s", headphone ? "connected" : "disconnected"); -#ifdef IPOD_VIDEO - if(probed_ramsize == 64) - x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 2); - else - x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 3); - lcd_putsf(0, 8, "Ibat: %d mA", x); - lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000); +#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 #elif defined TOSHIBA_GIGABEAT_S int line = 3; Index: firmware/export/powermgmt.h =================================================================== --- firmware/export/powermgmt.h (revision 29321) +++ firmware/export/powermgmt.h (working copy) @@ -178,5 +178,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 29321) +++ firmware/export/config/ipodvideo.h (working copy) @@ -122,7 +122,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 */ @@ -153,12 +152,10 @@ * if USB/MAIN power is discernable and hardware doesn't compel charging */ #define HAVE_USB_CHARGING_ENABLE -/* 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 29321) +++ firmware/export/config/ipodnano2g.h (working copy) @@ -148,6 +148,8 @@ /* Hardware controlled charging with monitoring */ #define CONFIG_CHARGING CHARGING_MONITOR +/* Define this for using dynamic current/runtime estimation */ +#define HAVE_DYNAMIC_RUNTIME_ESTIMATION /* define current usage levels */ #define CURRENT_NORMAL 17 /* playback @48MHz clock, lcd sleep*/ #define CURRENT_BACKLIGHT 23 /* maximum brightness */ Index: firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c =================================================================== --- firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c (revision 29321) +++ firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c (working copy) @@ -86,3 +86,11 @@ audiohw_enable_lineout(enable); } #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 29321) +++ firmware/target/arm/ipod/powermgmt-ipod-pcf.c (working copy) @@ -20,6 +20,7 @@ * ****************************************************************************/ +#include "system.h" #include "config.h" #include "adc.h" #include "powermgmt.h" @@ -132,3 +133,16 @@ audiohw_enable_lineout(enable); } #endif + +#ifndef BOOTLOADER +#ifdef HAVE_DYNAMIC_RUNTIME_ESTIMATION +unsigned int read_battery_current(void) +{ + /* Return battery current in mA */ + if (probed_ramsize == 64) + return (adc_read(ADC_4066_ISTAT) * 2400) / (2 * 1024); + else + return (adc_read(ADC_4066_ISTAT) * 2400) / (3 * 1024); +} +#endif +#endif Index: firmware/powermgmt.c =================================================================== --- firmware/powermgmt.c (revision 29321) +++ firmware/powermgmt.c (working copy) @@ -380,6 +380,7 @@ */ static int runcurrent(void) { +#ifndef HAVE_DYNAMIC_RUNTIME_ESTIMATION int current = CURRENT_NORMAL; #ifndef BOOTLOADER @@ -423,6 +424,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 29321) +++ uisimulator/common/powermgmt-sim.c (working copy) @@ -150,6 +150,13 @@ } #endif +#ifdef HAVE_DYNAMIC_RUNTIME_ESTIMATION +unsigned int read_battery_current(void) +{ + return (CURRENT_NORMAL * 1000); +} +#endif + void reset_poweroff_timer(void) { }