Work-in-progress rework of charging status reading & display: * Changed several charging related HAVE_* macros into one multi-value CONFIG_CHARGING. * Always use proper macros for charging states. * Battery symbol charging animation now starts from current level on all targets with charging. Two-colour animation kept for non-b&w targets. Round down fill level while charging as before, but round to nearest pixel value for discharging on all targets. * Charging anim fixed on player. * Some code cleanup.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10080 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2006-06-06 22:23:52 +00:00
parent 8c9e22580e
commit 0dd1f8ec11
43 changed files with 300 additions and 350 deletions

View file

@ -1334,8 +1334,8 @@ bool view_battery(void)
snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100); snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
lcd_puts(0, 2, buf); lcd_puts(0, 2, buf);
#endif #endif
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
snprintf(buf, 30, "Chgr: %s %s", snprintf(buf, 30, "Chgr: %s %s",
charger_inserted() ? "present" : "absent", charger_inserted() ? "present" : "absent",
charger_enabled ? "on" : "off"); charger_enabled ? "on" : "off");
@ -1345,8 +1345,8 @@ bool view_battery(void)
snprintf(buf, 30, "long delta: %d", long_delta); snprintf(buf, 30, "long delta: %d", long_delta);
lcd_puts(0, 6, buf); lcd_puts(0, 6, buf);
lcd_puts(0, 7, power_message); lcd_puts(0, 7, power_message);
#else /* !HAVE_CHARGE_CTRL */ #else /* CONFIG_CHARGING != CHARGING_CONTROL */
#if defined IPOD_NANO || defined IPOD_VIDEO #if defined IPOD_NANO || defined IPOD_VIDEO
int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false; int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true; int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
int dock = (GPIOA_INPUT_VAL & 0x10)?true:false; int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
@ -1373,8 +1373,8 @@ bool view_battery(void)
charger_inserted() ? "present" : "absent"); charger_inserted() ? "present" : "absent");
lcd_puts(0, 3, buf); lcd_puts(0, 3, buf);
#endif #endif
#endif /* !HAVE_CHARGE_CTRL */ #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
#endif /* HAVE_CHARGING */ #endif /* CONFIG_CHARGING */
break; break;
case 2: /* voltage deltas: */ case 2: /* voltage deltas: */
@ -1393,7 +1393,7 @@ bool view_battery(void)
case 3: /* remaining time estimation: */ case 3: /* remaining time estimation: */
lcd_clear_display(); lcd_clear_display();
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
snprintf(buf, 30, "charge_state: %d", charge_state); snprintf(buf, 30, "charge_state: %d", charge_state);
lcd_puts(0, 0, buf); lcd_puts(0, 0, buf);
@ -1408,7 +1408,7 @@ bool view_battery(void)
snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec); snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
lcd_puts(0, 4, buf); lcd_puts(0, 4, buf);
#endif /* HAVE_CHARGE_CTRL */ #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
snprintf(buf, 30, "Last PwrHist: %d.%02d V", snprintf(buf, 30, "Last PwrHist: %d.%02d V",
power_history[0] / 100, power_history[0] / 100,
@ -1465,7 +1465,7 @@ static bool view_runtime(void)
#endif #endif
if (state & 1) { if (state & 1) {
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
if (charger_inserted() if (charger_inserted()
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
|| usb_powered() || usb_powered()

View file

@ -823,7 +823,7 @@ static char* get_tag(struct wps_data* wps_data,
} }
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
case 'p': /* External power plugged in? */ case 'p': /* External power plugged in? */
{ {
if(charger_input_state==CHARGER) if(charger_input_state==CHARGER)
@ -832,9 +832,7 @@ static char* get_tag(struct wps_data* wps_data,
return NULL; return NULL;
} }
#endif #endif
#if defined(HAVE_CHARGE_CTRL) || \ #if CONFIG_CHARGING >= CHARGING_MONITOR
defined (HAVE_CHARGE_STATE) || \
CONFIG_BATTERY == BATT_LIION2200
case 'c': /* Charging */ case 'c': /* Charging */
{ {
if (charge_state == CHARGING || charge_state == TOPOFF) { if (charge_state == CHARGING || charge_state == TOPOFF) {

View file

@ -107,37 +107,73 @@ struct gui_syncstatusbar statusbars;
void gui_statusbar_init(struct gui_statusbar * bar) void gui_statusbar_init(struct gui_statusbar * bar)
{ {
bar->last_volume = -1000; /* -1000 means "first update ever" */ bar->redraw_volume = true;
bar->battery_icon_switch_tick = 0; bar->volume_icon_switch_tick = bar->battery_icon_switch_tick = current_tick;
bar->animated_level = 0;
} }
void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw) void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
{ {
struct screen * display = bar->display; struct screen * display = bar->display;
#ifdef CONFIG_RTC
struct tm* tm; /* For Time */
#endif /* CONFIG_RTC */
#ifdef HAVE_LCD_CHARCELLS #ifdef HAVE_LCD_CHARCELLS
int vol; int val;
(void)force_redraw; /* players always "redraw" */ (void)force_redraw; /* players always "redraw" */
#endif /* HAVE_LCD_CHARCELLS */ #endif /* HAVE_LCD_CHARCELLS */
bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
#ifdef HAVE_CHARGING
bar->info.inserted = (charger_input_state == CHARGER);
#endif
bar->info.battlevel = battery_level(); bar->info.battlevel = battery_level();
bar->info.battery_safe = battery_level_safe(); #ifdef HAVE_USB_POWER
bar->info.usb_power = usb_powered();
#endif
#ifdef CONFIG_CHARGING
bar->info.inserted = (charger_input_state == CHARGER);
if (bar->info.inserted)
{
bar->info.battery_state = true;
#if CONFIG_CHARGING >= CHARGING_MONITOR
/* zero battery run time if charging */
if (charge_state > DISCHARGING)
lasttime = current_tick;
/* animate battery if charging */
if ((charge_state == DISCHARGING) || (charge_state == TRICKLE))
{
bar->info.batt_charge_step = -1;
}
else
{
#else
lasttime = current_tick;
{
#endif
/* animate in (max.) 4 steps, starting near the current charge level */
if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick))
{
if (++bar->info.batt_charge_step > 3)
bar->info.batt_charge_step = bar->info.battlevel / 34;
bar->battery_icon_switch_tick = current_tick + HZ;
}
}
}
else
#endif
{
bar->info.batt_charge_step = -1;
if (battery_level_safe())
bar->info.battery_state = true;
else
/* blink battery if level is low */
if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
(bar->info.battlevel > -1))
{
bar->info.battery_state = !bar->info.battery_state;
bar->battery_icon_switch_tick = current_tick + HZ;
}
}
bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
#ifdef CONFIG_RTC
tm = get_time();
bar->info.hour = tm->tm_hour;
bar->info.minute = tm->tm_min;
#endif /* CONFIG_RTC */
bar->info.shuffle = global_settings.playlist_shuffle; bar->info.shuffle = global_settings.playlist_shuffle;
#ifdef HAS_BUTTON_HOLD #ifdef HAS_BUTTON_HOLD
bar->info.keylock = button_hold(); bar->info.keylock = button_hold();
@ -149,24 +185,25 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
#endif #endif
bar->info.repeat = global_settings.repeat_mode; bar->info.repeat = global_settings.repeat_mode;
bar->info.playmode = current_playmode(); bar->info.playmode = current_playmode();
#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
if(!display->has_disk_led) if(!display->has_disk_led)
bar->info.led = led_read(HZ/2); /* delay should match polling interval */ bar->info.led = led_read(HZ/2); /* delay should match polling interval */
#endif #endif
#ifdef CONFIG_RTC
#ifdef HAVE_USB_POWER {
bar->info.usb_power = usb_powered(); struct tm* tm = get_time();
#endif /* HAVE_USB_POWER */ bar->info.hour = tm->tm_hour;
bar->info.minute = tm->tm_min;
}
#endif /* CONFIG_RTC */
/* only redraw if forced to, or info has changed */ /* only redraw if forced to, or info has changed */
if (force_redraw || if (force_redraw || bar->redraw_volume ||
bar->info.inserted ||
!bar->info.battery_safe ||
bar->info.redraw_volume ||
memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info))) memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
{ {
display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
display->fillrect(0,0,display->width,8); display->fillrect(0, 0, display->width, STATUSBAR_HEIGHT);
display->set_drawmode(DRMODE_SOLID); display->set_drawmode(DRMODE_SOLID);
#else #else
@ -175,65 +212,10 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
{ {
#endif /* HAVE_LCD_BITMAP */ #endif /* HAVE_LCD_BITMAP */
#ifdef HAVE_CHARGING
if (bar->info.inserted) {
battery_state = true;
#if defined(HAVE_CHARGE_CTRL) || \
defined(HAVE_CHARGE_STATE) || \
CONFIG_BATTERY == BATT_LIION2200
/* zero battery run time if charging */
if (charge_state > DISCHARGING) {
lasttime = current_tick;
}
/* animate battery if charging */
if ((charge_state == CHARGING)
#ifdef HAVE_CHARGE_CTRL
|| (charge_state == TOPOFF)
#endif
) {
#else
lasttime = current_tick;
{
#endif
/* animate in three steps (34% per step for a better look) */
#ifndef HAVE_CHARGE_STATE
bar->info.battlevel = 0;
#endif
if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) {
if (bar->animated_level == 100)
{
bar->animated_level = bar->info.battlevel;
}
else
{
bar->animated_level += 34;
if (bar->animated_level > 100)
bar->animated_level = 100;
}
bar->battery_icon_switch_tick = current_tick + HZ;
}
}
}
else
#endif /* HAVE_CHARGING */
{
bar->animated_level = 0;
if (bar->info.battery_safe)
battery_state = true;
else {
/* blink battery if level is low */
if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
(bar->info.battlevel > -1)) {
bar->battery_icon_switch_tick = current_tick+HZ;
battery_state = !battery_state;
}
}
}
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
if (battery_state) if (bar->info.battery_state)
gui_statusbar_icon_battery(display, bar->info.battlevel, gui_statusbar_icon_battery(display, bar->info.battlevel,
bar->animated_level); bar->info.batt_charge_step);
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
if (bar->info.usb_power) if (bar->info.usb_power)
display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug], display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
@ -243,14 +225,15 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
else else
#endif /* HAVE_USB_POWER */ #endif /* HAVE_USB_POWER */
/* draw power plug if charging */ /* draw power plug if charging */
#ifdef CONFIG_CHARGING
if (bar->info.inserted) if (bar->info.inserted)
display->mono_bitmap(bitmap_icons_7x8[Icon_Plug], display->mono_bitmap(bitmap_icons_7x8[Icon_Plug],
STATUSBAR_PLUG_X_POS, STATUSBAR_PLUG_X_POS,
STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH, STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
STATUSBAR_HEIGHT); STATUSBAR_HEIGHT);
#endif
bar->info.redraw_volume = gui_statusbar_icon_volume(bar, bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume);
bar->info.volume);
gui_statusbar_icon_play_state(display, current_playmode() + gui_statusbar_icon_play_state(display, current_playmode() +
Icon_Play); Icon_Play);
@ -292,20 +275,24 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
#ifdef HAVE_LCD_CHARCELLS #ifdef HAVE_LCD_CHARCELLS
if (bar->info.battlevel > -1) display->icon(ICON_BATTERY, bar->info.battery_state);
display->icon(ICON_BATTERY, battery_state);
display->icon(ICON_BATTERY_1, bar->info.battlevel > 25); if (bar->info.batt_charge_step > -1)
display->icon(ICON_BATTERY_2, bar->info.battlevel > 50); val = bar->info.batt_charge_step;
display->icon(ICON_BATTERY_3, bar->info.battlevel > 75); else
val = (bar->info.battlevel * 3 + 50) / 100;
display->icon(ICON_BATTERY_1, val >= 1);
display->icon(ICON_BATTERY_2, val >= 2);
display->icon(ICON_BATTERY_3, val >= 3);
vol = 100 * (bar->info.volume - sound_min(SOUND_VOLUME)) val = 10 * (bar->info.volume - sound_min(SOUND_VOLUME))
/ (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME)); / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
display->icon(ICON_VOLUME, true); display->icon(ICON_VOLUME, true);
display->icon(ICON_VOLUME_1, vol > 10); display->icon(ICON_VOLUME_1, val >= 1);
display->icon(ICON_VOLUME_2, vol > 30); display->icon(ICON_VOLUME_2, val >= 3);
display->icon(ICON_VOLUME_3, vol > 50); display->icon(ICON_VOLUME_3, val >= 5);
display->icon(ICON_VOLUME_4, vol > 70); display->icon(ICON_VOLUME_4, val >= 7);
display->icon(ICON_VOLUME_5, vol > 90); display->icon(ICON_VOLUME_5, val >= 9);
display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY); display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE); display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
@ -326,40 +313,41 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
* Print battery icon to status bar * Print battery icon to status bar
*/ */
void gui_statusbar_icon_battery(struct screen * display, int percent, void gui_statusbar_icon_battery(struct screen * display, int percent,
int animated_percent) int batt_charge_step)
{ {
int fill, endfill; int fill, endfill;
char buffer[5]; char buffer[5];
unsigned int width, height; unsigned int width, height;
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
unsigned int prevfg = LCD_DEFAULT_FG; unsigned int prevfg = 0;
#endif #endif
/* fill battery */ #ifdef CONFIG_CHARGING
fill = percent; if (batt_charge_step >= 0)
if (fill < 0) {
fill = 0; fill = percent * (STATUSBAR_BATTERY_WIDTH-3) / 100;
if (fill > 100) endfill = 34 * batt_charge_step * (STATUSBAR_BATTERY_WIDTH-3) / 100;
fill = 100; }
else
#else
(void)batt_charge_step;
#endif
{
fill = endfill = (percent * (STATUSBAR_BATTERY_WIDTH-3) + 50) / 100;
}
endfill = animated_percent; #if CONFIG_CHARGING == CHARGING_MONITOR && !defined(SIMULATOR)
if (endfill < 0) /* Certain charge controlled targets */
endfill = 0;
if (endfill > 100)
endfill = 100;
#if (defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)) && \
!defined(SIMULATOR) /* Certain charge controlled targets */
/* show graphical animation when charging instead of numbers */ /* show graphical animation when charging instead of numbers */
if ((global_settings.battery_display) && if ((global_settings.battery_display) &&
(charge_state != 1) && (charge_state != CHARGING) &&
(percent > -1)) { (percent > -1)) {
#else /* all others */ #else /* all others */
if (global_settings.battery_display && (percent > -1)) { if (global_settings.battery_display && (percent > -1)) {
#endif #endif
/* Numeric display */ /* Numeric display */
display->setfont(FONT_SYSFIXED); display->setfont(FONT_SYSFIXED);
snprintf(buffer, sizeof(buffer), "%3d", fill); snprintf(buffer, sizeof(buffer), "%3d", percent);
display->getstringsize(buffer, &width, &height); display->getstringsize(buffer, &width, &height);
if (height <= STATUSBAR_HEIGHT) if (height <= STATUSBAR_HEIGHT)
display->putsxy(STATUSBAR_BATTERY_X_POS display->putsxy(STATUSBAR_BATTERY_X_POS
@ -374,7 +362,6 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2, display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2,
STATUSBAR_Y_POS + 4); STATUSBAR_Y_POS + 4);
fill = fill * 15 / 100;
display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1, display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
fill, 5); fill, 5);
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
@ -384,9 +371,8 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
display->set_foreground(LCD_DARKGRAY); display->set_foreground(LCD_DARKGRAY);
} }
#endif #endif
endfill = endfill * 15 / 100 - fill; display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill, STATUSBAR_Y_POS + 1, endfill - fill, 5);
STATUSBAR_Y_POS + 1, endfill, 5);
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
if (display->depth > 1) if (display->depth > 1)
display->set_foreground(prevfg); display->set_foreground(prevfg);
@ -507,6 +493,7 @@ void gui_statusbar_icon_lock(struct screen * display)
STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT); STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT);
} }
#ifdef HAS_REMOTE_BUTTON_HOLD
/* /*
* Print remote lock when remote hold is enabled * Print remote lock when remote hold is enabled
*/ */
@ -516,6 +503,7 @@ void gui_statusbar_icon_lock_remote(struct screen * display)
STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS, STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS,
STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT); STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT);
} }
#endif
#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
/* /*

View file

@ -31,38 +31,40 @@
struct status_info { struct status_info {
int battlevel; int battlevel;
int batt_charge_step;
int volume; int volume;
int playmode;
int repeat;
#ifdef CONFIG_RTC #ifdef CONFIG_RTC
int hour; int hour;
int minute; int minute;
#endif #endif
int playmode;
int repeat; #ifdef CONFIG_CHARGING
bool inserted; bool inserted;
#endif
#ifdef HAVE_USB_POWER
bool usb_power;
#endif
bool battery_state;
bool shuffle; bool shuffle;
bool keylock; bool keylock;
#ifdef HAS_REMOTE_BUTTON_HOLD #ifdef HAS_REMOTE_BUTTON_HOLD
bool keylockremote; bool keylockremote;
#endif #endif
bool battery_safe;
bool redraw_volume; /* true if the volume gauge needs updating */
#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
bool led; /* disk LED simulation in the status bar */ bool led; /* disk LED simulation in the status bar */
#endif #endif
#ifdef HAVE_USB_POWER
bool usb_power;
#endif
}; };
struct gui_statusbar struct gui_statusbar
{ {
/* Volume icon stuffs */ long battery_icon_switch_tick;
long volume_icon_switch_tick; long volume_icon_switch_tick;
int last_volume; int last_volume;
bool redraw_volume; /* true if the volume gauge needs updating */
long battery_icon_switch_tick;
int animated_level;
struct status_info info; struct status_info info;
struct status_info lastinfo; struct status_info lastinfo;
@ -95,7 +97,7 @@ extern void gui_statusbar_init(struct gui_statusbar * bar);
*/ */
extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw); extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw);
void gui_statusbar_icon_battery(struct screen * display, int percent, int animated_percent); void gui_statusbar_icon_battery(struct screen * display, int percent, int batt_charge_step);
bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume); bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
void gui_statusbar_icon_play_state(struct screen * display, int state); void gui_statusbar_icon_play_state(struct screen * display, int state);
void gui_statusbar_icon_play_mode(struct screen * display, int mode); void gui_statusbar_icon_play_mode(struct screen * display, int mode);

