FuriHal, Power, UnitTests: battery charging voltage limit API (#2063)

This commit is contained in:
Shane Synan
2022-12-08 01:57:49 -05:00
committed by GitHub
parent 6a470a464e
commit 5c3a5cd8f7
13 changed files with 173 additions and 4 deletions

View File

@@ -1194,6 +1194,7 @@ Function,+,furi_hal_power_enable_external_3_3v,void,
Function,+,furi_hal_power_enable_otg,void,
Function,+,furi_hal_power_gauge_is_ok,_Bool,
Function,+,furi_hal_power_get_bat_health_pct,uint8_t,
Function,+,furi_hal_power_get_battery_charging_voltage,float,
Function,+,furi_hal_power_get_battery_current,float,FuriHalPowerIC
Function,+,furi_hal_power_get_battery_design_capacity,uint32_t,
Function,+,furi_hal_power_get_battery_full_capacity,uint32_t,
@@ -1212,6 +1213,7 @@ Function,+,furi_hal_power_is_charging_done,_Bool,
Function,+,furi_hal_power_is_otg_enabled,_Bool,
Function,+,furi_hal_power_off,void,
Function,+,furi_hal_power_reset,void,
Function,+,furi_hal_power_set_battery_charging_voltage,void,float
Function,+,furi_hal_power_shutdown,void,
Function,+,furi_hal_power_sleep,void,
Function,+,furi_hal_power_sleep_available,_Bool,
1 entry status name type params
1194 Function + furi_hal_power_enable_otg void
1195 Function + furi_hal_power_gauge_is_ok _Bool
1196 Function + furi_hal_power_get_bat_health_pct uint8_t
1197 Function + furi_hal_power_get_battery_charging_voltage float
1198 Function + furi_hal_power_get_battery_current float FuriHalPowerIC
1199 Function + furi_hal_power_get_battery_design_capacity uint32_t
1200 Function + furi_hal_power_get_battery_full_capacity uint32_t
1213 Function + furi_hal_power_is_otg_enabled _Bool
1214 Function + furi_hal_power_off void
1215 Function + furi_hal_power_reset void
1216 Function + furi_hal_power_set_battery_charging_voltage void float
1217 Function + furi_hal_power_shutdown void
1218 Function + furi_hal_power_sleep void
1219 Function + furi_hal_power_sleep_available _Bool

View File

@@ -341,6 +341,20 @@ bool furi_hal_power_is_otg_enabled() {
return ret;
}
float furi_hal_power_get_battery_charging_voltage() {
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
float ret = (float)bq25896_get_vreg_voltage(&furi_hal_i2c_handle_power) / 1000.0f;
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
return ret;
}
void furi_hal_power_set_battery_charging_voltage(float voltage) {
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
// Adding 0.0005 is necessary because 4.016f is 4.015999794000, which gets truncated
bq25896_set_vreg_voltage(&furi_hal_i2c_handle_power, (uint16_t)(voltage * 1000.0f + 0.0005f));
furi_hal_i2c_release(&furi_hal_i2c_handle_power);
}
void furi_hal_power_check_otg_status() {
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
if(bq25896_check_otg_fault(&furi_hal_i2c_handle_power))
@@ -470,10 +484,10 @@ void furi_hal_power_info_get(PropertyValueCallback out, char sep, void* context)
if(sep == '.') {
property_value_out(&property_context, NULL, 2, "format", "major", "2");
property_value_out(&property_context, NULL, 2, "format", "minor", "0");
property_value_out(&property_context, NULL, 2, "format", "minor", "1");
} else {
property_value_out(&property_context, NULL, 3, "power", "info", "major", "1");
property_value_out(&property_context, NULL, 3, "power", "info", "minor", "0");
property_value_out(&property_context, NULL, 3, "power", "info", "minor", "1");
}
uint8_t charge = furi_hal_power_get_pct();
@@ -481,7 +495,7 @@ void furi_hal_power_info_get(PropertyValueCallback out, char sep, void* context)
const char* charge_state;
if(furi_hal_power_is_charging()) {
if(charge < 100) {
if((charge < 100) && (!furi_hal_power_is_charging_done())) {
charge_state = "charging";
} else {
charge_state = "charged";
@@ -491,6 +505,8 @@ void furi_hal_power_info_get(PropertyValueCallback out, char sep, void* context)
}
property_value_out(&property_context, NULL, 2, "charge", "state", charge_state);
uint16_t charge_voltage = (uint16_t)(furi_hal_power_get_battery_charging_voltage() * 1000.f);
property_value_out(&property_context, "%u", 2, "charge", "voltage", charge_voltage);
uint16_t voltage =
(uint16_t)(furi_hal_power_get_battery_voltage(FuriHalPowerICFuelGauge) * 1000.f);
property_value_out(&property_context, "%u", 2, "battery", "voltage", voltage);
@@ -567,6 +583,13 @@ void furi_hal_power_debug_get(PropertyValueCallback out, void* context) {
"charger",
"vbat",
bq25896_get_vbat_voltage(&furi_hal_i2c_handle_power));
property_value_out(
&property_context,
"%d",
2,
"charger",
"vreg",
bq25896_get_vreg_voltage(&furi_hal_i2c_handle_power));
property_value_out(
&property_context,
"%d",