diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/export/config-ondiofm.h | 2 | ||||
-rw-r--r-- | firmware/export/config-ondiosp.h | 2 | ||||
-rw-r--r-- | firmware/export/config.h | 6 | ||||
-rw-r--r-- | firmware/export/powermgmt.h | 8 | ||||
-rw-r--r-- | firmware/powermgmt.c | 38 |
5 files changed, 38 insertions, 18 deletions
diff --git a/firmware/export/config-ondiofm.h b/firmware/export/config-ondiofm.h index 99d4c483ea..79e7adbe58 100644 --- a/firmware/export/config-ondiofm.h +++ b/firmware/export/config-ondiofm.h | |||
@@ -26,7 +26,7 @@ | |||
26 | #define CONFIG_I2C I2C_ONDIO | 26 | #define CONFIG_I2C I2C_ONDIO |
27 | 27 | ||
28 | /* Type of mobile power */ | 28 | /* Type of mobile power */ |
29 | #define CONFIG_BATTERY BATT_3AAA_ALKALINE | 29 | #define CONFIG_BATTERY BATT_3AAA |
30 | 30 | ||
31 | /* Battery scale factor (average from 3 Ondios) */ | 31 | /* Battery scale factor (average from 3 Ondios) */ |
32 | #define BATTERY_SCALE_FACTOR 4735 | 32 | #define BATTERY_SCALE_FACTOR 4735 |
diff --git a/firmware/export/config-ondiosp.h b/firmware/export/config-ondiosp.h index 41bc83bf60..bda078a792 100644 --- a/firmware/export/config-ondiosp.h +++ b/firmware/export/config-ondiosp.h | |||
@@ -20,7 +20,7 @@ | |||
20 | #define CPU_FREQ 12000000 | 20 | #define CPU_FREQ 12000000 |
21 | 21 | ||
22 | /* Type of mobile power */ | 22 | /* Type of mobile power */ |
23 | #define CONFIG_BATTERY BATT_3AAA_ALKALINE | 23 | #define CONFIG_BATTERY BATT_3AAA |
24 | 24 | ||
25 | /* Battery scale factor (average from 3 Ondios) */ | 25 | /* Battery scale factor (average from 3 Ondios) */ |
26 | #define BATTERY_SCALE_FACTOR 4735 | 26 | #define BATTERY_SCALE_FACTOR 4735 |
diff --git a/firmware/export/config.h b/firmware/export/config.h index 4a55fbc622..64694af794 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -45,9 +45,9 @@ | |||
45 | #define GMINI100_PAD 4 | 45 | #define GMINI100_PAD 4 |
46 | 46 | ||
47 | /* CONFIG_BATTERY */ | 47 | /* CONFIG_BATTERY */ |
48 | #define BATT_LIION2200 2200 /* FM/V2 recorder type */ | 48 | #define BATT_LIION2200 2200 /* FM/V2 recorder type */ |
49 | #define BATT_4AA_NIMH 1500 | 49 | #define BATT_4AA_NIMH 1500 |
50 | #define BATT_3AAA_ALKALINE 1000 | 50 | #define BATT_3AAA 1000 /* Ondio */ |
51 | 51 | ||
52 | /* CONFIG_LCD */ | 52 | /* CONFIG_LCD */ |
53 | #define LCD_GMINI100 0 | 53 | #define LCD_GMINI100 0 |
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index 2847156f46..ce006e9145 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -26,13 +26,15 @@ | |||
26 | #define BATTERY_LEVEL_FULL 400 /* 4.00V */ | 26 | #define BATTERY_LEVEL_FULL 400 /* 4.00V */ |
27 | #define BATTERY_CAPACITY_MIN 2200 | 27 | #define BATTERY_CAPACITY_MIN 2200 |
28 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ | 28 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ |
29 | #elif CONFIG_BATTERY == BATT_3AAA_ALKALINE /* Ondio, Alkalines */ | 29 | #define BATTERY_TYPES_COUNT 1 |
30 | #elif CONFIG_BATTERY == BATT_3AAA /* Ondio */ | ||
30 | #define BATTERY_LEVEL_SHUTDOWN 260 /* 2.60V */ | 31 | #define BATTERY_LEVEL_SHUTDOWN 260 /* 2.60V */ |
31 | #define BATTERY_LEVEL_EMPTY 270 /* 2.70V */ | 32 | #define BATTERY_LEVEL_EMPTY 270 /* 2.70V */ |
32 | #define BATTERY_LEVEL_DANGEROUS 280 /* 2.80V */ | 33 | #define BATTERY_LEVEL_DANGEROUS 280 /* 2.80V */ |
33 | #define BATTERY_LEVEL_FULL 450 /* 4.50V */ | 34 | #define BATTERY_LEVEL_FULL 475 /* 4.75V */ |
34 | #define BATTERY_CAPACITY_MIN 500 | 35 | #define BATTERY_CAPACITY_MIN 500 |
35 | #define BATTERY_CAPACITY_MAX 1500 /* max. capacity selectable in settings */ | 36 | #define BATTERY_CAPACITY_MAX 1500 /* max. capacity selectable in settings */ |
37 | #define BATTERY_TYPES_COUNT 2 /* Alkalines or NiMH */ | ||
36 | #else /* Recorder, NiMH */ | 38 | #else /* Recorder, NiMH */ |
37 | #define BATTERY_LEVEL_SHUTDOWN 450 /* 4.50V */ | 39 | #define BATTERY_LEVEL_SHUTDOWN 450 /* 4.50V */ |
38 | #define BATTERY_LEVEL_EMPTY 465 /* 4.65V */ | 40 | #define BATTERY_LEVEL_EMPTY 465 /* 4.65V */ |
@@ -40,6 +42,7 @@ | |||
40 | #define BATTERY_LEVEL_FULL 585 /* 5.85V */ | 42 | #define BATTERY_LEVEL_FULL 585 /* 5.85V */ |
41 | #define BATTERY_CAPACITY_MIN 1500 | 43 | #define BATTERY_CAPACITY_MIN 1500 |
42 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ | 44 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ |
45 | #define BATTERY_TYPES_COUNT 1 | ||
43 | #endif | 46 | #endif |
44 | 47 | ||
45 | #define BATTERY_RANGE (BATTERY_LEVEL_FULL - BATTERY_LEVEL_EMPTY) | 48 | #define BATTERY_RANGE (BATTERY_LEVEL_FULL - BATTERY_LEVEL_EMPTY) |
@@ -111,6 +114,7 @@ bool battery_level_safe(void); | |||
111 | 114 | ||
112 | void set_poweroff_timeout(int timeout); | 115 | void set_poweroff_timeout(int timeout); |
113 | void set_battery_capacity(int capacity); /* set local battery capacity value */ | 116 | void set_battery_capacity(int capacity); /* set local battery capacity value */ |
117 | void set_battery_type(int type); /* set local battery type */ | ||
114 | 118 | ||
115 | void set_sleep_timer(int seconds); | 119 | void set_sleep_timer(int seconds); |
116 | int get_sleep_timer(void); | 120 | int get_sleep_timer(void); |
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 26759b647d..08f0be7d5f 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -89,20 +89,21 @@ static const int poweroff_idle_timeout_value[15] = | |||
89 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 | 89 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static const int percent_to_volt_decharge[11] = | 92 | static const short percent_to_volt_decharge[BATTERY_TYPES_COUNT][11] = |
93 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */ | 93 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */ |
94 | { | 94 | { |
95 | #if CONFIG_BATTERY == BATT_LIION2200 | 95 | #if CONFIG_BATTERY == BATT_LIION2200 |
96 | /* measured values */ | 96 | /* measured values */ |
97 | 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 | 97 | { 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 } |
98 | #elif CONFIG_BATTERY == BATT_3AAA_ALKALINE | 98 | #elif CONFIG_BATTERY == BATT_3AAA |
99 | /* taken from a textbook alkaline discharge graph, not measured */ | 99 | /* measured values */ |
100 | 270, 303, 324, 336, 348, 357, 366, 378, 390, 408, 450 | 100 | { 280, 325, 341, 353, 364, 374, 385, 395, 409, 427, 475 }, /* alkaline */ |
101 | { 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 } /* NiMH */ | ||
101 | #else /* NiMH */ | 102 | #else /* NiMH */ |
102 | /* original values were taken directly after charging, but it should show | 103 | /* original values were taken directly after charging, but it should show |
103 | 100% after turning off the device for some hours, too */ | 104 | 100% after turning off the device for some hours, too */ |
104 | 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 /* orig. values: | 105 | { 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 } |
105 | ...,528,560 */ | 106 | /* orig. values: ...,528,560 */ |
106 | #endif | 107 | #endif |
107 | }; | 108 | }; |
108 | 109 | ||
@@ -115,6 +116,16 @@ void set_battery_capacity(int capacity) | |||
115 | battery_capacity = BATTERY_CAPACITY_MIN; | 116 | battery_capacity = BATTERY_CAPACITY_MIN; |
116 | } | 117 | } |
117 | 118 | ||
119 | #if BATTERY_TYPES_COUNT > 1 | ||
120 | static int battery_type = 0; | ||
121 | |||
122 | void set_battery_type(int type) | ||
123 | { | ||
124 | battery_type = type; | ||
125 | battery_level_cached = -1; /* reset on type change */ | ||
126 | } | ||
127 | #endif | ||
128 | |||
118 | #if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 | 129 | #if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 |
119 | int charge_state = 0; /* at the beginning, the | 130 | int charge_state = 0; /* at the beginning, the |
120 | charger does nothing */ | 131 | charger does nothing */ |
@@ -136,7 +147,7 @@ int trickle_sec = 0; /* how many seconds should the | |||
136 | charger be enabled per | 147 | charger be enabled per |
137 | minute for trickle | 148 | minute for trickle |
138 | charging? */ | 149 | charging? */ |
139 | static const int percent_to_volt_charge[11] = | 150 | static const short percent_to_volt_charge[11] = |
140 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ | 151 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ |
141 | { | 152 | { |
142 | /* values guessed, see | 153 | /* values guessed, see |
@@ -170,7 +181,7 @@ int battery_time(void) | |||
170 | 181 | ||
171 | /* look into the percent_to_volt_* table and get a realistic battery level | 182 | /* look into the percent_to_volt_* table and get a realistic battery level |
172 | percentage */ | 183 | percentage */ |
173 | int voltage_to_percent(int voltage, const int* table) | 184 | int voltage_to_percent(int voltage, const short* table) |
174 | { | 185 | { |
175 | if (voltage <= table[0]) | 186 | if (voltage <= table[0]) |
176 | return 0; | 187 | return 0; |
@@ -195,6 +206,9 @@ void battery_level_update(void) | |||
195 | int level = 0; | 206 | int level = 0; |
196 | int c = 0; | 207 | int c = 0; |
197 | int i; | 208 | int i; |
209 | #if BATTERY_TYPES_COUNT == 1 /* single type */ | ||
210 | const int battery_type = 0; | ||
211 | #endif | ||
198 | 212 | ||
199 | /* calculate maximum over last 3 minutes (skip empty samples) */ | 213 | /* calculate maximum over last 3 minutes (skip empty samples) */ |
200 | for (i = 0; i < 3; i++) | 214 | for (i = 0; i < 3; i++) |
@@ -214,7 +228,8 @@ void battery_level_update(void) | |||
214 | 228 | ||
215 | #ifdef HAVE_CHARGE_CTRL | 229 | #ifdef HAVE_CHARGE_CTRL |
216 | if (charge_state == 0) { /* decharge */ | 230 | if (charge_state == 0) { /* decharge */ |
217 | level = voltage_to_percent(level, percent_to_volt_decharge); | 231 | level = voltage_to_percent(level, |
232 | percent_to_volt_decharge[battery_type]); | ||
218 | } | 233 | } |
219 | else if (charge_state == 1) { /* charge */ | 234 | else if (charge_state == 1) { /* charge */ |
220 | level = voltage_to_percent(level, percent_to_volt_charge); | 235 | level = voltage_to_percent(level, percent_to_volt_charge); |
@@ -223,7 +238,8 @@ void battery_level_update(void) | |||
223 | battery_level_cached = level = 100; | 238 | battery_level_cached = level = 100; |
224 | } | 239 | } |
225 | #else | 240 | #else |
226 | level = voltage_to_percent(level, percent_to_volt_decharge); | 241 | level = voltage_to_percent(level, |
242 | percent_to_volt_decharge[battery_type]); | ||
227 | /* always use the decharge table */ | 243 | /* always use the decharge table */ |
228 | #endif | 244 | #endif |
229 | 245 | ||