diff options
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 50b734bbbd..f18ea3c636 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -112,6 +112,20 @@ static void battery_status_update(void) | |||
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | void battery_read_info(int *adc, int *voltage, int *level) | ||
116 | { | ||
117 | battery_status_update(); | ||
118 | |||
119 | if (adc) | ||
120 | *adc = batt_centivolts*10000 / BATTERY_SCALE_FACTOR; | ||
121 | |||
122 | if (voltage) | ||
123 | *voltage = batt_centivolts; | ||
124 | |||
125 | if (level) | ||
126 | *level = batt_level; | ||
127 | } | ||
128 | |||
115 | unsigned int battery_voltage(void) | 129 | unsigned int battery_voltage(void) |
116 | { | 130 | { |
117 | battery_status_update(); | 131 | battery_status_update(); |
@@ -167,6 +181,8 @@ static const unsigned int battery_level_dangerous[BATTERY_TYPES_COUNT] = | |||
167 | 105, 115 /* alkaline, NiHM */ | 181 | 105, 115 /* alkaline, NiHM */ |
168 | #elif CONFIG_BATTERY == BATT_LIPOL1300 /* iRiver H1x0 */ | 182 | #elif CONFIG_BATTERY == BATT_LIPOL1300 /* iRiver H1x0 */ |
169 | 339 | 183 | 339 |
184 | #elif CONFIG_BATTERY == BATT_IAUDIO_X5 | ||
185 | 354 | ||
170 | #elif CONFIG_BATTERY == BATT_LPCS355385 /* iriver H10 20GB */ | 186 | #elif CONFIG_BATTERY == BATT_LPCS355385 /* iriver H10 20GB */ |
171 | 376 | 187 | 376 |
172 | #elif CONFIG_BATTERY == BATT_BP009 /* iriver H10 5/6GB */ | 188 | #elif CONFIG_BATTERY == BATT_BP009 /* iriver H10 5/6GB */ |
@@ -192,6 +208,13 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | |||
192 | * for the 1300 mAh stock battery. */ | 208 | * for the 1300 mAh stock battery. */ |
193 | // { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 } | 209 | // { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 } |
194 | { 337, 366, 372, 374, 378, 381, 385, 392, 399, 408, 417 } | 210 | { 337, 366, 372, 374, 378, 381, 385, 392, 399, 408, 417 } |
211 | #elif CONFIG_BATTERY == BATT_IAUDIO_X5 | ||
212 | /* iAudio x5 series - still experimenting with best curve */ | ||
213 | // Lithium ion discharge curve | ||
214 | { 355, 356, 357, 359, 362, 365, 369, 374, 380, 387, 395 } | ||
215 | // Linear | ||
216 | // { 355, 360, 364, 369, 373, 378, 382, 387, 391, 390, 400 } | ||
217 | // { 355, 359, 363, 367, 371, 375, 379, 383, 387, 391, 395 } | ||
195 | #elif CONFIG_BATTERY == BATT_LPCS355385 | 218 | #elif CONFIG_BATTERY == BATT_LPCS355385 |
196 | /* iriver H10 20GB */ | 219 | /* iriver H10 20GB */ |
197 | { 376, 380, 385, 387, 390, 395, 402, 407, 411, 418, 424 } | 220 | { 376, 380, 385, 387, 390, 395, 402, 407, 411, 418, 424 } |
@@ -289,9 +312,25 @@ static long sleeptimer_endtick; | |||
289 | 312 | ||
290 | static long last_event_tick; | 313 | static long last_event_tick; |
291 | 314 | ||
315 | static int voltage_to_battery_level(int battery_centivolts); | ||
292 | static void battery_status_update(void); | 316 | static void battery_status_update(void); |
293 | static int runcurrent(void); | 317 | static int runcurrent(void); |
294 | 318 | ||
319 | void battery_read_info(int *adc, int *voltage, int *level) | ||
320 | { | ||
321 | int adc_battery = adc_read(ADC_UNREG_POWER); | ||
322 | int centivolts = adc_battery*BATTERY_SCALE_FACTOR / 10000; | ||
323 | |||
324 | if (adc) | ||
325 | *adc = adc_battery; | ||
326 | |||
327 | if (voltage) | ||
328 | *voltage = centivolts; | ||
329 | |||
330 | if (level) | ||
331 | *level = voltage_to_battery_level(centivolts); | ||
332 | } | ||
333 | |||
295 | unsigned int battery_voltage(void) | 334 | unsigned int battery_voltage(void) |
296 | { | 335 | { |
297 | return battery_centivolts; | 336 | return battery_centivolts; |
@@ -387,14 +426,14 @@ static int voltage_to_percent(int voltage, const short* table) | |||
387 | 426 | ||
388 | /* update battery level and estimated runtime, called once per minute or | 427 | /* update battery level and estimated runtime, called once per minute or |
389 | * when battery capacity / type settings are changed */ | 428 | * when battery capacity / type settings are changed */ |
390 | static void battery_status_update(void) | 429 | static int voltage_to_battery_level(int battery_centivolts) |
391 | { | 430 | { |
392 | int level; | 431 | int level; |
393 | 432 | ||
394 | #if CONFIG_CHARGING >= CHARGING_MONITOR | 433 | #if CONFIG_CHARGING >= CHARGING_MONITOR |
395 | if (charge_state == DISCHARGING) { | 434 | if (charge_state == DISCHARGING) { |
396 | level = voltage_to_percent(battery_centivolts, | 435 | level = voltage_to_percent(battery_centivolts, |
397 | percent_to_volt_discharge[battery_type]); | 436 | percent_to_volt_discharge[battery_type]); |
398 | } | 437 | } |
399 | else if (charge_state == CHARGING) { | 438 | else if (charge_state == CHARGING) { |
400 | /* battery level is defined to be < 100% until charging is finished */ | 439 | /* battery level is defined to be < 100% until charging is finished */ |
@@ -407,9 +446,16 @@ static void battery_status_update(void) | |||
407 | #else | 446 | #else |
408 | /* always use the discharge table */ | 447 | /* always use the discharge table */ |
409 | level = voltage_to_percent(battery_centivolts, | 448 | level = voltage_to_percent(battery_centivolts, |
410 | percent_to_volt_discharge[battery_type]); | 449 | percent_to_volt_discharge[battery_type]); |
411 | #endif | 450 | #endif |
412 | 451 | ||
452 | return level; | ||
453 | } | ||
454 | |||
455 | static void battery_status_update(void) | ||
456 | { | ||
457 | int level = voltage_to_battery_level(battery_centivolts); | ||
458 | |||
413 | #ifndef HAVE_MMC /* this adjustment is only needed for HD based */ | 459 | #ifndef HAVE_MMC /* this adjustment is only needed for HD based */ |
414 | if (battery_percent == -1) { /* first run of this procedure */ | 460 | if (battery_percent == -1) { /* first run of this procedure */ |
415 | /* The battery voltage is usually a little lower directly after | 461 | /* The battery voltage is usually a little lower directly after |
@@ -699,7 +745,6 @@ static void power_thread(void) | |||
699 | #endif | 745 | #endif |
700 | 746 | ||
701 | /* initialize the voltages for the exponential filter */ | 747 | /* initialize the voltages for the exponential filter */ |
702 | |||
703 | avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR * | 748 | avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR * |
704 | BATT_AVE_SAMPLES; | 749 | BATT_AVE_SAMPLES; |
705 | battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; | 750 | battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; |
@@ -1010,7 +1055,6 @@ void powermgmt_init(void) | |||
1010 | { | 1055 | { |
1011 | /* init history to 0 */ | 1056 | /* init history to 0 */ |
1012 | memset(power_history, 0x00, sizeof(power_history)); | 1057 | memset(power_history, 0x00, sizeof(power_history)); |
1013 | |||
1014 | create_thread(power_thread, power_stack, sizeof(power_stack), | 1058 | create_thread(power_thread, power_stack, sizeof(power_stack), |
1015 | power_thread_name IF_PRIO(, PRIORITY_SYSTEM)); | 1059 | power_thread_name IF_PRIO(, PRIORITY_SYSTEM)); |
1016 | } | 1060 | } |