View file

@ -228,7 +228,7 @@ void init(void)
{ {
int rc; int rc;
bool mounted = false; bool mounted = false;
#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
/* if nobody initialized ATA before, I consider this a cold start */ /* if nobody initialized ATA before, I consider this a cold start */
bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
#endif #endif
@ -295,7 +295,7 @@ void init(void)
screen_access_init(); screen_access_init();
gui_syncstatusbar_init(&statusbars); gui_syncstatusbar_init(&statusbars);
#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
if (coldstart && charger_inserted() if (coldstart && charger_inserted()
&& !global_settings.car_adapter_mode && !global_settings.car_adapter_mode
#ifdef ATA_POWER_PLAYERSTYLE #ifdef ATA_POWER_PLAYERSTYLE
@ -433,7 +433,7 @@ void init(void)
} }
#endif /* #ifdef AUTOROCK */ #endif /* #ifdef AUTOROCK */
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
car_adapter_mode_init(); car_adapter_mode_init();
#endif #endif
} }

View file

@ -169,12 +169,12 @@ bool show_info(void)
#endif #endif
lcd_puts_scroll(0, y++, (unsigned char *)s); lcd_puts_scroll(0, y++, (unsigned char *)s);
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
if (charge_state == 1) if (charge_state == CHARGING)
snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_CHARGE)); snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_CHARGE));
else if (charge_state == 2) else if (charge_state == TOPOFF)
snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TOPOFF_CHARGE)); snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TOPOFF_CHARGE));
else if (charge_state == 3) else if (charge_state == TRICKLE)
snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TRICKLE_CHARGE)); snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TRICKLE_CHARGE));
else else
#endif #endif

