diff options
author | Vic Yang <victoryang@chromium.org> | 2013-05-27 15:22:59 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-05-28 12:53:50 -0700 |
commit | 99e3fc93e697d646925972790060805e72e39da5 (patch) | |
tree | 1cc32ed16466f48a9197e28d7b4b233473b5efbc /common | |
parent | 455fc92b195d1c0f58c84808bcc7a30ca0cc31e7 (diff) | |
download | chrome-ec-99e3fc93e697d646925972790060805e72e39da5.tar.gz |
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>
Diffstat (limited to 'common')
-rw-r--r-- | common/lp5562_battery_led.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/common/lp5562_battery_led.c b/common/lp5562_battery_led.c index 56f41709df..f041499f7a 100644 --- a/common/lp5562_battery_led.c +++ b/common/lp5562_battery_led.c @@ -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) |