diff --git a/common/charge_state.c b/common/charge_state.c index caa9caa6b6..e907d5e90a 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -331,14 +331,14 @@ static enum power_state state_idle(struct power_state_context *ctx) ctx->curr.charging_current) return PWR_STATE_INIT; - if (ctx->curr.batt.state_of_charge >= STOP_CHARGE_THRESHOLD) + if (batt->state_of_charge >= STOP_CHARGE_THRESHOLD) return PWR_STATE_UNCHANGE; /* Configure init charger state and switch to charge state */ - if (ctx->curr.batt.desired_voltage && - ctx->curr.batt.desired_current) { + if (batt->desired_voltage && batt->desired_current) { /* Set charger output constraints */ - if (batt->desired_current < ctx->charger->current_min) { + if (batt->desired_current < ctx->charger->current_min && + batt->state_of_charge < PRE_CHARGE_THRESHOLD) { /* Trickle charging */ if (charger_set_current(c_info->current_min) || charger_set_voltage(batt->voltage)) @@ -373,7 +373,8 @@ static enum power_state state_charge(struct power_state_context *ctx) return PWR_STATE_ERROR; if (batt->desired_current < c_info->current_min && - batt->desired_current > 0) + batt->desired_current > 0 && + batt->state_of_charge < PRE_CHARGE_THRESHOLD) return trickle_charge(ctx); /* Check charger reset */ diff --git a/include/battery.h b/include/battery.h index b5b3909abe..9f3cb4cad7 100644 --- a/include/battery.h +++ b/include/battery.h @@ -18,6 +18,8 @@ #define STOP_CHARGE_THRESHOLD 100 /* Threshold for power led to turn green */ #define POWERLED_GREEN_THRESHOLD 90 +/* Precharge only when state of charge is below this level */ +#define PRE_CHARGE_THRESHOLD 25 /* Define the lightbar color thresholds */ #define LIGHTBAR_POWER_THRESHOLD_FULL 99