diff options
author | Dave Parker <dparker@chromium.org> | 2013-08-02 18:20:57 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-08-07 12:43:48 -0700 |
commit | 63a71a6adce21a0354cf8d2245170da824f7d8c2 (patch) | |
tree | 55cd196292622db198c5b2861e4359cb6228973c /common/led_common.c | |
parent | f2b56fcb9fe078d5a29f1c3744e47e77240cd4e7 (diff) | |
download | chrome-ec-63a71a6adce21a0354cf8d2245170da824f7d8c2.tar.gz |
Peppy ectool led command
Glue between the existing ectool led command and the
led control logic.
BUG=chrome-os-partner:20776
BRANCH=peppy
TEST=Manual. Run "ectool led" commands:
Should pass:
ectool led power blue|yellow|off|auto|blue=1 yellow=1
ectool led battery blue|yellow|off|auto|blue=1 yellow=1
Should fail:
ectool led adapter <color>
ectool led power|battery red|green|white
Signed-off-by: Dave Parker <dparker@chromium.org>
Change-Id: I2540940baa553866760dd9ae62278b6b845793ef
Reviewed-on: https://gerrit.chromium.org/gerrit/64627
Diffstat (limited to 'common/led_common.c')
-rw-r--r-- | common/led_common.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/common/led_common.c b/common/led_common.c new file mode 100644 index 0000000000..88abd841f6 --- /dev/null +++ b/common/led_common.c @@ -0,0 +1,70 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Common functions for blinking LEDs. + */ + +#include "console.h" +#include "ec_commands.h" +#include "hooks.h" +#include "host_command.h" +#include "led_common.h" +#include "util.h" + +#define LED_AUTO_CONTROL_FLAG(id) (1 << (id)) + +static uint32_t led_auto_control_flags = ~0x00; + +static int led_is_supported(enum ec_led_id led_id) +{ + int i; + + for (i = 0; i < supported_led_ids_count; i++) + if (led_id == supported_led_ids[i]) + return 1; + + return 0; +} + +void led_auto_control(enum ec_led_id led_id, int enable) +{ + if (enable) + led_auto_control_flags |= LED_AUTO_CONTROL_FLAG(led_id); + else + led_auto_control_flags &= ~LED_AUTO_CONTROL_FLAG(led_id); +} + +int led_auto_control_is_enabled(enum ec_led_id led_id) +{ + return (led_auto_control_flags & LED_AUTO_CONTROL_FLAG(led_id)) != 0; +} + +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; + + args->response_size = sizeof(*r); + memset(r->brightness_range, 0, sizeof(r->brightness_range)); + + if (!led_is_supported(p->led_id)) + return EC_RES_INVALID_PARAM; + + led_get_brightness_range(p->led_id, r->brightness_range); + if (p->flags & EC_LED_FLAGS_QUERY) + return EC_RES_SUCCESS; + + for (i = 0; i < EC_LED_COLOR_COUNT; i++) + if (r->brightness_range[i] == 0 && p->brightness[i] != 0) + return EC_RES_INVALID_PARAM; + + if (p->flags & EC_LED_FLAGS_AUTO) + led_auto_control(p->led_id, 1); + else if (led_set_brightness(p->led_id, p->brightness) != EC_SUCCESS) + return EC_RES_INVALID_PARAM; + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_LED_CONTROL, led_command_control, EC_VER_MASK(1)); |