diff options
author | Heikki Hannikainen <hessuh@rockbox.org> | 2002-08-06 10:52:51 +0000 |
---|---|---|
committer | Heikki Hannikainen <hessuh@rockbox.org> | 2002-08-06 10:52:51 +0000 |
commit | 6eb4254dfa78677a1e336d0f820d5b7fe05eba14 (patch) | |
tree | c7fdd02800453984c42323914ddf55ac36ade4a2 /apps | |
parent | 3f809e716dea26d77bf2cd8e70c3d709c3c25169 (diff) | |
download | rockbox-6eb4254dfa78677a1e336d0f820d5b7fe05eba14.tar.gz rockbox-6eb4254dfa78677a1e336d0f820d5b7fe05eba14.zip |
Added battery charger for the recorder and a power management debugger.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1547 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/debug_menu.c | 130 | ||||
-rw-r--r-- | apps/main.c | 3 | ||||
-rw-r--r-- | apps/settings.c | 15 | ||||
-rw-r--r-- | apps/settings.h | 1 | ||||
-rw-r--r-- | apps/settings_menu.c | 14 |
5 files changed, 156 insertions, 7 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 1c1a8170d7..d4d08bc673 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -33,6 +33,8 @@ | |||
33 | #include "rtc.h" | 33 | #include "rtc.h" |
34 | #include "debug.h" | 34 | #include "debug.h" |
35 | #include "thread.h" | 35 | #include "thread.h" |
36 | #include "powermgmt.h" | ||
37 | #include "system.h" | ||
36 | 38 | ||
37 | /*---------------------------------------------------*/ | 39 | /*---------------------------------------------------*/ |
38 | /* SPECIAL DEBUG STUFF */ | 40 | /* SPECIAL DEBUG STUFF */ |
@@ -154,7 +156,7 @@ void dbg_ports(void) | |||
154 | snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7)); | 156 | snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7)); |
155 | lcd_puts(0, 5, buf); | 157 | lcd_puts(0, 5, buf); |
156 | 158 | ||
157 | battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000; | 159 | battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; |
158 | batt_int = battery_voltage / 100; | 160 | batt_int = battery_voltage / 100; |
159 | batt_frac = battery_voltage % 100; | 161 | batt_frac = battery_voltage % 100; |
160 | 162 | ||
@@ -255,7 +257,7 @@ void dbg_ports(void) | |||
255 | } | 257 | } |
256 | lcd_puts(0, 0, buf); | 258 | lcd_puts(0, 0, buf); |
257 | 259 | ||
258 | battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000; | 260 | battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; |
259 | batt_int = battery_voltage / 100; | 261 | batt_int = battery_voltage / 100; |
260 | batt_frac = battery_voltage % 100; | 262 | batt_frac = battery_voltage % 100; |
261 | 263 | ||
@@ -426,6 +428,129 @@ void dbg_mas_codec(void) | |||
426 | } | 428 | } |
427 | } | 429 | } |
428 | } | 430 | } |
431 | |||
432 | /* | ||
433 | * view_battery() shows a automatically scaled graph of the battery voltage | ||
434 | * over time. Usable for estimating battery life / charging rate. | ||
435 | * The power_history array is updated in power_thread of powermgmt.c. | ||
436 | */ | ||
437 | |||
438 | #define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0) | ||
439 | #define BAT_YSPACE (LCD_HEIGHT - 20) | ||
440 | |||
441 | void view_battery(void) | ||
442 | { | ||
443 | int view = 0; | ||
444 | int i, x, y; | ||
445 | int maxv, minv; | ||
446 | char buf[32]; | ||
447 | |||
448 | while(1) | ||
449 | { | ||
450 | switch (view) { | ||
451 | case 0: /* voltage history graph */ | ||
452 | /* Find maximum and minimum voltage for scaling */ | ||
453 | maxv = minv = 0; | ||
454 | for (i = BAT_FIRST_VAL; i < POWER_HISTORY_LEN; i++) { | ||
455 | if (power_history[i] > maxv) | ||
456 | maxv = power_history[i]; | ||
457 | if ((minv == 0) || ((power_history[i]) && (power_history[i] < minv)) ) | ||
458 | minv = power_history[i]; | ||
459 | } | ||
460 | |||
461 | if (minv < 1) | ||
462 | minv = 1; | ||
463 | if (maxv < 2) | ||
464 | maxv = 2; | ||
465 | |||
466 | lcd_clear_display(); | ||
467 | lcd_puts(0, 0, "Battery voltage:"); | ||
468 | snprintf(buf, 30, "scale %d.%02d-%d.%02d V", minv / 100, minv % 100, maxv / 100, maxv % 100); | ||
469 | lcd_puts(0, 1, buf); | ||
470 | |||
471 | x = 0; | ||
472 | for (i = BAT_FIRST_VAL+1; i < POWER_HISTORY_LEN; i++) { | ||
473 | y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv); | ||
474 | lcd_clearline(x, LCD_HEIGHT-1, x, 20); | ||
475 | lcd_drawline(x, LCD_HEIGHT-1, x, MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1)); | ||
476 | x++; | ||
477 | } | ||
478 | |||
479 | break; | ||
480 | |||
481 | case 1: /* status: */ | ||
482 | lcd_clear_display(); | ||
483 | lcd_puts(0, 0, "Power status:"); | ||
484 | |||
485 | y = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; | ||
486 | snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100); | ||
487 | lcd_puts(0, 1, buf); | ||
488 | y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000; | ||
489 | snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100); | ||
490 | lcd_puts(0, 2, buf); | ||
491 | snprintf(buf, 30, "Charger: %s", charger_inserted() ? "present" : "absent"); | ||
492 | lcd_puts(0, 3, buf); | ||
493 | #ifdef HAVE_CHARGE_CTRL | ||
494 | snprintf(buf, 30, "Charging: %s", charger_enabled ? "yes" : "no"); | ||
495 | lcd_puts(0, 4, buf); | ||
496 | #endif | ||
497 | y = 0; | ||
498 | for (i = 0; i < CHARGE_END_NEGD; i++) | ||
499 | y += power_history[POWER_HISTORY_LEN-1-i]*100 - power_history[POWER_HISTORY_LEN-1-i-1]*100; | ||
500 | y = y / CHARGE_END_NEGD; | ||
501 | |||
502 | snprintf(buf, 30, "short delta: %d", y); | ||
503 | lcd_puts(0, 5, buf); | ||
504 | |||
505 | y = 0; | ||
506 | for (i = 0; i < CHARGE_END_ZEROD; i++) | ||
507 | y += power_history[POWER_HISTORY_LEN-1-i]*100 - power_history[POWER_HISTORY_LEN-1-i-1]*100; | ||
508 | y = y / CHARGE_END_ZEROD; | ||
509 | |||
510 | snprintf(buf, 30, "long delta: %d", y); | ||
511 | lcd_puts(0, 6, buf); | ||
512 | |||
513 | #ifdef HAVE_CHARGE_CTRL | ||
514 | lcd_puts(0, 7, power_message); | ||
515 | #endif | ||
516 | break; | ||
517 | |||
518 | case 2: /* voltage deltas: */ | ||
519 | lcd_clear_display(); | ||
520 | lcd_puts(0, 0, "Voltage deltas:"); | ||
521 | |||
522 | for (i = 0; i <= 6; i++) { | ||
523 | y = power_history[POWER_HISTORY_LEN-1-i] - power_history[POWER_HISTORY_LEN-1-i-1]; | ||
524 | snprintf(buf, 30, "-%d min: %s%d.%02d V", i, | ||
525 | (y < 0) ? "-" : "", | ||
526 | ((y < 0) ? y * -1 : y) / 100, ((y < 0) ? y * -1 : y ) % 100); | ||
527 | lcd_puts(0, i+1, buf); | ||
528 | } | ||
529 | break; | ||
530 | } | ||
531 | |||
532 | lcd_update(); | ||
533 | sleep(HZ/2); | ||
534 | |||
535 | switch(button_get(false)) | ||
536 | { | ||
537 | case BUTTON_UP: | ||
538 | if (view) | ||
539 | view--; | ||
540 | break; | ||
541 | |||
542 | case BUTTON_DOWN: | ||
543 | if (view < 2) | ||
544 | view++; | ||
545 | break; | ||
546 | |||
547 | case BUTTON_LEFT: | ||
548 | case BUTTON_OFF: | ||
549 | return; | ||
550 | } | ||
551 | } | ||
552 | } | ||
553 | |||
429 | #endif | 554 | #endif |
430 | 555 | ||
431 | void debug_menu(void) | 556 | void debug_menu(void) |
@@ -443,6 +568,7 @@ void debug_menu(void) | |||
443 | { "View MAS regs", dbg_mas }, | 568 | { "View MAS regs", dbg_mas }, |
444 | #ifdef ARCHOS_RECORDER | 569 | #ifdef ARCHOS_RECORDER |
445 | { "View MAS codec", dbg_mas_codec }, | 570 | { "View MAS codec", dbg_mas_codec }, |
571 | { "View battery", view_battery }, | ||
446 | #endif | 572 | #endif |
447 | }; | 573 | }; |
448 | 574 | ||
diff --git a/apps/main.c b/apps/main.c index 83ccd7586f..df7d7c128f 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "menu.h" | 30 | #include "menu.h" |
31 | #include "system.h" | 31 | #include "system.h" |
32 | #include "usb.h" | 32 | #include "usb.h" |
33 | #include "powermgmt.h" | ||
33 | #include "adc.h" | 34 | #include "adc.h" |
34 | #include "i2c.h" | 35 | #include "i2c.h" |
35 | #ifndef SIMULATOR | 36 | #ifndef SIMULATOR |
@@ -157,6 +158,8 @@ void init(void) | |||
157 | 158 | ||
158 | status_init(); | 159 | status_init(); |
159 | usb_start_monitoring(); | 160 | usb_start_monitoring(); |
161 | |||
162 | power_init(); | ||
160 | } | 163 | } |
161 | 164 | ||
162 | int main(void) | 165 | int main(void) |
diff --git a/apps/settings.c b/apps/settings.c index 7f1c1af34d..4160721e8a 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "ata.h" | 32 | #include "ata.h" |
33 | #include "power.h" | 33 | #include "power.h" |
34 | #include "backlight.h" | 34 | #include "backlight.h" |
35 | #include "powermgmt.h" | ||
35 | 36 | ||
36 | struct user_settings global_settings; | 37 | struct user_settings global_settings; |
37 | 38 | ||
@@ -57,12 +58,12 @@ offset abs | |||
57 | 0x0f 0x23 <scroll speed & WPS display byte> | 58 | 0x0f 0x23 <scroll speed & WPS display byte> |
58 | 0x10 0x24 <playlist options byte> | 59 | 0x10 0x24 <playlist options byte> |
59 | 0x11 0x25 <AVC byte> | 60 | 0x11 0x25 <AVC byte> |
60 | 61 | ||
61 | <all unused space filled with 0xff> | 62 | <all unused space filled with 0xff> |
62 | 63 | ||
63 | the geeky but useless statistics part: | 64 | the geeky but useless statistics part: |
64 | 0x24 <total uptime in seconds: 32 bits uint, actually unused for now> | 65 | 0x24 <total uptime in seconds: 32 bits uint, actually unused for now> |
65 | 66 | ||
66 | 0x2a <checksum 2 bytes: xor of 0x0-0x29> | 67 | 0x2a <checksum 2 bytes: xor of 0x0-0x29> |
67 | 68 | ||
68 | Config memory is reset to 0xff and initialized with 'factory defaults' if | 69 | Config memory is reset to 0xff and initialized with 'factory defaults' if |
@@ -265,7 +266,8 @@ int settings_save( void ) | |||
265 | rtc_config_block[0xe] = (unsigned char) | 266 | rtc_config_block[0xe] = (unsigned char) |
266 | ((global_settings.playlist_shuffle & 1) | | 267 | ((global_settings.playlist_shuffle & 1) | |
267 | ((global_settings.mp3filter & 1) << 1) | | 268 | ((global_settings.mp3filter & 1) << 1) | |
268 | ((global_settings.sort_case & 1) << 2)); | 269 | ((global_settings.sort_case & 1) << 2) | |
270 | ((global_settings.discharge & 1) << 3)); | ||
269 | 271 | ||
270 | rtc_config_block[0xf] = (unsigned char) | 272 | rtc_config_block[0xf] = (unsigned char) |
271 | ((global_settings.scroll_speed << 3) | | 273 | ((global_settings.scroll_speed << 3) | |
@@ -332,8 +334,9 @@ void settings_load(void) | |||
332 | global_settings.playlist_shuffle = rtc_config_block[0xe] & 1; | 334 | global_settings.playlist_shuffle = rtc_config_block[0xe] & 1; |
333 | global_settings.mp3filter = (rtc_config_block[0xe] >> 1) & 1; | 335 | global_settings.mp3filter = (rtc_config_block[0xe] >> 1) & 1; |
334 | global_settings.sort_case = (rtc_config_block[0xe] >> 2) & 1; | 336 | global_settings.sort_case = (rtc_config_block[0xe] >> 2) & 1; |
337 | global_settings.discharge = (rtc_config_block[0xe] >> 3) & 1; | ||
335 | } | 338 | } |
336 | 339 | ||
337 | c = rtc_config_block[0xf] >> 3; | 340 | c = rtc_config_block[0xf] >> 3; |
338 | if (c != 31) | 341 | if (c != 31) |
339 | global_settings.scroll_speed = c; | 342 | global_settings.scroll_speed = c; |
@@ -350,6 +353,9 @@ void settings_load(void) | |||
350 | } | 353 | } |
351 | lcd_scroll_speed(global_settings.scroll_speed); | 354 | lcd_scroll_speed(global_settings.scroll_speed); |
352 | backlight_time(global_settings.backlight); | 355 | backlight_time(global_settings.backlight); |
356 | #ifdef HAVE_CHARGE_CTRL | ||
357 | charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI; | ||
358 | #endif | ||
353 | } | 359 | } |
354 | 360 | ||
355 | /* | 361 | /* |
@@ -373,6 +379,7 @@ void settings_reset(void) { | |||
373 | global_settings.mp3filter = true; | 379 | global_settings.mp3filter = true; |
374 | global_settings.sort_case = false; | 380 | global_settings.sort_case = false; |
375 | global_settings.playlist_shuffle = false; | 381 | global_settings.playlist_shuffle = false; |
382 | global_settings.discharge = 0; | ||
376 | global_settings.total_uptime = 0; | 383 | global_settings.total_uptime = 0; |
377 | global_settings.scroll_speed = 8; | 384 | global_settings.scroll_speed = 8; |
378 | } | 385 | } |
diff --git a/apps/settings.h b/apps/settings.h index ba6f32c37a..b39ac73c89 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -45,6 +45,7 @@ struct user_settings | |||
45 | int contrast; /* lcd contrast: 0-100 0=low 100=high */ | 45 | int contrast; /* lcd contrast: 0-100 0=low 100=high */ |
46 | int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */ | 46 | int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */ |
47 | int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */ | 47 | int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */ |
48 | bool discharge; /* maintain charge of at least: false = 90%, true = 10% */ | ||
48 | 49 | ||
49 | /* resume settings */ | 50 | /* resume settings */ |
50 | 51 | ||
diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 5c718869d9..4547966f38 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "settings_menu.h" | 32 | #include "settings_menu.h" |
33 | #include "backlight.h" | 33 | #include "backlight.h" |
34 | #include "playlist.h" /* for playlist_shuffle */ | 34 | #include "playlist.h" /* for playlist_shuffle */ |
35 | #include "powermgmt.h" | ||
35 | 36 | ||
36 | static void shuffle(void) | 37 | static void shuffle(void) |
37 | { | 38 | { |
@@ -67,6 +68,14 @@ static void wps_set(void) | |||
67 | set_option("[WPS display]", &global_settings.wps_display, names, 3 ); | 68 | set_option("[WPS display]", &global_settings.wps_display, names, 3 ); |
68 | } | 69 | } |
69 | 70 | ||
71 | #ifdef HAVE_CHARGE_CTRL | ||
72 | static void deep_discharge(void) | ||
73 | { | ||
74 | set_bool( "[Deep discharge]", &global_settings.discharge ); | ||
75 | charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI; | ||
76 | } | ||
77 | #endif | ||
78 | |||
70 | void settings_menu(void) | 79 | void settings_menu(void) |
71 | { | 80 | { |
72 | int m; | 81 | int m; |
@@ -76,7 +85,10 @@ void settings_menu(void) | |||
76 | { "Sort mode", sort_case }, | 85 | { "Sort mode", sort_case }, |
77 | { "Backlight Timer", backlight_timer }, | 86 | { "Backlight Timer", backlight_timer }, |
78 | { "Scroll speed", scroll_speed }, | 87 | { "Scroll speed", scroll_speed }, |
79 | { "While Playing", wps_set }, | 88 | { "While Playing", wps_set }, |
89 | #ifdef HAVE_CHARGE_CTRL | ||
90 | { "Deep discharge", deep_discharge }, | ||
91 | #endif | ||
80 | }; | 92 | }; |
81 | bool old_shuffle = global_settings.playlist_shuffle; | 93 | bool old_shuffle = global_settings.playlist_shuffle; |
82 | 94 | ||