summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/powermgmt-as3525.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/powermgmt-as3525.c')
-rw-r--r--firmware/target/arm/as3525/powermgmt-as3525.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/firmware/target/arm/as3525/powermgmt-as3525.c b/firmware/target/arm/as3525/powermgmt-as3525.c
index ac1ee79f00..47e037684a 100644
--- a/firmware/target/arm/as3525/powermgmt-as3525.c
+++ b/firmware/target/arm/as3525/powermgmt-as3525.c
@@ -21,36 +21,53 @@
21 21
22#include "config.h" 22#include "config.h"
23#include "adc.h" 23#include "adc.h"
24#include "adc-target.h"
24#include "powermgmt.h" 25#include "powermgmt.h"
25 26
26/* TODO */ 27/* TODO
28 Each as3525 target should probably define its own battery properties
29 (dangerous/shutoff battery level, discharge/charge curves) in a file
30 called powermgmt-<target>.c in its own sub-directory.
31
32 For now, this file provides simple uncalibrated settings to get at least
33 a basic reading for all as3525 targets with a lithium battery.
34 */
27 35
28const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = 36const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
29{ 37{
30 0 38 /* TODO: this is just an initial guess */
39 3400
31}; 40};
32 41
33const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = 42const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
34{ 43{
35 0 44 /* TODO: this is just an initial guess */
45 3300
36}; 46};
37 47
38/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ 48/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
39const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = 49const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
40{ 50{
41 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 51 /* TODO: simple uncalibrated curve, linear except for first 10% */
52 { 3300, 3390, 3480, 3570, 3660, 3750, 3840, 3930, 4020, 4110, 4200 }
42}; 53};
43 54
44#if CONFIG_CHARGING 55#if CONFIG_CHARGING
45/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ 56/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
46const unsigned short percent_to_volt_charge[11] = 57const unsigned short percent_to_volt_charge[11] =
47{ 58{
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 59 /* TODO: simple uncalibrated curve, linear except for first 10% */
60 3300, 3390, 3480, 3570, 3660, 3750, 3840, 3930, 4020, 4110, 4200
49}; 61};
50#endif /* CONFIG_CHARGING */ 62#endif /* CONFIG_CHARGING */
51 63
64/* ADC should read 0x3ff=5.12V */
65#define BATTERY_SCALE_FACTOR 5125
66/* full-scale ADC readout (2^10) in millivolt */
67
52/* Returns battery voltage from ADC [millivolts] */ 68/* Returns battery voltage from ADC [millivolts] */
53unsigned int battery_adc_voltage(void) 69unsigned int battery_adc_voltage(void)
54{ 70{
55 return 1; 71 return (adc_read(ADC_RTCSUP) * BATTERY_SCALE_FACTOR) >> 10;
56} 72}
73