diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2008-12-21 18:10:36 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2008-12-21 18:10:36 +0000 |
commit | 5667682dd204a07c52f057506fd2eef05bf63f2e (patch) | |
tree | a5f4f3cb22751362a9ed7774698ca55d27819d16 /firmware/export/powermgmt.h | |
parent | c3c15cce88481a2504eb492ba06b6a691d8e998d (diff) | |
download | rockbox-5667682dd204a07c52f057506fd2eef05bf63f2e.tar.gz rockbox-5667682dd204a07c52f057506fd2eef05bf63f2e.zip |
Gigabeat S: Implement charging and power control to charge from AC or USB. Hold MENU while plugging USB cable to charge from USB without connecting. Under Windows, plugging USB for charging only but not connecting still needs to be properly handled (driver popup issue) but it will charge when connected normally-- no issue under Linux. Some accomodating changes made to powermgmt.c will soon be made nicer.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19547 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/export/powermgmt.h')
-rw-r--r-- | firmware/export/powermgmt.h | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index 70c4b70d7a..c333795ad7 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -30,17 +30,26 @@ | |||
30 | #define CHARGE_END_LONGD 50 /* stop when N minutes have passed with | 30 | #define CHARGE_END_LONGD 50 /* stop when N minutes have passed with |
31 | * avg delta being < -0.02 V */ | 31 | * avg delta being < -0.02 V */ |
32 | 32 | ||
33 | #if CONFIG_CHARGING >= CHARGING_MONITOR | ||
34 | typedef enum { /* sorted by increasing charging current */ | 33 | typedef enum { /* sorted by increasing charging current */ |
34 | #if CONFIG_CHARGING >= CHARGING_MONITOR | ||
35 | CHARGE_STATE_DISABLED = -2, /* Disable charger use */ | ||
36 | CHARGE_STATE_ERROR = -1, /* Some error occurred that should not allow | ||
37 | further attempts without user intervention */ | ||
38 | #endif | ||
35 | DISCHARGING = 0, | 39 | DISCHARGING = 0, |
40 | #if CONFIG_CHARGING >= CHARGING_MONITOR | ||
36 | TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */ | 41 | TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */ |
42 | /* For LiIon, the low-current precharge mode if battery | ||
43 | was very low */ | ||
37 | TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */ | 44 | TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */ |
38 | CHARGING /* Can occur for all CONFIG_CHARGING options */ | 45 | /* For LiIon, constant voltage phase */ |
46 | CHARGING, /* Can occur for all CONFIG_CHARGING options */ | ||
47 | /* For LiIon, the constant current phase */ | ||
48 | #endif | ||
39 | } charge_state_type; | 49 | } charge_state_type; |
40 | 50 | ||
41 | /* tells what the charger is doing */ | 51 | /* tells what the charger is doing */ |
42 | extern charge_state_type charge_state; | 52 | extern charge_state_type charge_state; |
43 | #endif /* CONFIG_CHARGING >= CHARGING_MONITOR */ | ||
44 | 53 | ||
45 | #ifdef CONFIG_CHARGING | 54 | #ifdef CONFIG_CHARGING |
46 | /* | 55 | /* |
@@ -48,10 +57,10 @@ extern charge_state_type charge_state; | |||
48 | * one time through the power loop when the charger has been plugged in. | 57 | * one time through the power loop when the charger has been plugged in. |
49 | */ | 58 | */ |
50 | typedef enum { | 59 | typedef enum { |
51 | NO_CHARGER, | 60 | NO_CHARGER = 0, /* No charger is present */ |
52 | CHARGER_UNPLUGGED, /* transient state */ | 61 | CHARGER_UNPLUGGED, /* Transitional state during CHARGER=>NO_CHARGER */ |
53 | CHARGER_PLUGGED, /* transient state */ | 62 | CHARGER_PLUGGED, /* Transitional state during NO_CHARGER=>CHARGER */ |
54 | CHARGER | 63 | CHARGER /* Charger is present */ |
55 | } charger_input_state_type; | 64 | } charger_input_state_type; |
56 | 65 | ||
57 | /* tells the state of the charge input */ | 66 | /* tells the state of the charge input */ |
@@ -154,6 +163,11 @@ extern int trickle_sec; /* trickle charge: How many seconds per minute | |||
154 | # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */ | 163 | # define MAX_CHG_V 10250 /* anything over 10.25v gives CURRENT_MAX_CHG */ |
155 | #endif /* not ONDIO */ | 164 | #endif /* not ONDIO */ |
156 | 165 | ||
166 | #if CONFIG_CHARGING == CHARGING_TARGET | ||
167 | /* Include target-specific definitions */ | ||
168 | #include "powermgmt-target.h" | ||
169 | #endif | ||
170 | |||
157 | extern unsigned short power_history[POWER_HISTORY_LEN]; | 171 | extern unsigned short power_history[POWER_HISTORY_LEN]; |
158 | extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT]; | 172 | extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT]; |
159 | extern const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT]; | 173 | extern const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT]; |
@@ -165,6 +179,12 @@ extern const unsigned short percent_to_volt_charge[11]; | |||
165 | /* Start up power management thread */ | 179 | /* Start up power management thread */ |
166 | void powermgmt_init(void); | 180 | void powermgmt_init(void); |
167 | 181 | ||
182 | /* Do target portion of init (for CHARGING_TARGET) - called on power thread */ | ||
183 | void powermgmt_init_target(void); | ||
184 | |||
185 | /* Handle frequent tasks and call charging_algorithm_small_step */ | ||
186 | void power_thread_sleep(int ticks); | ||
187 | |||
168 | #endif /* SIMULATOR */ | 188 | #endif /* SIMULATOR */ |
169 | 189 | ||
170 | /* Returns battery statust */ | 190 | /* Returns battery statust */ |
@@ -173,12 +193,20 @@ int battery_time(void); /* minutes */ | |||
173 | unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */ | 193 | unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */ |
174 | unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */ | 194 | unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */ |
175 | 195 | ||
196 | /* Set the filtered battery voltage (to adjust it before beginning a charge | ||
197 | cycle for instance where old, loaded readings will likely be invalid). */ | ||
198 | void set_filtered_battery_voltage(int millivolts); | ||
199 | |||
176 | /* read unfiltered battery info */ | 200 | /* read unfiltered battery info */ |
177 | void battery_read_info(int *voltage, int *level); | 201 | void battery_read_info(int *voltage, int *level); |
178 | 202 | ||
179 | /* Tells if the battery level is safe for disk writes */ | 203 | /* Tells if the battery level is safe for disk writes */ |
180 | bool battery_level_safe(void); | 204 | bool battery_level_safe(void); |
181 | 205 | ||
206 | #ifdef TARGET_POWERMGMT_FILTER_CHARGE_STATE | ||
207 | int powermgmt_filter_charge_state(void); | ||
208 | #endif | ||
209 | |||
182 | void set_poweroff_timeout(int timeout); | 210 | void set_poweroff_timeout(int timeout); |
183 | void set_battery_capacity(int capacity); /* set local battery capacity value */ | 211 | void set_battery_capacity(int capacity); /* set local battery capacity value */ |
184 | void set_battery_type(int type); /* set local battery type */ | 212 | void set_battery_type(int type); /* set local battery type */ |
@@ -190,7 +218,11 @@ void reset_poweroff_timer(void); | |||
190 | void cancel_shutdown(void); | 218 | void cancel_shutdown(void); |
191 | void shutdown_hw(void); | 219 | void shutdown_hw(void); |
192 | void sys_poweroff(void); | 220 | void sys_poweroff(void); |
221 | /* Returns true if the system should force shutdown for some reason - | ||
222 | * eg. low battery */ | ||
223 | bool query_force_shutdown(void); | ||
193 | #ifdef HAVE_ACCESSORY_SUPPLY | 224 | #ifdef HAVE_ACCESSORY_SUPPLY |
194 | void accessory_supply_set(bool); | 225 | void accessory_supply_set(bool); |
195 | #endif | 226 | #endif |
196 | #endif | 227 | |
228 | #endif /* _POWERMGMT_H_ */ | ||