View file

@ -491,7 +491,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
return false; return false;
} }
#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
if(!charger_inserted()) if(!charger_inserted())
#endif #endif
{ {
@ -509,7 +509,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
return false; return false;
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
static bool waiting_to_resume_play = false; static bool waiting_to_resume_play = false;
static long play_resume_tick; static long play_resume_tick;
@ -584,7 +584,7 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
if (!clean_shutdown(callback, parameter)) if (!clean_shutdown(callback, parameter))
return SYS_POWEROFF; return SYS_POWEROFF;
break; break;
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
case SYS_CHARGER_CONNECTED: case SYS_CHARGER_CONNECTED:
car_adapter_mode_processing(true); car_adapter_mode_processing(true);
return SYS_CHARGER_CONNECTED; return SYS_CHARGER_CONNECTED;

View file

@ -58,7 +58,7 @@
#include "dsp.h" #include "dsp.h"
#endif #endif
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
#include "power.h" #include "power.h"
#endif #endif
@ -359,9 +359,9 @@ static const struct plugin_api rockbox_api = {
#ifndef SIMULATOR #ifndef SIMULATOR
battery_voltage, battery_voltage,
#endif #endif
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
charger_inserted, charger_inserted,
# ifdef HAVE_CHARGE_STATE # if CONFIG_CHARGING == CHARGING_MONITOR
charging_state, charging_state,
# endif # endif
#endif #endif

View file

@ -421,9 +421,9 @@ struct plugin_api {
#ifndef SIMULATOR #ifndef SIMULATOR
unsigned int (*battery_voltage)(void); unsigned int (*battery_voltage)(void);
#endif #endif
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
bool (*charger_inserted)(void); bool (*charger_inserted)(void);
# ifdef HAVE_CHARGE_STATE # if CONFIG_CHARGING == CHARGING_MONITOR
bool (*charging_state)(void); bool (*charging_state)(void);
# endif # endif
#endif #endif

View file

@ -128,14 +128,14 @@ void exit_tsr(void)
/* use long for aligning */ /* use long for aligning */
unsigned long thread_stack[THREAD_STACK_SIZE/sizeof(long)]; unsigned long thread_stack[THREAD_STACK_SIZE/sizeof(long)];
#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) #if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
unsigned int charge_state(void) unsigned int charge_state(void)
{ {
unsigned int ret = 0; unsigned int ret = 0;
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
if(rb->charger_inserted()) if(rb->charger_inserted())
ret = BIT_CHARGER; ret = BIT_CHARGER;
#ifdef HAVE_CHARGE_STATE #if CONFIG_CHARGING == CHARGING_MONITOR
if(rb->charging_state()) if(rb->charging_state())
ret |= BIT_CHARGING; ret |= BIT_CHARGING;
#endif #endif
@ -154,7 +154,7 @@ void thread(void)
int fd, buffelements, tick = 1, i = 0, skipped = 0, exit = 0; int fd, buffelements, tick = 1, i = 0, skipped = 0, exit = 0;
int fst = 0, lst = 0; /* first and last skipped tick */ int fst = 0, lst = 0; /* first and last skipped tick */
unsigned int last_voltage = 0; unsigned int last_voltage = 0;
#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) #if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
unsigned int last_state = 0; unsigned int last_state = 0;
#endif #endif
long sleep_time; long sleep_time;
@ -202,9 +202,9 @@ void thread(void)
rb->fdprintf(fd, rb->fdprintf(fd,
"%02d:%02d:%02d, %05d, %03d%%, " "%02d:%02d:%02d, %05d, %03d%%, "
"%02d:%02d, %04d, %04d" "%02d:%02d, %04d, %04d"
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
", %c" ", %c"
#ifdef HAVE_CHARGE_STATE #if CONFIG_CHARGING == CHARGING_MONITOR
", %c" ", %c"
#endif #endif
#endif #endif
@ -215,7 +215,7 @@ void thread(void)
HMS(secs), secs, bat[j].level, HMS(secs), secs, bat[j].level,
bat[j].eta / 60, bat[j].eta % 60, bat[j].eta / 60, bat[j].eta % 60,
#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) #if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
(bat[j].voltage & (bat[j].voltage &
(~(BIT_CHARGER|BIT_CHARGING|BIT_USB_POWER))) (~(BIT_CHARGER|BIT_CHARGING|BIT_USB_POWER)))
*10, *10,
@ -223,9 +223,9 @@ void thread(void)
bat[j].voltage * 10, bat[j].voltage * 10,
#endif #endif
temp + 1 + (j-i) temp + 1 + (j-i)
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
,(bat[j].voltage & BIT_CHARGER)?'A':'-' ,(bat[j].voltage & BIT_CHARGER)?'A':'-'
#ifdef HAVE_CHARGE_STATE #if CONFIG_CHARGING == CHARGING_MONITOR
,(bat[j].voltage & BIT_CHARGING)?'C':'-' ,(bat[j].voltage & BIT_CHARGING)?'C':'-'
#endif #endif
#endif #endif
@ -260,7 +260,7 @@ void thread(void)
timeflag = true; timeflag = true;
if(last_voltage != (current_voltage=rb->battery_voltage()) if(last_voltage != (current_voltage=rb->battery_voltage())
#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) #if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
|| last_state != charge_state() || last_state != charge_state()
#endif #endif
) )
@ -280,7 +280,7 @@ void thread(void)
bat[i].level = rb->battery_level(); bat[i].level = rb->battery_level();
bat[i].eta = rb->battery_time(); bat[i].eta = rb->battery_time();
last_voltage = bat[i].voltage = current_voltage; last_voltage = bat[i].voltage = current_voltage;
#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) #if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
bat[i].voltage |= last_state = charge_state(); bat[i].voltage |= last_state = charge_state();
#endif #endif
i++; i++;
@ -421,10 +421,10 @@ int main(void)
"Battery type: %d mAh Buffer Entries: %d\n" "Battery type: %d mAh Buffer Entries: %d\n"
" Time:, Seconds:, Level:, Time Left:, Voltage[mV]:," " Time:, Seconds:, Level:, Time Left:, Voltage[mV]:,"
" M/DA:" " M/DA:"
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
", C:" ", C:"
#endif #endif
#ifdef HAVE_CHARGE_STATE #if CONFIG_CHARGING == CHARGING_MONITOR
", S:" ", S:"
#endif #endif
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER

View file

@ -149,7 +149,7 @@ unsigned short adc_read(int channel)
} }
#endif #endif
#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
void charging_display_info(bool animate) void charging_display_info(bool animate)
@ -178,16 +178,16 @@ void charging_display_info(bool animate)
lcd_puts(0, 7, buf); lcd_puts(0, 7, buf);
} }
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
snprintf(buf, 32, "Charge mode:"); snprintf(buf, 32, "Charge mode:");
lcd_puts(0, 2, buf); lcd_puts(0, 2, buf);
if (charge_state == 1) if (charge_state == CHARGING)
snprintf(buf, 32, str(LANG_BATTERY_CHARGE)); snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
else if (charge_state == 2) else if (charge_state == TOPOFF)
snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE)); snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
else if (charge_state == 3) else if (charge_state == TRICKLE)
snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE)); snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
else else
snprintf(buf, 32, "not charging"); snprintf(buf, 32, "not charging");
@ -195,7 +195,7 @@ void charging_display_info(bool animate)
lcd_puts(0, 3, buf); lcd_puts(0, 3, buf);
if (!charger_enabled) if (!charger_enabled)
animate = false; animate = false;
#endif /* HAVE_CHARGE_CTRL */ #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
/* middle part */ /* middle part */
@ -351,7 +351,7 @@ int charging_screen(void)
#endif #endif
return rc; return rc;
} }
#endif /* HAVE_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */ #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */
#if (CONFIG_KEYPAD != PLAYER_PAD) #if (CONFIG_KEYPAD != PLAYER_PAD)
/* returns: /* returns:
@ -660,7 +660,7 @@ bool quick_screen_f3(int button_enter)
#endif /* BUTTON_F3 */ #endif /* BUTTON_F3 */
#endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */ #endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
#if defined(HAVE_CHARGING) || defined(SIMULATOR) #if defined(CONFIG_CHARGING) || defined(SIMULATOR)
void charging_splash(void) void charging_splash(void)
{ {
gui_syncsplash(2*HZ, true, (unsigned char *)str(LANG_BATTERY_CHARGE)); gui_syncsplash(2*HZ, true, (unsigned char *)str(LANG_BATTERY_CHARGE));

View file

@ -243,7 +243,7 @@ static const struct bit_entry rtc_bits[] =
{6, S_O(contrast), 40, "contrast", NULL }, {6, S_O(contrast), 40, "contrast", NULL },
#ifdef CONFIG_BACKLIGHT #ifdef CONFIG_BACKLIGHT
{5, S_O(backlight_timeout), 5, "backlight timeout", backlight_times_conf }, {5, S_O(backlight_timeout), 5, "backlight timeout", backlight_times_conf },
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
{5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged", {5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged",
backlight_times_conf }, backlight_times_conf },
#endif #endif
@ -276,7 +276,7 @@ static const struct bit_entry rtc_bits[] =
{12, S_O(battery_capacity), BATTERY_CAPACITY_DEFAULT, "battery capacity", {12, S_O(battery_capacity), BATTERY_CAPACITY_DEFAULT, "battery capacity",
NULL }, /* 1500...3200 for NiMH, 2200...3200 for LiIon, NULL }, /* 1500...3200 for NiMH, 2200...3200 for LiIon,
500...1500 for Alkaline */ 500...1500 for Alkaline */
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
{1, S_O(car_adapter_mode), false, "car adapter mode", off_on }, {1, S_O(car_adapter_mode), false, "car adapter mode", off_on },
#endif #endif
/* tuner */ /* tuner */
@ -296,7 +296,7 @@ static const struct bit_entry rtc_bits[] =
{1, S_O(remote_flip_display), false, "remote flip display", off_on }, {1, S_O(remote_flip_display), false, "remote flip display", off_on },
{5, S_O(remote_backlight_timeout), 5, "remote backlight timeout", {5, S_O(remote_backlight_timeout), 5, "remote backlight timeout",
backlight_times_conf }, backlight_times_conf },
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
{5, S_O(remote_backlight_timeout_plugged), 11, {5, S_O(remote_backlight_timeout_plugged), 11,
"remote backlight timeout plugged", backlight_times_conf }, "remote backlight timeout plugged", backlight_times_conf },
#endif #endif
@ -1018,13 +1018,13 @@ void settings_apply(void)
lcd_remote_emireduce(global_settings.remote_reduce_ticking); lcd_remote_emireduce(global_settings.remote_reduce_ticking);
#endif #endif
remote_backlight_set_timeout(global_settings.remote_backlight_timeout); remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged); remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged);
#endif #endif
#endif #endif
#ifdef CONFIG_BACKLIGHT #ifdef CONFIG_BACKLIGHT
backlight_set_timeout(global_settings.backlight_timeout); backlight_set_timeout(global_settings.backlight_timeout);
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged); backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
#endif #endif
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)

