diff options
author | Bill Richardson <wfrichar@chromium.org> | 2012-09-21 13:27:47 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-09-21 16:48:53 -0700 |
commit | e802e4fa37e1506ef19a5e38f86decbaa0ca0121 (patch) | |
tree | ce5ec50d4704c651928bcbf2879d9078d8403b9a /util/lbplay.c | |
parent | eee90a3f351c45a575623f4b9f89fa7be491937a (diff) | |
download | chrome-ec-e802e4fa37e1506ef19a5e38f86decbaa0ca0121.tar.gz |
Refactor lightbar host command to pass messages the new way.
We recently changed the way host messages are passed to the EC to make it
work nicer across I2C. When we did, we updated all the internal structs
except those used for lightbar commands. This CL updates the lightbar
commands too.
BUG=chrome-os-partner:11277
BRANCH=all
TEST=manual
This shouldn't change anything, but you can ensure that by poking at the
lightbar manually. On Link, run this from a root shell:
ectool lightbar seq stop
ectool lightbar 4 ff 00 ff
ectool lightbar seq run
With the first command, the lightbar pattern should freeze.
With the second command, it should turn magenta.
With the third command, it should resume pulsing as before.
Change-Id: Ic5dc4c827b3b4459288d7d9bd7d06af8a5176b3c
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33798
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util/lbplay.c')
-rw-r--r-- | util/lbplay.c | 111 |
1 files changed, 56 insertions, 55 deletions
diff --git a/util/lbplay.c b/util/lbplay.c index 9acabaddfb..8658368160 100644 --- a/util/lbplay.c +++ b/util/lbplay.c @@ -18,40 +18,36 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define LB_SIZES(SUBCMD) { \ + sizeof(((struct ec_params_lightbar *)0)->SUBCMD) \ + + sizeof(((struct ec_params_lightbar *)0)->cmd), \ + sizeof(((struct ec_response_lightbar *)0)->SUBCMD) } static const struct { uint8_t insize; uint8_t outsize; } lb_command_paramcount[] = { - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.dump), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.dump) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.off), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.off) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.on), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.on) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.init), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.init) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.brightness), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.brightness) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.seq), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.seq) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.reg), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.reg) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.rgb), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.rgb) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.get_seq), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.get_seq) }, - { sizeof(((struct ec_params_lightbar_cmd *)0)->in.demo), - sizeof(((struct ec_params_lightbar_cmd *)0)->out.demo) }, + LB_SIZES(dump), + LB_SIZES(off), + LB_SIZES(on), + LB_SIZES(init), + LB_SIZES(brightness), + LB_SIZES(seq), + LB_SIZES(reg), + LB_SIZES(rgb), + LB_SIZES(get_seq), + LB_SIZES(demo) }; +#undef LB_SIZES static void lb_cmd_noargs(enum lightbar_command cmd) { - struct ec_params_lightbar_cmd param; - param.in.cmd = cmd; + struct ec_params_lightbar param; + struct ec_response_lightbar resp; + param.cmd = cmd; ec_command(EC_CMD_LIGHTBAR_CMD, 0, - ¶m, lb_command_paramcount[param.in.cmd].insize, - ¶m, lb_command_paramcount[param.in.cmd].outsize); + ¶m, lb_command_paramcount[param.cmd].insize, + &resp, lb_command_paramcount[param.cmd].outsize); } inline void lightbar_off(void) @@ -71,68 +67,73 @@ inline void lightbar_init_vals(void) void lightbar_brightness(int newval) { - struct ec_params_lightbar_cmd param; - param.in.cmd = LIGHTBAR_CMD_BRIGHTNESS; - param.in.brightness.num = newval; + struct ec_params_lightbar param; + struct ec_response_lightbar resp; + param.cmd = LIGHTBAR_CMD_BRIGHTNESS; + param.brightness.num = newval; ec_command(EC_CMD_LIGHTBAR_CMD, 0, - ¶m, lb_command_paramcount[param.in.cmd].insize, - ¶m, lb_command_paramcount[param.in.cmd].outsize); + ¶m, lb_command_paramcount[param.cmd].insize, + &resp, lb_command_paramcount[param.cmd].outsize); } void lightbar_sequence(enum lightbar_sequence num) { - struct ec_params_lightbar_cmd param; - param.in.cmd = LIGHTBAR_CMD_SEQ; - param.in.seq.num = num; + struct ec_params_lightbar param; + struct ec_response_lightbar resp; + param.cmd = LIGHTBAR_CMD_SEQ; + param.seq.num = num; ec_command(EC_CMD_LIGHTBAR_CMD, 0, - ¶m, lb_command_paramcount[param.in.cmd].insize, - ¶m, lb_command_paramcount[param.in.cmd].outsize); + ¶m, lb_command_paramcount[param.cmd].insize, + &resp, lb_command_paramcount[param.cmd].outsize); } void lightbar_reg(uint8_t ctrl, uint8_t reg, uint8_t val) { - struct ec_params_lightbar_cmd param; - param.in.cmd = LIGHTBAR_CMD_REG; - param.in.reg.ctrl = ctrl; - param.in.reg.reg = reg; - param.in.reg.value = val; + struct ec_params_lightbar param; + struct ec_response_lightbar resp; + param.cmd = LIGHTBAR_CMD_REG; + param.reg.ctrl = ctrl; + param.reg.reg = reg; + param.reg.value = val; ec_command(EC_CMD_LIGHTBAR_CMD, 0, - ¶m, lb_command_paramcount[param.in.cmd].insize, - ¶m, lb_command_paramcount[param.in.cmd].outsize); + ¶m, lb_command_paramcount[param.cmd].insize, + &resp, lb_command_paramcount[param.cmd].outsize); } void lightbar_rgb(int led, int red, int green, int blue) { - struct ec_params_lightbar_cmd param; - param.in.cmd = LIGHTBAR_CMD_RGB; - param.in.rgb.led = led; - param.in.rgb.red = red; - param.in.rgb.green = green; - param.in.rgb.blue = blue; + struct ec_params_lightbar param; + struct ec_response_lightbar resp; + param.cmd = LIGHTBAR_CMD_RGB; + param.rgb.led = led; + param.rgb.red = red; + param.rgb.green = green; + param.rgb.blue = blue; ec_command(EC_CMD_LIGHTBAR_CMD, 0, - ¶m, lb_command_paramcount[param.in.cmd].insize, - ¶m, lb_command_paramcount[param.in.cmd].outsize); + ¶m, lb_command_paramcount[param.cmd].insize, + &resp, lb_command_paramcount[param.cmd].outsize); } void wait_for_ec_to_stop(void) { int r; - struct ec_params_lightbar_cmd param; + struct ec_params_lightbar param; + struct ec_response_lightbar resp; int count = 0; do { usleep(100000); - param.in.cmd = LIGHTBAR_CMD_GET_SEQ; + param.cmd = LIGHTBAR_CMD_GET_SEQ; r = ec_command(EC_CMD_LIGHTBAR_CMD, 0, ¶m, - lb_command_paramcount[param.in.cmd].insize, - ¶m, - lb_command_paramcount[param.in.cmd].outsize); + lb_command_paramcount[param.cmd].insize, + &resp, + lb_command_paramcount[param.cmd].outsize); if (count++ > 10) { fprintf(stderr, "EC isn't responding\n"); exit(1); } - } while (r < 0 && param.out.get_seq.num != LIGHTBAR_STOP); + } while (r < 0 && resp.get_seq.num != LIGHTBAR_STOP); } int main(int argc, char **argv) |