Rework powermgmt to enable code re-use on appliation and sims.
* Introduce CONFIG_BATTERY_MEASURE define, to allow targets (application)
to break powermgmt.c's assumption about the ability to read battery voltage.
There's now additionally percentage (android) and remaining time measure
(maemo). No measure at all also works (sdl app). If voltage can't be measured,
then battery_level() is king and it'll be used for power_history and runtime
estimation.
* Implement target's API in the simulator, i.e. _battery_voltage(), so it
doesn't need to implement it's own powermgmt.c and other stubs. Now
the sim behaves much more like a native target, although it still
changes the simulated battery voltage quickly,
* Other changes include include renaming battery_adc_voltage() to
_battery_voltage(), for consistency with the new target functions and
making some of the apps code aware that voltage and runtime estimation
is not always available.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31548 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index b4d917a..3404071 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -900,8 +900,7 @@
return simplelist_show_list(&info);
}
#endif
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
-#ifdef HAVE_LCD_BITMAP
+#if (CONFIG_BATTERY_MEASURE != 0) && defined(HAVE_LCD_BITMAP) && !defined(SIMULATOR)
/*
* view_battery() shows a automatically scaled graph of the battery voltage
* over time. Usable for estimating battery life / charging rate.
@@ -909,13 +908,14 @@
*/
#define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
-#define BAT_YSPACE (LCD_HEIGHT - 20)
+#define BAT_TSPACE 20
+#define BAT_YSPACE (LCD_HEIGHT - BAT_TSPACE)
static bool view_battery(void)
{
int view = 0;
- int i, x, y, y1, y2, grid, graph;
+ int i, x, y, z, y1, y2, grid, graph;
unsigned short maxv, minv;
lcd_setfont(FONT_SYSFIXED);
@@ -934,19 +934,28 @@
if (power_history[i] < minv)
minv = power_history[i];
}
-
+ /* print header */
+#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
/* adjust grid scale */
if ((maxv - minv) > 50)
grid = 50;
else
grid = 5;
-
- /* print header */
+
lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
power_history[0] % 1000);
lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
grid);
+#elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
+ /* adjust grid scale */
+ if ((maxv - minv) > 10)
+ grid = 10;
+ else
+ grid = 1;
+ lcd_putsf(0, 0, "battery %d%%", power_history[0]);
+ lcd_putsf(0, 1, "%d%%-%d%% (%d %%)", minv, maxv, grid);
+#endif
i = 1;
while ((y = (minv - (minv % grid)+i*grid)) < maxv)
@@ -971,11 +980,11 @@
{
y1 = (power_history[i] - minv) * BAT_YSPACE /
(maxv - minv);
- y1 = MIN(MAX(LCD_HEIGHT-1 - y1, 20),
+ y1 = MIN(MAX(LCD_HEIGHT-1 - y1, BAT_TSPACE),
LCD_HEIGHT-1);
y2 = (power_history[i-1] - minv) * BAT_YSPACE /
(maxv - minv);
- y2 = MIN(MAX(LCD_HEIGHT-1 - y2, 20),
+ y2 = MIN(MAX(LCD_HEIGHT-1 - y2, BAT_TSPACE),
LCD_HEIGHT-1);
lcd_set_drawmode(DRMODE_SOLID);
@@ -999,10 +1008,13 @@
lcd_putsf(0, 0, "Pwr status: %s",
charging_state() ? "charging" : "discharging");
#else
- lcd_puts(0, 0, "Power status:");
+ lcd_puts(0, 0, "Power status: unknown");
#endif
- battery_read_info(&y, NULL);
- lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000);
+ battery_read_info(&y, &z);
+ if (y > 0)
+ lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z);
+ else if (z > 0)
+ lcd_putsf(0, 1, "Battery: %d %%", z);
#ifdef ADC_EXT_POWER
y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
@@ -1169,16 +1181,23 @@
#endif /* target type */
#endif /* CONFIG_CHARGING */
break;
-
case 2: /* voltage deltas: */
+#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
lcd_puts(0, 0, "Voltage deltas:");
-
- for (i = 0; i <= 6; i++) {
+ for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
y = power_history[i] - power_history[i+1];
- lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i,
- (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
+ lcd_putsf(0, i+1, "-%d min: %c%d.%03d V", i,
+ (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y) / 1000,
((y < 0) ? y * -1 : y ) % 1000);
}
+#elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
+ lcd_puts(0, 0, "Percentage deltas:");
+ for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
+ y = power_history[i] - power_history[i+1];
+ lcd_putsf(0, i+1, "-%d min: %c%d%%", i,
+ (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y));
+ }
+#endif
break;
case 3: /* remaining time estimation: */
@@ -1195,13 +1214,19 @@
lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
#endif /* ARCHOS_RECORDER */
+#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
power_history[0] / 1000,
power_history[0] % 1000);
+#endif
lcd_putsf(0, 6, "battery level: %d%%", battery_level());
- lcd_putsf(0, 7, "Est. remain: %d m", battery_time());
+ int time_left = battery_time();
+ if (time_left >= 0)
+ lcd_putsf(0, 7, "Est. remain: %d m", time_left);
+ else
+ lcd_puts(0, 7, "Estimation n/a");
break;
}
@@ -1228,8 +1253,7 @@
return false;
}
-#endif /* HAVE_LCD_BITMAP */
-#endif
+#endif /* (CONFIG_BATTERY_MEASURE != 0) && HAVE_LCD_BITMAP */
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
#if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
@@ -2168,7 +2192,7 @@
{ "View CPU stats", dbg_cpuinfo },
#endif
#ifdef HAVE_LCD_BITMAP
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
+#if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR)
{ "View battery", view_battery },
#endif
#ifndef APPLICATION
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index 169c4a3..bae8ae8 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -1068,9 +1068,13 @@
case SKIN_TOKEN_BATTERY_VOLTS:
{
- unsigned int v = battery_voltage();
- snprintf(buf, buf_size, "%d.%02d", v / 1000, (v % 1000) / 10);
- return buf;
+ int v = battery_voltage();
+ if (v >= 0) {
+ snprintf(buf, buf_size, "%d.%02d", v / 1000, (v % 1000) / 10);
+ return buf;
+ } else {
+ return "?";
+ }
}
case SKIN_TOKEN_BATTERY_TIME:
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c
index cefc395..b7472a6 100644
--- a/apps/menus/main_menu.c
+++ b/apps/menus/main_menu.c
@@ -210,7 +210,7 @@
snprintf(buffer, buffer_len, str(LANG_BATTERY_TIME),
battery_level(), battery_time() / 60, battery_time() % 60);
else
- return "(n/a)";
+ return "Battery n/a"; /* translating worth it? */
break;
case INFO_DISK1: /* disk usage 1 */
#ifdef HAVE_MULTIVOLUME
@@ -289,9 +289,11 @@
#endif /* CONFIG_CHARGING = */
if (battery_level() >= 0)
{
+ int time_left = battery_time();
talk_id(LANG_BATTERY_TIME, false);
talk_value(battery_level(), UNIT_PERCENT, true);
- talk_value(battery_time() *60, UNIT_TIME, true);
+ if (time_left >= 0)
+ talk_value(time_left * 60, UNIT_TIME, true);
}
else talk_id(VOICE_BLANK, false);
break;
diff --git a/apps/menus/theme_menu.c b/apps/menus/theme_menu.c
index e1077a5..5e04191 100644
--- a/apps/menus/theme_menu.c
+++ b/apps/menus/theme_menu.c
@@ -219,7 +219,11 @@
#if CONFIG_KEYPAD == RECORDER_PAD
&buttonbar,
#endif
- &volume_type, &battery_display);
+ &volume_type
+#if (CONFIG_BATTERY_MEASURE != 0)
+ , &battery_display
+#endif
+ );
#endif /* HAVE_LCD_BITMAP */
/* */
diff --git a/apps/misc.c b/apps/misc.c
index b1def59..30c7471 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -277,6 +277,7 @@
if (batt_safe)
{
+ int level;
#ifdef HAVE_TAGCACHE
if (!tagcache_prepare_shutdown())
{
@@ -285,7 +286,8 @@
return false;
}
#endif
- if (battery_level() > 10)
+ level = battery_level();
+ if (level > 10 || level < 0)
splash(0, str(LANG_SHUTTINGDOWN));
else
{
diff --git a/apps/plugin.c b/apps/plugin.c
index f17ad3c..2528075 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -664,9 +664,7 @@
battery_level,
battery_level_safe,
battery_time,
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
battery_voltage,
-#endif
#if CONFIG_CHARGING
charger_inserted,
# if CONFIG_CHARGING >= CHARGING_MONITOR
diff --git a/apps/plugin.h b/apps/plugin.h
index 0bb7262..918206a 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -794,9 +794,7 @@
int (*battery_level)(void);
bool (*battery_level_safe)(void);
int (*battery_time)(void);
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
- unsigned int (*battery_voltage)(void);
-#endif
+ int (*battery_voltage)(void);
#if CONFIG_CHARGING
bool (*charger_inserted)(void);
# if CONFIG_CHARGING >= CHARGING_MONITOR
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index 1b14c0d..a72579e 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -1,5 +1,5 @@
/* plugins common to all models */
-#ifndef SIMULATOR
+#if !defined(SIMULATOR) && (CONFIG_BATTERY_MEASURE != 0)
battery_bench.c
#endif
chessclock.c
diff --git a/apps/settings.h b/apps/settings.h
index 676e5bf..d0fd320 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -638,7 +638,7 @@
/* power settings */
int poweroff; /* idle power off timer */
-#ifdef BATTERY_CAPACITY_DEFAULT
+#if BATTERY_CAPACITY_DEFAULT > 0
int battery_capacity; /* in mAh */
#endif
diff --git a/apps/settings_list.c b/apps/settings_list.c
index c9003bb..dff5ed2 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -838,7 +838,7 @@
NULL, NULL, NULL),
/* use this setting for user code even if there's no exchangable battery
* support enabled */
-#ifdef BATTERY_CAPACITY_DEFAULT
+#if BATTERY_CAPACITY_DEFAULT > 0
/* define min/max/inc for this file if there's only one battery */
#ifndef BATTERY_CAPACITY_MIN
#define BATTERY_CAPACITY_MIN BATTERY_CAPACITY_DEFAULT
diff --git a/bootloader/gigabeat-s.c b/bootloader/gigabeat-s.c
index 909194e..04c3242 100644
--- a/bootloader/gigabeat-s.c
+++ b/bootloader/gigabeat-s.c
@@ -358,7 +358,7 @@
printf("Version " RBVERSION);
adc_init();
- batt = battery_adc_voltage();
+ batt = _battery_voltage();
printf("Battery: %d.%03d V", batt / 1000, batt % 1000);
check_battery_safe();
diff --git a/bootloader/iaudio_coldfire.c b/bootloader/iaudio_coldfire.c
index 9c829c4..b22af0e 100644
--- a/bootloader/iaudio_coldfire.c
+++ b/bootloader/iaudio_coldfire.c
@@ -110,7 +110,7 @@
{
int battery_voltage, batt_int, batt_frac;
- battery_voltage = battery_adc_voltage();
+ battery_voltage = _battery_voltage();
batt_int = battery_voltage / 1000;
batt_frac = (battery_voltage % 1000) / 10;
diff --git a/bootloader/iriver_h1x0.c b/bootloader/iriver_h1x0.c
index 1afbafa..9042737 100644
--- a/bootloader/iriver_h1x0.c
+++ b/bootloader/iriver_h1x0.c
@@ -170,7 +170,7 @@
{
int battery_voltage, batt_int, batt_frac;
- battery_voltage = battery_adc_voltage();
+ battery_voltage = _battery_voltage();
batt_int = battery_voltage / 1000;
batt_frac = (battery_voltage % 1000) / 10;
diff --git a/bootloader/iriver_h300.c b/bootloader/iriver_h300.c
index 893532c..b6d7da2 100644
--- a/bootloader/iriver_h300.c
+++ b/bootloader/iriver_h300.c
@@ -112,7 +112,7 @@
{
int battery_voltage, batt_int, batt_frac;
- battery_voltage = battery_adc_voltage();
+ battery_voltage = _battery_voltage();
batt_int = battery_voltage / 1000;
batt_frac = (battery_voltage % 1000) / 10;
diff --git a/bootloader/mpio_hd200_hd300.c b/bootloader/mpio_hd200_hd300.c
index be36daf..3e4ba76 100644
--- a/bootloader/mpio_hd200_hd300.c
+++ b/bootloader/mpio_hd200_hd300.c
@@ -160,7 +160,7 @@
int battery_voltage, batt_int, batt_frac;
- battery_voltage = battery_adc_voltage();
+ battery_voltage = _battery_voltage();
batt_int = battery_voltage / 1000;
batt_frac = (battery_voltage % 1000) / 10;
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 0143b9c..2dd8b7b 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -14,7 +14,6 @@
#endif
#ifndef SAMSUNG_YPR0 /* uses as3514 rtc */
-target/hosted/powermgmt.c
target/hosted/rtc.c
#endif
#endif
diff --git a/firmware/drivers/audio/android.c b/firmware/drivers/audio/android.c
index 300bb08..8bd0263 100644
--- a/firmware/drivers/audio/android.c
+++ b/firmware/drivers/audio/android.c
@@ -59,3 +59,5 @@
{
(void)balance;
}
+
+void audiohw_close(void) {}
diff --git a/firmware/drivers/audio/sdl.c b/firmware/drivers/audio/sdl.c
index 1a42466..b9df35b 100644
--- a/firmware/drivers/audio/sdl.c
+++ b/firmware/drivers/audio/sdl.c
@@ -167,6 +167,9 @@
void audiohw_set_depth_3d(int value)
{ (void)value; }
#endif
+
+void audiohw_close(void) {}
+
#ifdef CONFIG_SAMPR_TYPES
unsigned int pcm_sampr_to_hw_sampr(unsigned int samplerate,
unsigned int type)
diff --git a/firmware/export/config.h b/firmware/export/config.h
index f5bc778..85c8301 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -184,6 +184,15 @@
* charging or specific programming is required to
* use the charging hardware. */
+/* CONFIG_BATTERY_MEASURE bits */
+#define VOLTAGE_MEASURE 1 /* Target can report battery voltage
+ * Usually native ports */
+#define PERCENTAGE_MEASURE 2 /* Target can report remaining capacity in %
+ * Usually application/hosted ports */
+#define TIME_MEASURE 4 /* Target can report remaining time estimation
+ Usually application ports, and only
+ if the estimation is better that ours
+ (which it probably is) */
/* CONFIG_LCD */
#define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */
#define LCD_SSD1801 2 /* as used by Archos Player/Studio */
@@ -603,6 +612,11 @@
#define CONFIG_CHARGING 0
#endif
+#ifndef CONFIG_BATTERY_MEASURE
+#define CONFIG_BATTERY_MEASURE 0
+#define NO_LOW_BATTERY_SHUTDOWN
+#endif
+
#ifndef CONFIG_RTC
#define CONFIG_RTC 0
#endif
@@ -611,6 +625,10 @@
#define BATTERY_TYPES_COUNT 0
#endif
+#ifndef BATTERY_CAPACITY_DEFAULT
+#define BATTERY_CAPACITY_DEFAULT 0
+#endif
+
#ifndef BATTERY_CAPACITY_INC
#define BATTERY_CAPACITY_INC 0
#endif
diff --git a/firmware/export/config/android.h b/firmware/export/config/android.h
index 41ecacf..6261a80 100644
--- a/firmware/export/config/android.h
+++ b/firmware/export/config/android.h
@@ -86,11 +86,9 @@
#define HAVE_HEADPHONE_DETECTION
-/* Define current usage levels. */
-#define CURRENT_NORMAL 88 /* 18 hours from a 1600 mAh battery */
-#define CURRENT_BACKLIGHT 30 /* TBD */
-#define CURRENT_RECORD 0 /* no recording yet */
+#define CONFIG_BATTERY_MEASURE PERCENTAGE_MEASURE
+#define NO_LOW_BATTERY_SHUTDOWN
/* Define this to the CPU frequency */
/*
#define CPU_FREQ 48000000
diff --git a/firmware/export/config/archosfmrecorder.h b/firmware/export/config/archosfmrecorder.h
index 3e2c7e9..6b1f07f 100644
--- a/firmware/export/config/archosfmrecorder.h
+++ b/firmware/export/config/archosfmrecorder.h
@@ -91,6 +91,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
#define CURRENT_NORMAL 145 /* usual current in mA */
#define CURRENT_RECORD 35 /* additional recording current */
#define CURRENT_USB 500 /* usual current in mA in USB mode */
diff --git a/firmware/export/config/archosondiofm.h b/firmware/export/config/archosondiofm.h
index 516845e..1a1115f 100644
--- a/firmware/export/config/archosondiofm.h
+++ b/firmware/export/config/archosondiofm.h
@@ -73,6 +73,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 2 /* Alkalines or NiMH */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define this if the unit should not shut down on low battery. */
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/archosondiosp.h b/firmware/export/config/archosondiosp.h
index ba957f7..aad66b7 100644
--- a/firmware/export/config/archosondiosp.h
+++ b/firmware/export/config/archosondiosp.h
@@ -60,6 +60,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 2 /* Alkalines or NiMH */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define this if the unit should not shut down on low battery. */
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/archosplayer.h b/firmware/export/config/archosplayer.h
index bc75433..af12557 100644
--- a/firmware/export/config/archosplayer.h
+++ b/firmware/export/config/archosplayer.h
@@ -49,6 +49,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
#define CURRENT_NORMAL 145 /* usual current in mA */
#define CURRENT_USB 500 /* usual current in mA in USB mode */
diff --git a/firmware/export/config/archosrecorder.h b/firmware/export/config/archosrecorder.h
index be7c872..6c708fb 100644
--- a/firmware/export/config/archosrecorder.h
+++ b/firmware/export/config/archosrecorder.h
@@ -80,6 +80,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
#if MEMORYSIZE < 8
#define CURRENT_NORMAL 145 /* usual current in mA */
#else
diff --git a/firmware/export/config/archosrecorderv2.h b/firmware/export/config/archosrecorderv2.h
index e2f3b66..dae34ef 100644
--- a/firmware/export/config/archosrecorderv2.h
+++ b/firmware/export/config/archosrecorderv2.h
@@ -86,6 +86,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
#define CURRENT_NORMAL 145 /* usual current in mA */
#define CURRENT_RECORD 35 /* additional recording current */
#define CURRENT_USB 500 /* usual current in mA in USB mode */
diff --git a/firmware/export/config/cowond2.h b/firmware/export/config/cowond2.h
index ebaa636..03fbb4f 100644
--- a/firmware/export/config/cowond2.h
+++ b/firmware/export/config/cowond2.h
@@ -136,6 +136,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/creativezv.h b/firmware/export/config/creativezv.h
index 0fd216a..568144b 100644
--- a/firmware/export/config/creativezv.h
+++ b/firmware/export/config/creativezv.h
@@ -130,6 +130,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
//#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/gigabeatfx.h b/firmware/export/config/gigabeatfx.h
index b64f3f5..fbaa4a0 100644
--- a/firmware/export/config/gigabeatfx.h
+++ b/firmware/export/config/gigabeatfx.h
@@ -129,6 +129,8 @@
#define BATTERY_CAPACITY_INC 25 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/gigabeats.h b/firmware/export/config/gigabeats.h
index 685076b..f7fdc44 100644
--- a/firmware/export/config/gigabeats.h
+++ b/firmware/export/config/gigabeats.h
@@ -173,6 +173,8 @@
#define BATTERY_CAPACITY_INC 25 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* TODO: have a proper status displayed in the bootloader and have it
* work! */
/* Charging implemented in a target-specific algorithm */
diff --git a/firmware/export/config/gogearhdd1630.h b/firmware/export/config/gogearhdd1630.h
index e9bbfb8..05f1a47 100644
--- a/firmware/export/config/gogearhdd1630.h
+++ b/firmware/export/config/gogearhdd1630.h
@@ -141,6 +141,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/gogearhdd6330.h b/firmware/export/config/gogearhdd6330.h
index fc326da..b8ee918 100644
--- a/firmware/export/config/gogearhdd6330.h
+++ b/firmware/export/config/gogearhdd6330.h
@@ -144,6 +144,8 @@
#define BATTERY_CAPACITY_INC 20 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/gogearsa9200.h b/firmware/export/config/gogearsa9200.h
index b91430e..e29c8dc 100644
--- a/firmware/export/config/gogearsa9200.h
+++ b/firmware/export/config/gogearsa9200.h
@@ -125,6 +125,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config/hifimanhm60x.h b/firmware/export/config/hifimanhm60x.h
index 6ac4380..bdc6124 100644
--- a/firmware/export/config/hifimanhm60x.h
+++ b/firmware/export/config/hifimanhm60x.h
@@ -130,6 +130,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/hifimanhm801.h b/firmware/export/config/hifimanhm801.h
index 469c423..a5b5aee 100644
--- a/firmware/export/config/hifimanhm801.h
+++ b/firmware/export/config/hifimanhm801.h
@@ -118,6 +118,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/iaudio7.h b/firmware/export/config/iaudio7.h
index 8a04bc0..0664ff0 100644
--- a/firmware/export/config/iaudio7.h
+++ b/firmware/export/config/iaudio7.h
@@ -131,6 +131,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
#define CONFIG_CHARGING CHARGING_SIMPLE
/* Define this if you have a TCC770 */
diff --git a/firmware/export/config/iaudiom3.h b/firmware/export/config/iaudiom3.h
index 6fdf11c..d2f9064 100644
--- a/firmware/export/config/iaudiom3.h
+++ b/firmware/export/config/iaudiom3.h
@@ -114,6 +114,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/iaudiom5.h b/firmware/export/config/iaudiom5.h
index ad86308..0bc3ed5 100644
--- a/firmware/export/config/iaudiom5.h
+++ b/firmware/export/config/iaudiom5.h
@@ -138,6 +138,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/iaudiox5.h b/firmware/export/config/iaudiox5.h
index 2083095..b88583c 100644
--- a/firmware/export/config/iaudiox5.h
+++ b/firmware/export/config/iaudiox5.h
@@ -141,6 +141,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/ipod1g2g.h b/firmware/export/config/ipod1g2g.h
index 0ce5d45..b2b1f4a 100644
--- a/firmware/export/config/ipod1g2g.h
+++ b/firmware/export/config/ipod1g2g.h
@@ -130,6 +130,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
//#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/ipod3g.h b/firmware/export/config/ipod3g.h
index e7d8bff..16bd107 100644
--- a/firmware/export/config/ipod3g.h
+++ b/firmware/export/config/ipod3g.h
@@ -137,6 +137,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/ipod4g.h b/firmware/export/config/ipod4g.h
index 957e3a4..5ddde1b 100644
--- a/firmware/export/config/ipod4g.h
+++ b/firmware/export/config/ipod4g.h
@@ -143,6 +143,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/ipod6g.h b/firmware/export/config/ipod6g.h
index 95837cc..08c0f27 100644
--- a/firmware/export/config/ipod6g.h
+++ b/firmware/export/config/ipod6g.h
@@ -145,6 +145,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/ipodcolor.h b/firmware/export/config/ipodcolor.h
index cf02101..9768ac3 100644
--- a/firmware/export/config/ipodcolor.h
+++ b/firmware/export/config/ipodcolor.h
@@ -130,6 +130,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/ipodmini1g.h b/firmware/export/config/ipodmini1g.h
index 04fa68e..b1f6fa1 100644
--- a/firmware/export/config/ipodmini1g.h
+++ b/firmware/export/config/ipodmini1g.h
@@ -141,6 +141,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define current usage levels */
#define CURRENT_NORMAL 50 /* PP5024 uses ~40mA, so add some for disk */
#define CURRENT_BACKLIGHT 20 /* FIXME: This needs to be measured */
diff --git a/firmware/export/config/ipodmini2g.h b/firmware/export/config/ipodmini2g.h
index c10284e..27edf10 100644
--- a/firmware/export/config/ipodmini2g.h
+++ b/firmware/export/config/ipodmini2g.h
@@ -142,6 +142,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define current usage levels */
#define CURRENT_NORMAL 50 /* PP5024 uses ~40mA, so add some for disk */
#define CURRENT_BACKLIGHT 20 /* FIXME: This needs to be measured */
diff --git a/firmware/export/config/ipodnano1g.h b/firmware/export/config/ipodnano1g.h
index 50f0511..40f6cf2 100644
--- a/firmware/export/config/ipodnano1g.h
+++ b/firmware/export/config/ipodnano1g.h
@@ -134,6 +134,8 @@
#define BATTERY_CAPACITY_INC 20 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/ipodnano2g.h b/firmware/export/config/ipodnano2g.h
index e0941e0..2e4f189 100644
--- a/firmware/export/config/ipodnano2g.h
+++ b/firmware/export/config/ipodnano2g.h
@@ -148,6 +148,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/ipodvideo.h b/firmware/export/config/ipodvideo.h
index c4e2cb2..7e123d0 100644
--- a/firmware/export/config/ipodvideo.h
+++ b/firmware/export/config/ipodvideo.h
@@ -149,6 +149,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/iriverh10.h b/firmware/export/config/iriverh10.h
index d2d7a0c..3611093 100644
--- a/firmware/export/config/iriverh10.h
+++ b/firmware/export/config/iriverh10.h
@@ -127,6 +127,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/iriverh100.h b/firmware/export/config/iriverh100.h
index 1a89c7c..6447265 100644
--- a/firmware/export/config/iriverh100.h
+++ b/firmware/export/config/iriverh100.h
@@ -131,6 +131,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/iriverh10_5gb.h b/firmware/export/config/iriverh10_5gb.h
index 0ad83cb..84c0b37 100644
--- a/firmware/export/config/iriverh10_5gb.h
+++ b/firmware/export/config/iriverh10_5gb.h
@@ -110,6 +110,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/iriverh120.h b/firmware/export/config/iriverh120.h
index 199b948..5bab810 100644
--- a/firmware/export/config/iriverh120.h
+++ b/firmware/export/config/iriverh120.h
@@ -135,6 +135,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/iriverh300.h b/firmware/export/config/iriverh300.h
index dbe7013..4250153 100644
--- a/firmware/export/config/iriverh300.h
+++ b/firmware/export/config/iriverh300.h
@@ -130,6 +130,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/iriverifp7xx.h b/firmware/export/config/iriverifp7xx.h
index 78c0783..1de6adc 100644
--- a/firmware/export/config/iriverifp7xx.h
+++ b/firmware/export/config/iriverifp7xx.h
@@ -70,6 +70,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 2 /* Alkalines or NiMH */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define this if the unit should not shut down on low battery. */
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/logikdax.h b/firmware/export/config/logikdax.h
index 45f5651..ed6cbba 100644
--- a/firmware/export/config/logikdax.h
+++ b/firmware/export/config/logikdax.h
@@ -102,6 +102,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define this if the unit should not shut down on low battery. */
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/lyreproto1.h b/firmware/export/config/lyreproto1.h
index 1413adc..95808cf 100644
--- a/firmware/export/config/lyreproto1.h
+++ b/firmware/export/config/lyreproto1.h
@@ -84,6 +84,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
#define CONFIG_CPU AT91SAM9260
/* Define this to the CPU frequency */
diff --git a/firmware/export/config/meizum3.h b/firmware/export/config/meizum3.h
index 7cba1c7..d1a2b8f 100644
--- a/firmware/export/config/meizum3.h
+++ b/firmware/export/config/meizum3.h
@@ -119,6 +119,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging, software can monitor plug and charge state */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/meizum6sl.h b/firmware/export/config/meizum6sl.h
index 28c0fc0..e0e5e9d 100644
--- a/firmware/export/config/meizum6sl.h
+++ b/firmware/export/config/meizum6sl.h
@@ -119,6 +119,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/meizum6sp.h b/firmware/export/config/meizum6sp.h
index f88be04..34d7c92 100644
--- a/firmware/export/config/meizum6sp.h
+++ b/firmware/export/config/meizum6sp.h
@@ -125,6 +125,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/mini2440.h b/firmware/export/config/mini2440.h
index 4b4a137..9b794ec 100644
--- a/firmware/export/config/mini2440.h
+++ b/firmware/export/config/mini2440.h
@@ -95,6 +95,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/***************************************************************************/
diff --git a/firmware/export/config/mpiohd200.h b/firmware/export/config/mpiohd200.h
index f85b9a2..1369172 100644
--- a/firmware/export/config/mpiohd200.h
+++ b/firmware/export/config/mpiohd200.h
@@ -116,6 +116,8 @@
#define CODEC_SRCTRL_88200HZ (0x1E << 1)
#define BATTERY_TYPES_COUNT 1
+
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
#define BATTERY_CAPACITY_DEFAULT 850 /* this is wild guess */
#define BATTERY_CAPACITY_MIN 800 /* min. capacity selectable */
#define BATTERY_CAPACITY_MAX 2500 /* max. capacity selectable */
diff --git a/firmware/export/config/mpiohd300.h b/firmware/export/config/mpiohd300.h
index 6728d5c..8343a90 100644
--- a/firmware/export/config/mpiohd300.h
+++ b/firmware/export/config/mpiohd300.h
@@ -119,6 +119,8 @@
#define CODEC_SRCTRL_88200HZ (0x1E << 1)
#define BATTERY_TYPES_COUNT 1
+
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
#define BATTERY_CAPACITY_DEFAULT 1200 /* this is wild guess */
#define BATTERY_CAPACITY_MIN 800 /* min. capacity selectable */
#define BATTERY_CAPACITY_MAX 2500 /* max. capacity selectable */
diff --git a/firmware/export/config/mrobe100.h b/firmware/export/config/mrobe100.h
index 1b373a9..510475d 100644
--- a/firmware/export/config/mrobe100.h
+++ b/firmware/export/config/mrobe100.h
@@ -142,6 +142,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/mrobe500.h b/firmware/export/config/mrobe500.h
index 590f8a9..6f8bc6c 100644
--- a/firmware/export/config/mrobe500.h
+++ b/firmware/export/config/mrobe500.h
@@ -197,6 +197,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define current usage levels */
#define CURRENT_NORMAL 85 /* Measured */
#define CURRENT_BACKLIGHT 200 /* Over 200 mA total measured when on */
diff --git a/firmware/export/config/nokian8xx.h b/firmware/export/config/nokian8xx.h
index f11fa87..55f96f7 100644
--- a/firmware/export/config/nokian8xx.h
+++ b/firmware/export/config/nokian8xx.h
@@ -74,12 +74,11 @@
#define HAVE_SDL
#define HAVE_SDL_AUDIO
-#define HAVE_SW_TONE_CONTROLS
+#define HAVE_SW_TONE_CONTROLS
-/* Define current usage levels. */
-#define CURRENT_NORMAL 88 /* 18 hours from a 1600 mAh battery */
-#define CURRENT_BACKLIGHT 30 /* TBD */
-#define CURRENT_RECORD 0 /* no recording yet */
+/* can provide both remaining percentage and time information */
+#define CONFIG_BATTERY_MEASURE (PERCENTAGE_MEASURE|TIME_MEASURE)
+#define NO_LOW_BATTERY_SHUTDOWN
/* Define this to the CPU frequency */
/*
diff --git a/firmware/export/config/nokian900.h b/firmware/export/config/nokian900.h
index a36aebf..1e74fd5 100644
--- a/firmware/export/config/nokian900.h
+++ b/firmware/export/config/nokian900.h
@@ -74,14 +74,11 @@
#define HAVE_SDL
#define HAVE_SDL_AUDIO
-#define HAVE_SW_TONE_CONTROLS
+#define HAVE_SW_TONE_CONTROLS
-/* Define current usage levels. */
-#define CURRENT_NORMAL 88 /* 18 hours from a 1600 mAh battery */
-#define CURRENT_BACKLIGHT 30 /* TBD */
-#define CURRENT_RECORD 0 /* no recording yet */
-
-/* Define this to the CPU frequency */
+/* can provide both remaining percentage and time information */
+#define CONFIG_BATTERY_MEASURE (PERCENTAGE_MEASURE|TIME_MEASURE)
+#define NO_LOW_BATTERY_SHUTDOWN
/*
#define CPU_FREQ 48000000
*/
diff --git a/firmware/export/config/ondavx747.h b/firmware/export/config/ondavx747.h
index e01c6cc..45aec00 100644
--- a/firmware/export/config/ondavx747.h
+++ b/firmware/export/config/ondavx747.h
@@ -157,6 +157,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/ondavx767.h b/firmware/export/config/ondavx767.h
index b2bac4f..44a7aa0 100644
--- a/firmware/export/config/ondavx767.h
+++ b/firmware/export/config/ondavx767.h
@@ -132,6 +132,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
//#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/ondavx777.h b/firmware/export/config/ondavx777.h
index b9167e0..0319816 100644
--- a/firmware/export/config/ondavx777.h
+++ b/firmware/export/config/ondavx777.h
@@ -151,6 +151,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/rk27generic.h b/firmware/export/config/rk27generic.h
index d7b63f0..6cebb8c 100644
--- a/firmware/export/config/rk27generic.h
+++ b/firmware/export/config/rk27generic.h
@@ -136,6 +136,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/samsungyh820.h b/firmware/export/config/samsungyh820.h
index d7d5411..74cd052 100644
--- a/firmware/export/config/samsungyh820.h
+++ b/firmware/export/config/samsungyh820.h
@@ -134,6 +134,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/samsungyh920.h b/firmware/export/config/samsungyh920.h
index 5255a05..73f226d 100644
--- a/firmware/export/config/samsungyh920.h
+++ b/firmware/export/config/samsungyh920.h
@@ -141,6 +141,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/samsungyh925.h b/firmware/export/config/samsungyh925.h
index 3e072dd..c95d1e5 100644
--- a/firmware/export/config/samsungyh925.h
+++ b/firmware/export/config/samsungyh925.h
@@ -138,6 +138,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/samsungypr0.h b/firmware/export/config/samsungypr0.h
index 2de36dc..735db1f 100644
--- a/firmware/export/config/samsungypr0.h
+++ b/firmware/export/config/samsungypr0.h
@@ -132,6 +132,8 @@
#define CURRENT_NORMAL 24 /* ~25h, on 600mAh that's about 24mA */
#define CURRENT_BACKLIGHT 62 /* ~6,5h -> 92mA. Minus 24mA normal that gives us 68mA */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Linux controlls charging, we can monitor */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/samsungyps3.h b/firmware/export/config/samsungyps3.h
index 3062d5c..cef3b60 100644
--- a/firmware/export/config/samsungyps3.h
+++ b/firmware/export/config/samsungyps3.h
@@ -118,6 +118,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging, software can monitor plug and charge state */
#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/sansac100.h b/firmware/export/config/sansac100.h
index e61e426..5aabfc2 100644
--- a/firmware/export/config/sansac100.h
+++ b/firmware/export/config/sansac100.h
@@ -92,6 +92,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define this if the unit should not shut down on low battery. */
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/sansac200.h b/firmware/export/config/sansac200.h
index 74d3d94..479623f 100644
--- a/firmware/export/config/sansac200.h
+++ b/firmware/export/config/sansac200.h
@@ -142,6 +142,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config/sansac200v2.h b/firmware/export/config/sansac200v2.h
index a5b857f..742d66f 100644
--- a/firmware/export/config/sansac200v2.h
+++ b/firmware/export/config/sansac200v2.h
@@ -138,6 +138,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansaclip.h b/firmware/export/config/sansaclip.h
index 4e21466..617e661 100644
--- a/firmware/export/config/sansaclip.h
+++ b/firmware/export/config/sansaclip.h
@@ -141,6 +141,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansaclipplus.h b/firmware/export/config/sansaclipplus.h
index 083b96a..b753f58 100644
--- a/firmware/export/config/sansaclipplus.h
+++ b/firmware/export/config/sansaclipplus.h
@@ -148,6 +148,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansaclipv2.h b/firmware/export/config/sansaclipv2.h
index cb2392a..4358fe5 100644
--- a/firmware/export/config/sansaclipv2.h
+++ b/firmware/export/config/sansaclipv2.h
@@ -144,6 +144,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansaclipzip.h b/firmware/export/config/sansaclipzip.h
index 043b102..696125e 100644
--- a/firmware/export/config/sansaclipzip.h
+++ b/firmware/export/config/sansaclipzip.h
@@ -149,6 +149,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansaconnect.h b/firmware/export/config/sansaconnect.h
index 714534d..a0f5179 100644
--- a/firmware/export/config/sansaconnect.h
+++ b/firmware/export/config/sansaconnect.h
@@ -149,6 +149,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define current usage levels */
#if 0
/* TODO */
diff --git a/firmware/export/config/sansae200.h b/firmware/export/config/sansae200.h
index dd5747a..c5b53e6 100644
--- a/firmware/export/config/sansae200.h
+++ b/firmware/export/config/sansae200.h
@@ -142,6 +142,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config/sansae200v2.h b/firmware/export/config/sansae200v2.h
index a03dfe0..19346db 100644
--- a/firmware/export/config/sansae200v2.h
+++ b/firmware/export/config/sansae200v2.h
@@ -152,6 +152,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansafuze.h b/firmware/export/config/sansafuze.h
index 2e9c261..f905bc7 100644
--- a/firmware/export/config/sansafuze.h
+++ b/firmware/export/config/sansafuze.h
@@ -156,6 +156,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansafuzeplus.h b/firmware/export/config/sansafuzeplus.h
index 880bbae..1c8fdad 100644
--- a/firmware/export/config/sansafuzeplus.h
+++ b/firmware/export/config/sansafuzeplus.h
@@ -140,6 +140,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansafuzev2.h b/firmware/export/config/sansafuzev2.h
index 8231236..ae25592 100644
--- a/firmware/export/config/sansafuzev2.h
+++ b/firmware/export/config/sansafuzev2.h
@@ -161,6 +161,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_TARGET
diff --git a/firmware/export/config/sansam200.h b/firmware/export/config/sansam200.h
index c5eade8..2c37f91 100644
--- a/firmware/export/config/sansam200.h
+++ b/firmware/export/config/sansam200.h
@@ -98,6 +98,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define this if the unit should not shut down on low battery. */
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/sansam200v4.h b/firmware/export/config/sansam200v4.h
index 7559361..ef371e5 100644
--- a/firmware/export/config/sansam200v4.h
+++ b/firmware/export/config/sansam200v4.h
@@ -118,6 +118,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* define this if the unit should not shut down on low battery. */
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/sansaview.h b/firmware/export/config/sansaview.h
index 829f67a..89da943 100644
--- a/firmware/export/config/sansaview.h
+++ b/firmware/export/config/sansaview.h
@@ -129,6 +129,8 @@
#define BATTERY_CAPACITY_INC 0 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Charging implemented in a target-specific algorithm */
#define CONFIG_CHARGING CHARGING_SIMPLE
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config/sdlapp.h b/firmware/export/config/sdlapp.h
index a55b7e3..ac43a0f 100644
--- a/firmware/export/config/sdlapp.h
+++ b/firmware/export/config/sdlapp.h
@@ -80,11 +80,6 @@
#define HAVE_SW_TONE_CONTROLS
-/* Define current usage levels. */
-#define CURRENT_NORMAL 88 /* 18 hours from a 1600 mAh battery */
-#define CURRENT_BACKLIGHT 30 /* TBD */
-#define CURRENT_RECORD 0 /* no recording yet */
-
/* Define this to the CPU frequency */
/*
#define CPU_FREQ 48000000
diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h
index f0c9f47..f565e61 100644
--- a/firmware/export/config/sim.h
+++ b/firmware/export/config/sim.h
@@ -36,6 +36,11 @@
#undef CONFIG_STORAGE
+#if defined(CONFIG_CHARGING) && CONFIG_CHARGING > CHARGING_MONITOR
+#undef CONFIG_CHARGING
+#define CONFIG_CHARGING CHARGING_MONITOR
+#endif
+
#undef CONFIG_USBOTG
#undef USB_HANDLED_BY_OF
diff --git a/firmware/export/config/tatungtpj1022.h b/firmware/export/config/tatungtpj1022.h
index 247ca47..15d5cf2 100644
--- a/firmware/export/config/tatungtpj1022.h
+++ b/firmware/export/config/tatungtpj1022.h
@@ -85,6 +85,8 @@
#define BATTERY_CAPACITY_INC 10 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging? FIXME */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/vibe500.h b/firmware/export/config/vibe500.h
index ad22990..da53005 100644
--- a/firmware/export/config/vibe500.h
+++ b/firmware/export/config/vibe500.h
@@ -126,6 +126,8 @@
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging, software can monitor plug and charge state */
#define CONFIG_CHARGING CHARGING_SIMPLE
diff --git a/firmware/export/config/zenvisionm30gb.h b/firmware/export/config/zenvisionm30gb.h
index 335257d..c644813 100644
--- a/firmware/export/config/zenvisionm30gb.h
+++ b/firmware/export/config/zenvisionm30gb.h
@@ -131,6 +131,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
//#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/config/zenvisionm60gb.h b/firmware/export/config/zenvisionm60gb.h
index 6235308..321dd5d 100644
--- a/firmware/export/config/zenvisionm60gb.h
+++ b/firmware/export/config/zenvisionm60gb.h
@@ -130,6 +130,8 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
/* Hardware controlled charging with monitoring */
//#define CONFIG_CHARGING CHARGING_MONITOR
diff --git a/firmware/export/power.h b/firmware/export/power.h
index 2aea20c..d46b9ba 100644
--- a/firmware/export/power.h
+++ b/firmware/export/power.h
@@ -23,7 +23,6 @@
#include "config.h"
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) || defined(SIMULATOR)
#if CONFIG_CHARGING
enum power_input_flags {
/* No external power source? Default. */
@@ -101,6 +100,4 @@
bool tuner_powered(void);
#endif
-#endif
-
#endif /* _POWER_H_ */
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 837767f..9e9d3d0 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -78,8 +78,6 @@
/* Start up power management thread */
void powermgmt_init(void) INIT_ATTR;
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
-
/* Generic current values that are intentionally meaningless - config header
* should define proper numbers.*/
@@ -130,13 +128,18 @@
extern const unsigned short percent_to_volt_charge[11];
#endif
-#endif /* PLATFORM_NATIVE */
-
-/* Returns battery statust */
+/* Returns battery status, filtered for runtime estimation */
int battery_level(void); /* percent */
int battery_time(void); /* minutes */
-unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */
-unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */
+int battery_voltage(void); /* filtered batt. voltage in millivolts */
+
+/* Implemented by the target, unfiltered */
+int _battery_level(void); /* percent */
+int _battery_time(void); /* minutes */
+int _battery_voltage(void); /* voltage in millivolts */
+#if CONFIG_CHARGING >= CHARGING_TARGET
+void powermgmt_init_target(void);
+#endif
#ifdef HAVE_BATTERY_SWITCH
unsigned int input_millivolts(void); /* voltage that device is running from */
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 008e4a4..b4f8aab 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -86,7 +86,14 @@
static int poweroff_timeout = 0;
static long last_event_tick = 0;
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
+#if (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE) == PERCENTAGE_MEASURE
+int _battery_voltage(void) { return -1; }
+
+const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11];
+const unsigned short percent_to_volt_charge[11];
+
+#elif (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE) == VOLTAGE_MEASURE
+int _battery_level(void) { return -1; }
/*
* Average battery voltage and charger voltage, filtered via a digital
* exponential filter (aka. exponential moving average, scaled):
@@ -95,10 +102,22 @@
static unsigned int avgbat;
/* filtered battery voltage, millivolts */
static unsigned int battery_millivolts;
+#elif (CONFIG_BATTERY_MEASURE == 0)
+int _battery_voltage(void) { return -1; }
+int _battery_level(void) { return -1; }
+
+const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11];
+const unsigned short percent_to_volt_charge[11];
+#endif
+
+#if !(CONFIG_BATTERY_MEASURE & TIME_MEASURE)
+static int powermgmt_est_runningtime_min;
+int _battery_time(void) { return powermgmt_est_runningtime_min; }
+#endif
+
/* default value, mAh */
static int battery_capacity = BATTERY_CAPACITY_DEFAULT;
-
#if BATTERY_TYPES_COUNT > 1
static int battery_type = 0;
#else
@@ -115,7 +134,6 @@
#endif
static const char power_thread_name[] = "power";
-static int powermgmt_est_runningtime_min = -1;
static int voltage_to_battery_level(int battery_millivolts);
static void battery_status_update(void);
@@ -126,13 +144,18 @@
void battery_read_info(int *voltage, int *level)
{
- int millivolts = battery_adc_voltage();
+ int millivolts = _battery_voltage();
+ int percent;
if (voltage)
*voltage = millivolts;
- if (level)
- *level = voltage_to_battery_level(millivolts);
+ if (level) {
+ percent = voltage_to_battery_level(millivolts);
+ if (percent < 0)
+ percent = _battery_level();
+ *level = percent;
+ }
}
#if BATTERY_TYPES_COUNT > 1
@@ -148,6 +171,7 @@
}
#endif
+#ifdef BATTERY_CAPACITY_MIN
void set_battery_capacity(int capacity)
{
if (capacity > BATTERY_CAPACITY_MAX)
@@ -159,6 +183,7 @@
battery_status_update(); /* recalculate the battery status */
}
+#endif
int get_battery_capacity(void)
{
@@ -167,7 +192,16 @@
int battery_time(void)
{
- return powermgmt_est_runningtime_min;
+#if ((CONFIG_BATTERY_MEASURE & TIME_MEASURE) == 0)
+
+#ifndef CURRENT_NORMAL /* no estimation without current */
+ return -1;
+#endif
+ if (battery_capacity <= 0) /* nor without capacity */
+ return -1;
+
+#endif
+ return _battery_time();
}
/* Returns battery level in percent */
@@ -180,17 +214,13 @@
return battery_percent;
}
-/* Returns filtered battery voltage [millivolts] */
-unsigned int battery_voltage(void)
-{
- return battery_millivolts;
-}
-
/* Tells if the battery level is safe for disk writes */
bool battery_level_safe(void)
{
#if defined(NO_LOW_BATTERY_SHUTDOWN)
return true;
+#elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
+ return (battery_percent > 0);
#elif defined(HAVE_BATTERY_SWITCH)
/* Cannot rely upon the battery reading to be valid and the
* device could be powered externally. */
@@ -228,6 +258,9 @@
{
int level;
+ if (battery_millivolts < 0)
+ return -1;
+
#if CONFIG_CHARGING >= CHARGING_MONITOR
if (charging_state()) {
/* battery level is defined to be < 100% until charging is finished */
@@ -249,7 +282,8 @@
static void battery_status_update(void)
{
- int level = voltage_to_battery_level(battery_millivolts);
+ int millivolt, level;
+ battery_read_info(&millivolt, &level);
#ifdef CURRENT_NORMAL /*don't try to estimate run or charge
time without normal current defined*/
@@ -264,7 +298,8 @@
#endif
/* discharging: remaining running time */
- if (battery_millivolts > percent_to_volt_discharge[0][0]) {
+ if (level > 0 && (millivolt > percent_to_volt_discharge[battery_type][0]
+ || millivolt < 0)) {
/* linear extrapolation */
powermgmt_est_runningtime_min = (level + battery_percent)*60
* battery_capacity / 200 / runcurrent();
@@ -272,8 +307,6 @@
if (0 > powermgmt_est_runningtime_min) {
powermgmt_est_runningtime_min = 0;
}
-#else
- powermgmt_est_runningtime_min=-1;
#endif
battery_percent = level;
@@ -348,6 +381,8 @@
{
#if defined(NO_LOW_BATTERY_SHUTDOWN)
return false;
+#elif CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE
+ return battery_percent == 0;
#elif defined(HAVE_BATTERY_SWITCH)
/* Cannot rely upon the battery reading to be valid and the
* device could be powered externally. */
@@ -490,6 +525,101 @@
}
#endif /* CONFIG_CHARGING */
+
+#if CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE
+/* Returns filtered battery voltage [millivolts] */
+int battery_voltage(void)
+{
+ return battery_millivolts;
+}
+
+static void average_init(void)
+{
+ /* initialize the voltages for the exponential filter */
+ avgbat = _battery_voltage() + 15;
+
+#ifdef HAVE_DISK_STORAGE /* this adjustment is only needed for HD based */
+ /* The battery voltage is usually a little lower directly after
+ turning on, because the disk was used heavily. Raise it by 5% */
+#if CONFIG_CHARGING
+ if (!charger_inserted()) /* only if charger not connected */
+#endif
+ {
+ avgbat += (percent_to_volt_discharge[battery_type][6] -
+ percent_to_volt_discharge[battery_type][5]) / 2;
+ }
+#endif /* HAVE_DISK_STORAGE */
+
+ avgbat = avgbat * BATT_AVE_SAMPLES;
+ battery_millivolts = power_history[0] = avgbat / BATT_AVE_SAMPLES;
+}
+
+static void average_step(void)
+{
+ avgbat += _battery_voltage() - avgbat / BATT_AVE_SAMPLES;
+ /*
+ * battery_millivolts is the millivolt-scaled filtered battery value.
+ */
+ battery_millivolts = avgbat / BATT_AVE_SAMPLES;
+}
+
+static void average_step_low(void)
+{
+ battery_millivolts = (_battery_voltage() + battery_millivolts + 1) / 2;
+ avgbat += battery_millivolts - avgbat / BATT_AVE_SAMPLES;
+}
+
+static void init_battery_percent(void)
+{
+#if CONFIG_CHARGING
+ if (charger_inserted()) {
+ battery_percent = voltage_to_percent(battery_millivolts,
+ percent_to_volt_charge);
+ }
+ else
+#endif
+ {
+ battery_percent = voltage_to_percent(battery_millivolts,
+ percent_to_volt_discharge[battery_type]);
+ battery_percent += battery_percent < 100;
+ }
+
+}
+
+static int power_hist_item(void)
+{
+ return battery_millivolts;
+}
+#define power_history_unit() battery_millivolts
+
+#else
+int battery_voltage(void)
+{
+ return -1;
+}
+
+static void average_init(void) {}
+static void average_step(void) {}
+static void average_step_low(void) {}
+static void init_battery_percent(void)
+{
+ battery_percent = _battery_level();
+}
+
+static int power_hist_item(void)
+{
+ return battery_percent;
+}
+#endif
+
+static void collect_power_history(void)
+{
+ /* rotate the power history */
+ memmove(&power_history[1], &power_history[0],
+ sizeof(power_history) - sizeof(power_history[0]));
+ power_history[0] = power_hist_item();
+}
+
/*
* Monitor the presence of a charger and perform critical frequent steps
* such as running the battery voltage filter.
@@ -519,33 +649,23 @@
|| charger_input_state == CHARGER
#endif
) {
- avgbat += battery_adc_voltage() - avgbat / BATT_AVE_SAMPLES;
- /*
- * battery_millivolts is the millivolt-scaled filtered battery value.
- */
- battery_millivolts = avgbat / BATT_AVE_SAMPLES;
-
+ average_step();
/* update battery status every time an update is available */
battery_status_update();
}
else if (battery_percent < 8) {
+ average_step_low();
+ /* update battery status every time an update is available */
+ battery_status_update();
+
/*
* If battery is low, observe voltage during disk activity.
* Shut down if voltage drops below shutoff level and we are not
* using NiMH or Alkaline batteries.
*/
- battery_millivolts = (battery_adc_voltage() +
- battery_millivolts + 1) / 2;
-
- /* update battery status every time an update is available */
- battery_status_update();
-
if (!shutdown_timeout && query_force_shutdown()) {
sys_poweroff();
}
- else {
- avgbat += battery_millivolts - avgbat / BATT_AVE_SAMPLES;
- }
}
} /* power_thread_step */
@@ -555,7 +675,7 @@
/* Delay reading the first battery level */
#ifdef MROBE_100
- while (battery_adc_voltage() > 4200) /* gives false readings initially */
+ while (_battery_voltage() > 4200) /* gives false readings initially */
#endif
{
sleep(HZ/100);
@@ -566,38 +686,13 @@
power_thread_inputs = power_input_status();
#endif
- /* initialize the voltages for the exponential filter */
- avgbat = battery_adc_voltage() + 15;
-
-#ifdef HAVE_DISK_STORAGE /* this adjustment is only needed for HD based */
- /* The battery voltage is usually a little lower directly after
- turning on, because the disk was used heavily. Raise it by 5% */
-#if CONFIG_CHARGING
- if (!charger_inserted()) /* only if charger not connected */
-#endif
- {
- avgbat += (percent_to_volt_discharge[battery_type][6] -
- percent_to_volt_discharge[battery_type][5]) / 2;
- }
-#endif /* HAVE_DISK_STORAGE */
-
- avgbat = avgbat * BATT_AVE_SAMPLES;
- battery_millivolts = avgbat / BATT_AVE_SAMPLES;
- power_history[0] = battery_millivolts;
-
-#if CONFIG_CHARGING
- if (charger_inserted()) {
- battery_percent = voltage_to_percent(battery_millivolts,
- percent_to_volt_charge);
- }
- else
-#endif
- {
- battery_percent = voltage_to_percent(battery_millivolts,
- percent_to_volt_discharge[battery_type]);
- battery_percent += battery_percent < 100;
- }
-
+ /* initialize voltage averaging (if available) */
+ average_init();
+ /* get initial battery level value (in %) */
+ init_battery_percent();
+ /* get some initial data for the power curve */
+ collect_power_history();
+ /* call target specific init now */
powermgmt_init_target();
next_power_hist = current_tick + HZ*60;
@@ -609,7 +704,7 @@
#ifdef HAVE_BATTERY_SWITCH
if ((pwr ^ power_thread_inputs) & POWER_INPUT_BATTERY) {
sleep(HZ/10);
- reset_battery_filter(battery_adc_voltage());
+ reset_battery_filter(_battery_voltage());
}
#endif
power_thread_inputs = pwr;
@@ -627,21 +722,15 @@
/* Perform target tasks */
charging_algorithm_step();
- if (TIME_BEFORE(current_tick, next_power_hist))
- continue;
-
- /* increment to ensure there is a record for every minute
- * rather than go forward from the current tick */
- next_power_hist += HZ*60;
-
- /* rotate the power history */
- memmove(&power_history[1], &power_history[0],
- sizeof(power_history) - sizeof(power_history[0]));
-
- /* insert new value at the start, in millivolts 8-) */
- power_history[0] = battery_millivolts;
-
+ /* check if some idle or sleep timer wears off */
handle_auto_poweroff();
+
+ if (TIME_AFTER(current_tick, next_power_hist)) {
+ /* increment to ensure there is a record for every minute
+ * rather than go forward from the current tick */
+ next_power_hist += HZ*60;
+ collect_power_history();
+ }
}
} /* power_thread */
@@ -701,7 +790,6 @@
sleep(HZ/4);
power_off();
}
-#endif /* PLATFORM_NATIVE */
void set_poweroff_timeout(int timeout)
{
@@ -855,12 +943,10 @@
last_event_tick = current_tick;
}
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0)
if (!shutdown_timeout && query_force_shutdown()) {
backlight_on();
sys_poweroff();
}
-#endif
if (timeout &&
#if CONFIG_TUNER
diff --git a/firmware/target/arm/as3525/sansa-m200v4/powermgmt-m200v4.c b/firmware/target/arm/as3525/sansa-m200v4/powermgmt-m200v4.c
index cbd2c4b..829ed36 100644
--- a/firmware/target/arm/as3525/sansa-m200v4/powermgmt-m200v4.c
+++ b/firmware/target/arm/as3525/sansa-m200v4/powermgmt-m200v4.c
@@ -52,7 +52,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_VBAT) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/imx233/debug-imx233.c b/firmware/target/arm/imx233/debug-imx233.c
index 228d2ab..82ad86f 100644
--- a/firmware/target/arm/imx233/debug-imx233.c
+++ b/firmware/target/arm/imx233/debug-imx233.c
@@ -153,7 +153,7 @@
lcd_clear_display();
/* add battery readout in mV, this it is not the direct output of a channel */
- lcd_putsf(0, 0, "Battery(mV) %d", battery_adc_voltage());
+ lcd_putsf(0, 0, "Battery(mV) %d", _battery_voltage());
for(unsigned i = 0; i < NUM_ADC_CHANNELS; i++)
{
lcd_putsf(0, i + 1, "%s %d", imx233_adc_channel_name[i],
diff --git a/firmware/target/arm/imx233/powermgmt-imx233.c b/firmware/target/arm/imx233/powermgmt-imx233.c
index 87c48e7..0f3336d 100644
--- a/firmware/target/arm/imx233/powermgmt-imx233.c
+++ b/firmware/target/arm/imx233/powermgmt-imx233.c
@@ -38,7 +38,7 @@
static int timeout_4p2_ilimit_increase; /* timeout before increasing 4p2 ilimit */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
/* battery value is in 8mV LSB */
return __XTRACT(HW_POWER_BATTMONITOR, BATT_VAL) * 8;
diff --git a/firmware/target/arm/imx31/gigabeat-s/powermgmt-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/powermgmt-gigabeat-s.c
index d87e367..1a8e121 100644
--- a/firmware/target/arm/imx31/gigabeat-s/powermgmt-gigabeat-s.c
+++ b/firmware/target/arm/imx31/gigabeat-s/powermgmt-gigabeat-s.c
@@ -53,7 +53,7 @@
};
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
/* ADC reading 0-1023 = 2400mV-4700mV */
return ((adc_read(ADC_BATTERY) * 2303) >> 10) + 2400;
@@ -249,7 +249,7 @@
switch (type)
{
case ADC_BATTERY:
- reading = battery_adc_voltage();
+ reading = _battery_voltage();
break;
case ADC_CHARGER_CURRENT:
@@ -780,7 +780,7 @@
/* Battery voltage may have dropped and a charge cycle should
* start again. Debounced. */
if (autorecharge_counter < 0 &&
- battery_adc_voltage() < BATT_FULL_VOLTAGE)
+ _battery_voltage() < BATT_FULL_VOLTAGE)
{
/* Try starting a cycle now if battery isn't already topped
* off to allow user to ensure the battery is full. */
diff --git a/firmware/target/arm/ipod/1g2g/powermgmt-1g2g.c b/firmware/target/arm/ipod/1g2g/powermgmt-1g2g.c
index 1bc5de9..c3eca14 100644
--- a/firmware/target/arm/ipod/1g2g/powermgmt-1g2g.c
+++ b/firmware/target/arm/ipod/1g2g/powermgmt-1g2g.c
@@ -57,7 +57,7 @@
/* full-scale ADC readout (2^8) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
unsigned adcval = adc_read(ADC_UNREG_POWER);
diff --git a/firmware/target/arm/ipod/powermgmt-ipod-pcf.c b/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
index 44e908a..1241f47 100644
--- a/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
+++ b/firmware/target/arm/ipod/powermgmt-ipod-pcf.c
@@ -109,7 +109,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/iriver/h10/powermgmt-h10.c b/firmware/target/arm/iriver/h10/powermgmt-h10.c
index 9970c29..c20d802 100644
--- a/firmware/target/arm/iriver/h10/powermgmt-h10.c
+++ b/firmware/target/arm/iriver/h10/powermgmt-h10.c
@@ -67,7 +67,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c b/firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c
index c8d5584..ae33fc5 100644
--- a/firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c
+++ b/firmware/target/arm/olympus/mrobe-100/powermgmt-mr100.c
@@ -58,7 +58,7 @@
*/
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/pbell/vibe500/powermgmt-vibe500.c b/firmware/target/arm/pbell/vibe500/powermgmt-vibe500.c
index d84881c..dbd7d8c 100644
--- a/firmware/target/arm/pbell/vibe500/powermgmt-vibe500.c
+++ b/firmware/target/arm/pbell/vibe500/powermgmt-vibe500.c
@@ -51,7 +51,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/philips/hdd1630/powermgmt-hdd1630.c b/firmware/target/arm/philips/hdd1630/powermgmt-hdd1630.c
index 8090c62..7d13252 100644
--- a/firmware/target/arm/philips/hdd1630/powermgmt-hdd1630.c
+++ b/firmware/target/arm/philips/hdd1630/powermgmt-hdd1630.c
@@ -57,7 +57,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
/* return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; */
diff --git a/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c b/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
index 8090c62..7d13252 100644
--- a/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
+++ b/firmware/target/arm/philips/hdd6330/powermgmt-hdd6330.c
@@ -57,7 +57,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
/* return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; */
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c
index 76646d3..4ce90a4 100644
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c
+++ b/firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c
@@ -48,7 +48,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/powermgmt-ascodec.c b/firmware/target/arm/powermgmt-ascodec.c
index 3232a9a..c05fc7b 100644
--- a/firmware/target/arm/powermgmt-ascodec.c
+++ b/firmware/target/arm/powermgmt-ascodec.c
@@ -67,7 +67,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * 5125 + 512) >> 10;
}
@@ -85,7 +85,7 @@
unsigned int mv;
for (i = 0, mv = 0; i < 5; i++)
- mv += battery_adc_voltage();
+ mv += _battery_voltage();
reset_battery_filter(mv / 5);
}
diff --git a/firmware/target/arm/rk27xx/hm60x/powermgmt-hm60x.c b/firmware/target/arm/rk27xx/hm60x/powermgmt-hm60x.c
index 7b5b171..6ab7616 100644
--- a/firmware/target/arm/rk27xx/hm60x/powermgmt-hm60x.c
+++ b/firmware/target/arm/rk27xx/hm60x/powermgmt-hm60x.c
@@ -60,7 +60,7 @@
#define BATTERY_SCALE_FACTOR 6000
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c b/firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c
index a815d89..dc555be 100644
--- a/firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c
+++ b/firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c
@@ -54,7 +54,7 @@
/* TODO: simple uncalibrated curve */
{ 425, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520 };
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return adc_read(ADC_BATTERY);
}
diff --git a/firmware/target/arm/rk27xx/rk27generic/powermgmt-rk27generic.c b/firmware/target/arm/rk27xx/rk27generic/powermgmt-rk27generic.c
index 3960dab..ccbc098 100644
--- a/firmware/target/arm/rk27xx/rk27generic/powermgmt-rk27generic.c
+++ b/firmware/target/arm/rk27xx/rk27generic/powermgmt-rk27generic.c
@@ -60,7 +60,7 @@
#define BATTERY_SCALE_FACTOR 6000
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/powermgmt-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/powermgmt-meg-fx.c
index 49f7e2e..4cc43d0 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/powermgmt-meg-fx.c
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/powermgmt-meg-fx.c
@@ -54,7 +54,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/s3c2440/mini2440/powermgmt-mini2440.c b/firmware/target/arm/s3c2440/mini2440/powermgmt-mini2440.c
index 5281b10..9a05cd3 100644
--- a/firmware/target/arm/s3c2440/mini2440/powermgmt-mini2440.c
+++ b/firmware/target/arm/s3c2440/mini2440/powermgmt-mini2440.c
@@ -52,7 +52,7 @@
/* Returns battery voltage from ADC [millivolts] */
/* full-scale (2^10) in millivolt */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
/* Since we have no battery, return a fully charged value */
return 4000 * 1024 / 1000;
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c
index 52491cf..647c13e 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/powermgmt-nano2g.c
@@ -55,7 +55,7 @@
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
int compensation = (10 * (pmu_read_battery_current() - 7)) / 12;
if (charging_state()) return pmu_read_battery_voltage() - compensation;
diff --git a/firmware/target/arm/s5l8700/meizu-m3/powermgmt-m3.c b/firmware/target/arm/s5l8700/meizu-m3/powermgmt-m3.c
index 3960dab..ccbc098 100644
--- a/firmware/target/arm/s5l8700/meizu-m3/powermgmt-m3.c
+++ b/firmware/target/arm/s5l8700/meizu-m3/powermgmt-m3.c
@@ -60,7 +60,7 @@
#define BATTERY_SCALE_FACTOR 6000
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/s5l8700/meizu-m6sp/powermgmt-m6sp.c b/firmware/target/arm/s5l8700/meizu-m6sp/powermgmt-m6sp.c
index 86b6e46..b59d0fa 100644
--- a/firmware/target/arm/s5l8700/meizu-m6sp/powermgmt-m6sp.c
+++ b/firmware/target/arm/s5l8700/meizu-m6sp/powermgmt-m6sp.c
@@ -58,7 +58,7 @@
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c
index 6caeafd..b88ac16 100644
--- a/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c
@@ -55,7 +55,7 @@
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
int compensation = (10 * (pmu_read_battery_current() - 7)) / 12;
if (charging_state()) return pmu_read_battery_voltage() - compensation;
diff --git a/firmware/target/arm/samsung/yh820/powermgmt-yh820.c b/firmware/target/arm/samsung/yh820/powermgmt-yh820.c
index 4955904..180194c 100644
--- a/firmware/target/arm/samsung/yh820/powermgmt-yh820.c
+++ b/firmware/target/arm/samsung/yh820/powermgmt-yh820.c
@@ -52,7 +52,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
/* return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10; */
return 4100;
diff --git a/firmware/target/arm/samsung/yh920/powermgmt-yh920.c b/firmware/target/arm/samsung/yh920/powermgmt-yh920.c
index 0ea3c5d..f33afb3 100644
--- a/firmware/target/arm/samsung/yh920/powermgmt-yh920.c
+++ b/firmware/target/arm/samsung/yh920/powermgmt-yh920.c
@@ -52,7 +52,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/samsung/yh925/powermgmt-yh925.c b/firmware/target/arm/samsung/yh925/powermgmt-yh925.c
index 3eb5dd6..ab9cbcd 100644
--- a/firmware/target/arm/samsung/yh925/powermgmt-yh925.c
+++ b/firmware/target/arm/samsung/yh925/powermgmt-yh925.c
@@ -52,7 +52,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/sandisk/sansa-view/powermgmt-view.c b/firmware/target/arm/sandisk/sansa-view/powermgmt-view.c
index 459b60d..870a883 100644
--- a/firmware/target/arm/sandisk/sansa-view/powermgmt-view.c
+++ b/firmware/target/arm/sandisk/sansa-view/powermgmt-view.c
@@ -23,7 +23,7 @@
#include "adc.h"
#include "powermgmt.h"
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return 0;
}
diff --git a/firmware/target/arm/tatung/tpj1022/powermgmt-tpj1022.c b/firmware/target/arm/tatung/tpj1022/powermgmt-tpj1022.c
index ef7919d..cc91012 100644
--- a/firmware/target/arm/tatung/tpj1022/powermgmt-tpj1022.c
+++ b/firmware/target/arm/tatung/tpj1022/powermgmt-tpj1022.c
@@ -56,7 +56,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c
index 9b65bbd..bc7ead6 100644
--- a/firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c
+++ b/firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c
@@ -59,7 +59,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
static unsigned last_tick = 0;
diff --git a/firmware/target/arm/tcc77x/powermgmt-tcc77x.c b/firmware/target/arm/tcc77x/powermgmt-tcc77x.c
index 90c66d3..07a5677 100644
--- a/firmware/target/arm/tcc77x/powermgmt-tcc77x.c
+++ b/firmware/target/arm/tcc77x/powermgmt-tcc77x.c
@@ -59,7 +59,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return current_voltage;
}
diff --git a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c
index 9b2320b..91361fe 100644
--- a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c
+++ b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c
@@ -61,7 +61,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
static unsigned last_tick = 0;
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c
index a6d1934..23ee9c6 100644
--- a/firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c
+++ b/firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c
@@ -50,7 +50,7 @@
};
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return current_voltage;
}
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c
index 5da0369..78f9bbb 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/powermgmt-mr500.c
@@ -60,7 +60,7 @@
};
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
short bat1, bat2, aux;
static unsigned last_tick = 0;
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c
index c42f56b..8b3f051 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c
@@ -53,7 +53,7 @@
};
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return current_battery_level;
}
diff --git a/firmware/target/coldfire/iaudio/m3/powermgmt-m3.c b/firmware/target/coldfire/iaudio/m3/powermgmt-m3.c
index bb8f5cf..b97d691 100644
--- a/firmware/target/coldfire/iaudio/m3/powermgmt-m3.c
+++ b/firmware/target/coldfire/iaudio/m3/powermgmt-m3.c
@@ -52,7 +52,7 @@
/* full-scale ADC readout (2^8) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 8;
}
diff --git a/firmware/target/coldfire/iaudio/powermgmt-iaudio.c b/firmware/target/coldfire/iaudio/powermgmt-iaudio.c
index 4bfea20..5691526 100644
--- a/firmware/target/coldfire/iaudio/powermgmt-iaudio.c
+++ b/firmware/target/coldfire/iaudio/powermgmt-iaudio.c
@@ -53,7 +53,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/coldfire/iriver/h100/powermgmt-h100.c b/firmware/target/coldfire/iriver/h100/powermgmt-h100.c
index e238711..20e1a88 100644
--- a/firmware/target/coldfire/iriver/h100/powermgmt-h100.c
+++ b/firmware/target/coldfire/iriver/h100/powermgmt-h100.c
@@ -53,7 +53,7 @@
/* full-scale ADC readout (2^8) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 8;
}
diff --git a/firmware/target/coldfire/iriver/h300/powermgmt-h300.c b/firmware/target/coldfire/iriver/h300/powermgmt-h300.c
index 95a5741..00aad31 100644
--- a/firmware/target/coldfire/iriver/h300/powermgmt-h300.c
+++ b/firmware/target/coldfire/iriver/h300/powermgmt-h300.c
@@ -53,7 +53,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c b/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c
index 9d95938..964d551 100644
--- a/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c
+++ b/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c
@@ -51,7 +51,7 @@
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 11;
}
diff --git a/firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c b/firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c
index bdfe9b5..ffd0190 100644
--- a/firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c
+++ b/firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c
@@ -51,7 +51,7 @@
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 11;
}
diff --git a/firmware/target/hosted/android/powermgmt-android.c b/firmware/target/hosted/android/powermgmt-android.c
index dcbd7a6..1e70a81 100644
--- a/firmware/target/hosted/android/powermgmt-android.c
+++ b/firmware/target/hosted/android/powermgmt-android.c
@@ -28,10 +28,10 @@
extern jclass RockboxService_class;
extern jobject RockboxService_instance;
-static jfieldID _battery_level;
+static jfieldID __battery_level;
static jobject BatteryMonitor_instance;
-void powermgmt_init_target(void)
+static void new_battery_monitor(void)
{
JNIEnv e = *env_ptr;
jclass class = e->FindClass(env_ptr, "org/rockbox/monitors/BatteryMonitor");
@@ -43,29 +43,15 @@
RockboxService_instance);
/* cache the battery level field id */
- _battery_level = (*env_ptr)->GetFieldID(env_ptr,
+ __battery_level = (*env_ptr)->GetFieldID(env_ptr,
class,
"mBattLevel", "I");
}
-int battery_level(void)
+int _battery_level(void)
{
- return (*env_ptr)->GetIntField(env_ptr, BatteryMonitor_instance, _battery_level);
+ if (!BatteryMonitor_instance)
+ new_battery_monitor();
+ return (*env_ptr)->GetIntField(env_ptr, BatteryMonitor_instance, __battery_level);
}
-int battery_time(void)
-{ /* cannot calculate yet */
- return 0;
-}
-
-/* should always be safe on android targets, the host shuts us down before */
-bool battery_level_safe(void)
-{
- return true;
-}
-
-/* TODO */
-unsigned battery_voltage(void)
-{
- return 0;
-}
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
index fba7ff4..e48e910 100644
--- a/firmware/target/hosted/android/system-android.c
+++ b/firmware/target/hosted/android/system-android.c
@@ -45,7 +45,7 @@
/* this is used to return from the entry point of the native library. */
static jmp_buf poweroff_buf;
-void shutdown_hw(void)
+void power_off(void)
{
longjmp(poweroff_buf, 1);
}
diff --git a/firmware/target/hosted/maemo/maemo-thread.c b/firmware/target/hosted/maemo/maemo-thread.c
index a32a563..2f1d033 100644
--- a/firmware/target/hosted/maemo/maemo-thread.c
+++ b/firmware/target/hosted/maemo/maemo-thread.c
@@ -163,40 +163,14 @@
return 0;
}
-/** Rockbox battery related functions */
-void battery_status_update(void)
-{
- battery_percent = maemo_battery_level;
- send_battery_level_event();
-}
-
-/* Returns true if any power input is connected - charging-capable
- * or not. */
-bool power_input_present(void)
-{
- return false;
-}
-
-unsigned battery_voltage(void)
-{
- return 0;
-}
-
/* Returns battery level in percent */
-int battery_level(void)
+int _battery_level(void)
{
- battery_status_update();
return maemo_battery_level;
}
/* Return remaining battery time in minutes */
-int battery_time(void)
+int _battery_time(void)
{
- battery_status_update();
return maemo_remaining_time_sec / 60;
}
-
-bool battery_level_safe(void)
-{
- return battery_level() >= 5;
-}
diff --git a/firmware/target/hosted/powermgmt.c b/firmware/target/hosted/powermgmt.c
deleted file mode 100644
index bf05e5f..0000000
--- a/firmware/target/hosted/powermgmt.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2011 by Thomas Jarosch
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "powermgmt.h"
-#include "thread.h"
-#include "kernel.h"
-
-static char power_stack[DEFAULT_STACK_SIZE];
-static const char power_thread_name[] = "power";
-
-void powermgmt_init_target(void);
-
-#if !(CONFIG_PLATFORM & PLATFORM_ANDROID)
-void powermgmt_init_target(void)
-{
- /* Nothing to do */
-}
-#endif
-
-static void power_thread(void)
-{
- powermgmt_init_target();
-
- while (1)
- {
- /* Sleep two seconds */
- sleep(HZ*2);
-
- handle_auto_poweroff();
- }
-} /* power_thread */
-
-void powermgmt_init(void)
-{
- create_thread(power_thread, power_stack, sizeof(power_stack), 0,
- power_thread_name IF_PRIO(, PRIORITY_SYSTEM)
- IF_COP(, CPU));
-}
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index 93a8a7c..87b2e0c 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -196,7 +196,7 @@
return 0;
}
-void shutdown_hw(void)
+void power_off(void)
{
/* Shut down SDL event loop */
SDL_Event event;
diff --git a/firmware/target/hosted/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
index 0c162a6..9c90f7e 100644
--- a/firmware/target/hosted/ypr0/powermgmt-ypr0.c
+++ b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
@@ -70,7 +70,7 @@
/* Returns battery voltage from ADC [millivolts],
* adc returns voltage in 5mV steps */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return adc_read(3) * 5;
}
@@ -80,5 +80,5 @@
const unsigned short charged_thres = 4170;
bool ret = (power_input_status() == POWER_INPUT_MAIN_CHARGER);
/* dont indicate for > ~95% */
- return ret && (battery_adc_voltage() <= charged_thres);
+ return ret && (_battery_voltage() <= charged_thres);
}
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c
index 99d73fa..e6f0cd9 100644
--- a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c
+++ b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c
@@ -102,7 +102,7 @@
#define BATTERY_SCALE_FACTOR 7500
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
unsigned int dummy, bat_val;
diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c b/firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c
index 98dbf08..710da6b 100644
--- a/firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c
+++ b/firmware/target/mips/ingenic_jz47xx/onda_vx767/sadc-onda_vx767.c
@@ -67,7 +67,7 @@
#define BATTERY_SCALE_FACTOR 1875
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
unsigned int dummy, timeout=HZ/4;
diff --git a/firmware/target/sh/archos/fm_v2/powermgmt-fm_v2.c b/firmware/target/sh/archos/fm_v2/powermgmt-fm_v2.c
index 20596dd..5dd7f26 100644
--- a/firmware/target/sh/archos/fm_v2/powermgmt-fm_v2.c
+++ b/firmware/target/sh/archos/fm_v2/powermgmt-fm_v2.c
@@ -54,7 +54,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/sh/archos/ondio/powermgmt-ondio.c b/firmware/target/sh/archos/ondio/powermgmt-ondio.c
index dc0c37b..dc3cab0 100644
--- a/firmware/target/sh/archos/ondio/powermgmt-ondio.c
+++ b/firmware/target/sh/archos/ondio/powermgmt-ondio.c
@@ -46,7 +46,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/sh/archos/player/powermgmt-player.c b/firmware/target/sh/archos/player/powermgmt-player.c
index b9a4fe3..8aa03d8 100644
--- a/firmware/target/sh/archos/player/powermgmt-player.c
+++ b/firmware/target/sh/archos/player/powermgmt-player.c
@@ -56,7 +56,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/firmware/target/sh/archos/recorder/powermgmt-recorder.c b/firmware/target/sh/archos/recorder/powermgmt-recorder.c
index 47f0093..0bce158 100644
--- a/firmware/target/sh/archos/recorder/powermgmt-recorder.c
+++ b/firmware/target/sh/archos/recorder/powermgmt-recorder.c
@@ -60,7 +60,7 @@
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */
-unsigned int battery_adc_voltage(void)
+int _battery_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
}
diff --git a/uisimulator/common/SOURCES b/uisimulator/common/SOURCES
index a632706..939f163 100644
--- a/uisimulator/common/SOURCES
+++ b/uisimulator/common/SOURCES
@@ -9,10 +9,7 @@
fmradio.c
backlight-sim.c
stubs.c
+powermgmt-sim.c
#endif
io.c
-/* this is still needed for application since it has some stubs */
-#if !(CONFIG_PLATFORM & PLATFORM_MAEMO)
-powermgmt-sim.c
-#endif
diff --git a/uisimulator/common/lcd-common.c b/uisimulator/common/lcd-common.c
index 2acf4b3..47ca114 100644
--- a/uisimulator/common/lcd-common.c
+++ b/uisimulator/common/lcd-common.c
@@ -119,3 +119,9 @@
return retval;
}
#endif
+
+#ifdef HAVE_LCD_SHUTDOWN
+void lcd_shutdown(void)
+{
+}
+#endif
diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c
index e747d7d..2d9acab 100644
--- a/uisimulator/common/powermgmt-sim.c
+++ b/uisimulator/common/powermgmt-sim.c
@@ -24,24 +24,25 @@
#include <time.h>
#include "kernel.h"
#include "powermgmt.h"
+#include "power.h"
-#define BATT_MINMVOLT 2500 /* minimum millivolts of battery */
-#define BATT_MAXMVOLT 4500 /* maximum millivolts of battery */
+#define BATT_MINMVOLT 3300 /* minimum millivolts of battery */
+#define BATT_MAXMVOLT 4300 /* maximum millivolts of battery */
#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
minutes */
extern void send_battery_level_event(void);
extern int last_sent_battery_level;
extern int battery_percent;
+static bool charging = false;
static unsigned int battery_millivolts = BATT_MAXMVOLT;
-/* estimated remaining time in minutes */
-static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME;
+
+void powermgmt_init_target(void) {}
static void battery_status_update(void)
{
static time_t last_change = 0;
- static bool charging = false;
time_t now;
time(&now);
@@ -76,57 +77,34 @@
battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
(BATT_MAXMVOLT - BATT_MINMVOLT);
-
- powermgmt_est_runningtime_min =
- battery_percent * BATT_MAXRUNTIME / 100;
}
-
- send_battery_level_event();
}
-void battery_read_info(int *voltage, int *level)
-{
- battery_status_update();
+const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = { 3200 };
+const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = { 3200 };
- if (voltage)
- *voltage = battery_millivolts;
+/* make the simulated curve nicely linear */
+const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
+{ { 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 } };
+const unsigned short percent_to_volt_charge[11] =
+{ 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300 };
- if (level)
- *level = battery_percent;
-}
-unsigned int battery_voltage(void)
+int _battery_voltage(void)
{
battery_status_update();
return battery_millivolts;
}
-int battery_level(void)
+#if CONFIG_CHARGING
+unsigned int power_input_status(void)
{
- battery_status_update();
- return battery_percent;
+ return charging ? POWER_INPUT_NONE : POWER_INPUT_MAIN;
}
-int battery_time(void)
+bool charging_state(void)
{
- battery_status_update();
- return powermgmt_est_runningtime_min;
-}
-
-bool battery_level_safe(void)
-{
- return battery_level() >= 10;
-}
-
-void set_battery_capacity(int capacity)
-{
- (void)capacity;
-}
-
-#if BATTERY_TYPES_COUNT > 1
-void set_battery_type(int type)
-{
- (void)type;
+ return charging;
}
#endif
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index f8b8fdc..ba4faff 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -317,32 +317,6 @@
}
#endif
-#if CONFIG_CHARGING
-bool charger_inserted(void)
-{
- return false;
-}
-
-bool power_input_present(void)
-{
- return false;
-}
-
-unsigned int power_input_status(void)
-{
-#ifdef HAVE_BATTERY_SWITCH
- return POWER_INPUT_BATTERY;
-#else
- return POWER_INPUT_NONE;
-#endif
-}
-
-bool charging_state(void)
-{
- return false;
-}
-#endif /* CONFIG_CHARGING */
-
#ifndef USB_NONE
bool usb_inserted(void)
{