summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-03-13 16:11:30 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-03-13 16:11:30 +0000
commit451ee0b11c4eb1e60370c5fef94bc85945d8e092 (patch)
treef8473fddb4e3e6153eda8909353c859276ed56e3
parentb4171645a53841b829bea6cd53f62ea0c3d520ff (diff)
downloadrockbox-451ee0b11c4eb1e60370c5fef94bc85945d8e092.tar.gz
rockbox-451ee0b11c4eb1e60370c5fef94bc85945d8e092.zip
Charging state reporting for iriver players. Values calibrated with
1900 mAh Ionity battery; might need recalibration with the stock battery. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9030 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/statusbar.c53
-rw-r--r--apps/gui/statusbar.h12
-rw-r--r--firmware/drivers/power.c5
-rw-r--r--firmware/export/config-h100.h3
-rw-r--r--firmware/export/config-h120.h3
-rw-r--r--firmware/powermgmt.c11
6 files changed, 65 insertions, 22 deletions
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c
index 8acfd1ca7f..c9b27aea7c 100644
--- a/apps/gui/statusbar.c
+++ b/apps/gui/statusbar.c
@@ -109,9 +109,7 @@ void gui_statusbar_init(struct gui_statusbar * bar)
109{ 109{
110 bar->last_volume = -1000; /* -1000 means "first update ever" */ 110 bar->last_volume = -1000; /* -1000 means "first update ever" */
111 bar->battery_icon_switch_tick = 0; 111 bar->battery_icon_switch_tick = 0;
112#ifdef HAVE_CHARGING 112 bar->animated_level = 0;
113 bar->battery_charge_step = 0;
114#endif
115} 113}
116 114
117void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw) 115void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
@@ -199,11 +197,20 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
199 { 197 {
200#endif 198#endif
201 /* animate in three steps (34% per step for a better look) */ 199 /* animate in three steps (34% per step for a better look) */
202 bar->info.battlevel = bar->battery_charge_step * 34; 200#ifndef HAVE_CHARGE_STATE
203 if (bar->info.battlevel > 100) 201 bar->info.battlevel = 0;
204 bar->info.battlevel = 100; 202#endif
205 if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) { 203 if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) {
206 bar->battery_charge_step=(bar->battery_charge_step+1)%4; 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 }
207 bar->battery_icon_switch_tick = current_tick + HZ; 214 bar->battery_icon_switch_tick = current_tick + HZ;
208 } 215 }
209 } 216 }
@@ -211,6 +218,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
211 else 218 else
212#endif /* HAVE_CHARGING */ 219#endif /* HAVE_CHARGING */
213 { 220 {
221 bar->animated_level = 0;
214 if (bar->info.battery_safe) 222 if (bar->info.battery_safe)
215 battery_state = true; 223 battery_state = true;
216 else { 224 else {
@@ -224,7 +232,8 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
224 } 232 }
225#ifdef HAVE_LCD_BITMAP 233#ifdef HAVE_LCD_BITMAP
226 if (battery_state) 234 if (battery_state)
227 gui_statusbar_icon_battery(display, bar->info.battlevel); 235 gui_statusbar_icon_battery(display, bar->info.battlevel,
236 bar->animated_level);
228#ifdef HAVE_USB_POWER 237#ifdef HAVE_USB_POWER
229 if (bar->info.usb_power) 238 if (bar->info.usb_power)
230 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug], 239 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
@@ -316,11 +325,15 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
316/* 325/*
317 * Print battery icon to status bar 326 * Print battery icon to status bar
318 */ 327 */
319void gui_statusbar_icon_battery(struct screen * display, int percent) 328void gui_statusbar_icon_battery(struct screen * display, int percent,
329 int animated_percent)
320{ 330{
321 int fill; 331 int fill, endfill;
322 char buffer[5]; 332 char buffer[5];
323 unsigned int width, height; 333 unsigned int width, height;
334#if LCD_DEPTH > 1
335 unsigned int prevfg = LCD_DEFAULT_FG;
336#endif
324 337
325 /* fill battery */ 338 /* fill battery */
326 fill = percent; 339 fill = percent;
@@ -329,6 +342,12 @@ void gui_statusbar_icon_battery(struct screen * display, int percent)
329 if (fill > 100) 342 if (fill > 100)
330 fill = 100; 343 fill = 100;
331 344
345 endfill = animated_percent;
346 if (endfill < 0)
347 endfill = 0;
348 if (endfill > 100)
349 endfill = 100;
350
332#if (defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)) && \ 351#if (defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)) && \
333 !defined(SIMULATOR) /* Certain charge controlled targets */ 352 !defined(SIMULATOR) /* Certain charge controlled targets */
334 /* show graphical animation when charging instead of numbers */ 353 /* show graphical animation when charging instead of numbers */
@@ -358,6 +377,20 @@ void gui_statusbar_icon_battery(struct screen * display, int percent)
358 fill = fill * 15 / 100; 377 fill = fill * 15 / 100;
359 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1, 378 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
360 fill, 5); 379 fill, 5);
380#if LCD_DEPTH > 1
381 if (display->depth > 1)
382 {
383 prevfg = display->get_foreground();
384 display->set_foreground(LCD_DARKGRAY);
385 }
386#endif
387 endfill = endfill * 15 / 100 - fill;
388 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
389 STATUSBAR_Y_POS + 1, endfill, 5);
390#if LCD_DEPTH > 1
391 if (display->depth > 1)
392 display->set_foreground(prevfg);
393#endif
361 } 394 }
362 395
363 if (percent == -1) { 396 if (percent == -1) {
diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h
index 650b49d63b..03add6a6d9 100644
--- a/apps/gui/statusbar.h
+++ b/apps/gui/statusbar.h
@@ -53,9 +53,6 @@ struct status_info {
53#ifdef HAVE_USB_POWER 53#ifdef HAVE_USB_POWER
54 bool usb_power; 54 bool usb_power;
55#endif 55#endif
56#ifdef HAVE_CHARGING
57 int battery_charge_step;
58#endif
59}; 56};
60 57
61struct gui_statusbar 58struct gui_statusbar
@@ -63,12 +60,9 @@ struct gui_statusbar
63 /* Volume icon stuffs */ 60 /* Volume icon stuffs */
64 long volume_icon_switch_tick; 61 long volume_icon_switch_tick;
65 int last_volume; 62 int last_volume;
66 63
67 long battery_icon_switch_tick; 64 long battery_icon_switch_tick;
68 65 int animated_level;
69#ifdef HAVE_CHARGING
70 int battery_charge_step;
71#endif
72 66
73 struct status_info info; 67 struct status_info info;
74 struct status_info lastinfo; 68 struct status_info lastinfo;
@@ -101,7 +95,7 @@ extern void gui_statusbar_init(struct gui_statusbar * bar);
101 */ 95 */
102extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw); 96extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw);
103 97
104void gui_statusbar_icon_battery(struct screen * display, int percent); 98void gui_statusbar_icon_battery(struct screen * display, int percent, int animated_percent);
105bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume); 99bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
106void gui_statusbar_icon_play_state(struct screen * display, int state); 100void gui_statusbar_icon_play_state(struct screen * display, int state);
107void gui_statusbar_icon_play_mode(struct screen * display, int mode); 101void gui_statusbar_icon_play_mode(struct screen * display, int mode);
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c
index 9f3a10cc84..3df8460222 100644
--- a/firmware/drivers/power.c
+++ b/firmware/drivers/power.c
@@ -150,8 +150,13 @@ void charger_enable(bool on)
150#endif 150#endif
151 151
152#ifdef HAVE_CHARGE_STATE 152#ifdef HAVE_CHARGE_STATE
153/* Returns true if the unit is charging the batteries. */
153bool charging_state(void) { 154bool charging_state(void) {
155#if defined(IRIVER_H100_SERIES)
156 return charger_inserted();
157#else /* Iriver H300 */
154 return (GPIO_READ & 0x00800000)?true:false; 158 return (GPIO_READ & 0x00800000)?true:false;
159#endif
155} 160}
156#endif 161#endif
157 162
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h
index 87598c208e..d35a35bb60 100644
--- a/firmware/export/config-h100.h
+++ b/firmware/export/config-h100.h
@@ -78,6 +78,9 @@
78/* Define this if the platform can charge batteries */ 78/* Define this if the platform can charge batteries */
79#define HAVE_CHARGING 1 79#define HAVE_CHARGING 1
80 80
81/* For units with a hardware charger that reports charge state */
82#define HAVE_CHARGE_STATE 1
83
81/* define this if the hardware can be powered off while charging */ 84/* define this if the hardware can be powered off while charging */
82#define HAVE_POWEROFF_WHILE_CHARGING 85#define HAVE_POWEROFF_WHILE_CHARGING
83 86
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index fd62243d8a..8426940da8 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -73,6 +73,9 @@
73/* Define this if the platform can charge batteries */ 73/* Define this if the platform can charge batteries */
74#define HAVE_CHARGING 1 74#define HAVE_CHARGING 1
75 75
76/* For units with a hardware charger that reports charge state */
77#define HAVE_CHARGE_STATE 1
78
76/* define this if the hardware can be powered off while charging */ 79/* define this if the hardware can be powered off while charging */
77#define HAVE_POWEROFF_WHILE_CHARGING 80#define HAVE_POWEROFF_WHILE_CHARGING
78 81
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index e4330a48c0..8f4f22fb3f 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -140,7 +140,10 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
140 { 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 } /* NiMH */ 140 { 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 } /* NiMH */
141#elif CONFIG_BATTERY == BATT_LIPOL1300 141#elif CONFIG_BATTERY == BATT_LIPOL1300
142 /* Below 337 the backlight starts flickering during HD access */ 142 /* Below 337 the backlight starts flickering during HD access */
143 { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 } 143 /* Calibrated for Ionity 1900 mAh battery. If necessary, re-calibrate
144 * for the 1300 mAh stock battery. */
145// { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 }
146 { 337, 366, 372, 374, 378, 381, 385, 392, 399, 408, 417 }
144#else /* NiMH */ 147#else /* NiMH */
145 /* original values were taken directly after charging, but it should show 148 /* original values were taken directly after charging, but it should show
146 100% after turning off the device for some hours, too */ 149 100% after turning off the device for some hours, too */
@@ -156,7 +159,9 @@ charger_input_state_type charger_input_state IDATA_ATTR;
156static const short percent_to_volt_charge[11] = 159static const short percent_to_volt_charge[11] =
157{ 160{
158#if CONFIG_BATTERY == BATT_LIPOL1300 161#if CONFIG_BATTERY == BATT_LIPOL1300
159 340, 349, 358, 367, 376, 385, 394, 403, 408, 413, 418 /* Estimated */ 162 /* Calibrated for 1900 mAh Ionity battery (estimated 90% charge when
163 entering in trickle-charging). We will never reach 100%. */
164 340, 390, 394, 399, 400, 404, 407, 413, 417, 422, 426
160#else 165#else
161 /* values guessed, see 166 /* values guessed, see
162 http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone 167 http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone
@@ -533,8 +538,8 @@ static void power_thread_sleep(int ticks)
533#ifdef HAVE_CHARGE_STATE 538#ifdef HAVE_CHARGE_STATE
534 switch (charger_input_state) { 539 switch (charger_input_state) {
535 case CHARGER_UNPLUGGED: 540 case CHARGER_UNPLUGGED:
536 charge_state = DISCHARGING;
537 case NO_CHARGER: 541 case NO_CHARGER:
542 charge_state = DISCHARGING;
538 break; 543 break;
539 case CHARGER_PLUGGED: 544 case CHARGER_PLUGGED:
540 case CHARGER: 545 case CHARGER: