hosted: Consolidate the code that polls the battery charging status

affects all hiby targets, fiiom3k, and ibasso dx50/dx90

As well as deduplicating a small pile of code, this also implements
hysteresis so we're not doing a sysfs read/lookup multiple times
back-to-back every time the power management tick fires.

Change-Id: I2f7672acbb36341becf67e07960c24c681270d09
This commit is contained in:
Solomon Peachy 2021-03-10 18:10:00 -05:00
parent b3b8310e4e
commit 555299af9f
19 changed files with 80 additions and 187 deletions

View file

@ -35,28 +35,6 @@ const char * const sysfs_bat_voltage =
const char * const sysfs_bat_capacity =
"/sys/class/power_supply/battery/capacity";
const char * const sysfs_bat_status =
"/sys/class/power_supply/battery/status";
const char * const sysfs_pow_supply =
"/sys/class/power_supply/usb/present";
unsigned int xduoo_power_input_status(void)
{
int present = 0;
sysfs_get_int(sysfs_pow_supply, &present);
return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
}
bool xduoo_power_charging_status(void)
{
char buf[12] = {0};
sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
return (strncmp(buf, "Charging", 8) == 0);
}
unsigned int xduoo_power_get_battery_voltage(void)
{
int battery_voltage;

View file

@ -23,9 +23,6 @@
#include <stdbool.h>
#include "config.h"
unsigned int xduoo_power_input_status(void);
bool xduoo_power_charging_status(void);
unsigned int xduoo_power_get_battery_voltage(void);
unsigned int xduoo_power_get_battery_capacity(void);
#endif /* _POWER_XDUOO_H_ */

View file

@ -44,12 +44,6 @@ const unsigned short const percent_to_volt_charge[11] =
3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
};
unsigned int power_input_status(void)
{
/* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
return xduoo_power_input_status();
}
#if defined(XDUOO_X3II)
int _battery_voltage(void)
{
@ -63,8 +57,3 @@ int _battery_level(void)
return xduoo_power_get_battery_capacity();
}
#endif
bool charging_state(void)
{
return xduoo_power_charging_status();
}