summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-05-27 15:22:59 +0800
committerChromeBot <chrome-bot@google.com>2013-06-02 14:12:13 -0700
commit7efb1289d6c99db37b120cc2bc7ae19efd4be879 (patch)
tree68030b7ddcdd67431f46e3b482de3dead3cacb44
parent9e98cfbb82c79e889bdc5ce9cdc6301ef008c26b (diff)
downloadchrome-ec-7efb1289d6c99db37b120cc2bc7ae19efd4be879.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 Original-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> (cherry picked from commit 99e3fc93e697d646925972790060805e72e39da5) Change-Id: I1cb266681c19cdadcb72fe1974bf4c7858534c2f Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/56905 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/board.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/board/spring/board.c b/board/spring/board.c
index f9c8fd8312..95792f9780 100644
--- a/board/spring/board.c
+++ b/board/spring/board.c
@@ -350,20 +350,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 board_stablize_led(enum led_state_t desired_state)