diff --git a/common/led_lp5562.c b/common/led_lp5562.c index fe33b7e7fb..420f391ce5 100644 --- a/common/led_lp5562.c +++ b/common/led_lp5562.c @@ -13,10 +13,14 @@ #include "lp5562.h" #include "pmu_tpschrome.h" #include "smart_battery.h" +#include "timer.h" #include "util.h" #define GREEN_LED_THRESHOLD 94 +/* Minimal interval between changing LED color to green and yellow. */ +#define LED_WAIT_INTERVAL (15 * SECOND) + /* We use yellow LED instead of blue LED. Re-map colors here. */ #define LED_COLOR_NONE LP5562_COLOR_NONE #define LED_COLOR_GREEN LP5562_COLOR_GREEN @@ -121,6 +125,12 @@ static void battery_led_update(void) static int led_power = -1; int new_led_power; + /* + * The time before which we should not change LED + * color between green and yellow. + */ + static timestamp_t led_update_deadline = {.val = 0}; + /* Determine LED power */ new_led_power = extpower_is_present(); if (new_led_power != led_power) { @@ -129,6 +139,7 @@ static void battery_led_update(void) } else { rv = lp5562_poweroff(); set_led_color(LED_STATE_OFF); + led_update_deadline.val = 0; } if (!rv) led_power = new_led_power; @@ -178,6 +189,16 @@ static void battery_led_update(void) break; } + if (state == LED_STATE_SOLID_GREEN || + state == LED_STATE_SOLID_YELLOW) { + if (!timestamp_expired(led_update_deadline, NULL)) + return; + led_update_deadline.val = + get_time().val + LED_WAIT_INTERVAL; + } else { + led_update_deadline.val = 0; + } + set_led_color(state); } DECLARE_HOOK(HOOK_SECOND, battery_led_update, HOOK_PRIO_DEFAULT);