diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2022-03-28 12:52:36 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-03-29 21:21:54 +0000 |
commit | 9b2ef47ab9ee59606ca4e7d0a3a5594bdd756fff (patch) | |
tree | c3417f4a7bdf0d9a4cd36bfb3a0050b6633ce86d /util/ectool.c | |
parent | 34fb416205ff1fca268023f61c9952442e3daf37 (diff) | |
download | chrome-ec-9b2ef47ab9ee59606ca4e7d0a3a5594bdd756fff.tar.gz |
RGBKBD: Add EC_CMD_RGBKBD_SET_COLOR command
Host programs call EC_CMD_RGBKBD_SET_COLOR to change the LED colors
of an RGB keyboard.
Example command execution on Vell against Prism:
localhost ~ # ectool --device 18d1:5022 rgbkbd 10 0x010203
EC prints:
HC resp:080000000002000101000000
HC 0x13a.0:0a01010203
RGBKBD: Set [10,0] to color=[1,2,3] (gid=0 offset=60)
BUG=b:223465912
BRANCH=None
TEST=Prism/Vell. See above. make run-rgb_keyboard.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: Ic6235ca575ed488fe166b0873f8a5596c63dc2b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3546569
Reviewed-by: caveh jalali <caveh@chromium.org>
Diffstat (limited to 'util/ectool.c')
-rw-r--r-- | util/ectool.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c index c3e85823fb..1f7826a447 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -279,6 +279,8 @@ const char help_str[] = " Requests that the EC will automatically reboot the AP after a\n" " configurable number of seconds the next time we enter the G3\n" " power state.\n" + " rgbkbd ...\n" + " Set/get RGB keyboard status, config, etc..\n" " rollbackinfo\n" " Print rollback block information\n" " rtcget\n" @@ -1286,6 +1288,89 @@ int cmd_reboot_ap_on_g3(int argc, char *argv[]) return (rv < 0 ? rv : 0); } +static void cmd_rgbkbd_help(char *cmd) +{ + fprintf(stderr, + " Usage1: %s <key> <RGB>\n" + " Set the color of <key> to <RGB>.\n" + "\n", + cmd); +} + +static int cmd_rgbkbd_parse_rgb_text(const char *text, struct rgb_s *color) +{ + uint32_t rgb; + char *e; + + rgb = strtoul(text, &e, 0); + if ((e && *e) || rgb > EC_RGBKBD_MAX_RGB_COLOR) { + fprintf(stderr, "Invalid color '%s'.\n", text); + return -1; + } + color->r = (rgb >> 16) & 0xff; + color->g = (rgb >> 8) & 0xff; + color->b = (rgb >> 0) & 0xff; + + return 0; +} + +static int cmd_rgbkbd_set_color(int argc, char *argv[]) +{ + struct ec_params_rgbkbd_set_color *p; + int i, key, outlen; + char *e; + int rv = -1; + + outlen = sizeof(*p) + sizeof(struct rgb_s) * EC_RGBKBD_MAX_KEY_COUNT; + p = malloc(outlen); + if (p == NULL) + return -1; + memset(p, 0, outlen); + + key = strtol(argv[1], &e, 0); + if ((e && *e) || key >= EC_RGBKBD_MAX_KEY_COUNT) { + fprintf(stderr, "Invalid key ID '%s'.\n", argv[1]); + goto out; + } + p->start_key = key; + + if (argc - 2 > EC_RGBKBD_MAX_KEY_COUNT) { + fprintf(stderr, "# of colors exceed max key count.\n"); + goto out; + } + + for (i = 2; i < argc; i++) { + if (cmd_rgbkbd_parse_rgb_text(argv[i], &p->color[p->length])) + goto out; + p->length++; + } + + outlen = sizeof(*p) + sizeof(struct rgb_s) * p->length; + rv = ec_command(EC_CMD_RGBKBD_SET_COLOR, 0, p, outlen, NULL, 0); + +out: + free(p); + + return rv; +} + +static int cmd_rgbkbd(int argc, char *argv[]) +{ + int rv = -1;; + + if (argc < 3) { + cmd_rgbkbd_help(argv[0]); + return -1; + } + + if (2 < argc) { + /* Usage 1 */ + rv = cmd_rgbkbd_set_color(argc, argv); + } + + return (rv < 0 ? rv : 0); +} + int cmd_button(int argc, char *argv[]) { struct ec_params_button p; @@ -10653,6 +10738,7 @@ const struct command commands[] = { {"rand", cmd_rand}, {"readtest", cmd_read_test}, {"reboot_ec", cmd_reboot_ec}, + {"rgbkbd", cmd_rgbkbd}, {"rollbackinfo", cmd_rollback_info}, {"rtcget", cmd_rtc_get}, {"rtcgetalarm", cmd_rtc_get_alarm}, |