Skip to content

Commit

Permalink
Reduce rgb matrix firmware size
Browse files Browse the repository at this point in the history
  • Loading branch information
XScorpion2 authored and drashna committed May 19, 2019
1 parent e7af237 commit c9a7161
Show file tree
Hide file tree
Showing 31 changed files with 312 additions and 399 deletions.
8 changes: 8 additions & 0 deletions quantum/rgb_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER;
#endif

// Generic effect runners
#include "rgb_matrix_runners/effect_runner_dx_dy_dist.h"
#include "rgb_matrix_runners/effect_runner_dx_dy.h"
#include "rgb_matrix_runners/effect_runner_i.h"
#include "rgb_matrix_runners/effect_runner_sin_cos_i.h"
#include "rgb_matrix_runners/effect_runner_reactive.h"
#include "rgb_matrix_runners/effect_runner_reactive_splash.h"

// ------------------------------------------
// -----Begin rgb effect includes macros-----
#define RGB_MATRIX_EFFECT(name)
Expand Down
18 changes: 5 additions & 13 deletions quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
RGB_MATRIX_EFFECT(BAND_PINWHEEL_SAT)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool BAND_PINWHEEL_SAT(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void BAND_PINWHEEL_SAT_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) {
hsv->s = rgb_matrix_config.sat - time - atan2_8(dy, dx) * 3;
}

HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - 112;
int16_t dy = g_led_config.point[i].y - 32;
hsv.s = rgb_matrix_config.sat - time - atan2_8(dy, dx) * 3;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool BAND_PINWHEEL_SAT(effect_params_t* params) {
return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
18 changes: 5 additions & 13 deletions quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
RGB_MATRIX_EFFECT(BAND_PINWHEEL_VAL)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool BAND_PINWHEEL_VAL(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void BAND_PINWHEEL_VAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) {
hsv->v = rgb_matrix_config.val - time - atan2_8(dy, dx) * 3;
}

HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - 112;
int16_t dy = g_led_config.point[i].y - 32;
hsv.v = rgb_matrix_config.val - time - atan2_8(dy, dx) * 3;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool BAND_PINWHEEL_VAL(effect_params_t* params) {
return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
18 changes: 6 additions & 12 deletions quantum/rgb_matrix_animations/colorband_sat_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
RGB_MATRIX_EFFECT(BAND_SAT)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool BAND_SAT(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);

HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
static void BAND_SAT_math(HSV* hsv, uint8_t i, uint8_t time) {
int16_t s = rgb_matrix_config.sat - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8;
hsv.s = s < 0 ? 0 : s;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
hsv->s = s < 0 ? 0 : s;
}

bool BAND_SAT(effect_params_t* params) {
return effect_runner_i(params, &BAND_SAT_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
19 changes: 5 additions & 14 deletions quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@
RGB_MATRIX_EFFECT(BAND_SPIRAL_SAT)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool BAND_SPIRAL_SAT(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void BAND_SPIRAL_SAT_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
hsv->s = rgb_matrix_config.sat + dist - time - atan2_8(dy, dx);
}

HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - 112;
int16_t dy = g_led_config.point[i].y - 32;
uint8_t dist = sqrt16(dx * dx + dy * dy);
hsv.s = rgb_matrix_config.sat + dist - time - atan2_8(dy, dx);
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool BAND_SPIRAL_SAT(effect_params_t* params) {
return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
19 changes: 5 additions & 14 deletions quantum/rgb_matrix_animations/colorband_spiral_val_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@
RGB_MATRIX_EFFECT(BAND_SPIRAL_VAL)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool BAND_SPIRAL_VAL(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void BAND_SPIRAL_VAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
hsv->v = rgb_matrix_config.val + dist - time - atan2_8(dy, dx);
}

HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - 112;
int16_t dy = g_led_config.point[i].y - 32;
uint8_t dist = sqrt16(dx * dx + dy * dy);
hsv.v = rgb_matrix_config.val + dist - time - atan2_8(dy, dx);
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool BAND_SPIRAL_VAL(effect_params_t* params) {
return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
18 changes: 6 additions & 12 deletions quantum/rgb_matrix_animations/colorband_val_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
RGB_MATRIX_EFFECT(BAND_VAL)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool BAND_VAL(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);

HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
static void BAND_VAL_math(HSV* hsv, uint8_t i, uint8_t time) {
int16_t v = rgb_matrix_config.val - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8;
hsv.v = v < 0 ? 0 : v;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
hsv->v = v < 0 ? 0 : v;
}

bool BAND_VAL(effect_params_t* params) {
return effect_runner_i(params, &BAND_VAL_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
16 changes: 6 additions & 10 deletions quantum/rgb_matrix_animations/cycle_all_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
RGB_MATRIX_EFFECT(CYCLE_ALL)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool CYCLE_ALL(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void CYCLE_ALL_math(HSV* hsv, uint8_t i, uint8_t time)
{
hsv->h = time;
}

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
hsv.h = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool CYCLE_ALL(effect_params_t* params) {
return effect_runner_i(params, &CYCLE_ALL_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
16 changes: 5 additions & 11 deletions quantum/rgb_matrix_animations/cycle_left_right_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
RGB_MATRIX_EFFECT(CYCLE_LEFT_RIGHT)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool CYCLE_LEFT_RIGHT(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void CYCLE_LEFT_RIGHT_math(HSV* hsv, uint8_t i, uint8_t time) {
hsv->h = g_led_config.point[i].x - time;
}

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
hsv.h = g_led_config.point[i].x - time;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool CYCLE_LEFT_RIGHT(effect_params_t* params) {
return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
19 changes: 5 additions & 14 deletions quantum/rgb_matrix_animations/cycle_out_in_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@
RGB_MATRIX_EFFECT(CYCLE_OUT_IN)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool CYCLE_OUT_IN(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void CYCLE_OUT_IN_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
hsv->h = 3 * dist / 2 + time;
}

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x;
int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
uint8_t dist = sqrt16(dx * dx + dy * dy);
hsv.h = 3 * dist / 2 + time;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool CYCLE_OUT_IN(effect_params_t* params) {
return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
21 changes: 7 additions & 14 deletions quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
RGB_MATRIX_EFFECT(CYCLE_OUT_IN_DUAL)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool CYCLE_OUT_IN_DUAL(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = (k_rgb_matrix_center.x / 2) - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x);
int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
static void CYCLE_OUT_IN_DUAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) {
dx = (k_rgb_matrix_center.x / 2) - abs8(dx);
uint8_t dist = sqrt16(dx * dx + dy * dy);
hsv.h = 3 * dist + time;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
hsv->h = 3 * dist + time;
}

bool CYCLE_OUT_IN_DUAL(effect_params_t* params) {
return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
18 changes: 5 additions & 13 deletions quantum/rgb_matrix_animations/cycle_pinwheel_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
RGB_MATRIX_EFFECT(CYCLE_PINWHEEL)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool CYCLE_PINWHEEL(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void CYCLE_PINWHEEL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) {
hsv->h = atan2_8(dy, dx) + time;
}

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - 112;
int16_t dy = g_led_config.point[i].y - 32;
hsv.h = atan2_8(dy, dx) + time;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool CYCLE_PINWHEEL(effect_params_t* params) {
return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
19 changes: 5 additions & 14 deletions quantum/rgb_matrix_animations/cycle_spiral_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@
RGB_MATRIX_EFFECT(CYCLE_SPIRAL)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool CYCLE_SPIRAL(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void CYCLE_SPIRAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) {
hsv->h = dist - time - atan2_8(dy, dx);
}

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - 112;
int16_t dy = g_led_config.point[i].y - 32;
uint8_t dist = sqrt16(dx * dx + dy * dy);
hsv.h = dist - time - atan2_8(dy, dx);
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool CYCLE_SPIRAL(effect_params_t* params) {
return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
16 changes: 5 additions & 11 deletions quantum/rgb_matrix_animations/cycle_up_down_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
RGB_MATRIX_EFFECT(CYCLE_UP_DOWN)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool CYCLE_UP_DOWN(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void CYCLE_UP_DOWN_math(HSV* hsv, uint8_t i, uint8_t time) {
hsv->h = g_led_config.point[i].y - time;
}

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
hsv.h = g_led_config.point[i].y - time;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool CYCLE_UP_DOWN(effect_params_t* params) {
return effect_runner_i(params, &CYCLE_UP_DOWN_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
18 changes: 5 additions & 13 deletions quantum/rgb_matrix_animations/dual_beacon_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
RGB_MATRIX_EFFECT(DUAL_BEACON)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

bool DUAL_BEACON(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
static void DUAL_BEACON_math(HSV* hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) {
hsv->h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin) / 128 + rgb_matrix_config.hue;
}

HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
int8_t cos_value = cos8(time) - 128;
int8_t sin_value = sin8(time) - 128;
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
hsv.h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos_value + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin_value) / 128 + rgb_matrix_config.hue;
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
bool DUAL_BEACON(effect_params_t* params) {
return effect_runner_sin_cos_i(params, &DUAL_BEACON_math);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
Expand Down
Loading

0 comments on commit c9a7161

Please sign in to comment.