diff options
author | Vic Yang <victoryang@chromium.org> | 2013-09-05 11:14:47 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-09-10 18:24:11 +0000 |
commit | c0c90c6f18bf806d3b435cbe6a91cddca42ec6a5 (patch) | |
tree | 2bdb311433a21c00bce87660d913e7bafbaa4c26 | |
parent | c2e8372b418610f2095ea79be214f3352fed2b44 (diff) | |
download | chrome-ec-c0c90c6f18bf806d3b435cbe6a91cddca42ec6a5.tar.gz |
kirby: Set LED color according to charging status
This sets LED to yellow for charging and battery-assist mode, green for
full and near-full, and red for error.
BUG=chrome-os-partner:22056
TEST=Unplug battery and see LED go red after 30 seconds
TEST=Charge battery and see yellow LED
TEST=See green LED when battery is charged
TEST=Unplug AC and see LED turned off
BRANCH=None
Change-Id: I7a512f3b0e6cbdf760c0cbd49cd63c26dc9f8539
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/168182
-rw-r--r-- | common/led_kirby.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/common/led_kirby.c b/common/led_kirby.c index 1395bc4820..44a1b7b891 100644 --- a/common/led_kirby.c +++ b/common/led_kirby.c @@ -5,12 +5,20 @@ * Kirby LED driver. */ +#include "charge_state.h" #include "common.h" #include "console.h" +#include "extpower.h" #include "gpio.h" +#include "hooks.h" #include "pwm.h" #include "util.h" +/* Brightness of each color. Range = 0 - 100. */ +#define BRIGHTNESS_RED 50 +#define BRIGHTNESS_GREEN 25 +#define BRIGHTNESS_YELLOW 50 + void led_set_color(uint8_t red, uint8_t green, uint8_t yellow) { if (!yellow) @@ -38,6 +46,39 @@ void led_set_color(uint8_t red, uint8_t green, uint8_t yellow) } } +static void led_update_color(void) +{ + enum power_state state = charge_get_state(); + + /* check ac. no ac -> off */ + if (!extpower_is_present()) { + led_set_color(0, 0, 0); + return; + } + + switch (state) { + case PWR_STATE_CHARGE: + led_set_color(0, 0, BRIGHTNESS_YELLOW); + break; + case PWR_STATE_IDLE: + case PWR_STATE_CHARGE_NEAR_FULL: + led_set_color(0, BRIGHTNESS_GREEN, 0); + break; + case PWR_STATE_ERROR: + led_set_color(BRIGHTNESS_RED, 0, 0); + break; + case PWR_STATE_INIT: + case PWR_STATE_UNCHANGE: + case PWR_STATE_IDLE0: + case PWR_STATE_REINIT: + case PWR_STATE_DISCHARGE: + break; + } +} +DECLARE_HOOK(HOOK_INIT, led_update_color, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_AC_CHANGE, led_update_color, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_CHARGE_STATE_CHANGE, led_update_color, HOOK_PRIO_DEFAULT); + /*****************************************************************************/ /* Console commands */ |