mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 17:41:54 +00:00
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
This commit is contained in:
committed by
chrome-internal-fetch
parent
c2e8372b41
commit
c0c90c6f18
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user