diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-01-19 07:47:34 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-01-19 07:47:34 +0000 |
commit | cdacab3d89cdbbd8fd7c20b3b340e27352e6737e (patch) | |
tree | ad1746cf51bdb56a1cdcabf0c38eb6a53244c431 /firmware | |
parent | 13414ae77a77d96ef2cb210d644880b847c9ca6f (diff) | |
download | rockbox-cdacab3d89cdbbd8fd7c20b3b340e27352e6737e.tar.gz rockbox-cdacab3d89cdbbd8fd7c20b3b340e27352e6737e.zip |
Charging state reporting on H3x0
Don't read the GPIO every refresh of statusbar or gwps for plugged state, use a
variable exported from powermgmt instead.
Allow Custom WPS to access %bc for battery charge state on targets that support
this.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8383 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/power.c | 6 | ||||
-rw-r--r-- | firmware/export/config-h300.h | 3 | ||||
-rw-r--r-- | firmware/export/power.h | 1 | ||||
-rw-r--r-- | firmware/export/powermgmt.h | 30 | ||||
-rw-r--r-- | firmware/powermgmt.c | 53 |
5 files changed, 71 insertions, 22 deletions
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c index da97233e57..8a20890228 100644 --- a/firmware/drivers/power.c +++ b/firmware/drivers/power.c | |||
@@ -148,6 +148,12 @@ void charger_enable(bool on) | |||
148 | } | 148 | } |
149 | #endif | 149 | #endif |
150 | 150 | ||
151 | #ifdef HAVE_CHARGE_STATE | ||
152 | bool charging_state(void) { | ||
153 | return (GPIO_READ & 0x00800000)?true:false; | ||
154 | } | ||
155 | #endif | ||
156 | |||
151 | #ifdef HAVE_SPDIF_POWER | 157 | #ifdef HAVE_SPDIF_POWER |
152 | void spdif_power_enable(bool on) | 158 | void spdif_power_enable(bool on) |
153 | { | 159 | { |
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index 806ae0a079..ded20c9129 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h | |||
@@ -72,6 +72,9 @@ | |||
72 | /* Define this if the platform can charge batteries */ | 72 | /* Define this if the platform can charge batteries */ |
73 | #define HAVE_CHARGING 1 | 73 | #define HAVE_CHARGING 1 |
74 | 74 | ||
75 | /* For units with a hardware charger that reports charge state */ | ||
76 | #define HAVE_CHARGE_STATE 1 | ||
77 | |||
75 | /* define this if the hardware can be powered off while charging */ | 78 | /* define this if the hardware can be powered off while charging */ |
76 | #define HAVE_POWEROFF_WHILE_CHARGING | 79 | #define HAVE_POWEROFF_WHILE_CHARGING |
77 | 80 | ||
diff --git a/firmware/export/power.h b/firmware/export/power.h index bf645522ef..9f91e25f15 100644 --- a/firmware/export/power.h +++ b/firmware/export/power.h | |||
@@ -25,6 +25,7 @@ extern bool charger_enabled; | |||
25 | 25 | ||
26 | void power_init(void); | 26 | void power_init(void); |
27 | bool charger_inserted(void); | 27 | bool charger_inserted(void); |
28 | bool charging_state(void); | ||
28 | void charger_enable(bool on); | 29 | void charger_enable(bool on); |
29 | void ide_power_enable(bool on); | 30 | void ide_power_enable(bool on); |
30 | bool ide_powered(void); | 31 | bool ide_powered(void); |
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index 3c4a61fb87..25c18eabad 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -79,18 +79,38 @@ extern int trickle_sec; /* trickle charge: How many seconds per minute | |||
79 | 79 | ||
80 | #endif /* HAVE_CHARGE_CTRL */ | 80 | #endif /* HAVE_CHARGE_CTRL */ |
81 | 81 | ||
82 | #if defined(HAVE_CHARGE_CTRL) || (CONFIG_BATTERY == BATT_LIION2200) | 82 | #if defined(HAVE_CHARGE_CTRL) || \ |
83 | (CONFIG_BATTERY == BATT_LIION2200) || \ | ||
84 | defined(HAVE_CHARGE_STATE) | ||
83 | typedef enum { | 85 | typedef enum { |
84 | DISCHARGING, | 86 | DISCHARGING, |
85 | CHARGING, | 87 | CHARGING, |
88 | #ifdef HAVE_CHARGE_CTRL | ||
86 | TOPOFF, | 89 | TOPOFF, |
87 | TRICKLE | 90 | TRICKLE |
91 | #endif | ||
88 | } charge_state_type; | 92 | } charge_state_type; |
89 | 93 | ||
90 | /* tells what the charger is doing */ | 94 | /* tells what the charger is doing */ |
91 | extern charge_state_type charge_state; | 95 | extern charge_state_type charge_state; |
92 | #endif /* defined(HAVE_CHARGE_CTRL) || (CONFIG_BATTERY == BATT_LIION2200) */ | 96 | #endif /* defined(HAVE_CHARGE_CTRL) || (CONFIG_BATTERY == BATT_LIION2200) */ |
93 | 97 | ||
98 | #ifdef HAVE_CHARGING | ||
99 | /* | ||
100 | * Flag that the charger has been plugged in/removed: this is set for exactly | ||
101 | * one time through the power loop when the charger has been plugged in. | ||
102 | */ | ||
103 | typedef enum { | ||
104 | NO_CHARGER, | ||
105 | CHARGER_UNPLUGGED, /* transient state */ | ||
106 | CHARGER_PLUGGED, /* transient state */ | ||
107 | CHARGER | ||
108 | } charger_input_state_type; | ||
109 | |||
110 | /* tells the state of the charge input */ | ||
111 | extern charger_input_state_type charger_input_state; | ||
112 | #endif | ||
113 | |||
94 | #ifdef HAVE_MMC /* Values for Ondio */ | 114 | #ifdef HAVE_MMC /* Values for Ondio */ |
95 | # define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */ | 115 | # define CURRENT_NORMAL 95 /* average, nearly proportional to 1/U */ |
96 | # define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */ | 116 | # define CURRENT_USB 1 /* host powered in USB mode; avoid zero-div */ |
@@ -106,9 +126,13 @@ extern charge_state_type charge_state; | |||
106 | 126 | ||
107 | # define CURRENT_MIN_CHG 70 /* minimum charge current */ | 127 | # define CURRENT_MIN_CHG 70 /* minimum charge current */ |
108 | # define MIN_CHG_V 8500 /* at 8.5v charger voltage get CURRENT_MIN_CHG */ | 128 | # define MIN_CHG_V 8500 /* at 8.5v charger voltage get CURRENT_MIN_CHG */ |
109 | # define CURRENT_MAX_CHG 350 /* maximum charging current */ | 129 | # ifdef IRIVER_H300_SERIES |
130 | # define CURRENT_MAX_CHG 650 /* maximum charging current */ | ||
131 | # else | ||
132 | # define CURRENT_MAX_CHG 350 /* maximum charging current */ | ||
133 | # endif | ||
110 | # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */ | 134 | # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */ |
111 | #endif /* HAVE_MMC */ | 135 | #endif /* not HAVE_MMC */ |
112 | 136 | ||
113 | extern unsigned int bat; /* filtered battery voltage, centivolts */ | 137 | extern unsigned int bat; /* filtered battery voltage, centivolts */ |
114 | extern unsigned short power_history[POWER_HISTORY_LEN]; | 138 | extern unsigned short power_history[POWER_HISTORY_LEN]; |
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 4b3999751c..7bf2d58284 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -145,33 +145,28 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | |||
145 | }; | 145 | }; |
146 | 146 | ||
147 | #ifdef HAVE_CHARGING | 147 | #ifdef HAVE_CHARGING |
148 | charger_input_state_type charger_input_state IDATA_ATTR; | ||
149 | |||
148 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ | 150 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ |
149 | static const short percent_to_volt_charge[11] = | 151 | static const short percent_to_volt_charge[11] = |
150 | { | 152 | { |
153 | #if CONFIG_BATTERY == BATT_LIPOL1300 | ||
154 | 340, 349, 358, 367, 376, 385, 394, 403, 408, 413, 418 /* Estimated */ | ||
155 | #else | ||
151 | /* values guessed, see | 156 | /* values guessed, see |
152 | http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone | 157 | http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone |
153 | measures voltages over a charging cycle */ | 158 | measures voltages over a charging cycle */ |
154 | 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */ | 159 | 476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */ |
160 | #endif | ||
155 | }; | 161 | }; |
156 | #endif /* HAVE_CHARGING */ | 162 | #endif /* HAVE_CHARGING */ |
157 | 163 | ||
158 | #if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 | 164 | #if defined(HAVE_CHARGE_CTRL) || \ |
165 | CONFIG_BATTERY == BATT_LIION2200 || \ | ||
166 | defined(HAVE_CHARGE_STATE) | ||
159 | charge_state_type charge_state; /* charging mode */ | 167 | charge_state_type charge_state; /* charging mode */ |
160 | #endif | 168 | #endif |
161 | 169 | ||
162 | #ifdef HAVE_CHARGING | ||
163 | /* | ||
164 | * Flag that the charger has been plugged in/removed: this is set for exactly | ||
165 | * one time through the power loop when the charger has been plugged in. | ||
166 | */ | ||
167 | static enum { | ||
168 | NO_CHARGER, | ||
169 | CHARGER_UNPLUGGED, /* transient state */ | ||
170 | CHARGER_PLUGGED, /* transient state */ | ||
171 | CHARGER | ||
172 | } charger_input_state; | ||
173 | #endif | ||
174 | |||
175 | #ifdef HAVE_CHARGE_CTRL | 170 | #ifdef HAVE_CHARGE_CTRL |
176 | int long_delta; /* long term delta battery voltage */ | 171 | int long_delta; /* long term delta battery voltage */ |
177 | int short_delta; /* short term delta battery voltage */ | 172 | int short_delta; /* short term delta battery voltage */ |
@@ -317,7 +312,7 @@ static void battery_status_update(void) | |||
317 | { | 312 | { |
318 | int level; | 313 | int level; |
319 | 314 | ||
320 | #ifdef HAVE_CHARGE_CTRL | 315 | #if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE) |
321 | if (charge_state == DISCHARGING) { | 316 | if (charge_state == DISCHARGING) { |
322 | level = voltage_to_percent(battery_centivolts, | 317 | level = voltage_to_percent(battery_centivolts, |
323 | percent_to_volt_discharge[battery_type]); | 318 | percent_to_volt_discharge[battery_type]); |
@@ -520,6 +515,23 @@ static void power_thread_sleep(int ticks) | |||
520 | } | 515 | } |
521 | } | 516 | } |
522 | #endif | 517 | #endif |
518 | #ifdef HAVE_CHARGE_STATE | ||
519 | switch (charger_input_state) { | ||
520 | case CHARGER_UNPLUGGED: | ||
521 | charge_state = DISCHARGING; | ||
522 | case NO_CHARGER: | ||
523 | break; | ||
524 | case CHARGER_PLUGGED: | ||
525 | case CHARGER: | ||
526 | if (charging_state()) { | ||
527 | charge_state = CHARGING; | ||
528 | } else { | ||
529 | charge_state = DISCHARGING; | ||
530 | } | ||
531 | break; | ||
532 | } | ||
533 | |||
534 | #endif /* HAVE_CHARGE_STATE */ | ||
523 | 535 | ||
524 | small_ticks = MIN(HZ/2, ticks); | 536 | small_ticks = MIN(HZ/2, ticks); |
525 | sleep(small_ticks); | 537 | sleep(small_ticks); |
@@ -551,6 +563,7 @@ static void power_thread_sleep(int ticks) | |||
551 | battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; | 563 | battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; |
552 | 564 | ||
553 | } | 565 | } |
566 | |||
554 | #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) | 567 | #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) |
555 | /* | 568 | /* |
556 | * If we have a lot of pending writes or if the disk is spining, | 569 | * If we have a lot of pending writes or if the disk is spining, |
@@ -821,7 +834,7 @@ static void power_thread(void) | |||
821 | snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge"); | 834 | snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge"); |
822 | } | 835 | } |
823 | 836 | ||
824 | #endif /* HAVE_CHARGE_CTRL*/ | 837 | #endif /* end HAVE_CHARGE_CTRL */ |
825 | 838 | ||
826 | /* sleep for a minute */ | 839 | /* sleep for a minute */ |
827 | 840 | ||
@@ -840,7 +853,7 @@ static void power_thread(void) | |||
840 | #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) | 853 | #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL) |
841 | if(usb_inserted()) { | 854 | if(usb_inserted()) { |
842 | if(fd >= 0) { | 855 | if(fd >= 0) { |
843 | /* It is probably too late to close the file but we can try... */ | 856 | /* It is probably too late to close the file but we can try...*/ |
844 | close(fd); | 857 | close(fd); |
845 | fd = -1; | 858 | fd = -1; |
846 | } | 859 | } |
@@ -855,9 +868,11 @@ static void power_thread(void) | |||
855 | } | 868 | } |
856 | } | 869 | } |
857 | if(fd >= 0) { | 870 | if(fd >= 0) { |
858 | snprintf(debug_message, DEBUG_MESSAGE_LEN, "%d, %d, %d, %d, %d, %d, %d, %d\n", | 871 | snprintf(debug_message, DEBUG_MESSAGE_LEN, |
872 | "%d, %d, %d, %d, %d, %d, %d, %d\n", | ||
859 | powermgmt_last_cycle_startstop_min, battery_centivolts, | 873 | powermgmt_last_cycle_startstop_min, battery_centivolts, |
860 | battery_percent, charger_input_state, charge_state, pid_p, pid_i, trickle_sec); | 874 | battery_percent, charger_input_state, charge_state, |
875 | pid_p, pid_i, trickle_sec); | ||
861 | write(fd, debug_message, strlen(debug_message)); | 876 | write(fd, debug_message, strlen(debug_message)); |
862 | wrcount++; | 877 | wrcount++; |
863 | } | 878 | } |