summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-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