summaryrefslogtreecommitdiff
path: root/common/lightbar.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2012-10-15 14:58:37 -0700
committerGerrit <chrome-bot@google.com>2012-10-15 17:47:01 -0700
commitaadfab96c0ccff88aefc161d07537604c9be4ba1 (patch)
tree5c27440b0152fcc2673539dfcfcb090670c3465f /common/lightbar.c
parent4dd3940d19196fc3f872f08ec30d6d5a6ad8ef28 (diff)
downloadchrome-ec-aadfab96c0ccff88aefc161d07537604c9be4ba1.tar.gz
Fix lightbar bug, add more tweaks.
I introduced a glitch in the parameterization CL. This fixes it, and makes the choice between the gentle throbbing and occasional pulse something that can be selected as a parameter. Default is the new pulsey style. BUG=chrome-os-partner:8039 BRANCH=Link TEST=manual Using the ectool that's part of this change, run these commands to flip between suspend and active displays: ectool lightbar seq s3s0 ectool lightbar seq s0s3 Change the "new_s0" value (0/1) and reload the params with ectool lightbar params | tee /tmp/w vi /tmp/w ectool lightbar params /tmp/w In each case you'll see some pretty patterns. Pass/Fail is an artistic decision. No QA required. Change-Id: I8de0b1b3cc77f65879befe95e110bbbce18846d9 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/35620 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/lightbar.c')
-rw-r--r--common/lightbar.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index 93e1d2ec11..fe32709116 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -168,8 +168,9 @@ static struct p_state {
/* Pattern variables for state S0. */
uint16_t w0; /* primary phase */
+ uint8_t ramp; /* ramp-in for S3->S0 */
- uint16_t _pad0; /* next item is __packed */
+ uint8_t _pad0; /* next item is __packed */
/* Tweakable parameters */
struct lightbar_params p;
@@ -179,11 +180,14 @@ static const struct lightbar_params default_params = {
.google_ramp_up = 2500,
.google_ramp_down = 10000,
.s3s0_ramp_up = 2000,
- .s0_tick_delay = { 5000, 3000 }, /* battery, AC */
+ .s0_tick_delay = { 45000, 30000 }, /* battery, AC */
+ .s0a_tick_delay = { 5000, 3000 }, /* battery, AC */
.s0s3_ramp_down = 2000,
.s3_sleep_for = 15000000, /* between checks */
.s3_tick_delay = 15000,
+ .new_s0 = 1, /* 0=gentle, 1=pulse */
+
.osc_min = { 0x40, 0x40 }, /* battery, AC */
.osc_max = { 0xff, 0xff }, /* battery, AC */
.w_ofs = {24, 24}, /* phase offset, 256 == 2*PI */
@@ -236,6 +240,7 @@ static void lb_restore_state(void)
st.cur_seq = st.prev_seq = LIGHTBAR_S5;
st.battery_level = LB_BATTERY_LEVELS - 1;
st.w0 = 0;
+ st.ramp = 0;
memcpy(&st.p, &default_params, sizeof(st.p));
CPRINTF("[%T LB state initialized]\n");
}
@@ -419,7 +424,15 @@ static inline float cycle_010(uint8_t i)
return i < 128 ? _ramp_table[i] : _ramp_table[256-i];
}
-/* This function provides a smooth oscillation between -0.5 and +0.5. */
+/* This function provides a smooth oscillation between -0.5 and +0.5.
+ * Zero starts at 0x00. */
+static inline float cycle_0P0N0(uint16_t i)
+{
+ uint8_t i8 = i & 0x00FF;
+ return cycle_010(i8+64) - 0.5f;
+}
+
+/* This function provides a pulsing oscillation between -0.5 and +0.5. */
static inline float cycle_NPN(uint16_t i)
{
if ((i / 256) % 4)
@@ -484,7 +497,7 @@ static uint32_t pulse_google_colors(void)
static uint32_t sequence_S3S0(void)
{
int w, r, g, b;
- float f, fmin;
+ float f, fmin, fmax, base_s0, goal;
int ci;
uint32_t res;
@@ -502,9 +515,12 @@ static uint32_t sequence_S3S0(void)
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;
+ goal = st.p.new_s0 ? fmin : base_s0;
for (w = 0; w <= 128; w++) {
- f = cycle_010(w) * fmin;
+ f = cycle_010(w) * goal;
r = st.p.color[ci].r * f;
g = st.p.color[ci].g * f;
b = st.p.color[ci].b * f;
@@ -514,6 +530,7 @@ static uint32_t sequence_S3S0(void)
/* Initial conditions */
st.w0 = 0;
+ st.ramp = 0;
/* Ready for S0 */
return 0;
@@ -524,11 +541,11 @@ static uint32_t sequence_S0(void)
{
int tick, last_tick;
timestamp_t start, now;
- uint32_t r, g, b;
+ uint8_t r, g, b;
int i, ci;
uint8_t w_ofs;
uint16_t w;
- float f, fmin, fmax, base_s0, osc_s0;
+ float f, fmin, fmax, base_s0, osc_s0, f_ramp;
start = get_time();
tick = last_tick = 0;
@@ -557,10 +574,16 @@ static uint32_t sequence_S0(void)
fmax = st.p.osc_max[st.battery_is_charging] / 255.0f;
base_s0 = (fmax + fmin) * 0.5f;
osc_s0 = fmax - fmin;
+ f_ramp = st.ramp / 255.0f;
for (i = 0; i < NUM_LEDS; i++) {
- w = st.w0 - i * w_ofs;
- f = base_s0 + osc_s0 * cycle_NPN(w);
+ if (st.p.new_s0) {
+ w = st.w0 - i * w_ofs;
+ f = base_s0 + osc_s0 * cycle_NPN(w);
+ } else {
+ w = st.w0 - i * w_ofs * f_ramp;
+ f = base_s0 + osc_s0 * cycle_0P0N0(w) * f_ramp;
+ }
r = st.p.color[ci].r * f;
g = st.p.color[ci].g * f;
b = st.p.color[ci].b * f;
@@ -573,7 +596,13 @@ static uint32_t sequence_S0(void)
else
st.w0++;
- WAIT_OR_RET(st.p.s0_tick_delay[st.battery_is_charging]);
+ /* Continue ramping in if needed */
+ if (st.ramp < 0xff)
+ st.ramp++;
+
+ i = st.p.new_s0 ? st.p.s0a_tick_delay[st.battery_is_charging]
+ : st.p.s0_tick_delay[st.battery_is_charging];
+ WAIT_OR_RET(i);
}
return 0;
}
@@ -1171,9 +1200,12 @@ static void show_params(const struct lightbar_params *p)
ccprintf("%d\t\t# .s3s0_ramp_up\n", p->s3s0_ramp_up);
ccprintf("%d\t\t# .s0_tick_delay (battery)\n", p->s0_tick_delay[0]);
ccprintf("%d\t\t# .s0_tick_delay (AC)\n", p->s0_tick_delay[1]);
+ ccprintf("%d\t\t# .s0a_tick_delay (battery)\n", p->s0a_tick_delay[0]);
+ ccprintf("%d\t\t# .s0a_tick_delay (AC)\n", p->s0a_tick_delay[1]);
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# .new_s0\n", p->new_s0);
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",