summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-10-10 17:43:02 -0700
committerGerrit <chrome-bot@google.com>2012-10-11 14:24:43 -0700
commitd6f05e0d616e4004b0bb0404b6c8dbe9f9198db4 (patch)
treed1f0077dd2c7989ccad4b892660dc9ead7c79fb3 /util
parentb00a446ec57323f84002722523783351f19e41b1 (diff)
downloadchrome-ec-d6f05e0d616e4004b0bb0404b6c8dbe9f9198db4.tar.gz
Parameterize the lightbar behavior as much as possible.
This change replaces most of the hard-coded lightbar constants with values that can be updated at run-time, so that if we change our minds about colors and timing we can tweak some of the values without requiring an EC/BIOS update. It also adds the "ectool lightbar params" command to get and set those values from the host. You can see the values from the EC console ("lightbar params"), but there's no way to set them. BUG=chrome-os-partner:8039 BRANCH=Link TEST=manual From the EC console, run lightbar params It should display the current values that can be changed. Log in to the host and run this to see the same values: ectool lightbar params Or edit and change them with this: ectool lightbar params > /tmp/vals.txt vi /tmp/vals.txt ectool lightbar params /tmp/vals.txt The updated parameters are persistent across EC jumps (RO->RW), but are lost when/if the EC reboots (as it will after the AP is off for 24 hours, for example). Change-Id: Ic2a3fd6f8062673432b48904933e0c7239b8658b Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35289 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/ectool.c156
-rw-r--r--util/lbplay.c4
2 files changed, 158 insertions, 2 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 9fb8a19635..5b1cec8be7 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -4,6 +4,7 @@
*/
#include <ctype.h>
+#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1061,7 +1062,9 @@ static const struct {
LB_SIZES(reg),
LB_SIZES(rgb),
LB_SIZES(get_seq),
- LB_SIZES(demo)
+ LB_SIZES(demo),
+ LB_SIZES(get_params),
+ LB_SIZES(set_params),
};
#undef LB_SIZES
@@ -1079,6 +1082,8 @@ static int lb_help(const char *cmd)
printf(" %s LED RED GREEN BLUE - set color manually"
" (LED=4 for all)\n", cmd);
printf(" %s demo 0|1 - turn demo mode on & off\n", cmd);
+ printf(" %s params [setfile] - get params"
+ " (or set from file)\n", cmd);
return 0;
}
@@ -1124,6 +1129,140 @@ static int lb_show_msg_names(void)
return 0;
}
+static int lb_read_params_from_file(const char *filename,
+ struct lightbar_params *p)
+{
+ FILE *fp;
+ char buf[80];
+ int val[4];
+ int r = 1;
+ int line = 0;
+ int want, got;
+ int i;
+
+ fp = fopen(filename, "rb");
+ if (!fp) {
+ fprintf(stderr, "Can't open %s: %s\n",
+ filename, strerror(errno));
+ return 1;
+ }
+
+ /* We must read the correct number of params from each line */
+#define READ(N) do { \
+ line++; \
+ want = (N); \
+ got = -1; \
+ if (!fgets(buf, sizeof(buf), fp)) \
+ goto done; \
+ got = sscanf(buf, "%i %i %i %i", \
+ &val[0], &val[1], &val[2], &val[3]); \
+ if (want != got) \
+ goto done; \
+ } while (0)
+
+
+ /* Do it */
+ READ(1); p->google_ramp_up = val[0];
+ READ(1); p->google_ramp_down = val[0];
+ READ(1); p->s3s0_ramp_up = val[0];
+ READ(1); p->s0_tick_delay[0] = val[0];
+ READ(1); p->s0_tick_delay[1] = val[0];
+ READ(1); p->s0s3_ramp_down = val[0];
+ READ(1); p->s3_sleep_for = val[0];
+ READ(1); p->s3_tick_delay = val[0];
+ READ(1); p->w_ofs = val[0];
+
+ READ(2);
+ p->bright_bl_off_fixed[0] = val[0];
+ p->bright_bl_off_fixed[1] = val[1];
+
+ READ(2);
+ p->bright_bl_on_min[0] = val[0];
+ p->bright_bl_on_min[1] = val[1];
+
+ READ(2);
+ p->bright_bl_on_max[0] = val[0];
+ p->bright_bl_on_max[1] = val[1];
+
+ READ(4);
+ p->s0_idx[0][0] = val[0];
+ p->s0_idx[0][1] = val[1];
+ p->s0_idx[0][2] = val[2];
+ p->s0_idx[0][3] = val[3];
+
+ READ(4);
+ p->s0_idx[1][0] = val[0];
+ p->s0_idx[1][1] = val[1];
+ p->s0_idx[1][2] = val[2];
+ p->s0_idx[1][3] = val[3];
+
+ READ(4);
+ p->s3_idx[0][0] = val[0];
+ p->s3_idx[0][1] = val[1];
+ p->s3_idx[0][2] = val[2];
+ p->s3_idx[0][3] = val[3];
+
+ READ(4);
+ p->s3_idx[1][0] = val[0];
+ p->s3_idx[1][1] = val[1];
+ p->s3_idx[1][2] = val[2];
+ p->s3_idx[1][3] = val[3];
+
+ for (i = 0; i < ARRAY_SIZE(p->color); i++) {
+ READ(3);
+ p->color[i].r = val[0];
+ p->color[i].g = val[1];
+ p->color[i].b = val[2];
+ }
+
+ /* Yay */
+ r = 0;
+done:
+ if (r)
+ fprintf(stderr, "problem with line %d: wanted %d, got %d\n",
+ line, want, got);
+ fclose(fp);
+ return r;
+}
+
+static void lb_show_params(const struct lightbar_params *p)
+{
+ int i;
+
+ printf("%d\t\t# .google_ramp_up\n", p->google_ramp_up);
+ printf("%d\t\t# .google_ramp_down\n", p->google_ramp_down);
+ printf("%d\t\t# .s3s0_ramp_up\n", p->s3s0_ramp_up);
+ printf("%d\t\t# .s0_tick_delay (battery)\n", p->s0_tick_delay[0]);
+ printf("%d\t\t# .s0_tick_delay (AC)\n", p->s0_tick_delay[1]);
+ printf("%d\t\t# .s0s3_ramp_down\n", p->s0s3_ramp_down);
+ printf("%d\t# .s3_sleep_for\n", p->s3_sleep_for);
+ printf("%d\t\t# .s3_tick_delay\n", p->s3_tick_delay);
+ printf("%d\t\t# .w_ofs\n", p->w_ofs);
+ printf("0x%02x 0x%02x\t# .bright_bl_off_fixed (battery, AC)\n",
+ p->bright_bl_off_fixed[0], p->bright_bl_off_fixed[1]);
+ printf("0x%02x 0x%02x\t# .bright_bl_on_min (battery, AC)\n",
+ p->bright_bl_on_min[0], p->bright_bl_on_min[1]);
+ printf("0x%02x 0x%02x\t# .bright_bl_on_max (battery, AC)\n",
+ p->bright_bl_on_max[0], p->bright_bl_on_max[1]);
+ printf("%d %d %d %d\t\t# .s0_idx[] (battery)\n",
+ p->s0_idx[0][0], p->s0_idx[0][1],
+ p->s0_idx[0][2], p->s0_idx[0][3]);
+ printf("%d %d %d %d\t\t# .s0_idx[] (AC)\n",
+ p->s0_idx[1][0], p->s0_idx[1][1],
+ p->s0_idx[1][2], p->s0_idx[1][3]);
+ printf("%d %d %d %d\t# .s3_idx[] (battery)\n",
+ p->s3_idx[0][0], p->s3_idx[0][1],
+ p->s3_idx[0][2], p->s3_idx[0][3]);
+ printf("%d %d %d %d\t# .s3_idx[] (AC)\n",
+ p->s3_idx[1][0], p->s3_idx[1][1],
+ p->s3_idx[1][2], p->s3_idx[1][3]);
+ for (i = 0; i < ARRAY_SIZE(p->color); i++)
+ printf("0x%02x 0x%02x 0x%02x\t# color[%d]\n",
+ p->color[i].r,
+ p->color[i].g,
+ p->color[i].b, i);
+}
+
static int cmd_lightbar(int argc, char **argv)
{
int i, r;
@@ -1152,6 +1291,21 @@ static int cmd_lightbar(int argc, char **argv)
if (argc == 2 && !strcasecmp(argv[1], "on"))
return lb_do_cmd(LIGHTBAR_CMD_ON, &param, &resp);
+ if (!strcasecmp(argv[1], "params")) {
+ if (argc > 2) {
+ r = lb_read_params_from_file(argv[2],
+ &param.set_params);
+ if (r)
+ return r;
+ return lb_do_cmd(LIGHTBAR_CMD_SET_PARAMS,
+ &param, &resp);
+ }
+ r = lb_do_cmd(LIGHTBAR_CMD_GET_PARAMS, &param, &resp);
+ if (!r)
+ lb_show_params(&resp.get_params);
+ return r;
+ }
+
if (argc == 3 && !strcasecmp(argv[1], "brightness")) {
char *e;
param.brightness.num = 0xff & strtoul(argv[2], &e, 16);
diff --git a/util/lbplay.c b/util/lbplay.c
index 8658368160..907374e9cc 100644
--- a/util/lbplay.c
+++ b/util/lbplay.c
@@ -35,7 +35,9 @@ static const struct {
LB_SIZES(reg),
LB_SIZES(rgb),
LB_SIZES(get_seq),
- LB_SIZES(demo)
+ LB_SIZES(demo),
+ LB_SIZES(get_params),
+ LB_SIZES(set_params)
};
#undef LB_SIZES