summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-06-06 22:23:52 +0000
committerJens Arnold <amiconn@rockbox.org>2006-06-06 22:23:52 +0000
commit0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f (patch)
treee3e77d4e6b25b82c82b3570cd8c4a988c7788e66
parent8c9e22580e220b793130ed3ac67b9c54e85b3d0f (diff)
downloadrockbox-0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f.tar.gz
rockbox-0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f.zip
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
-rw-r--r--apps/debug_menu.c18
-rw-r--r--apps/gui/gwps-common.c6
-rw-r--r--apps/gui/statusbar.c228
-rw-r--r--apps/gui/statusbar.h26
-rw-r--r--apps/main.c6
-rw-r--r--apps/main_menu.c8
-rw-r--r--apps/misc.c6
-rw-r--r--apps/plugin.c6
-rw-r--r--apps/plugin.h4
-rw-r--r--apps/plugins/battery_bench.c26
-rw-r--r--apps/screens.c16
-rw-r--r--apps/settings.c10
-rw-r--r--apps/settings_menu.c14
-rw-r--r--apps/status.c6
-rw-r--r--apps/status.h6
-rw-r--r--apps/tree.c4
-rw-r--r--firmware/backlight.c20
-rw-r--r--firmware/drivers/button.c4
-rw-r--r--firmware/drivers/power.c28
-rw-r--r--firmware/export/config-fmrecorder.h4
-rw-r--r--firmware/export/config-gigabeat.h4
-rw-r--r--firmware/export/config-gmini120.h4
-rw-r--r--firmware/export/config-gminisp.h4
-rw-r--r--firmware/export/config-h100.h8
-rw-r--r--firmware/export/config-h120.h8
-rw-r--r--firmware/export/config-h300.h10
-rw-r--r--firmware/export/config-iaudiox5.h4
-rw-r--r--firmware/export/config-ifp7xx.h4
-rw-r--r--firmware/export/config-ipod3g.h4
-rw-r--r--firmware/export/config-ipod4g.h4
-rw-r--r--firmware/export/config-ipodcolor.h4
-rw-r--r--firmware/export/config-ipodmini.h4
-rwxr-xr-xfirmware/export/config-ipodmini2g.h4
-rw-r--r--firmware/export/config-ipodnano.h4
-rw-r--r--firmware/export/config-ipodvideo.h6
-rw-r--r--firmware/export/config-player.h4
-rw-r--r--firmware/export/config-recorder.h7
-rw-r--r--firmware/export/config-recorderv2.h4
-rw-r--r--firmware/export/config.h5
-rw-r--r--firmware/export/power.h6
-rw-r--r--firmware/export/powermgmt.h22
-rw-r--r--firmware/powermgmt.c68
-rw-r--r--flash/bootbox/main.c14
43 files changed, 301 insertions, 351 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index fac570d39a..d426356d11 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -1334,8 +1334,8 @@ bool view_battery(void)
1334 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100); 1334 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1335 lcd_puts(0, 2, buf); 1335 lcd_puts(0, 2, buf);
1336#endif 1336#endif
1337#ifdef HAVE_CHARGING 1337#ifdef CONFIG_CHARGING
1338#ifdef HAVE_CHARGE_CTRL 1338#if CONFIG_CHARGING == CHARGING_CONTROL
1339 snprintf(buf, 30, "Chgr: %s %s", 1339 snprintf(buf, 30, "Chgr: %s %s",
1340 charger_inserted() ? "present" : "absent", 1340 charger_inserted() ? "present" : "absent",
1341 charger_enabled ? "on" : "off"); 1341 charger_enabled ? "on" : "off");
@@ -1345,8 +1345,8 @@ bool view_battery(void)
1345 snprintf(buf, 30, "long delta: %d", long_delta); 1345 snprintf(buf, 30, "long delta: %d", long_delta);
1346 lcd_puts(0, 6, buf); 1346 lcd_puts(0, 6, buf);
1347 lcd_puts(0, 7, power_message); 1347 lcd_puts(0, 7, power_message);
1348#else /* !HAVE_CHARGE_CTRL */ 1348#else /* CONFIG_CHARGING != CHARGING_CONTROL */
1349#if defined IPOD_NANO || defined IPOD_VIDEO 1349#if defined IPOD_NANO || defined IPOD_VIDEO
1350 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false; 1350 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1351 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true; 1351 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1352 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false; 1352 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
@@ -1373,8 +1373,8 @@ bool view_battery(void)
1373 charger_inserted() ? "present" : "absent"); 1373 charger_inserted() ? "present" : "absent");
1374 lcd_puts(0, 3, buf); 1374 lcd_puts(0, 3, buf);
1375#endif 1375#endif
1376#endif /* !HAVE_CHARGE_CTRL */ 1376#endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1377#endif /* HAVE_CHARGING */ 1377#endif /* CONFIG_CHARGING */
1378 break; 1378 break;
1379 1379
1380 case 2: /* voltage deltas: */ 1380 case 2: /* voltage deltas: */
@@ -1393,7 +1393,7 @@ bool view_battery(void)
1393 case 3: /* remaining time estimation: */ 1393 case 3: /* remaining time estimation: */
1394 lcd_clear_display(); 1394 lcd_clear_display();
1395 1395
1396#ifdef HAVE_CHARGE_CTRL 1396#if CONFIG_CHARGING == CHARGING_CONTROL
1397 snprintf(buf, 30, "charge_state: %d", charge_state); 1397 snprintf(buf, 30, "charge_state: %d", charge_state);
1398 lcd_puts(0, 0, buf); 1398 lcd_puts(0, 0, buf);
1399 1399
@@ -1408,7 +1408,7 @@ bool view_battery(void)
1408 1408
1409 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec); 1409 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1410 lcd_puts(0, 4, buf); 1410 lcd_puts(0, 4, buf);
1411#endif /* HAVE_CHARGE_CTRL */ 1411#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1412 1412
1413 snprintf(buf, 30, "Last PwrHist: %d.%02d V", 1413 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1414 power_history[0] / 100, 1414 power_history[0] / 100,
@@ -1465,7 +1465,7 @@ static bool view_runtime(void)
1465#endif 1465#endif
1466 1466
1467 if (state & 1) { 1467 if (state & 1) {
1468#ifdef HAVE_CHARGING 1468#ifdef CONFIG_CHARGING
1469 if (charger_inserted() 1469 if (charger_inserted()
1470#ifdef HAVE_USB_POWER 1470#ifdef HAVE_USB_POWER
1471 || usb_powered() 1471 || usb_powered()
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 5ab6ce8c82..171784c0ad 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -823,7 +823,7 @@ static char* get_tag(struct wps_data* wps_data,
823 } 823 }
824 } 824 }
825 825
826#ifdef HAVE_CHARGING 826#ifdef CONFIG_CHARGING
827 case 'p': /* External power plugged in? */ 827 case 'p': /* External power plugged in? */
828 { 828 {
829 if(charger_input_state==CHARGER) 829 if(charger_input_state==CHARGER)
@@ -832,9 +832,7 @@ static char* get_tag(struct wps_data* wps_data,
832 return NULL; 832 return NULL;
833 } 833 }
834#endif 834#endif
835#if defined(HAVE_CHARGE_CTRL) || \ 835#if CONFIG_CHARGING >= CHARGING_MONITOR
836 defined (HAVE_CHARGE_STATE) || \
837 CONFIG_BATTERY == BATT_LIION2200
838 case 'c': /* Charging */ 836 case 'c': /* Charging */
839 { 837 {
840 if (charge_state == CHARGING || charge_state == TOPOFF) { 838 if (charge_state == CHARGING || charge_state == TOPOFF) {
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c
index c9b27aea7c..b5d8b7c9ed 100644
--- a/apps/gui/statusbar.c
+++ b/apps/gui/statusbar.c
@@ -107,37 +107,73 @@ struct gui_syncstatusbar statusbars;
107 107
108void gui_statusbar_init(struct gui_statusbar * bar) 108void gui_statusbar_init(struct gui_statusbar * bar)
109{ 109{
110 bar->last_volume = -1000; /* -1000 means "first update ever" */ 110 bar->redraw_volume = true;
111 bar->battery_icon_switch_tick = 0; 111 bar->volume_icon_switch_tick = bar->battery_icon_switch_tick = current_tick;
112 bar->animated_level = 0;
113} 112}
114 113
115void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw) 114void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
116{ 115{
117 struct screen * display = bar->display; 116 struct screen * display = bar->display;
118#ifdef CONFIG_RTC
119 struct tm* tm; /* For Time */
120#endif /* CONFIG_RTC */
121 117
122#ifdef HAVE_LCD_CHARCELLS 118#ifdef HAVE_LCD_CHARCELLS
123 int vol; 119 int val;
124 (void)force_redraw; /* players always "redraw" */ 120 (void)force_redraw; /* players always "redraw" */
125#endif /* HAVE_LCD_CHARCELLS */ 121#endif /* HAVE_LCD_CHARCELLS */
126 122
127 bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume); 123 bar->info.battlevel = battery_level();
128#ifdef HAVE_CHARGING 124#ifdef HAVE_USB_POWER
125 bar->info.usb_power = usb_powered();
126#endif
127#ifdef CONFIG_CHARGING
129 bar->info.inserted = (charger_input_state == CHARGER); 128 bar->info.inserted = (charger_input_state == CHARGER);
129 if (bar->info.inserted)
130 {
131 bar->info.battery_state = true;
132
133#if CONFIG_CHARGING >= CHARGING_MONITOR
134
135 /* zero battery run time if charging */
136 if (charge_state > DISCHARGING)
137 lasttime = current_tick;
138
139 /* animate battery if charging */
140 if ((charge_state == DISCHARGING) || (charge_state == TRICKLE))
141 {
142 bar->info.batt_charge_step = -1;
143 }
144 else
145 {
146#else
147 lasttime = current_tick;
148 {
130#endif 149#endif
131 bar->info.battlevel = battery_level(); 150 /* animate in (max.) 4 steps, starting near the current charge level */
132 bar->info.battery_safe = battery_level_safe(); 151 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick))
152 {
153 if (++bar->info.batt_charge_step > 3)
154 bar->info.batt_charge_step = bar->info.battlevel / 34;
155 bar->battery_icon_switch_tick = current_tick + HZ;
156 }
157 }
158 }
159 else
160#endif
161 {
162 bar->info.batt_charge_step = -1;
163 if (battery_level_safe())
164 bar->info.battery_state = true;
165 else
166 /* blink battery if level is low */
167 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
168 (bar->info.battlevel > -1))
169 {
170 bar->info.battery_state = !bar->info.battery_state;
171 bar->battery_icon_switch_tick = current_tick + HZ;
172 }
173 }
133 174
175 bar->info.volume = sound_val2phys(SOUND_VOLUME, global_settings.volume);
134#ifdef HAVE_LCD_BITMAP 176#ifdef HAVE_LCD_BITMAP
135#ifdef CONFIG_RTC
136 tm = get_time();
137 bar->info.hour = tm->tm_hour;
138 bar->info.minute = tm->tm_min;
139#endif /* CONFIG_RTC */
140
141 bar->info.shuffle = global_settings.playlist_shuffle; 177 bar->info.shuffle = global_settings.playlist_shuffle;
142#ifdef HAS_BUTTON_HOLD 178#ifdef HAS_BUTTON_HOLD
143 bar->info.keylock = button_hold(); 179 bar->info.keylock = button_hold();
@@ -149,24 +185,25 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
149#endif 185#endif
150 bar->info.repeat = global_settings.repeat_mode; 186 bar->info.repeat = global_settings.repeat_mode;
151 bar->info.playmode = current_playmode(); 187 bar->info.playmode = current_playmode();
188
152#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) 189#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
153 if(!display->has_disk_led) 190 if(!display->has_disk_led)
154 bar->info.led = led_read(HZ/2); /* delay should match polling interval */ 191 bar->info.led = led_read(HZ/2); /* delay should match polling interval */
155#endif 192#endif
156 193#ifdef CONFIG_RTC
157#ifdef HAVE_USB_POWER 194 {
158 bar->info.usb_power = usb_powered(); 195 struct tm* tm = get_time();
159#endif /* HAVE_USB_POWER */ 196 bar->info.hour = tm->tm_hour;
197 bar->info.minute = tm->tm_min;
198 }
199#endif /* CONFIG_RTC */
160 200
161 /* only redraw if forced to, or info has changed */ 201 /* only redraw if forced to, or info has changed */
162 if (force_redraw || 202 if (force_redraw || bar->redraw_volume ||
163 bar->info.inserted ||
164 !bar->info.battery_safe ||
165 bar->info.redraw_volume ||
166 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info))) 203 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
167 { 204 {
168 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 205 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
169 display->fillrect(0,0,display->width,8); 206 display->fillrect(0, 0, display->width, STATUSBAR_HEIGHT);
170 display->set_drawmode(DRMODE_SOLID); 207 display->set_drawmode(DRMODE_SOLID);
171 208
172#else 209#else
@@ -175,65 +212,10 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
175 { 212 {
176#endif /* HAVE_LCD_BITMAP */ 213#endif /* HAVE_LCD_BITMAP */
177 214
178#ifdef HAVE_CHARGING
179 if (bar->info.inserted) {
180 battery_state = true;
181#if defined(HAVE_CHARGE_CTRL) || \
182 defined(HAVE_CHARGE_STATE) || \
183 CONFIG_BATTERY == BATT_LIION2200
184 /* zero battery run time if charging */
185 if (charge_state > DISCHARGING) {
186 lasttime = current_tick;
187 }
188
189 /* animate battery if charging */
190 if ((charge_state == CHARGING)
191#ifdef HAVE_CHARGE_CTRL
192 || (charge_state == TOPOFF)
193#endif
194 ) {
195#else
196 lasttime = current_tick;
197 {
198#endif
199 /* animate in three steps (34% per step for a better look) */
200#ifndef HAVE_CHARGE_STATE
201 bar->info.battlevel = 0;
202#endif
203 if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) {
204 if (bar->animated_level == 100)
205 {
206 bar->animated_level = bar->info.battlevel;
207 }
208 else
209 {
210 bar->animated_level += 34;
211 if (bar->animated_level > 100)
212 bar->animated_level = 100;
213 }
214 bar->battery_icon_switch_tick = current_tick + HZ;
215 }
216 }
217 }
218 else
219#endif /* HAVE_CHARGING */
220 {
221 bar->animated_level = 0;
222 if (bar->info.battery_safe)
223 battery_state = true;
224 else {
225 /* blink battery if level is low */
226 if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
227 (bar->info.battlevel > -1)) {
228 bar->battery_icon_switch_tick = current_tick+HZ;
229 battery_state = !battery_state;
230 }
231 }
232 }
233#ifdef HAVE_LCD_BITMAP 215#ifdef HAVE_LCD_BITMAP
234 if (battery_state) 216 if (bar->info.battery_state)
235 gui_statusbar_icon_battery(display, bar->info.battlevel, 217 gui_statusbar_icon_battery(display, bar->info.battlevel,
236 bar->animated_level); 218 bar->info.batt_charge_step);
237#ifdef HAVE_USB_POWER 219#ifdef HAVE_USB_POWER
238 if (bar->info.usb_power) 220 if (bar->info.usb_power)
239 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug], 221 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
@@ -243,14 +225,15 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
243 else 225 else
244#endif /* HAVE_USB_POWER */ 226#endif /* HAVE_USB_POWER */
245 /* draw power plug if charging */ 227 /* draw power plug if charging */
228#ifdef CONFIG_CHARGING
246 if (bar->info.inserted) 229 if (bar->info.inserted)
247 display->mono_bitmap(bitmap_icons_7x8[Icon_Plug], 230 display->mono_bitmap(bitmap_icons_7x8[Icon_Plug],
248 STATUSBAR_PLUG_X_POS, 231 STATUSBAR_PLUG_X_POS,
249 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH, 232 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
250 STATUSBAR_HEIGHT); 233 STATUSBAR_HEIGHT);
234#endif
251 235
252 bar->info.redraw_volume = gui_statusbar_icon_volume(bar, 236 bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume);
253 bar->info.volume);
254 gui_statusbar_icon_play_state(display, current_playmode() + 237 gui_statusbar_icon_play_state(display, current_playmode() +
255 Icon_Play); 238 Icon_Play);
256 239
@@ -292,20 +275,24 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
292 275
293 276
294#ifdef HAVE_LCD_CHARCELLS 277#ifdef HAVE_LCD_CHARCELLS
295 if (bar->info.battlevel > -1) 278 display->icon(ICON_BATTERY, bar->info.battery_state);
296 display->icon(ICON_BATTERY, battery_state); 279
297 display->icon(ICON_BATTERY_1, bar->info.battlevel > 25); 280 if (bar->info.batt_charge_step > -1)
298 display->icon(ICON_BATTERY_2, bar->info.battlevel > 50); 281 val = bar->info.batt_charge_step;
299 display->icon(ICON_BATTERY_3, bar->info.battlevel > 75); 282 else
300 283 val = (bar->info.battlevel * 3 + 50) / 100;
301 vol = 100 * (bar->info.volume - sound_min(SOUND_VOLUME)) 284 display->icon(ICON_BATTERY_1, val >= 1);
285 display->icon(ICON_BATTERY_2, val >= 2);
286 display->icon(ICON_BATTERY_3, val >= 3);
287
288 val = 10 * (bar->info.volume - sound_min(SOUND_VOLUME))
302 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME)); 289 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
303 display->icon(ICON_VOLUME, true); 290 display->icon(ICON_VOLUME, true);
304 display->icon(ICON_VOLUME_1, vol > 10); 291 display->icon(ICON_VOLUME_1, val >= 1);
305 display->icon(ICON_VOLUME_2, vol > 30); 292 display->icon(ICON_VOLUME_2, val >= 3);
306 display->icon(ICON_VOLUME_3, vol > 50); 293 display->icon(ICON_VOLUME_3, val >= 5);
307 display->icon(ICON_VOLUME_4, vol > 70); 294 display->icon(ICON_VOLUME_4, val >= 7);
308 display->icon(ICON_VOLUME_5, vol > 90); 295 display->icon(ICON_VOLUME_5, val >= 9);
309 296
310 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY); 297 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
311 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE); 298 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
@@ -326,40 +313,41 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
326 * Print battery icon to status bar 313 * Print battery icon to status bar
327 */ 314 */
328void gui_statusbar_icon_battery(struct screen * display, int percent, 315void gui_statusbar_icon_battery(struct screen * display, int percent,
329 int animated_percent) 316 int batt_charge_step)
330{ 317{
331 int fill, endfill; 318 int fill, endfill;
332 char buffer[5]; 319 char buffer[5];
333 unsigned int width, height; 320 unsigned int width, height;
334#if LCD_DEPTH > 1 321#if LCD_DEPTH > 1
335 unsigned int prevfg = LCD_DEFAULT_FG; 322 unsigned int prevfg = 0;
336#endif 323#endif
337 324
338 /* fill battery */ 325#ifdef CONFIG_CHARGING
339 fill = percent; 326 if (batt_charge_step >= 0)
340 if (fill < 0) 327 {
341 fill = 0; 328 fill = percent * (STATUSBAR_BATTERY_WIDTH-3) / 100;
342 if (fill > 100) 329 endfill = 34 * batt_charge_step * (STATUSBAR_BATTERY_WIDTH-3) / 100;
343 fill = 100; 330 }
344 331 else
345 endfill = animated_percent; 332#else
346 if (endfill < 0) 333 (void)batt_charge_step;
347 endfill = 0; 334#endif
348 if (endfill > 100) 335 {
349 endfill = 100; 336 fill = endfill = (percent * (STATUSBAR_BATTERY_WIDTH-3) + 50) / 100;
350 337 }
351#if (defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)) && \ 338
352 !defined(SIMULATOR) /* Certain charge controlled targets */ 339#if CONFIG_CHARGING == CHARGING_MONITOR && !defined(SIMULATOR)
340 /* Certain charge controlled targets */
353 /* show graphical animation when charging instead of numbers */ 341 /* show graphical animation when charging instead of numbers */
354 if ((global_settings.battery_display) && 342 if ((global_settings.battery_display) &&
355 (charge_state != 1) && 343 (charge_state != CHARGING) &&
356 (percent > -1)) { 344 (percent > -1)) {
357#else /* all others */ 345#else /* all others */
358 if (global_settings.battery_display && (percent > -1)) { 346 if (global_settings.battery_display && (percent > -1)) {
359#endif 347#endif
360 /* Numeric display */ 348 /* Numeric display */
361 display->setfont(FONT_SYSFIXED); 349 display->setfont(FONT_SYSFIXED);
362 snprintf(buffer, sizeof(buffer), "%3d", fill); 350 snprintf(buffer, sizeof(buffer), "%3d", percent);
363 display->getstringsize(buffer, &width, &height); 351 display->getstringsize(buffer, &width, &height);
364 if (height <= STATUSBAR_HEIGHT) 352 if (height <= STATUSBAR_HEIGHT)
365 display->putsxy(STATUSBAR_BATTERY_X_POS 353 display->putsxy(STATUSBAR_BATTERY_X_POS
@@ -374,7 +362,6 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
374 display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2, 362 display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2,
375 STATUSBAR_Y_POS + 4); 363 STATUSBAR_Y_POS + 4);
376 364
377 fill = fill * 15 / 100;
378 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1, 365 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
379 fill, 5); 366 fill, 5);
380#if LCD_DEPTH > 1 367#if LCD_DEPTH > 1
@@ -384,9 +371,8 @@ void gui_statusbar_icon_battery(struct screen * display, int percent,
384 display->set_foreground(LCD_DARKGRAY); 371 display->set_foreground(LCD_DARKGRAY);
385 } 372 }
386#endif 373#endif
387 endfill = endfill * 15 / 100 - fill; 374 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
388 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill, 375 STATUSBAR_Y_POS + 1, endfill - fill, 5);
389 STATUSBAR_Y_POS + 1, endfill, 5);
390#if LCD_DEPTH > 1 376#if LCD_DEPTH > 1
391 if (display->depth > 1) 377 if (display->depth > 1)
392 display->set_foreground(prevfg); 378 display->set_foreground(prevfg);
@@ -507,6 +493,7 @@ void gui_statusbar_icon_lock(struct screen * display)
507 STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT); 493 STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT);
508} 494}
509 495
496#ifdef HAS_REMOTE_BUTTON_HOLD
510/* 497/*
511 * Print remote lock when remote hold is enabled 498 * Print remote lock when remote hold is enabled
512 */ 499 */
@@ -516,6 +503,7 @@ void gui_statusbar_icon_lock_remote(struct screen * display)
516 STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS, 503 STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS,
517 STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT); 504 STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT);
518} 505}
506#endif
519 507
520#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) 508#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
521/* 509/*
diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h
index 03add6a6d9..a03c294523 100644
--- a/apps/gui/statusbar.h
+++ b/apps/gui/statusbar.h
@@ -31,38 +31,40 @@
31 31
32struct status_info { 32struct status_info {
33 int battlevel; 33 int battlevel;
34 int batt_charge_step;
34 int volume; 35 int volume;
36 int playmode;
37 int repeat;
35#ifdef CONFIG_RTC 38#ifdef CONFIG_RTC
36 int hour; 39 int hour;
37 int minute; 40 int minute;
38#endif 41#endif
39 int playmode; 42
40 int repeat; 43#ifdef CONFIG_CHARGING
41 bool inserted; 44 bool inserted;
45#endif
46#ifdef HAVE_USB_POWER
47 bool usb_power;
48#endif
49 bool battery_state;
42 bool shuffle; 50 bool shuffle;
43 bool keylock; 51 bool keylock;
44#ifdef HAS_REMOTE_BUTTON_HOLD 52#ifdef HAS_REMOTE_BUTTON_HOLD
45 bool keylockremote; 53 bool keylockremote;
46#endif 54#endif
47 bool battery_safe;
48 bool redraw_volume; /* true if the volume gauge needs updating */
49#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) 55#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
50 bool led; /* disk LED simulation in the status bar */ 56 bool led; /* disk LED simulation in the status bar */
51#endif 57#endif
52 58
53#ifdef HAVE_USB_POWER
54 bool usb_power;
55#endif
56}; 59};
57 60
58struct gui_statusbar 61struct gui_statusbar
59{ 62{
60 /* Volume icon stuffs */ 63 long battery_icon_switch_tick;
64
61 long volume_icon_switch_tick; 65 long volume_icon_switch_tick;
62 int last_volume; 66 int last_volume;
63 67 bool redraw_volume; /* true if the volume gauge needs updating */
64 long battery_icon_switch_tick;
65 int animated_level;
66 68
67 struct status_info info; 69 struct status_info info;
68 struct status_info lastinfo; 70 struct status_info lastinfo;
@@ -95,7 +97,7 @@ extern void gui_statusbar_init(struct gui_statusbar * bar);
95 */ 97 */
96extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw); 98extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw);
97 99
98void gui_statusbar_icon_battery(struct screen * display, int percent, int animated_percent); 100void gui_statusbar_icon_battery(struct screen * display, int percent, int batt_charge_step);
99bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume); 101bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
100void gui_statusbar_icon_play_state(struct screen * display, int state); 102void gui_statusbar_icon_play_state(struct screen * display, int state);
101void gui_statusbar_icon_play_mode(struct screen * display, int mode); 103void gui_statusbar_icon_play_mode(struct screen * display, int mode);
diff --git a/apps/main.c b/apps/main.c
index 0771b287f8..5867f79d2f 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -228,7 +228,7 @@ void init(void)
228{ 228{
229 int rc; 229 int rc;
230 bool mounted = false; 230 bool mounted = false;
231#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) 231#if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
232 /* if nobody initialized ATA before, I consider this a cold start */ 232 /* if nobody initialized ATA before, I consider this a cold start */
233 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ 233 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
234#endif 234#endif
@@ -295,7 +295,7 @@ void init(void)
295 screen_access_init(); 295 screen_access_init();
296 gui_syncstatusbar_init(&statusbars); 296 gui_syncstatusbar_init(&statusbars);
297 297
298#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) 298#if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
299 if (coldstart && charger_inserted() 299 if (coldstart && charger_inserted()
300 && !global_settings.car_adapter_mode 300 && !global_settings.car_adapter_mode
301#ifdef ATA_POWER_PLAYERSTYLE 301#ifdef ATA_POWER_PLAYERSTYLE
@@ -433,7 +433,7 @@ void init(void)
433 } 433 }
434#endif /* #ifdef AUTOROCK */ 434#endif /* #ifdef AUTOROCK */
435 435
436#ifdef HAVE_CHARGING 436#ifdef CONFIG_CHARGING
437 car_adapter_mode_init(); 437 car_adapter_mode_init();
438#endif 438#endif
439} 439}
diff --git a/apps/main_menu.c b/apps/main_menu.c
index e6c2bb76c2..eb94498c7e 100644
--- a/apps/main_menu.c
+++ b/apps/main_menu.c
@@ -169,12 +169,12 @@ bool show_info(void)
169#endif 169#endif
170 lcd_puts_scroll(0, y++, (unsigned char *)s); 170 lcd_puts_scroll(0, y++, (unsigned char *)s);
171 171
172#ifdef HAVE_CHARGE_CTRL 172#if CONFIG_CHARGING == CHARGING_CONTROL
173 if (charge_state == 1) 173 if (charge_state == CHARGING)
174 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_CHARGE)); 174 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_CHARGE));
175 else if (charge_state == 2) 175 else if (charge_state == TOPOFF)
176 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TOPOFF_CHARGE)); 176 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TOPOFF_CHARGE));
177 else if (charge_state == 3) 177 else if (charge_state == TRICKLE)
178 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TRICKLE_CHARGE)); 178 snprintf(s, sizeof(s), (char *)str(LANG_BATTERY_TRICKLE_CHARGE));
179 else 179 else
180#endif 180#endif
diff --git a/apps/misc.c b/apps/misc.c
index 96f913a7f9..0ab826c796 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -491,7 +491,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
491 return false; 491 return false;
492 } 492 }
493 493
494#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) 494#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
495 if(!charger_inserted()) 495 if(!charger_inserted())
496#endif 496#endif
497 { 497 {
@@ -509,7 +509,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
509 return false; 509 return false;
510} 510}
511 511
512#ifdef HAVE_CHARGING 512#ifdef CONFIG_CHARGING
513static bool waiting_to_resume_play = false; 513static bool waiting_to_resume_play = false;
514static long play_resume_tick; 514static long play_resume_tick;
515 515
@@ -584,7 +584,7 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
584 if (!clean_shutdown(callback, parameter)) 584 if (!clean_shutdown(callback, parameter))
585 return SYS_POWEROFF; 585 return SYS_POWEROFF;
586 break; 586 break;
587#ifdef HAVE_CHARGING 587#ifdef CONFIG_CHARGING
588 case SYS_CHARGER_CONNECTED: 588 case SYS_CHARGER_CONNECTED:
589 car_adapter_mode_processing(true); 589 car_adapter_mode_processing(true);
590 return SYS_CHARGER_CONNECTED; 590 return SYS_CHARGER_CONNECTED;
diff --git a/apps/plugin.c b/apps/plugin.c
index 1b1c406af4..1bc4817ecd 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -58,7 +58,7 @@
58#include "dsp.h" 58#include "dsp.h"
59#endif 59#endif
60 60
61#ifdef HAVE_CHARGING 61#ifdef CONFIG_CHARGING
62#include "power.h" 62#include "power.h"
63#endif 63#endif
64 64
@@ -359,9 +359,9 @@ static const struct plugin_api rockbox_api = {
359#ifndef SIMULATOR 359#ifndef SIMULATOR
360 battery_voltage, 360 battery_voltage,
361#endif 361#endif
362#ifdef HAVE_CHARGING 362#ifdef CONFIG_CHARGING
363 charger_inserted, 363 charger_inserted,
364# ifdef HAVE_CHARGE_STATE 364# if CONFIG_CHARGING == CHARGING_MONITOR
365 charging_state, 365 charging_state,
366# endif 366# endif
367#endif 367#endif
diff --git a/apps/plugin.h b/apps/plugin.h
index de8f267ec8..b4990b8fb6 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -421,9 +421,9 @@ struct plugin_api {
421#ifndef SIMULATOR 421#ifndef SIMULATOR
422 unsigned int (*battery_voltage)(void); 422 unsigned int (*battery_voltage)(void);
423#endif 423#endif
424#ifdef HAVE_CHARGING 424#ifdef CONFIG_CHARGING
425 bool (*charger_inserted)(void); 425 bool (*charger_inserted)(void);
426# ifdef HAVE_CHARGE_STATE 426# if CONFIG_CHARGING == CHARGING_MONITOR
427 bool (*charging_state)(void); 427 bool (*charging_state)(void);
428# endif 428# endif
429#endif 429#endif
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index 552be8a1ac..210ecbd9dd 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -128,14 +128,14 @@ void exit_tsr(void)
128/* use long for aligning */ 128/* use long for aligning */
129unsigned long thread_stack[THREAD_STACK_SIZE/sizeof(long)]; 129unsigned long thread_stack[THREAD_STACK_SIZE/sizeof(long)];
130 130
131#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) 131#if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
132unsigned int charge_state(void) 132unsigned int charge_state(void)
133{ 133{
134 unsigned int ret = 0; 134 unsigned int ret = 0;
135#ifdef HAVE_CHARGING 135#ifdef CONFIG_CHARGING
136 if(rb->charger_inserted()) 136 if(rb->charger_inserted())
137 ret = BIT_CHARGER; 137 ret = BIT_CHARGER;
138#ifdef HAVE_CHARGE_STATE 138#if CONFIG_CHARGING == CHARGING_MONITOR
139 if(rb->charging_state()) 139 if(rb->charging_state())
140 ret |= BIT_CHARGING; 140 ret |= BIT_CHARGING;
141#endif 141#endif
@@ -154,7 +154,7 @@ void thread(void)
154 int fd, buffelements, tick = 1, i = 0, skipped = 0, exit = 0; 154 int fd, buffelements, tick = 1, i = 0, skipped = 0, exit = 0;
155 int fst = 0, lst = 0; /* first and last skipped tick */ 155 int fst = 0, lst = 0; /* first and last skipped tick */
156 unsigned int last_voltage = 0; 156 unsigned int last_voltage = 0;
157#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) 157#if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
158 unsigned int last_state = 0; 158 unsigned int last_state = 0;
159#endif 159#endif
160 long sleep_time; 160 long sleep_time;
@@ -202,9 +202,9 @@ void thread(void)
202 rb->fdprintf(fd, 202 rb->fdprintf(fd,
203 "%02d:%02d:%02d, %05d, %03d%%, " 203 "%02d:%02d:%02d, %05d, %03d%%, "
204 "%02d:%02d, %04d, %04d" 204 "%02d:%02d, %04d, %04d"
205#ifdef HAVE_CHARGING 205#ifdef CONFIG_CHARGING
206 ", %c" 206 ", %c"
207#ifdef HAVE_CHARGE_STATE 207#if CONFIG_CHARGING == CHARGING_MONITOR
208 ", %c" 208 ", %c"
209#endif 209#endif
210#endif 210#endif
@@ -215,7 +215,7 @@ void thread(void)
215 215
216 HMS(secs), secs, bat[j].level, 216 HMS(secs), secs, bat[j].level,
217 bat[j].eta / 60, bat[j].eta % 60, 217 bat[j].eta / 60, bat[j].eta % 60,
218#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) 218#if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
219 (bat[j].voltage & 219 (bat[j].voltage &
220 (~(BIT_CHARGER|BIT_CHARGING|BIT_USB_POWER))) 220 (~(BIT_CHARGER|BIT_CHARGING|BIT_USB_POWER)))
221 *10, 221 *10,
@@ -223,9 +223,9 @@ void thread(void)
223 bat[j].voltage * 10, 223 bat[j].voltage * 10,
224#endif 224#endif
225 temp + 1 + (j-i) 225 temp + 1 + (j-i)
226#ifdef HAVE_CHARGING 226#ifdef CONFIG_CHARGING
227 ,(bat[j].voltage & BIT_CHARGER)?'A':'-' 227 ,(bat[j].voltage & BIT_CHARGER)?'A':'-'
228#ifdef HAVE_CHARGE_STATE 228#if CONFIG_CHARGING == CHARGING_MONITOR
229 ,(bat[j].voltage & BIT_CHARGING)?'C':'-' 229 ,(bat[j].voltage & BIT_CHARGING)?'C':'-'
230#endif 230#endif
231#endif 231#endif
@@ -260,7 +260,7 @@ void thread(void)
260 timeflag = true; 260 timeflag = true;
261 261
262 if(last_voltage != (current_voltage=rb->battery_voltage()) 262 if(last_voltage != (current_voltage=rb->battery_voltage())
263#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) 263#if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
264 || last_state != charge_state() 264 || last_state != charge_state()
265#endif 265#endif
266 ) 266 )
@@ -280,7 +280,7 @@ void thread(void)
280 bat[i].level = rb->battery_level(); 280 bat[i].level = rb->battery_level();
281 bat[i].eta = rb->battery_time(); 281 bat[i].eta = rb->battery_time();
282 last_voltage = bat[i].voltage = current_voltage; 282 last_voltage = bat[i].voltage = current_voltage;
283#if defined(HAVE_CHARGING) || defined(HAVE_USB_POWER) 283#if defined(CONFIG_CHARGING) || defined(HAVE_USB_POWER)
284 bat[i].voltage |= last_state = charge_state(); 284 bat[i].voltage |= last_state = charge_state();
285#endif 285#endif
286 i++; 286 i++;
@@ -421,10 +421,10 @@ int main(void)
421 "Battery type: %d mAh Buffer Entries: %d\n" 421 "Battery type: %d mAh Buffer Entries: %d\n"
422 " Time:, Seconds:, Level:, Time Left:, Voltage[mV]:," 422 " Time:, Seconds:, Level:, Time Left:, Voltage[mV]:,"
423 " M/DA:" 423 " M/DA:"
424#ifdef HAVE_CHARGING 424#ifdef CONFIG_CHARGING
425 ", C:" 425 ", C:"
426#endif 426#endif
427#ifdef HAVE_CHARGE_STATE 427#if CONFIG_CHARGING == CHARGING_MONITOR
428 ", S:" 428 ", S:"
429#endif 429#endif
430#ifdef HAVE_USB_POWER 430#ifdef HAVE_USB_POWER
diff --git a/apps/screens.c b/apps/screens.c
index 20a0b58749..51201525d4 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -149,7 +149,7 @@ unsigned short adc_read(int channel)
149} 149}
150#endif 150#endif
151 151
152#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) 152#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
153 153
154#ifdef HAVE_LCD_BITMAP 154#ifdef HAVE_LCD_BITMAP
155void charging_display_info(bool animate) 155void charging_display_info(bool animate)
@@ -178,16 +178,16 @@ void charging_display_info(bool animate)
178 lcd_puts(0, 7, buf); 178 lcd_puts(0, 7, buf);
179 } 179 }
180 180
181#ifdef HAVE_CHARGE_CTRL 181#if CONFIG_CHARGING == CHARGING_CONTROL
182 182
183 snprintf(buf, 32, "Charge mode:"); 183 snprintf(buf, 32, "Charge mode:");
184 lcd_puts(0, 2, buf); 184 lcd_puts(0, 2, buf);
185 185
186 if (charge_state == 1) 186 if (charge_state == CHARGING)
187 snprintf(buf, 32, str(LANG_BATTERY_CHARGE)); 187 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
188 else if (charge_state == 2) 188 else if (charge_state == TOPOFF)
189 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE)); 189 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
190 else if (charge_state == 3) 190 else if (charge_state == TRICKLE)
191 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE)); 191 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
192 else 192 else
193 snprintf(buf, 32, "not charging"); 193 snprintf(buf, 32, "not charging");
@@ -195,7 +195,7 @@ void charging_display_info(bool animate)
195 lcd_puts(0, 3, buf); 195 lcd_puts(0, 3, buf);
196 if (!charger_enabled) 196 if (!charger_enabled)
197 animate = false; 197 animate = false;
198#endif /* HAVE_CHARGE_CTRL */ 198#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
199 199
200 200
201 /* middle part */ 201 /* middle part */
@@ -351,7 +351,7 @@ int charging_screen(void)
351#endif 351#endif
352 return rc; 352 return rc;
353} 353}
354#endif /* HAVE_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */ 354#endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING */
355 355
356#if (CONFIG_KEYPAD != PLAYER_PAD) 356#if (CONFIG_KEYPAD != PLAYER_PAD)
357/* returns: 357/* returns:
@@ -660,7 +660,7 @@ bool quick_screen_f3(int button_enter)
660#endif /* BUTTON_F3 */ 660#endif /* BUTTON_F3 */
661#endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */ 661#endif /* CONFIG_KEYPAD in (RECORDER_PAD |IRIVER_H100_PAD | IRIVER_H300_PAD) */
662 662
663#if defined(HAVE_CHARGING) || defined(SIMULATOR) 663#if defined(CONFIG_CHARGING) || defined(SIMULATOR)
664void charging_splash(void) 664void charging_splash(void)
665{ 665{
666 gui_syncsplash(2*HZ, true, (unsigned char *)str(LANG_BATTERY_CHARGE)); 666 gui_syncsplash(2*HZ, true, (unsigned char *)str(LANG_BATTERY_CHARGE));
diff --git a/apps/settings.c b/apps/settings.c
index 0d6ee1d376..6d7f250436 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -243,7 +243,7 @@ static const struct bit_entry rtc_bits[] =
243 {6, S_O(contrast), 40, "contrast", NULL }, 243 {6, S_O(contrast), 40, "contrast", NULL },
244#ifdef CONFIG_BACKLIGHT 244#ifdef CONFIG_BACKLIGHT
245 {5, S_O(backlight_timeout), 5, "backlight timeout", backlight_times_conf }, 245 {5, S_O(backlight_timeout), 5, "backlight timeout", backlight_times_conf },
246#ifdef HAVE_CHARGING 246#ifdef CONFIG_CHARGING
247 {5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged", 247 {5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged",
248 backlight_times_conf }, 248 backlight_times_conf },
249#endif 249#endif
@@ -276,7 +276,7 @@ static const struct bit_entry rtc_bits[] =
276 {12, S_O(battery_capacity), BATTERY_CAPACITY_DEFAULT, "battery capacity", 276 {12, S_O(battery_capacity), BATTERY_CAPACITY_DEFAULT, "battery capacity",
277 NULL }, /* 1500...3200 for NiMH, 2200...3200 for LiIon, 277 NULL }, /* 1500...3200 for NiMH, 2200...3200 for LiIon,
278 500...1500 for Alkaline */ 278 500...1500 for Alkaline */
279#ifdef HAVE_CHARGING 279#ifdef CONFIG_CHARGING
280 {1, S_O(car_adapter_mode), false, "car adapter mode", off_on }, 280 {1, S_O(car_adapter_mode), false, "car adapter mode", off_on },
281#endif 281#endif
282 /* tuner */ 282 /* tuner */
@@ -296,7 +296,7 @@ static const struct bit_entry rtc_bits[] =
296 {1, S_O(remote_flip_display), false, "remote flip display", off_on }, 296 {1, S_O(remote_flip_display), false, "remote flip display", off_on },
297 {5, S_O(remote_backlight_timeout), 5, "remote backlight timeout", 297 {5, S_O(remote_backlight_timeout), 5, "remote backlight timeout",
298 backlight_times_conf }, 298 backlight_times_conf },
299#ifdef HAVE_CHARGING 299#ifdef CONFIG_CHARGING
300 {5, S_O(remote_backlight_timeout_plugged), 11, 300 {5, S_O(remote_backlight_timeout_plugged), 11,
301 "remote backlight timeout plugged", backlight_times_conf }, 301 "remote backlight timeout plugged", backlight_times_conf },
302#endif 302#endif
@@ -1018,13 +1018,13 @@ void settings_apply(void)
1018 lcd_remote_emireduce(global_settings.remote_reduce_ticking); 1018 lcd_remote_emireduce(global_settings.remote_reduce_ticking);
1019#endif 1019#endif
1020 remote_backlight_set_timeout(global_settings.remote_backlight_timeout); 1020 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
1021#ifdef HAVE_CHARGING 1021#ifdef CONFIG_CHARGING
1022 remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged); 1022 remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged);
1023#endif 1023#endif
1024#endif 1024#endif
1025#ifdef CONFIG_BACKLIGHT 1025#ifdef CONFIG_BACKLIGHT
1026 backlight_set_timeout(global_settings.backlight_timeout); 1026 backlight_set_timeout(global_settings.backlight_timeout);
1027#ifdef HAVE_CHARGING 1027#ifdef CONFIG_CHARGING
1028 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged); 1028 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
1029#endif 1029#endif
1030#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 1030#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index bcf5a784c0..821ad53dec 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -81,7 +81,7 @@ void dac_line_in(bool enable);
81#include "backdrop.h" 81#include "backdrop.h"
82#endif 82#endif
83 83
84#ifdef HAVE_CHARGING 84#ifdef CONFIG_CHARGING
85static bool car_adapter_mode(void) 85static bool car_adapter_mode(void)
86{ 86{
87 return set_bool( str(LANG_CAR_ADAPTER_MODE), 87 return set_bool( str(LANG_CAR_ADAPTER_MODE),
@@ -177,7 +177,7 @@ static bool caption_backlight(void)
177 &global_settings.caption_backlight); 177 &global_settings.caption_backlight);
178} 178}
179 179
180#ifdef HAVE_CHARGING 180#ifdef CONFIG_CHARGING
181static bool backlight_timer_plugged(void) 181static bool backlight_timer_plugged(void)
182{ 182{
183 return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING), 183 return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING),
@@ -248,7 +248,7 @@ static bool remote_backlight_timer(void)
248 remote_backlight_set_timeout ); 248 remote_backlight_set_timeout );
249} 249}
250 250
251#ifdef HAVE_CHARGING 251#ifdef CONFIG_CHARGING
252static bool remote_backlight_timer_plugged(void) 252static bool remote_backlight_timer_plugged(void)
253{ 253{
254 return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING), 254 return set_option((char *)str(LANG_BACKLIGHT_ON_WHEN_CHARGING),
@@ -1715,7 +1715,7 @@ static bool lcd_settings_menu(void)
1715 static const struct menu_item items[] = { 1715 static const struct menu_item items[] = {
1716#ifdef CONFIG_BACKLIGHT 1716#ifdef CONFIG_BACKLIGHT
1717 { ID2P(LANG_BACKLIGHT), backlight_timer }, 1717 { ID2P(LANG_BACKLIGHT), backlight_timer },
1718#ifdef HAVE_CHARGING 1718#ifdef CONFIG_CHARGING
1719 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged }, 1719 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged },
1720#endif 1720#endif
1721 { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight }, 1721 { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight },
@@ -1763,7 +1763,7 @@ static bool lcd_remote_settings_menu(void)
1763 1763
1764 static const struct menu_item items[] = { 1764 static const struct menu_item items[] = {
1765 { ID2P(LANG_BACKLIGHT), remote_backlight_timer }, 1765 { ID2P(LANG_BACKLIGHT), remote_backlight_timer },
1766#ifdef HAVE_CHARGING 1766#ifdef CONFIG_CHARGING
1767 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), 1767 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING),
1768 remote_backlight_timer_plugged }, 1768 remote_backlight_timer_plugged },
1769#endif 1769#endif
@@ -1860,10 +1860,8 @@ static bool battery_settings_menu(void)
1860 { ID2P(LANG_BATTERY_TYPE), battery_type }, 1860 { ID2P(LANG_BATTERY_TYPE), battery_type },
1861#endif 1861#endif
1862#else 1862#else
1863#ifndef HAVE_CHARGE_CTRL
1864 { "Dummy", NULL }, /* to have an entry at all, in the simulator */ 1863 { "Dummy", NULL }, /* to have an entry at all, in the simulator */
1865#endif 1864#endif
1866#endif
1867 }; 1865 };
1868 1866
1869 m=menu_init( items, sizeof(items) / sizeof(*items), NULL, 1867 m=menu_init( items, sizeof(items) / sizeof(*items), NULL,
@@ -1975,7 +1973,7 @@ static bool system_settings_menu(void)
1975#if CONFIG_CODEC == MAS3507D 1973#if CONFIG_CODEC == MAS3507D
1976 { ID2P(LANG_LINE_IN), line_in }, 1974 { ID2P(LANG_LINE_IN), line_in },
1977#endif 1975#endif
1978#ifdef HAVE_CHARGING 1976#ifdef CONFIG_CHARGING
1979 { ID2P(LANG_CAR_ADAPTER_MODE), car_adapter_mode }, 1977 { ID2P(LANG_CAR_ADAPTER_MODE), car_adapter_mode },
1980#endif 1978#endif
1981 }; 1979 };
diff --git a/apps/status.c b/apps/status.c
index 5c5fb3eaa6..ca8a4d63ef 100644
--- a/apps/status.c
+++ b/apps/status.c
@@ -49,12 +49,6 @@
49 49
50enum playmode ff_mode; 50enum playmode ff_mode;
51 51
52long switch_tick;
53bool battery_state = true;
54#ifdef HAVE_CHARGING
55int battery_charge_step = 0;
56#endif
57
58void status_init(void) 52void status_init(void)
59{ 53{
60 ff_mode = 0; 54 ff_mode = 0;
diff --git a/apps/status.h b/apps/status.h
index 68319257b8..f42352be8e 100644
--- a/apps/status.h
+++ b/apps/status.h
@@ -21,12 +21,6 @@
21 21
22extern enum playmode ff_mode; 22extern enum playmode ff_mode;
23 23
24extern long switch_tick;
25extern bool battery_state;
26#ifdef HAVE_CHARGING
27extern int battery_charge_step;
28#endif
29
30#if defined(HAVE_LCD_CHARCELLS) 24#if defined(HAVE_LCD_CHARCELLS)
31extern bool record; 25extern bool record;
32extern bool audio; 26extern bool audio;
diff --git a/apps/tree.c b/apps/tree.c
index 35cefb163d..72e7bc4504 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -644,7 +644,7 @@ static bool dirbrowse(void)
644 if (!global_settings.party_mode) 644 if (!global_settings.party_mode)
645 audio_stop(); 645 audio_stop();
646 } 646 }
647#if defined(HAVE_CHARGING) && \ 647#if defined(CONFIG_CHARGING) && \
648 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF) 648 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
649 else { 649 else {
650 if (!charger_inserted()) { 650 if (!charger_inserted()) {
@@ -658,7 +658,7 @@ static bool dirbrowse(void)
658#endif 658#endif
659 } 659 }
660 break; 660 break;
661#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) 661#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
662 case TREE_OFF | BUTTON_REPEAT: 662 case TREE_OFF | BUTTON_REPEAT:
663 if (charger_inserted()) { 663 if (charger_inserted()) {
664 charging_splash(); 664 charging_splash();
diff --git a/firmware/backlight.c b/firmware/backlight.c
index aac438c673..76ffc6f0e4 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -156,14 +156,14 @@ static struct event_queue backlight_queue;
156 156
157static int backlight_timer; 157static int backlight_timer;
158static int backlight_timeout = 5*HZ; 158static int backlight_timeout = 5*HZ;
159#ifdef HAVE_CHARGING 159#ifdef CONFIG_CHARGING
160static int backlight_timeout_plugged = 5*HZ; 160static int backlight_timeout_plugged = 5*HZ;
161#endif 161#endif
162 162
163#ifdef HAVE_REMOTE_LCD 163#ifdef HAVE_REMOTE_LCD
164static int remote_backlight_timer; 164static int remote_backlight_timer;
165static int remote_backlight_timeout = 5*HZ; 165static int remote_backlight_timeout = 5*HZ;
166#ifdef HAVE_CHARGING 166#ifdef CONFIG_CHARGING
167static int remote_backlight_timeout_plugged = 5*HZ; 167static int remote_backlight_timeout_plugged = 5*HZ;
168#endif 168#endif
169#endif 169#endif
@@ -370,7 +370,7 @@ void backlight_thread(void)
370 { 370 {
371#ifdef HAVE_REMOTE_LCD 371#ifdef HAVE_REMOTE_LCD
372 case REMOTE_BACKLIGHT_ON: 372 case REMOTE_BACKLIGHT_ON:
373#ifdef HAVE_CHARGING 373#ifdef CONFIG_CHARGING
374 if (charger_inserted() 374 if (charger_inserted()
375#ifdef HAVE_USB_POWER 375#ifdef HAVE_USB_POWER
376 || usb_powered() 376 || usb_powered()
@@ -399,7 +399,7 @@ void backlight_thread(void)
399 399
400#endif /* HAVE_REMOTE_LCD */ 400#endif /* HAVE_REMOTE_LCD */
401 case BACKLIGHT_ON: 401 case BACKLIGHT_ON:
402#ifdef HAVE_CHARGING 402#ifdef CONFIG_CHARGING
403 if (charger_inserted() 403 if (charger_inserted()
404#ifdef HAVE_USB_POWER 404#ifdef HAVE_USB_POWER
405 || usb_powered() 405 || usb_powered()
@@ -447,7 +447,7 @@ void backlight_thread(void)
447 447
448static void backlight_tick(void) 448static void backlight_tick(void)
449{ 449{
450#ifdef HAVE_CHARGING 450#ifdef CONFIG_CHARGING
451 static bool charger_was_inserted = false; 451 static bool charger_was_inserted = false;
452 bool charger_is_inserted = charger_inserted() 452 bool charger_is_inserted = charger_inserted()
453#ifdef HAVE_USB_POWER 453#ifdef HAVE_USB_POWER
@@ -463,7 +463,7 @@ static void backlight_tick(void)
463#endif 463#endif
464 } 464 }
465 charger_was_inserted = charger_is_inserted; 465 charger_was_inserted = charger_is_inserted;
466#endif /* HAVE_CHARGING */ 466#endif /* CONFIG_CHARGING */
467 467
468 if(backlight_timer) 468 if(backlight_timer)
469 { 469 {
@@ -535,7 +535,7 @@ bool is_backlight_on(void)
535/* return value in ticks; 0 means always on, <0 means always off */ 535/* return value in ticks; 0 means always on, <0 means always off */
536int backlight_get_current_timeout(void) 536int backlight_get_current_timeout(void)
537{ 537{
538#ifdef HAVE_CHARGING 538#ifdef CONFIG_CHARGING
539 if (charger_inserted() 539 if (charger_inserted()
540#ifdef HAVE_USB_POWER 540#ifdef HAVE_USB_POWER
541 || usb_powered() 541 || usb_powered()
@@ -558,7 +558,7 @@ void backlight_set_timeout(int index)
558 backlight_on(); 558 backlight_on();
559} 559}
560 560
561#ifdef HAVE_CHARGING 561#ifdef CONFIG_CHARGING
562void backlight_set_timeout_plugged(int index) 562void backlight_set_timeout_plugged(int index)
563{ 563{
564 if((unsigned)index >= sizeof(backlight_timeout_value)) 564 if((unsigned)index >= sizeof(backlight_timeout_value))
@@ -589,7 +589,7 @@ void remote_backlight_set_timeout(int index)
589 remote_backlight_on(); 589 remote_backlight_on();
590} 590}
591 591
592#ifdef HAVE_CHARGING 592#ifdef CONFIG_CHARGING
593void remote_backlight_set_timeout_plugged(int index) 593void remote_backlight_set_timeout_plugged(int index)
594{ 594{
595 if((unsigned)index >= sizeof(backlight_timeout_value)) 595 if((unsigned)index >= sizeof(backlight_timeout_value))
@@ -603,7 +603,7 @@ void remote_backlight_set_timeout_plugged(int index)
603/* return value in ticks; 0 means always on, <0 means always off */ 603/* return value in ticks; 0 means always on, <0 means always off */
604int remote_backlight_get_current_timeout(void) 604int remote_backlight_get_current_timeout(void)
605{ 605{
606#ifdef HAVE_CHARGING 606#ifdef CONFIG_CHARGING
607 if (charger_inserted() 607 if (charger_inserted()
608#ifdef HAVE_USB_POWER 608#ifdef HAVE_USB_POWER
609 || usb_powered() 609 || usb_powered()
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 6513fb4a3a..216c51ea15 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -490,7 +490,7 @@ static void button_tick(void)
490 || btn == BUTTON_RC_STOP 490 || btn == BUTTON_RC_STOP
491#endif 491#endif
492 ) && 492 ) &&
493#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) 493#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
494 !charger_inserted() && 494 !charger_inserted() &&
495#endif 495#endif
496 repeat_count > POWEROFF_COUNT) 496 repeat_count > POWEROFF_COUNT)
@@ -1248,7 +1248,7 @@ static int button_read(void)
1248 backlight_on(); 1248 backlight_on();
1249 } 1249 }
1250 /* TODO: add light handling for the remote */ 1250 /* TODO: add light handling for the remote */
1251 1251
1252 hold_button = button_hold(); 1252 hold_button = button_hold();
1253 remote_hold_button = remote_button_hold(); 1253 remote_hold_button = remote_button_hold();
1254 1254
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c
index c4b9fb5b7d..bda03b0f8b 100644
--- a/firmware/drivers/power.c
+++ b/firmware/drivers/power.c
@@ -29,7 +29,7 @@
29#include "pcf50606.h" 29#include "pcf50606.h"
30#include "usb.h" 30#include "usb.h"
31 31
32#ifdef HAVE_CHARGE_CTRL 32#if CONFIG_CHARGING == CHARGING_CONTROL
33bool charger_enabled; 33bool charger_enabled;
34#endif 34#endif
35 35
@@ -92,7 +92,7 @@ void power_init(void)
92 or_b(0x20, &PBIORL); 92 or_b(0x20, &PBIORL);
93 or_b(0x20, &PBDRL); /* hold power */ 93 or_b(0x20, &PBDRL); /* hold power */
94#endif 94#endif
95#ifdef HAVE_CHARGE_CTRL 95#if CONFIG_CHARGING == CHARGING_CONTROL
96 PBCR2 &= ~0x0c00; /* GPIO for PB5 */ 96 PBCR2 &= ~0x0c00; /* GPIO for PB5 */
97 or_b(0x20, &PBIORL); /* Set charging control bit to output */ 97 or_b(0x20, &PBIORL); /* Set charging control bit to output */
98 charger_enable(false); /* Default to charger OFF */ 98 charger_enable(false); /* Default to charger OFF */
@@ -106,7 +106,7 @@ void power_init(void)
106} 106}
107 107
108 108
109#ifdef HAVE_CHARGING 109#ifdef CONFIG_CHARGING
110bool charger_inserted(void) 110bool charger_inserted(void)
111{ 111{
112#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) 112#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
@@ -115,7 +115,7 @@ bool charger_inserted(void)
115 return (P7 & 0x80) == 0; 115 return (P7 & 0x80) == 0;
116#elif defined(IAUDIO_X5) 116#elif defined(IAUDIO_X5)
117 return (GPIO1_READ & 0x01000000)?true:false; 117 return (GPIO1_READ & 0x01000000)?true:false;
118#elif defined(HAVE_CHARGE_CTRL) 118#elif CONFIG_CHARGING == CHARGING_CONTROL
119 /* Recorder */ 119 /* Recorder */
120 return adc_read(ADC_EXT_POWER) > 0x100; 120 return adc_read(ADC_EXT_POWER) > 0x100;
121#elif defined (HAVE_FMADC) 121#elif defined (HAVE_FMADC)
@@ -133,9 +133,9 @@ bool charger_inserted(void)
133 return (PADR & 1) == 0; 133 return (PADR & 1) == 0;
134#endif 134#endif
135} 135}
136#endif /* HAVE_CHARGING */ 136#endif /* CONFIG_CHARGING */
137 137
138#ifdef HAVE_CHARGE_CTRL 138#if CONFIG_CHARGING == CHARGING_CONTROL
139void charger_enable(bool on) 139void charger_enable(bool on)
140{ 140{
141 if(on) 141 if(on)
@@ -151,14 +151,22 @@ void charger_enable(bool on)
151} 151}
152#endif 152#endif
153 153
154#ifdef HAVE_CHARGE_STATE 154#if CONFIG_CHARGING == CHARGING_MONITOR
155/* Returns true if the unit is charging the batteries. */ 155/* Returns true if the unit is charging the batteries. */
156bool charging_state(void) { 156bool charging_state(void) {
157#if defined(IRIVER_H100_SERIES) 157#if CONFIG_BATTERY == BATT_LIION2200
158 /* We use the information from the ADC_EXT_POWER ADC channel, which
159 tells us the charging current from the LTC1734. When DC is
160 connected (either via the external adapter, or via USB), we try
161 to determine if it is actively charging or only maintaining the
162 charge. My tests show that ADC readings below about 0x80 means
163 that the LTC1734 is only maintaining the charge. */
164 return adc_read(ADC_EXT_POWER) >= 0x80;
165#elif defined(IRIVER_H100_SERIES) /* FIXME */
158 return charger_inserted(); 166 return charger_inserted();
159#elif defined(IRIVER_H300_SERIES) 167#elif defined IRIVER_H300_SERIES
160 return (GPIO_READ & 0x00800000)?true:false; 168 return (GPIO_READ & 0x00800000)?true:false;
161#elif defined(IPOD_VIDEO) 169#elif defined IPOD_VIDEO
162 return (GPIOB_INPUT_VAL & 0x01)?false:true; 170 return (GPIOB_INPUT_VAL & 0x01)?false:true;
163#endif 171#endif
164} 172}
diff --git a/firmware/export/config-fmrecorder.h b/firmware/export/config-fmrecorder.h
index 8711640e93..7a78d48822 100644
--- a/firmware/export/config-fmrecorder.h
+++ b/firmware/export/config-fmrecorder.h
@@ -90,8 +90,8 @@
90/* How to detect USB */ 90/* How to detect USB */
91#define USB_FMRECORDERSTYLE 1 91#define USB_FMRECORDERSTYLE 1
92 92
93/* Define this if the platform can charge batteries */ 93/* Hardware controlled charging with monitoring */
94#define HAVE_CHARGING 1 94#define CONFIG_CHARGING CHARGING_MONITOR
95 95
96/* The start address index for ROM builds */ 96/* The start address index for ROM builds */
97/* #define ROM_START 0x14010 for behind original Archos */ 97/* #define ROM_START 0x14010 for behind original Archos */
diff --git a/firmware/export/config-gigabeat.h b/firmware/export/config-gigabeat.h
index 83a92ce140..1ebbdbf908 100644
--- a/firmware/export/config-gigabeat.h
+++ b/firmware/export/config-gigabeat.h
@@ -61,8 +61,8 @@
61 61
62#define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */ 62#define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */
63 63
64/* Define this if the platform can charge batteries */ 64/* Hardware controlled charging? FIXME */
65#define HAVE_CHARGING 1 65#define CONFIG_CHARGING CHARGING_SIMPLE
66 66
67/* define this if the hardware can be powered off while charging */ 67/* define this if the hardware can be powered off while charging */
68#define HAVE_POWEROFF_WHILE_CHARGING 68#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-gmini120.h b/firmware/export/config-gmini120.h
index 42424bb7b1..66ba7af09e 100644
--- a/firmware/export/config-gmini120.h
+++ b/firmware/export/config-gmini120.h
@@ -54,8 +54,8 @@
54#define BATTERY_SCALE_FACTOR 6465 54#define BATTERY_SCALE_FACTOR 6465
55/* chosen values at random -- jyp */ 55/* chosen values at random -- jyp */
56 56
57/* Define this if the platform can charge batteries */ 57/* Hardware controlled charging? FIXME */
58#define HAVE_CHARGING 1 58#define CONFIG_CHARGING CHARGING_SIMPLE
59 59
60#define CPU_FREQ 30000000 60#define CPU_FREQ 30000000
61/* approximate value (and false in general since freq is variable) */ 61/* approximate value (and false in general since freq is variable) */
diff --git a/firmware/export/config-gminisp.h b/firmware/export/config-gminisp.h
index e066661061..8df7b0f5a1 100644
--- a/firmware/export/config-gminisp.h
+++ b/firmware/export/config-gminisp.h
@@ -45,8 +45,8 @@
45#define BATTERY_SCALE_FACTOR 6465 45#define BATTERY_SCALE_FACTOR 6465
46/* chosen values at random -- jyp */ 46/* chosen values at random -- jyp */
47 47
48/* Define this if the platform can charge batteries */ 48/* Hardware controlled charging? FIXME */
49#define HAVE_CHARGING 1 49#define CONFIG_CHARGING CHARGING_SIMPLE
50 50
51#define CPU_FREQ 30000000 51#define CPU_FREQ 30000000
52/* approximate value (and false in general since freq is variable) */ 52/* approximate value (and false in general since freq is variable) */
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h
index d53adcec14..4461cc2d44 100644
--- a/firmware/export/config-h100.h
+++ b/firmware/export/config-h100.h
@@ -89,11 +89,9 @@
89#define BATTERY_TYPES_COUNT 1 /* only one type */ 89#define BATTERY_TYPES_COUNT 1 /* only one type */
90#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */ 90#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */
91 91
92/* Define this if the platform can charge batteries */ 92/* Hardware controlled charging */
93#define HAVE_CHARGING 1 93//#define CONFIG_CHARGING CHARGING_SIMPLE
94 94#define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */
95/* For units with a hardware charger that reports charge state */
96#define HAVE_CHARGE_STATE 1
97 95
98/* define this if the hardware can be powered off while charging */ 96/* define this if the hardware can be powered off while charging */
99#define HAVE_POWEROFF_WHILE_CHARGING 97#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index 34f5059b69..f2cd8c2665 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -84,11 +84,9 @@
84/* Define if we have a hardware defect that causes ticking on the audio line */ 84/* Define if we have a hardware defect that causes ticking on the audio line */
85#define HAVE_REMOTE_LCD_TICKING 85#define HAVE_REMOTE_LCD_TICKING
86 86
87/* Define this if the platform can charge batteries */ 87/* Hardware controlled charging */
88#define HAVE_CHARGING 1 88//#define CONFIG_CHARGING CHARGING_SIMPLE
89 89#define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */
90/* For units with a hardware charger that reports charge state */
91#define HAVE_CHARGE_STATE 1
92 90
93/* define this if the hardware can be powered off while charging */ 91/* define this if the hardware can be powered off while charging */
94#define HAVE_POWEROFF_WHILE_CHARGING 92#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index ae1940c987..7ed54958ca 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -85,14 +85,8 @@
85/* Define if we have a hardware defect that causes ticking on the audio line */ 85/* Define if we have a hardware defect that causes ticking on the audio line */
86#define HAVE_REMOTE_LCD_TICKING 86#define HAVE_REMOTE_LCD_TICKING
87 87
88/* Define this if the platform can charge batteries */ 88/* Hardware controlled charging with monitoring */
89#define HAVE_CHARGING 1 89#define CONFIG_CHARGING CHARGING_MONITOR
90
91/* For units with a hardware charger that reports charge state */
92#define HAVE_CHARGE_STATE 1
93
94/* define this if the hardware can be powered off while charging */
95#define HAVE_POWEROFF_WHILE_CHARGING
96 90
97/* The size of the flash ROM */ 91/* The size of the flash ROM */
98#define FLASH_SIZE 0x400000 92#define FLASH_SIZE 0x400000
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h
index 4690feb8fe..b16a142a28 100644
--- a/firmware/export/config-iaudiox5.h
+++ b/firmware/export/config-iaudiox5.h
@@ -65,8 +65,8 @@
65 65
66#define HAVE_TLV320 66#define HAVE_TLV320
67 67
68/* Define this if the platform can charge batteries */ 68/* Hardware controlled charging? FIXME */
69#define HAVE_CHARGING 1 69#define CONFIG_CHARGING CHARGING_SIMPLE
70 70
71/* define this if the hardware can be powered off while charging */ 71/* define this if the hardware can be powered off while charging */
72#define HAVE_POWEROFF_WHILE_CHARGING 72#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ifp7xx.h b/firmware/export/config-ifp7xx.h
index 9e5a432260..6247625618 100644
--- a/firmware/export/config-ifp7xx.h
+++ b/firmware/export/config-ifp7xx.h
@@ -56,8 +56,8 @@
56 56
57#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */ 57#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */
58 58
59/* Define this if the platform can charge batteries */ 59/* Hardware controlled charging? FIXME */
60//#define HAVE_CHARGING 1 60//#define CONFIG_CHARGING CHARGING_SIMPLE
61 61
62/* define this if the hardware can be powered off while charging */ 62/* define this if the hardware can be powered off while charging */
63//#define HAVE_POWEROFF_WHILE_CHARGING 63//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipod3g.h b/firmware/export/config-ipod3g.h
index a611dfdcaa..b3b5d14e85 100644
--- a/firmware/export/config-ipod3g.h
+++ b/firmware/export/config-ipod3g.h
@@ -68,8 +68,8 @@
68#define BATTERY_TYPES_COUNT 1 /* only one type */ 68#define BATTERY_TYPES_COUNT 1 /* only one type */
69#define BATTERY_SCALE_FACTOR 5865 69#define BATTERY_SCALE_FACTOR 5865
70 70
71/* Define this if the platform can charge batteries */ 71/* Hardware controlled charging? FIXME */
72//#define HAVE_CHARGING 1 72//#define CONFIG_CHARGING CHARGING_SIMPLE
73 73
74/* define this if the hardware can be powered off while charging */ 74/* define this if the hardware can be powered off while charging */
75//#define HAVE_POWEROFF_WHILE_CHARGING 75//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipod4g.h b/firmware/export/config-ipod4g.h
index fa664acdb6..46abbdf72b 100644
--- a/firmware/export/config-ipod4g.h
+++ b/firmware/export/config-ipod4g.h
@@ -70,8 +70,8 @@
70#define BATTERY_TYPES_COUNT 1 /* only one type */ 70#define BATTERY_TYPES_COUNT 1 /* only one type */
71#define BATTERY_SCALE_FACTOR 5865 71#define BATTERY_SCALE_FACTOR 5865
72 72
73/* Define this if the platform can charge batteries */ 73/* Hardware controlled charging? FIXME */
74//#define HAVE_CHARGING 1 74//#define CONFIG_CHARGING CHARGING_SIMPLE
75 75
76/* define this if the hardware can be powered off while charging */ 76/* define this if the hardware can be powered off while charging */
77//#define HAVE_POWEROFF_WHILE_CHARGING 77//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h
index b8f3d89346..e063e93737 100644
--- a/firmware/export/config-ipodcolor.h
+++ b/firmware/export/config-ipodcolor.h
@@ -69,8 +69,8 @@
69#define BATTERY_TYPES_COUNT 1 /* only one type */ 69#define BATTERY_TYPES_COUNT 1 /* only one type */
70#define BATTERY_SCALE_FACTOR 5865 70#define BATTERY_SCALE_FACTOR 5865
71 71
72/* Define this if the platform can charge batteries */ 72/* Hardware controlled charging? FIXME */
73//#define HAVE_CHARGING 1 73//#define CONFIG_CHARGING CHARGING_SIMPLE
74 74
75/* define this if the hardware can be powered off while charging */ 75/* define this if the hardware can be powered off while charging */
76//#define HAVE_POWEROFF_WHILE_CHARGING 76//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodmini.h b/firmware/export/config-ipodmini.h
index 64be801577..4871ea0acc 100644
--- a/firmware/export/config-ipodmini.h
+++ b/firmware/export/config-ipodmini.h
@@ -70,8 +70,8 @@
70#define BATTERY_TYPES_COUNT 1 /* only one type */ 70#define BATTERY_TYPES_COUNT 1 /* only one type */
71#define BATTERY_SCALE_FACTOR 5865 71#define BATTERY_SCALE_FACTOR 5865
72 72
73/* Define this if the platform can charge batteries */ 73/* Hardware controlled charging? FIXME */
74//#define HAVE_CHARGING 1 74//#define CONFIG_CHARGING CHARGING_SIMPLE
75 75
76/* define this if the hardware can be powered off while charging */ 76/* define this if the hardware can be powered off while charging */
77//#define HAVE_POWEROFF_WHILE_CHARGING 77//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodmini2g.h b/firmware/export/config-ipodmini2g.h
index 454309a786..adbb0973ac 100755
--- a/firmware/export/config-ipodmini2g.h
+++ b/firmware/export/config-ipodmini2g.h
@@ -73,8 +73,8 @@
73#define BATTERY_TYPES_COUNT 1 /* only one type */ 73#define BATTERY_TYPES_COUNT 1 /* only one type */
74#define BATTERY_SCALE_FACTOR 5865 74#define BATTERY_SCALE_FACTOR 5865
75 75
76/* Define this if the platform can charge batteries */ 76/* Hardware controlled charging? FIXME */
77//#define HAVE_CHARGING 1 77//#define CONFIG_CHARGING CHARGING_SIMPLE
78 78
79/* define this if the hardware can be powered off while charging */ 79/* define this if the hardware can be powered off while charging */
80//#define HAVE_POWEROFF_WHILE_CHARGING 80//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h
index b7116bf249..3d4deb3abd 100644
--- a/firmware/export/config-ipodnano.h
+++ b/firmware/export/config-ipodnano.h
@@ -74,8 +74,8 @@
74#define BATTERY_TYPES_COUNT 1 /* only one type */ 74#define BATTERY_TYPES_COUNT 1 /* only one type */
75#define BATTERY_SCALE_FACTOR 5865 75#define BATTERY_SCALE_FACTOR 5865
76 76
77/* Define this if the platform can charge batteries */ 77/* Hardware controlled charging? FIXME */
78//#define HAVE_CHARGING 1 78//#define CONFIG_CHARGING CHARGING_SIMPLE
79 79
80/* define this if the hardware can be powered off while charging */ 80/* define this if the hardware can be powered off while charging */
81//#define HAVE_POWEROFF_WHILE_CHARGING 81//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h
index 1bbcfec157..79ef1a85ac 100644
--- a/firmware/export/config-ipodvideo.h
+++ b/firmware/export/config-ipodvideo.h
@@ -74,14 +74,12 @@
74#define BATTERY_TYPES_COUNT 1 /* only one type */ 74#define BATTERY_TYPES_COUNT 1 /* only one type */
75#define BATTERY_SCALE_FACTOR 5865 75#define BATTERY_SCALE_FACTOR 5865
76 76
77/* Define this if the platform can charge batteries */ 77/* Hardware controlled charging with monitoring */
78#define HAVE_CHARGING 1 78#define CONFIG_CHARGING CHARGING_MONITOR
79 79
80/* define this if the hardware can be powered off while charging */ 80/* define this if the hardware can be powered off while charging */
81//#define HAVE_POWEROFF_WHILE_CHARGING 81//#define HAVE_POWEROFF_WHILE_CHARGING
82 82
83#define HAVE_CHARGE_STATE 1
84
85/* The start address index for ROM builds */ 83/* The start address index for ROM builds */
86#define ROM_START 0x00000000 84#define ROM_START 0x00000000
87 85
diff --git a/firmware/export/config-player.h b/firmware/export/config-player.h
index 324a0a2300..3dfdb0e727 100644
--- a/firmware/export/config-player.h
+++ b/firmware/export/config-player.h
@@ -67,8 +67,8 @@
67/* How to detect USB */ 67/* How to detect USB */
68#define USB_PLAYERSTYLE 1 68#define USB_PLAYERSTYLE 1
69 69
70/* Define this if the platform can charge batteries */ 70/* Hardware controlled charging */
71#define HAVE_CHARGING 1 71#define CONFIG_CHARGING CHARGING_SIMPLE
72 72
73/* The start address index for ROM builds */ 73/* The start address index for ROM builds */
74/* #define ROM_START 0xD010 for behind original Archos */ 74/* #define ROM_START 0xD010 for behind original Archos */
diff --git a/firmware/export/config-recorder.h b/firmware/export/config-recorder.h
index 92dd07695d..854b1c1ade 100644
--- a/firmware/export/config-recorder.h
+++ b/firmware/export/config-recorder.h
@@ -45,9 +45,6 @@
45/* Define this if you have a SH7034 */ 45/* Define this if you have a SH7034 */
46#define CONFIG_CPU SH7034 46#define CONFIG_CPU SH7034
47 47
48/* Define this if you have charging control */
49#define HAVE_CHARGE_CTRL
50
51/* Define this if you have ATA power-off control */ 48/* Define this if you have ATA power-off control */
52#define HAVE_ATA_POWER_OFF 49#define HAVE_ATA_POWER_OFF
53 50
@@ -80,8 +77,8 @@
80/* How to detect USB */ 77/* How to detect USB */
81#define USB_RECORDERSTYLE 1 78#define USB_RECORDERSTYLE 1
82 79
83/* Define this if the platform can charge batteries */ 80/* Software controlled charging */
84#define HAVE_CHARGING 1 81#define CONFIG_CHARGING CHARGING_CONTROL
85 82
86/* The start address index for ROM builds */ 83/* The start address index for ROM builds */
87/* #define ROM_START 0x11010 for behind original Archos */ 84/* #define ROM_START 0x11010 for behind original Archos */
diff --git a/firmware/export/config-recorderv2.h b/firmware/export/config-recorderv2.h
index b508836080..09823cffb2 100644
--- a/firmware/export/config-recorderv2.h
+++ b/firmware/export/config-recorderv2.h
@@ -90,8 +90,8 @@
90/* How to detect USB */ 90/* How to detect USB */
91#define USB_FMRECORDERSTYLE 1 91#define USB_FMRECORDERSTYLE 1
92 92
93/* Define this if the platform can charge batteries */ 93/* Hardware controlled charging with monitoring */
94#define HAVE_CHARGING 1 94#define CONFIG_CHARGING CHARGING_MONITOR
95 95
96/* The start address index for ROM builds */ 96/* The start address index for ROM builds */
97/* #define ROM_START 0x12010 for behind original Archos */ 97/* #define ROM_START 0x12010 for behind original Archos */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index d919b8b4f6..910aeca4eb 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -68,6 +68,11 @@
68#define BATT_3AAA 1000 /* Ondio */ 68#define BATT_3AAA 1000 /* Ondio */
69#define BATT_LIPOL1300 1300 /* the type used in iRiver h1x0 models */ 69#define BATT_LIPOL1300 1300 /* the type used in iRiver h1x0 models */
70 70
71/* CONFIG_CHARGING */
72#define CHARGING_SIMPLE 1 /* Simple, hardware controlled charging */
73#define CHARGING_MONITOR 2 /* Hardware controlled charging with monitoring */
74#define CHARGING_CONTROL 3 /* Software controlled charging */
75
71/* CONFIG_LCD */ 76/* CONFIG_LCD */
72#define LCD_GMINI100 0 77#define LCD_GMINI100 0
73#define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */ 78#define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */
diff --git a/firmware/export/power.h b/firmware/export/power.h
index be8ebda5b0..dc6c09d9f9 100644
--- a/firmware/export/power.h
+++ b/firmware/export/power.h
@@ -19,12 +19,12 @@
19#ifndef _POWER_H_ 19#ifndef _POWER_H_
20#define _POWER_H_ 20#define _POWER_H_
21 21
22#ifdef HAVE_CHARGE_CTRL 22#if CONFIG_CHARGING == CHARGING_CONTROL
23extern bool charger_enabled; 23extern bool charger_enabled;
24void charger_enable(bool on); 24void charger_enable(bool on);
25#endif 25#endif
26 26
27#ifdef HAVE_CHARGING 27#ifdef CONFIG_CHARGING
28bool charger_inserted(void); 28bool charger_inserted(void);
29#endif 29#endif
30 30
@@ -35,7 +35,7 @@ void ide_power_enable(bool on);
35 35
36void power_init(void); 36void power_init(void);
37 37
38# ifdef HAVE_CHARGE_STATE 38# if CONFIG_CHARGING == CHARGING_MONITOR
39bool charging_state(void); 39bool charging_state(void);
40# endif 40# endif
41 41
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 6c31aeec52..30fe60c293 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -28,7 +28,7 @@
28 28
29#ifndef SIMULATOR 29#ifndef SIMULATOR
30 30
31#ifdef HAVE_CHARGE_CTRL 31#if CONFIG_CHARGING == CHARGING_CONTROL
32#define START_TOPOFF_CHG 85 /* Battery % to start at top-off */ 32#define START_TOPOFF_CHG 85 /* Battery % to start at top-off */
33#define START_TRICKLE_CHG 95 /* Battery % to start at trickle */ 33#define START_TRICKLE_CHG 95 /* Battery % to start at trickle */
34 34
@@ -59,23 +59,21 @@ extern int pid_p; /* PID proportional term */
59extern int pid_i; /* PID integral term */ 59extern int pid_i; /* PID integral term */
60extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */ 60extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
61 61
62#endif /* HAVE_CHARGE_CTRL */ 62#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
63 63
64#if defined(HAVE_CHARGE_CTRL) || \ 64#if CONFIG_CHARGING >= CHARGING_MONITOR
65 (CONFIG_BATTERY == BATT_LIION2200) || \ 65typedef enum { /* sorted by increasing charging current */
66 defined(HAVE_CHARGE_STATE) 66 DISCHARGING = 0,
67typedef enum { 67 TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */
68 DISCHARGING, 68 TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */
69 CHARGING, 69 CHARGING /* Can occur for all CONFIG_CHARGING options */
70 TOPOFF,
71 TRICKLE
72} charge_state_type; 70} charge_state_type;
73 71
74/* tells what the charger is doing */ 72/* tells what the charger is doing */
75extern charge_state_type charge_state; 73extern charge_state_type charge_state;
76#endif /* defined(HAVE_CHARGE_CTRL) || (CONFIG_BATTERY == BATT_LIION2200) */ 74#endif /* CONFIG_CHARGING >= CHARGING_MONITOR */
77 75
78#ifdef HAVE_CHARGING 76#ifdef CONFIG_CHARGING
79/* 77/*
80 * Flag that the charger has been plugged in/removed: this is set for exactly 78 * Flag that the charger has been plugged in/removed: this is set for exactly
81 * one time through the power loop when the charger has been plugged in. 79 * one time through the power loop when the charger has been plugged in.
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 15977caed6..ee01fd862d 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -64,7 +64,7 @@
64 * in it (one sample per minute). This is only for very low level debug. 64 * in it (one sample per minute). This is only for very low level debug.
65 */ 65 */
66#undef DEBUG_FILE 66#undef DEBUG_FILE
67#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) 67#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
68#include "file.h" 68#include "file.h"
69#define DEBUG_FILE_NAME "/powermgmt.csv" 69#define DEBUG_FILE_NAME "/powermgmt.csv"
70#define DEBUG_MESSAGE_LEN 133 70#define DEBUG_MESSAGE_LEN 133
@@ -190,7 +190,7 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
190#endif 190#endif
191}; 191};
192 192
193#ifdef HAVE_CHARGING 193#ifdef CONFIG_CHARGING
194charger_input_state_type charger_input_state IDATA_ATTR; 194charger_input_state_type charger_input_state IDATA_ATTR;
195 195
196/* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ 196/* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */
@@ -207,15 +207,13 @@ static const short percent_to_volt_charge[11] =
207 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */ 207 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */
208#endif 208#endif
209}; 209};
210#endif /* HAVE_CHARGING */ 210#endif /* CONFIG_CHARGING */
211 211
212#if defined(HAVE_CHARGE_CTRL) || \ 212#if CONFIG_CHARGING >= CHARGING_MONITOR
213 CONFIG_BATTERY == BATT_LIION2200 || \
214 defined(HAVE_CHARGE_STATE)
215charge_state_type charge_state; /* charging mode */ 213charge_state_type charge_state; /* charging mode */
216#endif 214#endif
217 215
218#ifdef HAVE_CHARGE_CTRL 216#if CONFIG_CHARGING == CHARGING_CONTROL
219int long_delta; /* long term delta battery voltage */ 217int long_delta; /* long term delta battery voltage */
220int short_delta; /* short term delta battery voltage */ 218int short_delta; /* short term delta battery voltage */
221bool disk_activity_last_cycle = false; /* flag set to aid charger time 219bool disk_activity_last_cycle = false; /* flag set to aid charger time
@@ -235,7 +233,7 @@ int trickle_sec = 0; /* how many seconds should the
235 charging? */ 233 charging? */
236int pid_p = 0; /* PID proportional term */ 234int pid_p = 0; /* PID proportional term */
237int pid_i = 0; /* PID integral term */ 235int pid_i = 0; /* PID integral term */
238#endif /* HAVE_CHARGE_CTRL */ 236#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
239 237
240/* 238/*
241 * Average battery voltage and charger voltage, filtered via a digital 239 * Average battery voltage and charger voltage, filtered via a digital
@@ -366,7 +364,7 @@ static void battery_status_update(void)
366{ 364{
367 int level; 365 int level;
368 366
369#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE) 367#if CONFIG_CHARGING >= CHARGING_MONITOR
370 if (charge_state == DISCHARGING) { 368 if (charge_state == DISCHARGING) {
371 level = voltage_to_percent(battery_centivolts, 369 level = voltage_to_percent(battery_centivolts,
372 percent_to_volt_discharge[battery_type]); 370 percent_to_volt_discharge[battery_type]);
@@ -397,7 +395,7 @@ static void battery_status_update(void)
397 /* calculate estimated remaining running time */ 395 /* calculate estimated remaining running time */
398 /* discharging: remaining running time */ 396 /* discharging: remaining running time */
399 /* charging: remaining charging time */ 397 /* charging: remaining charging time */
400#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE) 398#if CONFIG_CHARGING >= CHARGING_MONITOR
401 if (charge_state == CHARGING) { 399 if (charge_state == CHARGING) {
402 powermgmt_est_runningtime_min = (100 - level) * battery_capacity / 100 400 powermgmt_est_runningtime_min = (100 - level) * battery_capacity / 100
403 * 60 / (CURRENT_MAX_CHG - runcurrent()); 401 * 60 / (CURRENT_MAX_CHG - runcurrent());
@@ -425,7 +423,7 @@ static void handle_auto_poweroff(void)
425 long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ; 423 long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ;
426 int audio_stat = audio_status(); 424 int audio_stat = audio_status();
427 425
428#ifdef HAVE_CHARGING 426#ifdef CONFIG_CHARGING
429 /* 427 /*
430 * Inhibit shutdown as long as the charger is plugged in. If it is 428 * Inhibit shutdown as long as the charger is plugged in. If it is
431 * unplugged, wait for a timeout period and then shut down. 429 * unplugged, wait for a timeout period and then shut down.
@@ -458,7 +456,7 @@ static void handle_auto_poweroff(void)
458 if(TIME_AFTER(current_tick, sleeptimer_endtick)) 456 if(TIME_AFTER(current_tick, sleeptimer_endtick))
459 { 457 {
460 audio_stop(); 458 audio_stop();
461#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) 459#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
462 if((charger_input_state == CHARGER) || 460 if((charger_input_state == CHARGER) ||
463 (charger_input_state == CHARGER_PLUGGED)) 461 (charger_input_state == CHARGER_PLUGGED))
464 { 462 {
@@ -538,7 +536,7 @@ static void power_thread_sleep(int ticks)
538 536
539 while (ticks > 0) { 537 while (ticks > 0) {
540 538
541#ifdef HAVE_CHARGING 539#ifdef CONFIG_CHARGING
542 /* 540 /*
543 * Detect charger plugged/unplugged transitions. On a plugged or 541 * Detect charger plugged/unplugged transitions. On a plugged or
544 * unplugged event, we return immediately, run once through the main 542 * unplugged event, we return immediately, run once through the main
@@ -577,7 +575,7 @@ static void power_thread_sleep(int ticks)
577 } 575 }
578 } 576 }
579#endif 577#endif
580#ifdef HAVE_CHARGE_STATE 578#if CONFIG_CHARGING == CHARGING_MONITOR
581 switch (charger_input_state) { 579 switch (charger_input_state) {
582 case CHARGER_UNPLUGGED: 580 case CHARGER_UNPLUGGED:
583 case NO_CHARGER: 581 case NO_CHARGER:
@@ -593,7 +591,7 @@ static void power_thread_sleep(int ticks)
593 break; 591 break;
594 } 592 }
595 593
596#endif /* HAVE_CHARGE_STATE */ 594#endif /* CONFIG_CHARGING == CHARGING_MONITOR */
597 595
598 small_ticks = MIN(HZ/2, ticks); 596 small_ticks = MIN(HZ/2, ticks);
599 sleep(small_ticks); 597 sleep(small_ticks);
@@ -628,13 +626,13 @@ static void power_thread_sleep(int ticks)
628 battery_status_update(); 626 battery_status_update();
629 627
630 } 628 }
631#ifdef HAVE_CHARGE_CTRL 629#if CONFIG_CHARGING == CHARGING_CONTROL
632 if (ata_disk_is_active()) { 630 if (ata_disk_is_active()) {
633 /* flag hdd use for charging calculation */ 631 /* flag hdd use for charging calculation */
634 disk_activity_last_cycle = true; 632 disk_activity_last_cycle = true;
635 } 633 }
636#endif 634#endif
637#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) 635#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
638 /* 636 /*
639 * If we have a lot of pending writes or if the disk is spining, 637 * If we have a lot of pending writes or if the disk is spining,
640 * fsync the debug log file. 638 * fsync the debug log file.
@@ -660,7 +658,7 @@ static void power_thread(void)
660{ 658{
661 int i; 659 int i;
662 short *phps, *phpd; /* power history rotation pointers */ 660 short *phps, *phpd; /* power history rotation pointers */
663#ifdef HAVE_CHARGE_CTRL 661#if CONFIG_CHARGING == CHARGING_CONTROL
664 unsigned int target_voltage = TRICKLE_VOLTAGE; /* desired topoff/trickle 662 unsigned int target_voltage = TRICKLE_VOLTAGE; /* desired topoff/trickle
665 * voltage level */ 663 * voltage level */
666 int charge_max_time_idle = 0; /* max. charging duration, calculated at 664 int charge_max_time_idle = 0; /* max. charging duration, calculated at
@@ -678,7 +676,7 @@ static void power_thread(void)
678 BATT_AVE_SAMPLES; 676 BATT_AVE_SAMPLES;
679 battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; 677 battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000;
680 678
681#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) 679#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
682 fd = -1; 680 fd = -1;
683 wrcount = 0; 681 wrcount = 0;
684#endif 682#endif
@@ -694,25 +692,7 @@ static void power_thread(void)
694 /* insert new value at the start, in centivolts 8-) */ 692 /* insert new value at the start, in centivolts 8-) */
695 power_history[0] = battery_centivolts; 693 power_history[0] = battery_centivolts;
696 694
697#if CONFIG_BATTERY == BATT_LIION2200 695#if CONFIG_CHARGING == CHARGING_CONTROL
698 /* We use the information from the ADC_EXT_POWER ADC channel, which
699 tells us the charging current from the LTC1734. When DC is
700 connected (either via the external adapter, or via USB), we try
701 to determine if it is actively charging or only maintaining the
702 charge. My tests show that ADC readings below about 0x80 means
703 that the LTC1734 is only maintaining the charge. */
704 if(charger_inserted()) {
705 if(adc_read(ADC_EXT_POWER) < 0x80) {
706 charge_state = TRICKLE;
707 } else {
708 charge_state = CHARGING;
709 }
710 } else {
711 charge_state = DISCHARGING;
712 }
713#endif /* # if CONFIG_BATTERY == BATT_LIION2200 */
714
715#ifdef HAVE_CHARGE_CTRL
716 if (charger_input_state == CHARGER_PLUGGED) { 696 if (charger_input_state == CHARGER_PLUGGED) {
717 pid_p = 0; 697 pid_p = 0;
718 pid_i = 0; 698 pid_i = 0;
@@ -876,7 +856,7 @@ static void power_thread(void)
876 } 856 }
877 } 857 }
878 } 858 }
879 else if (charge_state > CHARGING) /* top off or trickle */ 859 else if (charge_state != DISCHARGING) /* top off or trickle */
880 { 860 {
881 /* 861 /*
882 *Time to switch from topoff to trickle? 862 *Time to switch from topoff to trickle?
@@ -946,11 +926,11 @@ static void power_thread(void)
946 snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge"); 926 snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge");
947 } 927 }
948 928
949#endif /* end HAVE_CHARGE_CTRL */ 929#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
950 930
951 /* sleep for a minute */ 931 /* sleep for a minute */
952 932
953#ifdef HAVE_CHARGE_CTRL 933#if CONFIG_CHARGING == CHARGING_CONTROL
954 if(trickle_sec > 0) { 934 if(trickle_sec > 0) {
955 charger_enable(true); 935 charger_enable(true);
956 power_thread_sleep(HZ * trickle_sec); 936 power_thread_sleep(HZ * trickle_sec);
@@ -962,7 +942,7 @@ static void power_thread(void)
962 power_thread_sleep(HZ * 60); 942 power_thread_sleep(HZ * 60);
963#endif 943#endif
964 944
965#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) 945#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
966 if(usb_inserted()) { 946 if(usb_inserted()) {
967 if(fd >= 0) { 947 if(fd >= 0) {
968 /* It is probably too late to close the file but we can try...*/ 948 /* It is probably too late to close the file but we can try...*/
@@ -992,7 +972,7 @@ static void power_thread(void)
992#endif 972#endif
993 handle_auto_poweroff(); 973 handle_auto_poweroff();
994 974
995#ifdef HAVE_CHARGE_CTRL 975#if CONFIG_CHARGING == CHARGING_CONTROL
996 powermgmt_last_cycle_startstop_min++; 976 powermgmt_last_cycle_startstop_min++;
997#endif 977#endif
998 } 978 }
@@ -1029,7 +1009,7 @@ void cancel_shutdown(void)
1029void shutdown_hw(void) 1009void shutdown_hw(void)
1030{ 1010{
1031#ifndef SIMULATOR 1011#ifndef SIMULATOR
1032#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) 1012#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
1033 if(fd >= 0) { 1013 if(fd >= 0) {
1034 close(fd); 1014 close(fd);
1035 fd = -1; 1015 fd = -1;
diff --git a/flash/bootbox/main.c b/flash/bootbox/main.c
index ef215c092b..4f5efdd7c6 100644
--- a/flash/bootbox/main.c
+++ b/flash/bootbox/main.c
@@ -65,7 +65,7 @@ int show_logo(void)
65 return 0; 65 return 0;
66} 66}
67 67
68#ifdef HAVE_CHARGING 68#ifdef CONFIG_CHARGING
69/* 69/*
70bool backlight_get_on_when_charging(void) 70bool backlight_get_on_when_charging(void)
71{ 71{
@@ -83,12 +83,12 @@ void charging_screen(void)
83 83
84 do 84 do
85 { 85 {
86#ifdef HAVE_CHARGE_CTRL 86#if CONFIG_CHARGING == CHARGING_CONTROL
87 if (charge_state == 1) 87 if (charge_state == CHARGING)
88 msg = "charging"; 88 msg = "charging";
89 else if (charge_state == 2) 89 else if (charge_state == TOPOFF)
90 msg = "topoff charge"; 90 msg = "topoff charge";
91 else if (charge_state == 3) 91 else if (charge_state == TRICKLE)
92 msg = "trickle charge"; 92 msg = "trickle charge";
93 else 93 else
94 msg = "not charging"; 94 msg = "not charging";
@@ -130,7 +130,7 @@ void charging_screen(void)
130 } 130 }
131 } while (1); 131 } while (1);
132} 132}
133#endif /* HAVE_CHARGING */ 133#endif /* CONFIG_CHARGING */
134 134
135/* prompt user to plug USB and fix a problem */ 135/* prompt user to plug USB and fix a problem */
136void prompt_usb(const char* msg1, const char* msg2) 136void prompt_usb(const char* msg1, const char* msg2)
@@ -172,7 +172,7 @@ void main(void)
172 button_init(); 172 button_init();
173 powermgmt_init(); 173 powermgmt_init();
174 174
175#if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034) 175#if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
176 if (charger_inserted() 176 if (charger_inserted()
177#ifdef ATA_POWER_PLAYERSTYLE 177#ifdef ATA_POWER_PLAYERSTYLE
178 && !ide_powered() /* relies on probing result from bootloader */ 178 && !ide_powered() /* relies on probing result from bootloader */