forked from len0rd/rockbox
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
This commit is contained in:
parent
3f809e716d
commit
6eb4254dfa
5 changed files with 156 additions and 7 deletions
|
|
@ -33,6 +33,8 @@
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#include "powermgmt.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
/*---------------------------------------------------*/
|
/*---------------------------------------------------*/
|
||||||
/* SPECIAL DEBUG STUFF */
|
/* SPECIAL DEBUG STUFF */
|
||||||
|
|
@ -154,7 +156,7 @@ void dbg_ports(void)
|
||||||
snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
|
snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
|
||||||
lcd_puts(0, 5, buf);
|
lcd_puts(0, 5, buf);
|
||||||
|
|
||||||
battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000;
|
battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
|
||||||
batt_int = battery_voltage / 100;
|
batt_int = battery_voltage / 100;
|
||||||
batt_frac = battery_voltage % 100;
|
batt_frac = battery_voltage % 100;
|
||||||
|
|
||||||
|
|
@ -255,7 +257,7 @@ void dbg_ports(void)
|
||||||
}
|
}
|
||||||
lcd_puts(0, 0, buf);
|
lcd_puts(0, 0, buf);
|
||||||
|
|
||||||
battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000;
|
battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
|
||||||
batt_int = battery_voltage / 100;
|
batt_int = battery_voltage / 100;
|
||||||
batt_frac = battery_voltage % 100;
|
batt_frac = battery_voltage % 100;
|
||||||
|
|
||||||
|
|
@ -426,6 +428,129 @@ void dbg_mas_codec(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* view_battery() shows a automatically scaled graph of the battery voltage
|
||||||
|
* over time. Usable for estimating battery life / charging rate.
|
||||||
|
* The power_history array is updated in power_thread of powermgmt.c.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0)
|
||||||
|
#define BAT_YSPACE (LCD_HEIGHT - 20)
|
||||||
|
|
||||||
|
void view_battery(void)
|
||||||
|
{
|
||||||
|
int view = 0;
|
||||||
|
int i, x, y;
|
||||||
|
int maxv, minv;
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
switch (view) {
|
||||||
|
case 0: /* voltage history graph */
|
||||||
|
/* Find maximum and minimum voltage for scaling */
|
||||||
|
maxv = minv = 0;
|
||||||
|
for (i = BAT_FIRST_VAL; i < POWER_HISTORY_LEN; i++) {
|
||||||
|
if (power_history[i] > maxv)
|
||||||
|
maxv = power_history[i];
|
||||||
|
if ((minv == 0) || ((power_history[i]) && (power_history[i] < minv)) )
|
||||||
|
minv = power_history[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minv < 1)
|
||||||
|
minv = 1;
|
||||||
|
if (maxv < 2)
|
||||||
|
maxv = 2;
|
||||||
|
|
||||||
|
lcd_clear_display();
|
||||||
|
lcd_puts(0, 0, "Battery voltage:");
|
||||||
|
snprintf(buf, 30, "scale %d.%02d-%d.%02d V", minv / 100, minv % 100, maxv / 100, maxv % 100);
|
||||||
|
lcd_puts(0, 1, buf);
|
||||||
|
|
||||||
|
x = 0;
|
||||||
|
for (i = BAT_FIRST_VAL+1; i < POWER_HISTORY_LEN; i++) {
|
||||||
|
y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
|
||||||
|
lcd_clearline(x, LCD_HEIGHT-1, x, 20);
|
||||||
|
lcd_drawline(x, LCD_HEIGHT-1, x, MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: /* status: */
|
||||||
|
lcd_clear_display();
|
||||||
|
lcd_puts(0, 0, "Power status:");
|
||||||
|
|
||||||
|
y = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
|
||||||
|
snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
|
||||||
|
lcd_puts(0, 1, buf);
|
||||||
|
y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
|
||||||
|
snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
|
||||||
|
lcd_puts(0, 2, buf);
|
||||||
|
snprintf(buf, 30, "Charger: %s", charger_inserted() ? "present" : "absent");
|
||||||
|
lcd_puts(0, 3, buf);
|
||||||
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
|
snprintf(buf, 30, "Charging: %s", charger_enabled ? "yes" : "no");
|
||||||
|
lcd_puts(0, 4, buf);
|
||||||
|
#endif
|
||||||
|
y = 0;
|
||||||
|
for (i = 0; i < CHARGE_END_NEGD; i++)
|
||||||
|
y += power_history[POWER_HISTORY_LEN-1-i]*100 - power_history[POWER_HISTORY_LEN-1-i-1]*100;
|
||||||
|
y = y / CHARGE_END_NEGD;
|
||||||
|
|
||||||
|
snprintf(buf, 30, "short delta: %d", y);
|
||||||
|
lcd_puts(0, 5, buf);
|
||||||
|
|
||||||
|
y = 0;
|
||||||
|
for (i = 0; i < CHARGE_END_ZEROD; i++)
|
||||||
|
y += power_history[POWER_HISTORY_LEN-1-i]*100 - power_history[POWER_HISTORY_LEN-1-i-1]*100;
|
||||||
|
y = y / CHARGE_END_ZEROD;
|
||||||
|
|
||||||
|
snprintf(buf, 30, "long delta: %d", y);
|
||||||
|
lcd_puts(0, 6, buf);
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
|
lcd_puts(0, 7, power_message);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: /* voltage deltas: */
|
||||||
|
lcd_clear_display();
|
||||||
|
lcd_puts(0, 0, "Voltage deltas:");
|
||||||
|
|
||||||
|
for (i = 0; i <= 6; i++) {
|
||||||
|
y = power_history[POWER_HISTORY_LEN-1-i] - power_history[POWER_HISTORY_LEN-1-i-1];
|
||||||
|
snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
|
||||||
|
(y < 0) ? "-" : "",
|
||||||
|
((y < 0) ? y * -1 : y) / 100, ((y < 0) ? y * -1 : y ) % 100);
|
||||||
|
lcd_puts(0, i+1, buf);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
lcd_update();
|
||||||
|
sleep(HZ/2);
|
||||||
|
|
||||||
|
switch(button_get(false))
|
||||||
|
{
|
||||||
|
case BUTTON_UP:
|
||||||
|
if (view)
|
||||||
|
view--;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BUTTON_DOWN:
|
||||||
|
if (view < 2)
|
||||||
|
view++;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BUTTON_LEFT:
|
||||||
|
case BUTTON_OFF:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void debug_menu(void)
|
void debug_menu(void)
|
||||||
|
|
@ -443,6 +568,7 @@ void debug_menu(void)
|
||||||
{ "View MAS regs", dbg_mas },
|
{ "View MAS regs", dbg_mas },
|
||||||
#ifdef ARCHOS_RECORDER
|
#ifdef ARCHOS_RECORDER
|
||||||
{ "View MAS codec", dbg_mas_codec },
|
{ "View MAS codec", dbg_mas_codec },
|
||||||
|
{ "View battery", view_battery },
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
#include "powermgmt.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#ifndef SIMULATOR
|
#ifndef SIMULATOR
|
||||||
|
|
@ -157,6 +158,8 @@ void init(void)
|
||||||
|
|
||||||
status_init();
|
status_init();
|
||||||
usb_start_monitoring();
|
usb_start_monitoring();
|
||||||
|
|
||||||
|
power_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
#include "ata.h"
|
#include "ata.h"
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "backlight.h"
|
#include "backlight.h"
|
||||||
|
#include "powermgmt.h"
|
||||||
|
|
||||||
struct user_settings global_settings;
|
struct user_settings global_settings;
|
||||||
|
|
||||||
|
|
@ -265,7 +266,8 @@ int settings_save( void )
|
||||||
rtc_config_block[0xe] = (unsigned char)
|
rtc_config_block[0xe] = (unsigned char)
|
||||||
((global_settings.playlist_shuffle & 1) |
|
((global_settings.playlist_shuffle & 1) |
|
||||||
((global_settings.mp3filter & 1) << 1) |
|
((global_settings.mp3filter & 1) << 1) |
|
||||||
((global_settings.sort_case & 1) << 2));
|
((global_settings.sort_case & 1) << 2) |
|
||||||
|
((global_settings.discharge & 1) << 3));
|
||||||
|
|
||||||
rtc_config_block[0xf] = (unsigned char)
|
rtc_config_block[0xf] = (unsigned char)
|
||||||
((global_settings.scroll_speed << 3) |
|
((global_settings.scroll_speed << 3) |
|
||||||
|
|
@ -332,6 +334,7 @@ void settings_load(void)
|
||||||
global_settings.playlist_shuffle = rtc_config_block[0xe] & 1;
|
global_settings.playlist_shuffle = rtc_config_block[0xe] & 1;
|
||||||
global_settings.mp3filter = (rtc_config_block[0xe] >> 1) & 1;
|
global_settings.mp3filter = (rtc_config_block[0xe] >> 1) & 1;
|
||||||
global_settings.sort_case = (rtc_config_block[0xe] >> 2) & 1;
|
global_settings.sort_case = (rtc_config_block[0xe] >> 2) & 1;
|
||||||
|
global_settings.discharge = (rtc_config_block[0xe] >> 3) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = rtc_config_block[0xf] >> 3;
|
c = rtc_config_block[0xf] >> 3;
|
||||||
|
|
@ -350,6 +353,9 @@ void settings_load(void)
|
||||||
}
|
}
|
||||||
lcd_scroll_speed(global_settings.scroll_speed);
|
lcd_scroll_speed(global_settings.scroll_speed);
|
||||||
backlight_time(global_settings.backlight);
|
backlight_time(global_settings.backlight);
|
||||||
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
|
charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -373,6 +379,7 @@ void settings_reset(void) {
|
||||||
global_settings.mp3filter = true;
|
global_settings.mp3filter = true;
|
||||||
global_settings.sort_case = false;
|
global_settings.sort_case = false;
|
||||||
global_settings.playlist_shuffle = false;
|
global_settings.playlist_shuffle = false;
|
||||||
|
global_settings.discharge = 0;
|
||||||
global_settings.total_uptime = 0;
|
global_settings.total_uptime = 0;
|
||||||
global_settings.scroll_speed = 8;
|
global_settings.scroll_speed = 8;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ struct user_settings
|
||||||
int contrast; /* lcd contrast: 0-100 0=low 100=high */
|
int contrast; /* lcd contrast: 0-100 0=low 100=high */
|
||||||
int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */
|
int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */
|
||||||
int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */
|
int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */
|
||||||
|
bool discharge; /* maintain charge of at least: false = 90%, true = 10% */
|
||||||
|
|
||||||
/* resume settings */
|
/* resume settings */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
#include "settings_menu.h"
|
#include "settings_menu.h"
|
||||||
#include "backlight.h"
|
#include "backlight.h"
|
||||||
#include "playlist.h" /* for playlist_shuffle */
|
#include "playlist.h" /* for playlist_shuffle */
|
||||||
|
#include "powermgmt.h"
|
||||||
|
|
||||||
static void shuffle(void)
|
static void shuffle(void)
|
||||||
{
|
{
|
||||||
|
|
@ -67,6 +68,14 @@ static void wps_set(void)
|
||||||
set_option("[WPS display]", &global_settings.wps_display, names, 3 );
|
set_option("[WPS display]", &global_settings.wps_display, names, 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
|
static void deep_discharge(void)
|
||||||
|
{
|
||||||
|
set_bool( "[Deep discharge]", &global_settings.discharge );
|
||||||
|
charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void settings_menu(void)
|
void settings_menu(void)
|
||||||
{
|
{
|
||||||
int m;
|
int m;
|
||||||
|
|
@ -77,6 +86,9 @@ void settings_menu(void)
|
||||||
{ "Backlight Timer", backlight_timer },
|
{ "Backlight Timer", backlight_timer },
|
||||||
{ "Scroll speed", scroll_speed },
|
{ "Scroll speed", scroll_speed },
|
||||||
{ "While Playing", wps_set },
|
{ "While Playing", wps_set },
|
||||||
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
|
{ "Deep discharge", deep_discharge },
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
bool old_shuffle = global_settings.playlist_shuffle;
|
bool old_shuffle = global_settings.playlist_shuffle;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue