mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 02:35:28 +00:00
Cache LP5562 LED color
When we try to set LP5562 LED to the same color as it is currently, we should just skip the I2C commands. Let's cache its current color so that we don't waste time on unnecessary I2C transactions. BUG=chrome-os-partner:19705 TEST=Set LED color manually on spring and doesn't see it change. Unplug and plug in the charger, and see LED goes back to yellow after few seconds. BRANCH=spring Change-Id: I87e3cf7d53bccc45048ea64dad9925a362cddab7 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/56716 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
@@ -67,20 +67,33 @@ static int stop_led_engine(void)
|
||||
|
||||
static int set_led_color(enum led_state_t state)
|
||||
{
|
||||
static enum led_state_t last_state = LED_STATE_OFF;
|
||||
int rv;
|
||||
|
||||
ASSERT(state != LED_STATE_TRANSITION_ON &&
|
||||
state != LED_STATE_TRANSITION_OFF);
|
||||
|
||||
if (state == last_state)
|
||||
return EC_SUCCESS;
|
||||
|
||||
switch (state) {
|
||||
case LED_STATE_SOLID_RED:
|
||||
return lp5562_set_color(LED_COLOR_RED);
|
||||
rv = lp5562_set_color(LED_COLOR_RED);
|
||||
break;
|
||||
case LED_STATE_SOLID_GREEN:
|
||||
return lp5562_set_color(LED_COLOR_GREEN);
|
||||
rv = lp5562_set_color(LED_COLOR_GREEN);
|
||||
break;
|
||||
case LED_STATE_SOLID_YELLOW:
|
||||
case LED_STATE_BREATHING:
|
||||
return lp5562_set_color(LED_COLOR_YELLOW);
|
||||
rv = lp5562_set_color(LED_COLOR_YELLOW);
|
||||
break;
|
||||
default:
|
||||
return EC_ERROR_UNKNOWN;
|
||||
rv = EC_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (rv == EC_SUCCESS)
|
||||
last_state = state;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void stablize_led(enum led_state_t desired_state)
|
||||
|
||||
Reference in New Issue
Block a user