|
|
|
@ -30,8 +30,10 @@ struct battery_config {
@@ -30,8 +30,10 @@ struct battery_config {
|
|
|
|
|
static struct battery_config battery_config; |
|
|
|
|
|
|
|
|
|
static int lithium_ion_mv_to_pct(int16_t bat_mv) { |
|
|
|
|
// Magic function that maps mV to this discharge graph from adafruit: https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages
|
|
|
|
|
return round(106.818 + (-0.032685 - 106.818) / pow(1 + pow(bat_mv/3679.35, 58.979), 0.347386)); |
|
|
|
|
// Magic function that maps mV to this discharge graph from adafruit:
|
|
|
|
|
// https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages
|
|
|
|
|
return round(106.818 + |
|
|
|
|
(-0.032685 - 106.818) / pow(1 + pow(bat_mv / 3679.35, 58.979), 0.347386)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void battery_read(struct k_work *workd) { |
|
|
|
@ -56,10 +58,7 @@ static void battery_read(struct k_work *workd) {
@@ -56,10 +58,7 @@ static void battery_read(struct k_work *workd) {
|
|
|
|
|
|
|
|
|
|
K_WORK_DEFINE(battery_work, battery_read); |
|
|
|
|
|
|
|
|
|
static void battery_handler(struct k_timer *timer) |
|
|
|
|
{ |
|
|
|
|
k_work_submit(&battery_work); |
|
|
|
|
} |
|
|
|
|
static void battery_handler(struct k_timer *timer) { k_work_submit(&battery_work); } |
|
|
|
|
|
|
|
|
|
K_TIMER_DEFINE(battery_tick, battery_handler, NULL); |
|
|
|
|
|
|
|
|
@ -108,8 +107,6 @@ static int battery_setup(struct device *_arg) {
@@ -108,8 +107,6 @@ static int battery_setup(struct device *_arg) {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SYS_INIT(battery_setup, |
|
|
|
|
APPLICATION, |
|
|
|
|
CONFIG_APPLICATION_INIT_PRIORITY); |
|
|
|
|
SYS_INIT(battery_setup, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); |
|
|
|
|
|
|
|
|
|
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ |