diff options
-rw-r--r-- | common/led_kirby.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/common/led_kirby.c b/common/led_kirby.c index 44a1b7b891..53f11d10db 100644 --- a/common/led_kirby.c +++ b/common/led_kirby.c @@ -11,6 +11,7 @@ #include "extpower.h" #include "gpio.h" #include "hooks.h" +#include "host_command.h" #include "pwm.h" #include "util.h" @@ -19,6 +20,8 @@ #define BRIGHTNESS_GREEN 25 #define BRIGHTNESS_YELLOW 50 +static int led_auto_control = 1; + void led_set_color(uint8_t red, uint8_t green, uint8_t yellow) { if (!yellow) @@ -50,6 +53,9 @@ static void led_update_color(void) { enum power_state state = charge_get_state(); + if (!led_auto_control) + return; + /* check ac. no ac -> off */ if (!extpower_is_present()) { led_set_color(0, 0, 0); @@ -80,6 +86,45 @@ DECLARE_HOOK(HOOK_AC_CHANGE, led_update_color, HOOK_PRIO_DEFAULT); DECLARE_HOOK(HOOK_CHARGE_STATE_CHANGE, led_update_color, HOOK_PRIO_DEFAULT); /*****************************************************************************/ +/* Host commands */ + +static int led_command_control(struct host_cmd_handler_args *args) +{ + const struct ec_params_led_control *p = args->params; + struct ec_response_led_control *r = args->response; + int i; + uint8_t clipped[EC_LED_COLOR_COUNT]; + + /* Only support battery LED control */ + if (p->led_id != EC_LED_ID_BATTERY_LED) + return EC_RES_INVALID_PARAM; + + if (p->flags & EC_LED_FLAGS_AUTO) { + led_auto_control = 1; + led_update_color(); + } else if (!(p->flags & EC_LED_FLAGS_QUERY)) { + for (i = 0; i < EC_LED_COLOR_COUNT; ++i) + clipped[i] = MIN(p->brightness[i], 100); + led_auto_control = 0; + led_set_color(clipped[EC_LED_COLOR_RED], + clipped[EC_LED_COLOR_GREEN], + clipped[EC_LED_COLOR_YELLOW]); + } + + r->brightness_range[EC_LED_COLOR_RED] = 100; + r->brightness_range[EC_LED_COLOR_GREEN] = 100; + r->brightness_range[EC_LED_COLOR_BLUE] = 0; + r->brightness_range[EC_LED_COLOR_YELLOW] = 100; + r->brightness_range[EC_LED_COLOR_WHITE] = 0; + args->response_size = sizeof(struct ec_response_led_control); + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_LED_CONTROL, + led_command_control, + EC_VER_MASK(1)); + +/*****************************************************************************/ /* Console commands */ static int command_led(int argc, char **argv) |