From c9a9a719891a5bd8543f8b7bde02fca5db091732 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Fri, 12 Oct 2012 11:45:45 -0700 Subject: Set minimum brightness to 35%, variable osc settings. BUG=chrome-os-partner:8039 BRANCH=Link TEST=none More cosmetic changes. Signed-off-by: Bill Richardson Original-Change-Id: I1fd9318131ce55541d845ac8be5faa9334c3953f Reviewed-on: https://gerrit.chromium.org/gerrit/35484 Reviewed-by: Randall Spangler (cherry picked from commit eb59ac66bd2af435315d371ff45b09b2283e5fac) Change-Id: I5bc088c3b275bf03c73d95e1871ea82d2677046e Reviewed-on: https://gerrit.chromium.org/gerrit/35677 Reviewed-by: Rong Chang Tested-by: Rong Chang --- common/lightbar.c | 78 +++++++++++++++++++++++++++------------------------ include/battery.h | 6 ---- include/ec_commands.h | 14 ++++++--- util/ectool.c | 27 ++++++++++++++++-- 4 files changed, 77 insertions(+), 48 deletions(-) diff --git a/common/lightbar.c b/common/lightbar.c index e70e69bd3a..212b26aca5 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -168,10 +168,10 @@ static struct p_state { /* Pattern variables for state S0. */ uint8_t w0; /* primary phase */ - uint8_t amp; /* amplitude */ uint8_t ramp; /* ramp-in for S3->S0 */ uint8_t _pad0; /* next item is __packed */ + uint8_t _pad1; /* next item is __packed */ /* Tweakable parameters */ struct lightbar_params p; @@ -186,11 +186,15 @@ static const struct lightbar_params default_params = { .s3_sleep_for = 15000000, /* between checks */ .s3_tick_delay = 15000, - .w_ofs = 24, /* phase offset, 256 == 2*PI */ + .osc_min = { 0x40, 0x40 }, /* battery, AC */ + .osc_max = { 0xff, 0xff }, /* battery, AC */ + .w_ofs = {24, 24}, /* phase offset, 256 == 2*PI */ .bright_bl_off_fixed = {0x80, 0x80}, /* backlight off: battery, AC */ - .bright_bl_on_min = {0x40, 0x40}, /* backlight on: battery, AC */ + .bright_bl_on_min = {0x60, 0x60}, /* backlight on: battery, AC */ .bright_bl_on_max = {0xff, 0xff}, /* backlight on: battery, AC */ + + .battery_threshold = { 10, 40, 99 }, /* percent, lowest to highest */ .s0_idx = { { 5, 4, 4, 4 }, /* battery: 0 = red, other = blue */ { 5, 4, 4, 4 } /* AC: 0 = red, other = blue */ @@ -232,9 +236,8 @@ static void lb_restore_state(void) st.battery_is_charging, st.battery_level); } else { st.cur_seq = st.prev_seq = LIGHTBAR_S5; - st.battery_level = 3; + st.battery_level = LB_BATTERY_LEVELS - 1; st.w0 = 0; - st.amp = 0; st.ramp = 0; memcpy(&st.p, &default_params, sizeof(st.p)); CPRINTF("[%T LB state initialized]\n"); @@ -258,6 +261,7 @@ static int demo_mode; static void get_battery_level(void) { int pct = 0; + int i; if (demo_mode) return; @@ -267,14 +271,11 @@ static void get_battery_level(void) st.battery_is_charging = (PWR_STATE_DISCHARGE != charge_get_state()); #endif - /* For some reason we only have four states */ + /* Find the current battery level */ st.battery_level = 0; - if (pct >= LIGHTBAR_POWER_THRESHOLD_MEDIUM) - st.battery_level = 1; - if (pct >= LIGHTBAR_POWER_THRESHOLD_HIGH) - st.battery_level = 2; - if (pct >= LIGHTBAR_POWER_THRESHOLD_FULL) - st.battery_level = 3; + for (i = 0; i < LB_BATTERY_LEVELS - 1; i++) + if (pct >= st.p.battery_threshold[i]) + st.battery_level++; #ifdef CONFIG_TASK_PWM /* With nothing else to go on, use the keyboard backlight level to @@ -308,8 +309,8 @@ void demo_battery_level(int inc) return; st.battery_level += inc; - if (st.battery_level > 3) - st.battery_level = 3; + if (st.battery_level >= LB_BATTERY_LEVELS) + st.battery_level = LB_BATTERY_LEVELS - 1; else if (st.battery_level < 0) st.battery_level = 0; @@ -481,17 +482,11 @@ static uint32_t pulse_google_colors(void) return 0; } -/* Constants */ -#define MIN_S0 0.25f -#define MAX_S0 1.0f -#define BASE_S0 ((MIN_S0 + MAX_S0) * 0.5f) -#define OSC_S0 (MAX_S0 - MIN_S0) - /* CPU is waking from sleep. */ static uint32_t sequence_S3S0(void) { int w, r, g, b; - float f; + float f, fmin, fmax, base_s0; int ci; uint32_t res; @@ -507,8 +502,13 @@ static uint32_t sequence_S3S0(void) ci = st.p.s0_idx[st.battery_is_charging][st.battery_level]; if (ci >= ARRAY_SIZE(st.p.color)) ci = 0; + + fmin = st.p.osc_min[st.battery_is_charging] / 255.0f; + fmax = st.p.osc_max[st.battery_is_charging] / 255.0f; + base_s0 = (fmax + fmin) * 0.5f; + for (w = 0; w <= 128; w++) { - f = cycle_010(w) * BASE_S0; + f = cycle_010(w) * base_s0; r = st.p.color[ci].r * f; g = st.p.color[ci].g * f; b = st.p.color[ci].b * f; @@ -518,7 +518,6 @@ static uint32_t sequence_S3S0(void) /* Initial conditions */ st.w0 = 0; - st.amp = 0; st.ramp = 0; /* Ready for S0 */ @@ -532,8 +531,8 @@ static uint32_t sequence_S0(void) timestamp_t start, now; uint32_t r, g, b; int i, ci; - uint8_t w, target_amp; - float f, ff; + uint8_t w, w_ofs; + float f, fmin, fmax, base_s0, osc_s0; start = get_time(); tick = last_tick = 0; @@ -557,23 +556,21 @@ static uint32_t sequence_S0(void) ci = st.p.s0_idx[st.battery_is_charging][st.battery_level]; if (ci >= ARRAY_SIZE(st.p.color)) ci = 0; - ff = st.amp / 255.0f; + w_ofs = st.p.w_ofs[st.battery_is_charging]; + fmin = st.p.osc_min[st.battery_is_charging] / 255.0f; + fmax = st.p.osc_max[st.battery_is_charging] / 255.0f; + base_s0 = (fmax + fmin) * 0.5f; + osc_s0 = fmax - fmin; + for (i = 0; i < NUM_LEDS; i++) { - w = st.w0 - i * st.p.w_ofs * st.ramp / 255; - f = BASE_S0 + OSC_S0 * cycle_0P0N0(w) * ff; + w = st.w0 - i * w_ofs * st.ramp / 255; + f = base_s0 + osc_s0 * cycle_0P0N0(w); r = st.p.color[ci].r * f; g = st.p.color[ci].g * f; b = st.p.color[ci].b * f; lightbar_setrgb(i, r, g, b); } - /* Move gradually towards the target amplitude */ - target_amp = st.battery_is_charging ? 0xff : 0x80; - if (st.amp > target_amp) - st.amp--; - else if (st.amp < target_amp) - st.amp++; - /* Increment the phase */ if (st.battery_is_charging) st.w0--; @@ -1185,13 +1182,22 @@ static void show_params(const struct lightbar_params *p) ccprintf("%d\t\t# .s0s3_ramp_down\n", p->s0s3_ramp_down); ccprintf("%d\t# .s3_sleep_for\n", p->s3_sleep_for); ccprintf("%d\t\t# .s3_tick_delay\n", p->s3_tick_delay); - ccprintf("%d\t\t# .w_ofs\n", p->w_ofs); + ccprintf("0x%02x 0x%02x\t# .osc_min (battery, AC)\n", + p->osc_min[0], p->osc_min[1]); + ccprintf("0x%02x 0x%02x\t# .osc_max (battery, AC)\n", + p->osc_max[0], p->osc_max[1]); + ccprintf("%d %d\t\t# .w_ofs (battery, AC)\n", + p->w_ofs[0], p->w_ofs[1]); ccprintf("0x%02x 0x%02x\t# .bright_bl_off_fixed (battery, AC)\n", p->bright_bl_off_fixed[0], p->bright_bl_off_fixed[1]); ccprintf("0x%02x 0x%02x\t# .bright_bl_on_min (battery, AC)\n", p->bright_bl_on_min[0], p->bright_bl_on_min[1]); ccprintf("0x%02x 0x%02x\t# .bright_bl_on_max (battery, AC)\n", p->bright_bl_on_max[0], p->bright_bl_on_max[1]); + ccprintf("%d %d %d\t\t# .battery_threshold\n", + p->battery_threshold[0], + p->battery_threshold[1], + p->battery_threshold[2]); ccprintf("%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]); diff --git a/include/battery.h b/include/battery.h index c09e4eb76b..12b10422da 100644 --- a/include/battery.h +++ b/include/battery.h @@ -24,11 +24,5 @@ /* Precharge only when state of charge is below this level */ #define PRE_CHARGE_THRESHOLD 25 -/* Define the lightbar color thresholds, percentage */ -#define LIGHTBAR_POWER_THRESHOLD_FULL 99 -#define LIGHTBAR_POWER_THRESHOLD_HIGH 40 -#define LIGHTBAR_POWER_THRESHOLD_MEDIUM 25 -/* LOW is anything below MEDIUM */ - #endif /* __CROS_EC_BATTERY_H */ diff --git a/include/ec_commands.h b/include/ec_commands.h index 22b8b96177..2974980523 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -625,6 +625,7 @@ struct rgb_s { uint8_t r, g, b; }; +#define LB_BATTERY_LEVELS 4 /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a * host command, but the alignment is the same regardless. Keep it that way. */ @@ -638,17 +639,22 @@ struct lightbar_params { int s3_sleep_for; int s3_tick_delay; - /* Phase shift */ - uint8_t w_ofs; + /* Oscillation */ + uint8_t osc_min[2]; /* AC=0/1 */ + uint8_t osc_max[2]; /* AC=0/1 */ + uint8_t w_ofs[2]; /* AC=0/1 */ /* Brightness limits based on the backlight and AC. */ uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ uint8_t bright_bl_on_min[2]; /* AC=0/1 */ uint8_t bright_bl_on_max[2]; /* AC=0/1 */ + /* Battery level thresholds */ + uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; + /* Map [AC][battery_level] to color index */ - uint8_t s0_idx[2][4]; /* AP is running */ - uint8_t s3_idx[2][4]; /* AP is sleeping */ + uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ + uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ /* Color palette */ struct rgb_s color[8]; /* 0-3 are Google colors */ diff --git a/util/ectool.c b/util/ectool.c index 5b1cec8be7..5eadc4b9f3 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -1170,7 +1170,16 @@ static int lb_read_params_from_file(const char *filename, 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->osc_min[0] = val[0]; + p->osc_min[1] = val[1]; + READ(2); + p->osc_max[0] = val[0]; + p->osc_max[1] = val[1]; + READ(2); + p->w_ofs[0] = val[0]; + p->w_ofs[1] = val[1]; READ(2); p->bright_bl_off_fixed[0] = val[0]; @@ -1184,6 +1193,11 @@ static int lb_read_params_from_file(const char *filename, p->bright_bl_on_max[0] = val[0]; p->bright_bl_on_max[1] = val[1]; + READ(3); + p->battery_threshold[0] = val[0]; + p->battery_threshold[1] = val[1]; + p->battery_threshold[2] = val[2]; + READ(4); p->s0_idx[0][0] = val[0]; p->s0_idx[0][1] = val[1]; @@ -1237,13 +1251,22 @@ static void lb_show_params(const struct lightbar_params *p) 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# .osc_min (battery, AC)\n", + p->osc_min[0], p->osc_min[1]); + printf("0x%02x 0x%02x\t# .osc_max (battery, AC)\n", + p->osc_max[0], p->osc_max[1]); + printf("%d %d\t\t# .w_ofs (battery, AC)\n", + p->w_ofs[0], p->w_ofs[1]); 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\t\t# .battery_threshold\n", + p->battery_threshold[0], + p->battery_threshold[1], + p->battery_threshold[2]); 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]); -- cgit v1.2.1