mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-07 13:45:03 -05:00
hosted: consolidate sysfs-based battery measurement code
Several hosted targets read their battery state from a fixed sysfs path. Get rid of the duplicated code by handling this common case in power-linux.c. Some targets use non-standard units in sysfs instead of the typical microvolts / microamps, so allow the scale factors to be overridden by the target. Change-Id: I31dc4ffc7a2d2c066d00a74070f9f9849c1663d0
This commit is contained in:
parent
7ffdf50ba5
commit
806b71b2ed
20 changed files with 74 additions and 454 deletions
|
|
@ -34,7 +34,38 @@
|
|||
#endif
|
||||
|
||||
#ifdef BATTERY_DEV_NAME
|
||||
#define BATTERY_STATUS_PATH "/sys/class/power_supply/" BATTERY_DEV_NAME "/status"
|
||||
# define BATTERY_SYSFS_PATH "/sys/class/power_supply/" BATTERY_DEV_NAME
|
||||
# define BATTERY_STATUS_PATH BATTERY_SYSFS_PATH "/status"
|
||||
# define BATTERY_VOLTAGE_PATH BATTERY_SYSFS_PATH "/voltage_now"
|
||||
# define BATTERY_CURRENT_PATH BATTERY_SYSFS_PATH "/current_now"
|
||||
# define BATTERY_LEVEL_PATH BATTERY_SYSFS_PATH "/capacity"
|
||||
#endif
|
||||
|
||||
/* Voltage is normally in microvolts */
|
||||
#ifndef BATTERY_VOLTAGE_SCALE_MUL
|
||||
# define BATTERY_VOLTAGE_SCALE_MUL 1
|
||||
#endif
|
||||
|
||||
#ifndef BATTERY_VOLTAGE_SCALE_DIV
|
||||
# define BATTERY_VOLTAGE_SCALE_DIV 1000
|
||||
#endif
|
||||
|
||||
/* Current is normally in microamps */
|
||||
#ifndef BATTERY_CURRENT_SCALE_MUL
|
||||
# define BATTERY_CURRENT_SCALE_MUL 1
|
||||
#endif
|
||||
|
||||
#ifndef BATTERY_CURRENT_SCALE_DIV
|
||||
# define BATTERY_CURRENT_SCALE_DIV 1000
|
||||
#endif
|
||||
|
||||
/* Level is normally in whole percentage points (0-100) */
|
||||
#ifndef BATTERY_LEVEL_SCALE_MUL
|
||||
# define BATTERY_LEVEL_SCALE_MUL 1
|
||||
#endif
|
||||
|
||||
#ifndef BATTERY_LEVEL_SCALE_DIV
|
||||
# define BATTERY_LEVEL_SCALE_DIV 1
|
||||
#endif
|
||||
|
||||
#define POWER_STATUS_PATH "/sys/class/power_supply/" POWER_DEV_NAME "/online"
|
||||
|
|
@ -55,6 +86,36 @@ bool charging_state(void)
|
|||
}
|
||||
return last_power;
|
||||
}
|
||||
|
||||
#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
|
||||
int _battery_voltage(void)
|
||||
{
|
||||
int voltage = 0;
|
||||
sysfs_get_int(BATTERY_VOLTAGE_PATH, &voltage);
|
||||
|
||||
return (voltage * BATTERY_VOLTAGE_SCALE_MUL) / BATTERY_VOLTAGE_SCALE_DIV;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BATTERY_MEASURE & CURRENT_MEASURE)
|
||||
int _battery_current(void)
|
||||
{
|
||||
int current = 0;
|
||||
sysfs_get_int(BATTERY_CURRENT_PATH, ¤t);
|
||||
|
||||
return (current * BATTERY_CURRENT_SCALE_MUL) / BATTERY_CURRENT_SCALE_DIV;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
|
||||
int _battery_level(void)
|
||||
{
|
||||
int level = 0;
|
||||
sysfs_get_int(BATTERY_LEVEL_PATH, &level);
|
||||
|
||||
return (level * BATTERY_LEVEL_SCALE_MUL) / BATTERY_LEVEL_SCALE_DIV;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
unsigned int power_input_status(void)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue