diff options
author | Vic Yang <victoryang@chromium.org> | 2013-05-29 10:26:18 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-06-03 14:32:16 -0700 |
commit | e52aba6ecac45d2c27acc78316e835620840408a (patch) | |
tree | 7648425ebe293671a43ced7d824b72e6779b7e3f /common | |
parent | d6d3b7cbc5621519d54d231aba13aa4ab50651aa (diff) | |
download | chrome-ec-e52aba6ecac45d2c27acc78316e835620840408a.tar.gz |
Make ectool LED command more generic
This adds the option to specify which LED to control as well as the
ability to query the supported LED color on the board.
BUG=chrome-os-partner:19745
TEST=On Spring:
- ectool led 0 query -> See the max value for R, G, Y is 0x80.
- ectool led 1 query -> See error message.
- ectool led 0 yellow -> See LED turns yellow.
- ectool led 0 green=0x40 red=0x40 -> See green and red lit up.
- ectool led 0 auto -> See LED turns off (without charger.)
BRANCH=spring
Change-Id: Ibdde2f7450122f59383dad1030a0a2a985386f73
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/56877
Diffstat (limited to 'common')
-rw-r--r-- | common/lp5562_battery_led.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/common/lp5562_battery_led.c b/common/lp5562_battery_led.c index 02bf85b5da..3aebeb0b76 100644 --- a/common/lp5562_battery_led.c +++ b/common/lp5562_battery_led.c @@ -63,28 +63,46 @@ static int set_led_color(enum led_state_t state) /*****************************************************************************/ /* Host commands */ -static int led_command_set(struct host_cmd_handler_args *args) +static int led_command_control(struct host_cmd_handler_args *args) { - const struct ec_params_led_set *p = args->params; + 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) { if (!extpower_is_present()) lp5562_poweroff(); last_state = LED_STATE_OFF; led_auto_control = 1; - } else { + } else if (!(p->flags & EC_LED_FLAGS_QUERY)) { + for (i = 0; i < EC_LED_COLOR_COUNT; ++i) + clipped[i] = MIN(p->brightness[i], 0x80); led_auto_control = 0; if (!extpower_is_present()) lp5562_poweron(); - if (lp5562_set_color((p->r << 16) + (p->g << 8) + p->b)) + if (lp5562_set_color((clipped[EC_LED_COLOR_RED] << 16) + + (clipped[EC_LED_COLOR_GREEN] << 8) + + clipped[EC_LED_COLOR_YELLOW])) return EC_RES_ERROR; } + r->brightness_range[EC_LED_COLOR_RED] = 0x80; + r->brightness_range[EC_LED_COLOR_GREEN] = 0x80; + r->brightness_range[EC_LED_COLOR_BLUE] = 0x0; + r->brightness_range[EC_LED_COLOR_YELLOW] = 0x80; + r->brightness_range[EC_LED_COLOR_WHITE] = 0x0; + args->response_size = sizeof(struct ec_response_led_control); + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_LED_SET, - led_command_set, - EC_VER_MASK(0)); +DECLARE_HOST_COMMAND(EC_CMD_LED_CONTROL, + led_command_control, + EC_VER_MASK(1)); /*****************************************************************************/ /* Hooks */ |