summaryrefslogtreecommitdiff
path: root/firmware/export/powermgmt.h
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-12-21 18:10:36 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-12-21 18:10:36 +0000
commit5667682dd204a07c52f057506fd2eef05bf63f2e (patch)
treea5f4f3cb22751362a9ed7774698ca55d27819d16 /firmware/export/powermgmt.h
parentc3c15cce88481a2504eb492ba06b6a691d8e998d (diff)
downloadrockbox-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.h48
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
34typedef enum { /* sorted by increasing charging current */ 33typedef 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 */
42extern charge_state_type charge_state; 52extern 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 */
50typedef enum { 59typedef 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
157extern unsigned short power_history[POWER_HISTORY_LEN]; 171extern unsigned short power_history[POWER_HISTORY_LEN];
158extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT]; 172extern const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT];
159extern const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT]; 173extern 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 */
166void powermgmt_init(void); 180void powermgmt_init(void);
167 181
182/* Do target portion of init (for CHARGING_TARGET) - called on power thread */
183void powermgmt_init_target(void);
184
185/* Handle frequent tasks and call charging_algorithm_small_step */
186void 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 */
173unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */ 193unsigned int battery_adc_voltage(void); /* voltage from ADC in millivolts */
174unsigned int battery_voltage(void); /* filtered batt. voltage in millivolts */ 194unsigned 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). */
198void set_filtered_battery_voltage(int millivolts);
199
176/* read unfiltered battery info */ 200/* read unfiltered battery info */
177void battery_read_info(int *voltage, int *level); 201void 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 */
180bool battery_level_safe(void); 204bool battery_level_safe(void);
181 205
206#ifdef TARGET_POWERMGMT_FILTER_CHARGE_STATE
207int powermgmt_filter_charge_state(void);
208#endif
209
182void set_poweroff_timeout(int timeout); 210void set_poweroff_timeout(int timeout);
183void set_battery_capacity(int capacity); /* set local battery capacity value */ 211void set_battery_capacity(int capacity); /* set local battery capacity value */
184void set_battery_type(int type); /* set local battery type */ 212void set_battery_type(int type); /* set local battery type */
@@ -190,7 +218,11 @@ void reset_poweroff_timer(void);
190void cancel_shutdown(void); 218void cancel_shutdown(void);
191void shutdown_hw(void); 219void shutdown_hw(void);
192void sys_poweroff(void); 220void sys_poweroff(void);
221/* Returns true if the system should force shutdown for some reason -
222 * eg. low battery */
223bool query_force_shutdown(void);
193#ifdef HAVE_ACCESSORY_SUPPLY 224#ifdef HAVE_ACCESSORY_SUPPLY
194void accessory_supply_set(bool); 225void accessory_supply_set(bool);
195#endif 226#endif
196#endif 227
228#endif /* _POWERMGMT_H_ */