View file

@ -81,7 +81,7 @@ void dac_line_in(bool enable);
#include "backdrop.h" #include "backdrop.h"
#endif #endif
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
static bool car_adapter_mode(void) static bool car_adapter_mode(void)
{ {
return set_bool( str(LANG_CAR_ADAPTER_MODE), return set_bool( str(LANG_CAR_ADAPTER_MODE),
@ -177,7 +177,7 @@ static bool caption_backlight(void)
&global_settings.caption_backlight); &global_settings.caption_backlight);
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
static bool backlight_timer_plugged(void) static bool backlight_timer_plugged(void)
{ {
return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING), return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING),
@ -248,7 +248,7 @@ static bool remote_backlight_timer(void)
remote_backlight_set_timeout ); remote_backlight_set_timeout );
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
static bool remote_backlight_timer_plugged(void) static bool remote_backlight_timer_plugged(void)
{ {
return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING), return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING),
@ -1715,7 +1715,7 @@ static bool lcd_settings_menu(void)
static const struct menu_item items[] = { static const struct menu_item items[] = {
#ifdef CONFIG_BACKLIGHT #ifdef CONFIG_BACKLIGHT
{ ID2P(LANG_BACKLIGHT), backlight_timer }, { ID2P(LANG_BACKLIGHT), backlight_timer },
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
{ ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged }, { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged },
#endif #endif
{ ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight }, { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight },
@ -1763,7 +1763,7 @@ static bool lcd_remote_settings_menu(void)
static const struct menu_item items[] = { static const struct menu_item items[] = {
{ ID2P(LANG_BACKLIGHT), remote_backlight_timer }, { ID2P(LANG_BACKLIGHT), remote_backlight_timer },
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
{ ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING),
remote_backlight_timer_plugged }, remote_backlight_timer_plugged },
#endif #endif
@ -1860,9 +1860,7 @@ static bool battery_settings_menu(void)
{ ID2P(LANG_BATTERY_TYPE), battery_type }, { ID2P(LANG_BATTERY_TYPE), battery_type },
#endif #endif
#else #else
#ifndef HAVE_CHARGE_CTRL
{ "Dummy", NULL }, /* to have an entry at all, in the simulator */ { "Dummy", NULL }, /* to have an entry at all, in the simulator */
#endif
#endif #endif
}; };
@ -1975,7 +1973,7 @@ static bool system_settings_menu(void)
#if CONFIG_CODEC == MAS3507D #if CONFIG_CODEC == MAS3507D
{ ID2P(LANG_LINE_IN), line_in }, { ID2P(LANG_LINE_IN), line_in },
#endif #endif
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
{ ID2P(LANG_CAR_ADAPTER_MODE), car_adapter_mode }, { ID2P(LANG_CAR_ADAPTER_MODE), car_adapter_mode },
#endif #endif
}; };

