diff options
author | Ryan Caltabiano <rcalt2vt@gmail.com> | 2019-05-19 08:34:25 -0500 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-05-19 15:23:01 -0700 |
commit | c9a7161d934979770792ff1e91ccfcc3508d240b (patch) | |
tree | 6d31cfad88b4124a0d3e3b10ed2bf4c404cf7064 | |
parent | e7af23788fbcff8e5bea896b458fb8da1639e66d (diff) |
Reduce rgb matrix firmware size
31 files changed, 312 insertions, 399 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index a6a9549af4..98baf5cb58 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -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) diff --git a/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h b/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h index 3e6df1fbeb..cf9c0784a8 100644 --- a/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h +++ b/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h b/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h index 88cc7d1f23..05ad0ee323 100644 --- a/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h +++ b/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/colorband_sat_anim.h b/quantum/rgb_matrix_animations/colorband_sat_anim.h index 89773b6ce6..8a40473e4a 100644 --- a/quantum/rgb_matrix_animations/colorband_sat_anim.h +++ b/quantum/rgb_matrix_animations/colorband_sat_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h b/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h index 44955900a5..4af6c60b0d 100644 --- a/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h +++ b/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h b/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h index 5aea0c8da1..e787956a7a 100644 --- a/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h +++ b/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/colorband_val_anim.h b/quantum/rgb_matrix_animations/colorband_val_anim.h index bf41cec910..1e3740cea4 100644 --- a/quantum/rgb_matrix_animations/colorband_val_anim.h +++ b/quantum/rgb_matrix_animations/colorband_val_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h index e6319cad7f..380dbe05a4 100644 --- a/quantum/rgb_matrix_animations/cycle_all_anim.h +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h index d9a00530a0..f270fb42cc 100644 --- a/quantum/rgb_matrix_animations/cycle_left_right_anim.h +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/cycle_out_in_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_anim.h index 29209e4d7b..46c7efef25 100644 --- a/quantum/rgb_matrix_animations/cycle_out_in_anim.h +++ b/quantum/rgb_matrix_animations/cycle_out_in_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h index b2f79ceea0..2fdb4ba919 100644 --- a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h +++ b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h b/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h index 59d60ac077..29e2d92c92 100644 --- a/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h +++ b/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/cycle_spiral_anim.h b/quantum/rgb_matrix_animations/cycle_spiral_anim.h index 865309c252..a1354f60c1 100644 --- a/quantum/rgb_matrix_animations/cycle_spiral_anim.h +++ b/quantum/rgb_matrix_animations/cycle_spiral_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h index f2b31d9da5..b3ef4cdf2e 100644 --- a/quantum/rgb_matrix_animations/cycle_up_down_anim.h +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h index 59c91046d4..d34f146a5b 100644 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -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 diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h index 564e3c480a..061cac837c 100644 --- a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(RAINBOW_BEACON) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool RAINBOW_BEACON(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void RAINBOW_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) * 2 * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * 2 * 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); - int16_t cos_value = 2 * (cos8(time) - 128); - int16_t sin_value = 2 * (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 RAINBOW_BEACON(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h index 39352b0c13..f406566fa1 100644 --- a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h @@ -2,18 +2,12 @@ RGB_MATRIX_EFFECT(RAINBOW_MOVING_CHEVRON) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void RAINBOW_MOVING_CHEVRON_math(HSV* hsv, uint8_t i, uint8_t time) { + hsv->h = abs8(g_led_config.point[i].y - k_rgb_matrix_center.y) + (g_led_config.point[i].x - time) + rgb_matrix_config.hue; +} - 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 = abs8(g_led_config.point[i].y - 32) + (g_led_config.point[i].x - time) + 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 RAINBOW_MOVING_CHEVRON(effect_params_t* params) { + return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h index 7d189b927b..f19e9116d9 100644 --- a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(PINWHEELS) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool PINWHEELS(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void PINWHEELS_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) * 3 * cos + (56 - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x)) * 3 * 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); - int16_t cos_value = 3 * (cos8(time) - 128); - int16_t sin_value = 3 * (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 + (56 - abs8(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 PINWHEELS(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &PINWHEELS_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/solid_reactive_anim.h b/quantum/rgb_matrix_animations/solid_reactive_anim.h index 37e339907a..762a95db31 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h @@ -3,30 +3,12 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool SOLID_REACTIVE(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val }; - // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 - uint16_t max_tick = 65535 / rgb_matrix_config.speed; - // Relies on hue being 8-bit and wrapping - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - uint16_t tick = max_tick; - // Reverse search to find most recent key hit - for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { - if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { - tick = g_last_hit_tracker.tick[j]; - break; - } - } +static void SOLID_REACTIVE_math(HSV* hsv, uint16_t offset) { + hsv->h = rgb_matrix_config.hue + qsub8(130, offset); +} - uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); - hsv.h = rgb_matrix_config.hue + qsub8(130, offset); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool SOLID_REACTIVE(effect_params_t* params) { + return effect_runner_reactive(params, &SOLID_REACTIVE_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/solid_reactive_cross.h b/quantum/rgb_matrix_animations/solid_reactive_cross.h index 62210f82d6..99f22c694e 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_cross.h +++ b/quantum/rgb_matrix_animations/solid_reactive_cross.h @@ -11,45 +11,29 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -static bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, 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 count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - hsv.v = 0; - for (uint8_t j = start; j < count; j++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; - int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; - uint8_t dist = sqrt16(dx * dx + dy * dy); - int16_t dist2 = 16; - uint8_t dist3; - uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist; - dx = dx < 0 ? dx * -1 : dx; - dy = dy < 0 ? dy * -1 : dy; - dx = dx * dist2 > 255 ? 255 : dx * dist2; - dy = dy * dist2 > 255 ? 255 : dy * dist2; - dist3 = dx > dy ? dy : dx; - effect += dist3; - if (effect > 255) +static void SOLID_REACTIVE_CROSS_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick + dist; + dx = dx < 0 ? dx * -1 : dx; + dy = dy < 0 ? dy * -1 : dy; + dx = dx * 16 > 255 ? 255 : dx * 16; + dy = dy * 16 > 255 ? 255 : dy * 16; + effect += dx > dy ? dy : dx; + if (effect > 255) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - } - hsv.v = scale8(hsv.v, rgb_matrix_config.val); - 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 = qadd8(hsv->v, 255 - effect); } -bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { - return rgb_matrix_solid_reactive_multicross_range(0, params); +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +bool SOLID_REACTIVE_CROSS(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracke |