summaryrefslogtreecommitdiff
path: root/common/lightbar.c
diff options
context:
space:
mode:
authorEric Caruso <ejcaruso@chromium.org>2014-09-30 14:40:48 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-04 21:08:45 +0000
commit15eced037401c1749b634786754df17d8c58285f (patch)
tree5c04cfdb29c42e4d85c19dbf0e93490bdc94a2cc /common/lightbar.c
parent7bbf6d7bb3dd55a70a00e37561c747cd0a7cb315 (diff)
downloadchrome-ec-15eced037401c1749b634786754df17d8c58285f.tar.gz
lightbar: refactoring RAMP_ONCE and CYCLE_ONCE
These opcodes basically do the same thing, but with minor changes. We can factor this out to avoid code duplication. Saves 90 bytes. BUG=None BRANCH=ToT TEST=Inspected programs that use RAMP_ONCE and CYCLE_ONCE with both nonzero and zero ramp delay. Change-Id: I0105dbd4fc0af86beea993dbef85a0e0f01a0a90 Signed-off-by: Eric Caruso <ejcaruso@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/220604 Reviewed-by: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'common/lightbar.c')
-rw-r--r--common/lightbar.c71
1 files changed, 31 insertions, 40 deletions
diff --git a/common/lightbar.c b/common/lightbar.c
index e6b6e84f99..fb1adb41a3 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -1120,6 +1120,33 @@ static inline int get_interp_value(int led, int color, int interp)
return base + (delta * interp / FP_SCALE);
}
+static void set_all_leds(int color)
+{
+ int i, r, g, b;
+ for (i = 0; i < NUM_LEDS; i++) {
+ r = led_desc[i][color][LB_COL_RED];
+ g = led_desc[i][color][LB_COL_GREEN];
+ b = led_desc[i][color][LB_COL_BLUE];
+ lb_set_rgb(i, r, g, b);
+ }
+}
+
+static uint32_t ramp_all_leds(int stop_at)
+{
+ int w, i, r, g, b, f;
+ for (w = 0; w < stop_at; w++) {
+ f = cycle_010(w);
+ for (i = 0; i < NUM_LEDS; i++) {
+ r = get_interp_value(i, LB_COL_RED, f);
+ g = get_interp_value(i, LB_COL_GREEN, f);
+ b = get_interp_value(i, LB_COL_BLUE, f);
+ lb_set_rgb(i, r, g, b);
+ }
+ WAIT_OR_RET(lb_ramp_delay);
+ }
+ return EC_SUCCESS;
+}
+
/* RAMP_ONCE - simple gradient or color set
* If the ramp delay is set to zero, then this sets the color of
* all LEDs to their respective COLOR1.
@@ -1129,31 +1156,13 @@ static inline int get_interp_value(int led, int color, int interp)
*/
static uint32_t lightbyte_RAMP_ONCE(void)
{
- int w, i, r, g, b;
- int f;
-
/* special case for instantaneous set */
if (lb_ramp_delay == 0) {
- for (i = 0; i < NUM_LEDS; i++) {
- r = led_desc[i][LB_CONT_COLOR1][LB_COL_RED];
- g = led_desc[i][LB_CONT_COLOR1][LB_COL_GREEN];
- b = led_desc[i][LB_CONT_COLOR1][LB_COL_BLUE];
- lb_set_rgb(i, r, g, b);
- }
+ set_all_leds(LB_CONT_COLOR1);
return EC_SUCCESS;
}
- for (w = 0; w < 128; w++) {
- f = cycle_010(w);
- for (i = 0; i < NUM_LEDS; i++) {
- r = get_interp_value(i, LB_COL_RED, f);
- g = get_interp_value(i, LB_COL_GREEN, f);
- b = get_interp_value(i, LB_COL_BLUE, f);
- lb_set_rgb(i, r, g, b);
- }
- WAIT_OR_RET(lb_ramp_delay);
- }
- return EC_SUCCESS;
+ return ramp_all_leds(128);
}
/* CYCLE_ONCE - simple cycle or color set
@@ -1165,31 +1174,13 @@ static uint32_t lightbyte_RAMP_ONCE(void)
*/
static uint32_t lightbyte_CYCLE_ONCE(void)
{
- int w, i, r, g, b;
- int f;
-
/* special case for instantaneous set */
if (lb_ramp_delay == 0) {
- for (i = 0; i < NUM_LEDS; i++) {
- r = led_desc[i][LB_CONT_COLOR0][LB_COL_RED];
- g = led_desc[i][LB_CONT_COLOR0][LB_COL_GREEN];
- b = led_desc[i][LB_CONT_COLOR0][LB_COL_BLUE];
- lb_set_rgb(i, r, g, b);
- }
+ set_all_leds(LB_CONT_COLOR0);
return EC_SUCCESS;
}
- for (w = 0; w < 256; w++) {
- f = cycle_010(w);
- for (i = 0; i < NUM_LEDS; i++) {
- r = get_interp_value(i, LB_COL_RED, f);
- g = get_interp_value(i, LB_COL_GREEN, f);
- b = get_interp_value(i, LB_COL_BLUE, f);
- lb_set_rgb(i, r, g, b);
- }
- WAIT_OR_RET(lb_ramp_delay);
- }
- return EC_SUCCESS;
+ return ramp_all_leds(256);
}
/* CYCLE - repeating cycle