View file

@ -49,12 +49,6 @@
enum playmode ff_mode; enum playmode ff_mode;
long switch_tick;
bool battery_state = true;
#ifdef HAVE_CHARGING
int battery_charge_step = 0;
#endif
void status_init(void) void status_init(void)
{ {
ff_mode = 0; ff_mode = 0;

View file

@ -21,12 +21,6 @@
extern enum playmode ff_mode; extern enum playmode ff_mode;
extern long switch_tick;
extern bool battery_state;
#ifdef HAVE_CHARGING
extern int battery_charge_step;
#endif
#if defined(HAVE_LCD_CHARCELLS) #if defined(HAVE_LCD_CHARCELLS)
extern bool record; extern bool record;
extern bool audio; extern bool audio;

View file

@ -644,7 +644,7 @@ static bool dirbrowse(void)
if (!global_settings.party_mode) if (!global_settings.party_mode)
audio_stop(); audio_stop();
} }
#if defined(HAVE_CHARGING) && \ #if defined(CONFIG_CHARGING) && \
(CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF) (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
else { else {
if (!charger_inserted()) { if (!charger_inserted()) {
@ -658,7 +658,7 @@ static bool dirbrowse(void)
#endif #endif
} }
break; break;
#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
case TREE_OFF | BUTTON_REPEAT: case TREE_OFF | BUTTON_REPEAT:
if (charger_inserted()) { if (charger_inserted()) {
charging_splash(); charging_splash();

View file

@ -156,14 +156,14 @@ static struct event_queue backlight_queue;
static int backlight_timer; static int backlight_timer;
static int backlight_timeout = 5*HZ; static int backlight_timeout = 5*HZ;
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
static int backlight_timeout_plugged = 5*HZ; static int backlight_timeout_plugged = 5*HZ;
#endif #endif
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
static int remote_backlight_timer; static int remote_backlight_timer;
static int remote_backlight_timeout = 5*HZ; static int remote_backlight_timeout = 5*HZ;
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
static int remote_backlight_timeout_plugged = 5*HZ; static int remote_backlight_timeout_plugged = 5*HZ;
#endif #endif
#endif #endif
@ -370,7 +370,7 @@ void backlight_thread(void)
{ {
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
case REMOTE_BACKLIGHT_ON: case REMOTE_BACKLIGHT_ON:
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
if (charger_inserted() if (charger_inserted()
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
|| usb_powered() || usb_powered()
@ -399,7 +399,7 @@ void backlight_thread(void)
#endif /* HAVE_REMOTE_LCD */ #endif /* HAVE_REMOTE_LCD */
case BACKLIGHT_ON: case BACKLIGHT_ON:
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
if (charger_inserted() if (charger_inserted()
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
|| usb_powered() || usb_powered()
@ -447,7 +447,7 @@ void backlight_thread(void)
static void backlight_tick(void) static void backlight_tick(void)
{ {
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
static bool charger_was_inserted = false; static bool charger_was_inserted = false;
bool charger_is_inserted = charger_inserted() bool charger_is_inserted = charger_inserted()
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
@ -463,7 +463,7 @@ static void backlight_tick(void)
#endif #endif
} }
charger_was_inserted = charger_is_inserted; charger_was_inserted = charger_is_inserted;
#endif /* HAVE_CHARGING */ #endif /* CONFIG_CHARGING */
if(backlight_timer) if(backlight_timer)
{ {
@ -535,7 +535,7 @@ bool is_backlight_on(void)
/* return value in ticks; 0 means always on, <0 means always off */ /* return value in ticks; 0 means always on, <0 means always off */
int backlight_get_current_timeout(void) int backlight_get_current_timeout(void)
{ {
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
if (charger_inserted() if (charger_inserted()
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
|| usb_powered() || usb_powered()
@ -558,7 +558,7 @@ void backlight_set_timeout(int index)
backlight_on(); backlight_on();
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
void backlight_set_timeout_plugged(int index) void backlight_set_timeout_plugged(int index)
{ {
if((unsigned)index >= sizeof(backlight_timeout_value)) if((unsigned)index >= sizeof(backlight_timeout_value))
@ -589,7 +589,7 @@ void remote_backlight_set_timeout(int index)
remote_backlight_on(); remote_backlight_on();
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
void remote_backlight_set_timeout_plugged(int index) void remote_backlight_set_timeout_plugged(int index)
{ {
if((unsigned)index >= sizeof(backlight_timeout_value)) if((unsigned)index >= sizeof(backlight_timeout_value))
@ -603,7 +603,7 @@ void remote_backlight_set_timeout_plugged(int index)
/* return value in ticks; 0 means always on, <0 means always off */ /* return value in ticks; 0 means always on, <0 means always off */
int remote_backlight_get_current_timeout(void) int remote_backlight_get_current_timeout(void)
{ {
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
if (charger_inserted() if (charger_inserted()
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
|| usb_powered() || usb_powered()

View file

@ -490,7 +490,7 @@ static void button_tick(void)
|| btn == BUTTON_RC_STOP || btn == BUTTON_RC_STOP
#endif #endif
) && ) &&
#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
!charger_inserted() && !charger_inserted() &&
#endif #endif
repeat_count > POWEROFF_COUNT) repeat_count > POWEROFF_COUNT)
@ -1248,7 +1248,7 @@ static int button_read(void)
backlight_on(); backlight_on();
} }
/* TODO: add light handling for the remote */ /* TODO: add light handling for the remote */
hold_button = button_hold(); hold_button = button_hold();
remote_hold_button = remote_button_hold(); remote_hold_button = remote_button_hold();

View file

@ -29,7 +29,7 @@
#include "pcf50606.h" #include "pcf50606.h"
#include "usb.h" #include "usb.h"
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
bool charger_enabled; bool charger_enabled;
#endif #endif
@ -92,7 +92,7 @@ void power_init(void)
or_b(0x20, &PBIORL); or_b(0x20, &PBIORL);
or_b(0x20, &PBDRL); /* hold power */ or_b(0x20, &PBDRL); /* hold power */
#endif #endif
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
PBCR2 &= ~0x0c00; /* GPIO for PB5 */ PBCR2 &= ~0x0c00; /* GPIO for PB5 */
or_b(0x20, &PBIORL); /* Set charging control bit to output */ or_b(0x20, &PBIORL); /* Set charging control bit to output */
charger_enable(false); /* Default to charger OFF */ charger_enable(false); /* Default to charger OFF */
@ -106,7 +106,7 @@ void power_init(void)
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
bool charger_inserted(void) bool charger_inserted(void)
{ {
#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
@ -115,7 +115,7 @@ bool charger_inserted(void)
return (P7 & 0x80) == 0; return (P7 & 0x80) == 0;
#elif defined(IAUDIO_X5) #elif defined(IAUDIO_X5)
return (GPIO1_READ & 0x01000000)?true:false; return (GPIO1_READ & 0x01000000)?true:false;
#elif defined(HAVE_CHARGE_CTRL) #elif CONFIG_CHARGING == CHARGING_CONTROL
/* Recorder */ /* Recorder */
return adc_read(ADC_EXT_POWER) > 0x100; return adc_read(ADC_EXT_POWER) > 0x100;
#elif defined (HAVE_FMADC) #elif defined (HAVE_FMADC)
@ -133,9 +133,9 @@ bool charger_inserted(void)
return (PADR & 1) == 0; return (PADR & 1) == 0;
#endif #endif
} }
#endif /* HAVE_CHARGING */ #endif /* CONFIG_CHARGING */
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
void charger_enable(bool on) void charger_enable(bool on)
{ {
if(on) if(on)
@ -151,14 +151,22 @@ void charger_enable(bool on)
} }
#endif #endif
#ifdef HAVE_CHARGE_STATE #if CONFIG_CHARGING == CHARGING_MONITOR
/* Returns true if the unit is charging the batteries. */ /* Returns true if the unit is charging the batteries. */
bool charging_state(void) { bool charging_state(void) {
#if defined(IRIVER_H100_SERIES) #if CONFIG_BATTERY == BATT_LIION2200
/* We use the information from the ADC_EXT_POWER ADC channel, which
tells us the charging current from the LTC1734. When DC is
connected (either via the external adapter, or via USB), we try
to determine if it is actively charging or only maintaining the
charge. My tests show that ADC readings below about 0x80 means
that the LTC1734 is only maintaining the charge. */
return adc_read(ADC_EXT_POWER) >= 0x80;
#elif defined(IRIVER_H100_SERIES) /* FIXME */
return charger_inserted(); return charger_inserted();
#elif defined(IRIVER_H300_SERIES) #elif defined IRIVER_H300_SERIES
return (GPIO_READ & 0x00800000)?true:false; return (GPIO_READ & 0x00800000)?true:false;
#elif defined(IPOD_VIDEO) #elif defined IPOD_VIDEO
return (GPIOB_INPUT_VAL & 0x01)?false:true; return (GPIOB_INPUT_VAL & 0x01)?false:true;
#endif #endif
} }

View file

@ -90,8 +90,8 @@
/* How to detect USB */ /* How to detect USB */
#define USB_FMRECORDERSTYLE 1 #define USB_FMRECORDERSTYLE 1
/* Define this if the platform can charge batteries */ /* Hardware controlled charging with monitoring */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_MONITOR
/* The start address index for ROM builds */ /* The start address index for ROM builds */
/* #define ROM_START 0x14010 for behind original Archos */ /* #define ROM_START 0x14010 for behind original Archos */

View file

@ -61,8 +61,8 @@
#define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */ #define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING #define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -54,8 +54,8 @@
#define BATTERY_SCALE_FACTOR 6465 #define BATTERY_SCALE_FACTOR 6465
/* chosen values at random -- jyp */ /* chosen values at random -- jyp */
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_SIMPLE
#define CPU_FREQ 30000000 #define CPU_FREQ 30000000
/* approximate value (and false in general since freq is variable) */ /* approximate value (and false in general since freq is variable) */

View file

@ -45,8 +45,8 @@
#define BATTERY_SCALE_FACTOR 6465 #define BATTERY_SCALE_FACTOR 6465
/* chosen values at random -- jyp */ /* chosen values at random -- jyp */
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_SIMPLE
#define CPU_FREQ 30000000 #define CPU_FREQ 30000000
/* approximate value (and false in general since freq is variable) */ /* approximate value (and false in general since freq is variable) */

View file

@ -89,11 +89,9 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */ #define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */
/* Define this if the platform can charge batteries */ /* Hardware controlled charging */
#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
#define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */
/* For units with a hardware charger that reports charge state */
#define HAVE_CHARGE_STATE 1
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING #define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -84,11 +84,9 @@
/* Define if we have a hardware defect that causes ticking on the audio line */ /* Define if we have a hardware defect that causes ticking on the audio line */
#define HAVE_REMOTE_LCD_TICKING #define HAVE_REMOTE_LCD_TICKING
/* Define this if the platform can charge batteries */ /* Hardware controlled charging */
#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
#define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */
/* For units with a hardware charger that reports charge state */
#define HAVE_CHARGE_STATE 1
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING #define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -85,14 +85,8 @@
/* Define if we have a hardware defect that causes ticking on the audio line */ /* Define if we have a hardware defect that causes ticking on the audio line */
#define HAVE_REMOTE_LCD_TICKING #define HAVE_REMOTE_LCD_TICKING
/* Define this if the platform can charge batteries */ /* Hardware controlled charging with monitoring */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_MONITOR
/* For units with a hardware charger that reports charge state */
#define HAVE_CHARGE_STATE 1
/* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING
/* The size of the flash ROM */ /* The size of the flash ROM */
#define FLASH_SIZE 0x400000 #define FLASH_SIZE 0x400000

View file

@ -65,8 +65,8 @@
#define HAVE_TLV320 #define HAVE_TLV320
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING #define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -56,8 +56,8 @@
#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */ #define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
//#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -68,8 +68,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865 #define BATTERY_SCALE_FACTOR 5865
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
//#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -70,8 +70,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865 #define BATTERY_SCALE_FACTOR 5865
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
//#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -69,8 +69,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865 #define BATTERY_SCALE_FACTOR 5865
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
//#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -70,8 +70,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865 #define BATTERY_SCALE_FACTOR 5865
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
//#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -73,8 +73,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865 #define BATTERY_SCALE_FACTOR 5865
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
//#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -74,8 +74,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865 #define BATTERY_SCALE_FACTOR 5865
/* Define this if the platform can charge batteries */ /* Hardware controlled charging? FIXME */
//#define HAVE_CHARGING 1 //#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING

View file

@ -74,14 +74,12 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */ #define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865 #define BATTERY_SCALE_FACTOR 5865
/* Define this if the platform can charge batteries */ /* Hardware controlled charging with monitoring */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_MONITOR
/* define this if the hardware can be powered off while charging */ /* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING //#define HAVE_POWEROFF_WHILE_CHARGING
#define HAVE_CHARGE_STATE 1
/* The start address index for ROM builds */ /* The start address index for ROM builds */
#define ROM_START 0x00000000 #define ROM_START 0x00000000

View file

@ -67,8 +67,8 @@
/* How to detect USB */ /* How to detect USB */
#define USB_PLAYERSTYLE 1 #define USB_PLAYERSTYLE 1
/* Define this if the platform can charge batteries */ /* Hardware controlled charging */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_SIMPLE
/* The start address index for ROM builds */ /* The start address index for ROM builds */
/* #define ROM_START 0xD010 for behind original Archos */ /* #define ROM_START 0xD010 for behind original Archos */

View file

@ -45,9 +45,6 @@
/* Define this if you have a SH7034 */ /* Define this if you have a SH7034 */
#define CONFIG_CPU SH7034 #define CONFIG_CPU SH7034
/* Define this if you have charging control */
#define HAVE_CHARGE_CTRL
/* Define this if you have ATA power-off control */ /* Define this if you have ATA power-off control */
#define HAVE_ATA_POWER_OFF #define HAVE_ATA_POWER_OFF
@ -80,8 +77,8 @@
/* How to detect USB */ /* How to detect USB */
#define USB_RECORDERSTYLE 1 #define USB_RECORDERSTYLE 1
/* Define this if the platform can charge batteries */ /* Software controlled charging */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_CONTROL
/* The start address index for ROM builds */ /* The start address index for ROM builds */
/* #define ROM_START 0x11010 for behind original Archos */ /* #define ROM_START 0x11010 for behind original Archos */

View file

@ -90,8 +90,8 @@
/* How to detect USB */ /* How to detect USB */
#define USB_FMRECORDERSTYLE 1 #define USB_FMRECORDERSTYLE 1
/* Define this if the platform can charge batteries */ /* Hardware controlled charging with monitoring */
#define HAVE_CHARGING 1 #define CONFIG_CHARGING CHARGING_MONITOR
/* The start address index for ROM builds */ /* The start address index for ROM builds */
/* #define ROM_START 0x12010 for behind original Archos */ /* #define ROM_START 0x12010 for behind original Archos */

View file

@ -68,6 +68,11 @@
#define BATT_3AAA 1000 /* Ondio */ #define BATT_3AAA 1000 /* Ondio */
#define BATT_LIPOL1300 1300 /* the type used in iRiver h1x0 models */ #define BATT_LIPOL1300 1300 /* the type used in iRiver h1x0 models */
/* CONFIG_CHARGING */
#define CHARGING_SIMPLE 1 /* Simple, hardware controlled charging */
#define CHARGING_MONITOR 2 /* Hardware controlled charging with monitoring */
#define CHARGING_CONTROL 3 /* Software controlled charging */
/* CONFIG_LCD */ /* CONFIG_LCD */
#define LCD_GMINI100 0 #define LCD_GMINI100 0
#define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */ #define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */

View file

@ -19,12 +19,12 @@
#ifndef _POWER_H_ #ifndef _POWER_H_
#define _POWER_H_ #define _POWER_H_
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
extern bool charger_enabled; extern bool charger_enabled;
void charger_enable(bool on); void charger_enable(bool on);
#endif #endif
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
bool charger_inserted(void); bool charger_inserted(void);
#endif #endif
@ -35,7 +35,7 @@ void ide_power_enable(bool on);
void power_init(void); void power_init(void);
# ifdef HAVE_CHARGE_STATE # if CONFIG_CHARGING == CHARGING_MONITOR
bool charging_state(void); bool charging_state(void);
# endif # endif

View file

@ -28,7 +28,7 @@
#ifndef SIMULATOR #ifndef SIMULATOR
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
#define START_TOPOFF_CHG 85 /* Battery % to start at top-off */ #define START_TOPOFF_CHG 85 /* Battery % to start at top-off */
#define START_TRICKLE_CHG 95 /* Battery % to start at trickle */ #define START_TRICKLE_CHG 95 /* Battery % to start at trickle */
@ -59,23 +59,21 @@ extern int pid_p; /* PID proportional term */
extern int pid_i; /* PID integral term */ extern int pid_i; /* PID integral term */
extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */ extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
#endif /* HAVE_CHARGE_CTRL */ #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
#if defined(HAVE_CHARGE_CTRL) || \ #if CONFIG_CHARGING >= CHARGING_MONITOR
(CONFIG_BATTERY == BATT_LIION2200) || \ typedef enum { /* sorted by increasing charging current */
defined(HAVE_CHARGE_STATE) DISCHARGING = 0,
typedef enum { TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */
DISCHARGING, TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */
CHARGING, CHARGING /* Can occur for all CONFIG_CHARGING options */
TOPOFF,
TRICKLE
} charge_state_type; } charge_state_type;
/* tells what the charger is doing */ /* tells what the charger is doing */
extern charge_state_type charge_state; extern charge_state_type charge_state;
#endif /* defined(HAVE_CHARGE_CTRL) || (CONFIG_BATTERY == BATT_LIION2200) */ #endif /* CONFIG_CHARGING >= CHARGING_MONITOR */
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
/* /*
* Flag that the charger has been plugged in/removed: this is set for exactly * Flag that the charger has been plugged in/removed: this is set for exactly
* one time through the power loop when the charger has been plugged in. * one time through the power loop when the charger has been plugged in.

View file

@ -64,7 +64,7 @@
* in it (one sample per minute). This is only for very low level debug. * in it (one sample per minute). This is only for very low level debug.
*/ */
#undef DEBUG_FILE #undef DEBUG_FILE
#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) #if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
#include "file.h" #include "file.h"
#define DEBUG_FILE_NAME "/powermgmt.csv" #define DEBUG_FILE_NAME "/powermgmt.csv"
#define DEBUG_MESSAGE_LEN 133 #define DEBUG_MESSAGE_LEN 133
@ -190,7 +190,7 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
#endif #endif
}; };
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
charger_input_state_type charger_input_state IDATA_ATTR; charger_input_state_type charger_input_state IDATA_ATTR;
/* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */
@ -207,15 +207,13 @@ static const short percent_to_volt_charge[11] =
476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */ 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */
#endif #endif
}; };
#endif /* HAVE_CHARGING */ #endif /* CONFIG_CHARGING */
#if defined(HAVE_CHARGE_CTRL) || \ #if CONFIG_CHARGING >= CHARGING_MONITOR
CONFIG_BATTERY == BATT_LIION2200 || \
defined(HAVE_CHARGE_STATE)
charge_state_type charge_state; /* charging mode */ charge_state_type charge_state; /* charging mode */
#endif #endif
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
int long_delta; /* long term delta battery voltage */ int long_delta; /* long term delta battery voltage */
int short_delta; /* short term delta battery voltage */ int short_delta; /* short term delta battery voltage */
bool disk_activity_last_cycle = false; /* flag set to aid charger time bool disk_activity_last_cycle = false; /* flag set to aid charger time
@ -235,7 +233,7 @@ int trickle_sec = 0; /* how many seconds should the
charging? */ charging? */
int pid_p = 0; /* PID proportional term */ int pid_p = 0; /* PID proportional term */
int pid_i = 0; /* PID integral term */ int pid_i = 0; /* PID integral term */
#endif /* HAVE_CHARGE_CTRL */ #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
/* /*
* Average battery voltage and charger voltage, filtered via a digital * Average battery voltage and charger voltage, filtered via a digital
@ -366,7 +364,7 @@ static void battery_status_update(void)
{ {
int level; int level;
#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE) #if CONFIG_CHARGING >= CHARGING_MONITOR
if (charge_state == DISCHARGING) { if (charge_state == DISCHARGING) {
level = voltage_to_percent(battery_centivolts, level = voltage_to_percent(battery_centivolts,
percent_to_volt_discharge[battery_type]); percent_to_volt_discharge[battery_type]);
@ -397,7 +395,7 @@ static void battery_status_update(void)
/* calculate estimated remaining running time */ /* calculate estimated remaining running time */
/* discharging: remaining running time */ /* discharging: remaining running time */
/* charging: remaining charging time */ /* charging: remaining charging time */
#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE) #if CONFIG_CHARGING >= CHARGING_MONITOR
if (charge_state == CHARGING) { if (charge_state == CHARGING) {
powermgmt_est_runningtime_min = (100 - level) * battery_capacity / 100 powermgmt_est_runningtime_min = (100 - level) * battery_capacity / 100
* 60 / (CURRENT_MAX_CHG - runcurrent()); * 60 / (CURRENT_MAX_CHG - runcurrent());
@ -425,7 +423,7 @@ static void handle_auto_poweroff(void)
long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ; long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ;
int audio_stat = audio_status(); int audio_stat = audio_status();
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
/* /*
* Inhibit shutdown as long as the charger is plugged in. If it is * Inhibit shutdown as long as the charger is plugged in. If it is
* unplugged, wait for a timeout period and then shut down. * unplugged, wait for a timeout period and then shut down.
@ -458,7 +456,7 @@ static void handle_auto_poweroff(void)
if(TIME_AFTER(current_tick, sleeptimer_endtick)) if(TIME_AFTER(current_tick, sleeptimer_endtick))
{ {
audio_stop(); audio_stop();
#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
if((charger_input_state == CHARGER) || if((charger_input_state == CHARGER) ||
(charger_input_state == CHARGER_PLUGGED)) (charger_input_state == CHARGER_PLUGGED))
{ {
@ -538,7 +536,7 @@ static void power_thread_sleep(int ticks)
while (ticks > 0) { while (ticks > 0) {
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
/* /*
* Detect charger plugged/unplugged transitions. On a plugged or * Detect charger plugged/unplugged transitions. On a plugged or
* unplugged event, we return immediately, run once through the main * unplugged event, we return immediately, run once through the main
@ -577,7 +575,7 @@ static void power_thread_sleep(int ticks)
} }
} }
#endif #endif
#ifdef HAVE_CHARGE_STATE #if CONFIG_CHARGING == CHARGING_MONITOR
switch (charger_input_state) { switch (charger_input_state) {
case CHARGER_UNPLUGGED: case CHARGER_UNPLUGGED:
case NO_CHARGER: case NO_CHARGER:
@ -593,7 +591,7 @@ static void power_thread_sleep(int ticks)
break; break;
} }
#endif /* HAVE_CHARGE_STATE */ #endif /* CONFIG_CHARGING == CHARGING_MONITOR */
small_ticks = MIN(HZ/2, ticks); small_ticks = MIN(HZ/2, ticks);
sleep(small_ticks); sleep(small_ticks);
@ -628,13 +626,13 @@ static void power_thread_sleep(int ticks)
battery_status_update(); battery_status_update();
} }
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
if (ata_disk_is_active()) { if (ata_disk_is_active()) {
/* flag hdd use for charging calculation */ /* flag hdd use for charging calculation */
disk_activity_last_cycle = true; disk_activity_last_cycle = true;
} }
#endif #endif
#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) #if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
/* /*
* If we have a lot of pending writes or if the disk is spining, * If we have a lot of pending writes or if the disk is spining,
* fsync the debug log file. * fsync the debug log file.
@ -660,7 +658,7 @@ static void power_thread(void)
{ {
int i; int i;
short *phps, *phpd; /* power history rotation pointers */ short *phps, *phpd; /* power history rotation pointers */
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
unsigned int target_voltage = TRICKLE_VOLTAGE; /* desired topoff/trickle unsigned int target_voltage = TRICKLE_VOLTAGE; /* desired topoff/trickle
* voltage level */ * voltage level */
int charge_max_time_idle = 0; /* max. charging duration, calculated at int charge_max_time_idle = 0; /* max. charging duration, calculated at
@ -678,7 +676,7 @@ static void power_thread(void)
BATT_AVE_SAMPLES; BATT_AVE_SAMPLES;
battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000;
#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) #if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
fd = -1; fd = -1;
wrcount = 0; wrcount = 0;
#endif #endif
@ -694,25 +692,7 @@ static void power_thread(void)
/* insert new value at the start, in centivolts 8-) */ /* insert new value at the start, in centivolts 8-) */
power_history[0] = battery_centivolts; power_history[0] = battery_centivolts;
#if CONFIG_BATTERY == BATT_LIION2200 #if CONFIG_CHARGING == CHARGING_CONTROL
/* We use the information from the ADC_EXT_POWER ADC channel, which
tells us the charging current from the LTC1734. When DC is
connected (either via the external adapter, or via USB), we try
to determine if it is actively charging or only maintaining the
charge. My tests show that ADC readings below about 0x80 means
that the LTC1734 is only maintaining the charge. */
if(charger_inserted()) {
if(adc_read(ADC_EXT_POWER) < 0x80) {
charge_state = TRICKLE;
} else {
charge_state = CHARGING;
}
} else {
charge_state = DISCHARGING;
}
#endif /* # if CONFIG_BATTERY == BATT_LIION2200 */
#ifdef HAVE_CHARGE_CTRL
if (charger_input_state == CHARGER_PLUGGED) { if (charger_input_state == CHARGER_PLUGGED) {
pid_p = 0; pid_p = 0;
pid_i = 0; pid_i = 0;
@ -876,7 +856,7 @@ static void power_thread(void)
} }
} }
} }
else if (charge_state > CHARGING) /* top off or trickle */ else if (charge_state != DISCHARGING) /* top off or trickle */
{ {
/* /*
*Time to switch from topoff to trickle? *Time to switch from topoff to trickle?
@ -946,11 +926,11 @@ static void power_thread(void)
snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge"); snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge");
} }
#endif /* end HAVE_CHARGE_CTRL */ #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
/* sleep for a minute */ /* sleep for a minute */
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
if(trickle_sec > 0) { if(trickle_sec > 0) {
charger_enable(true); charger_enable(true);
power_thread_sleep(HZ * trickle_sec); power_thread_sleep(HZ * trickle_sec);
@ -962,7 +942,7 @@ static void power_thread(void)
power_thread_sleep(HZ * 60); power_thread_sleep(HZ * 60);
#endif #endif
#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) #if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
if(usb_inserted()) { if(usb_inserted()) {
if(fd >= 0) { if(fd >= 0) {
/* It is probably too late to close the file but we can try...*/ /* It is probably too late to close the file but we can try...*/
@ -992,7 +972,7 @@ static void power_thread(void)
#endif #endif
handle_auto_poweroff(); handle_auto_poweroff();
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
powermgmt_last_cycle_startstop_min++; powermgmt_last_cycle_startstop_min++;
#endif #endif
} }
@ -1029,7 +1009,7 @@ void cancel_shutdown(void)
void shutdown_hw(void) void shutdown_hw(void)
{ {
#ifndef SIMULATOR #ifndef SIMULATOR
#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) #if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
if(fd >= 0) { if(fd >= 0) {
close(fd); close(fd);
fd = -1; fd = -1;

View file

@ -65,7 +65,7 @@ int show_logo(void)
return 0; return 0;
} }
#ifdef HAVE_CHARGING #ifdef CONFIG_CHARGING
/* /*
bool backlight_get_on_when_charging(void) bool backlight_get_on_when_charging(void)
{ {
@ -83,12 +83,12 @@ void charging_screen(void)
do do
{ {
#ifdef HAVE_CHARGE_CTRL #if CONFIG_CHARGING == CHARGING_CONTROL
if (charge_state == 1) if (charge_state == CHARGING)
msg = "charging"; msg = "charging";
else if (charge_state == 2) else if (charge_state == TOPOFF)
msg = "topoff charge"; msg = "topoff charge";
else if (charge_state == 3) else if (charge_state == TRICKLE)
msg = "trickle charge"; msg = "trickle charge";
else else
msg = "not charging"; msg = "not charging";
@ -130,7 +130,7 @@ void charging_screen(void)
} }
} while (1); } while (1);
} }
#endif /* HAVE_CHARGING */ #endif /* CONFIG_CHARGING */
/* prompt user to plug USB and fix a problem */ /* prompt user to plug USB and fix a problem */
void prompt_usb(const char* msg1, const char* msg2) void prompt_usb(const char* msg1, const char* msg2)
@ -172,7 +172,7 @@ void main(void)
button_init(); button_init();
powermgmt_init(); powermgmt_init();
#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
if (charger_inserted() if (charger_inserted()
#ifdef ATA_POWER_PLAYERSTYLE #ifdef ATA_POWER_PLAYERSTYLE
&& !ide_powered() /* relies on probing result from bootloader */ && !ide_powered() /* relies on probing result from bootloader */