From f02cd18ad027cdb4992a19a16cfbd336ffb63124 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Tue, 30 Nov 2021 01:26:59 +0000 Subject: powermgmt: Refactor battery current estimation Create a new battery_current() function to report the the battery's charging/discharging current. Move the old runcurrent() implementation into it and clean up some of the related defines. Change-Id: I7dbe5b6532d291fa72add1cb23b30e3cbac8c3ca --- firmware/export/config/iaudiox5.h | 1 + firmware/export/config/ipod6g.h | 1 + firmware/export/config/mrobe500.h | 2 +- firmware/export/config/samsungypr0.h | 1 + firmware/export/config/samsungypr1.h | 1 + firmware/export/powermgmt.h | 19 +++---------------- 6 files changed, 8 insertions(+), 17 deletions(-) (limited to 'firmware/export') diff --git a/firmware/export/config/iaudiox5.h b/firmware/export/config/iaudiox5.h index 0164cd20fa..cae83dd952 100644 --- a/firmware/export/config/iaudiox5.h +++ b/firmware/export/config/iaudiox5.h @@ -151,6 +151,7 @@ #define CURRENT_NORMAL 65 /*2250mah/35h = 65 ma*/ #define CURRENT_BACKLIGHT 25 #define CURRENT_REMOTE 8 /* additional current when remote connected */ +#define CURRENT_RECORD 2 /* FIXME: placeholder value */ /* Define this if your LCD can set contrast */ #define HAVE_LCD_CONTRAST diff --git a/firmware/export/config/ipod6g.h b/firmware/export/config/ipod6g.h index fdf7e8e516..2e4afbdf63 100644 --- a/firmware/export/config/ipod6g.h +++ b/firmware/export/config/ipod6g.h @@ -158,6 +158,7 @@ /* define current usage levels */ #define CURRENT_NORMAL 18 /* playback @48MHz clock, backlight off */ #define CURRENT_BACKLIGHT 23 /* maximum brightness */ +#define CURRENT_RECORD 2 /* FIXME: placeholder value */ /* define this if the unit can be powered or charged via USB */ #define HAVE_USB_POWER diff --git a/firmware/export/config/mrobe500.h b/firmware/export/config/mrobe500.h index a7d72f76ac..ffc8a6bfb8 100644 --- a/firmware/export/config/mrobe500.h +++ b/firmware/export/config/mrobe500.h @@ -198,7 +198,7 @@ /* define current usage levels */ #define CURRENT_NORMAL 85 /* Measured */ #define CURRENT_BACKLIGHT 200 /* Over 200 mA total measured when on */ -#define CURRENT_RECORD 0 /* no recording */ +#define CURRENT_REMOTE 2 /* FIXME: placeholder value */ /* Hardware controlled charging with monitoring */ #define CONFIG_CHARGING CHARGING_MONITOR diff --git a/firmware/export/config/samsungypr0.h b/firmware/export/config/samsungypr0.h index 520eb08d01..88ba96504d 100644 --- a/firmware/export/config/samsungypr0.h +++ b/firmware/export/config/samsungypr0.h @@ -121,6 +121,7 @@ /* Define current usage levels. */ #define CURRENT_NORMAL 24 /* ~25h, on 600mAh that's about 24mA */ #define CURRENT_BACKLIGHT 62 /* ~6,5h -> 92mA. Minus 24mA normal that gives us 68mA */ +#define CURRENT_RECORD 2 /* FIXME: placeholder value */ #endif /* SIMULATOR */ diff --git a/firmware/export/config/samsungypr1.h b/firmware/export/config/samsungypr1.h index 50abfa323e..8ef76d60af 100644 --- a/firmware/export/config/samsungypr1.h +++ b/firmware/export/config/samsungypr1.h @@ -163,5 +163,6 @@ /* Define current usage levels. */ #define CURRENT_NORMAL 24 /* ~25h, on 600mAh that's about 24mA */ #define CURRENT_BACKLIGHT 62 /* ~6,5h -> 92mA. Minus 24mA normal that gives us 68mA */ +#define CURRENT_RECORD 2 /* FIXME: placeholder value */ #endif /* SIMULATOR */ diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index a4b924915c..c6fc3d5bdf 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h @@ -81,28 +81,13 @@ void powermgmt_init(void) INIT_ATTR; /* Generic current values that are intentionally meaningless - config header * should define proper numbers.*/ - -#ifndef CURRENT_BACKLIGHT -#define CURRENT_BACKLIGHT 5 /* additional current when backlight always on */ -#endif - -#if defined(HAVE_RECORDING) && !defined(CURRENT_RECORD) -#define CURRENT_RECORD 2 /* additional recording current */ -#endif /* HAVE_RECORDING && !CURRENT_RECORD*/ - #ifndef CURRENT_USB #define CURRENT_USB 2 /* usual current in mA in USB mode */ #endif -#if defined(HAVE_REMOTE_LCD) && !defined(CURRENT_REMOTE) -#define CURRENT_REMOTE 2 /* additional current when remote connected */ -#endif /* CURRENT_REMOTE && !HAVE_REMOTE_LCD */ - -#if CONFIG_CHARGING -#ifndef CURRENT_MAX_CHG +#if CONFIG_CHARGING && !defined(CURRENT_MAX_CHG) #define CURRENT_MAX_CHG 350 /* maximum charging current */ #endif -#endif /* CONFIG_CHARGING */ #ifndef BATT_AVE_SAMPLES /* slw filter constant unless otherwise specified */ @@ -126,6 +111,8 @@ extern const unsigned short percent_to_volt_charge[11]; int battery_level(void); /* percent */ int battery_time(void); /* minutes */ int battery_voltage(void); /* filtered batt. voltage in millivolts */ +int battery_current(void); /* battery current in milliamps + * (may just be a rough estimate) */ /* Implemented by the target, unfiltered */ int _battery_level(void); /* percent */ -- cgit v1.2.3