From c0c90c6f18bf806d3b435cbe6a91cddca42ec6a5 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Thu, 5 Sep 2013 11:14:47 +0800 Subject: [PATCH] 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 Reviewed-on: https://chromium-review.googlesource.com/168182 --- common/led_kirby.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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 */