]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Reduce rgb matrix firmware size
authorRyan Caltabiano <rcalt2vt@gmail.com>
Sun, 19 May 2019 13:34:25 +0000 (08:34 -0500)
committerDrashna Jaelre <drashna@live.com>
Sun, 19 May 2019 22:23:01 +0000 (15:23 -0700)
31 files changed:
quantum/rgb_matrix.c
quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h
quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h
quantum/rgb_matrix_animations/colorband_sat_anim.h
quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h
quantum/rgb_matrix_animations/colorband_spiral_val_anim.h
quantum/rgb_matrix_animations/colorband_val_anim.h
quantum/rgb_matrix_animations/cycle_all_anim.h
quantum/rgb_matrix_animations/cycle_left_right_anim.h
quantum/rgb_matrix_animations/cycle_out_in_anim.h
quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h
quantum/rgb_matrix_animations/cycle_pinwheel_anim.h
quantum/rgb_matrix_animations/cycle_spiral_anim.h
quantum/rgb_matrix_animations/cycle_up_down_anim.h
quantum/rgb_matrix_animations/dual_beacon_anim.h
quantum/rgb_matrix_animations/rainbow_beacon_anim.h
quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h
quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h
quantum/rgb_matrix_animations/solid_reactive_anim.h
quantum/rgb_matrix_animations/solid_reactive_cross.h
quantum/rgb_matrix_animations/solid_reactive_nexus.h
quantum/rgb_matrix_animations/solid_reactive_simple_anim.h
quantum/rgb_matrix_animations/solid_reactive_wide.h
quantum/rgb_matrix_animations/solid_splash_anim.h
quantum/rgb_matrix_animations/splash_anim.h
quantum/rgb_matrix_runners/effect_runner_dx_dy.h [new file with mode: 0644]
quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h [new file with mode: 0644]
quantum/rgb_matrix_runners/effect_runner_i.h [new file with mode: 0644]
quantum/rgb_matrix_runners/effect_runner_reactive.h [new file with mode: 0644]
quantum/rgb_matrix_runners/effect_runner_reactive_splash.h [new file with mode: 0644]
quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h [new file with mode: 0644]

index a6a9549af4ce558d02546fcae6cb11c7252e7ac0..98baf5cb5808e325da587d1dc0a748ba68757d17 100644 (file)
   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)
index 3e6df1fbeb8ebda370604f74973f5499ea17a488..cf9c0784a83e6815cbc86c1f87321bac93ba1af5 100644 (file)
@@ -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
index 88cc7d1f23d870966d5a0633cf32850def8efb25..05ad0ee32351d707927dc6595fdaf93a87d69ef8 100644 (file)
@@ -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
index 89773b6ce62b0ff4ca0cf5193e641d10c0e8b129..8a40473e4a41cdd43856be3a83447ff5d3358c32 100644 (file)
@@ -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
index 44955900a5daef442cf057c18fdcd1c55dc14669..4af6c60b0d280406000352d7cf80c5edafed30d3 100644 (file)
@@ -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
index 5aea0c8da11f59572080e8e6cd28252cf925c3f6..e787956a7a05c8e70e44060feef7a8412047d210 100644 (file)
@@ -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
index bf41cec910fe131069827038ddcea44151971cca..1e3740cea46de336e1cc8f29717d460caa57d53d 100644 (file)
@@ -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
index e6319cad7ffddaac864f9e2b974b38c837050e50..380dbe05a483629ae27eaac822fbdb87809bcb0b 100644 (file)
@@ -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
index d9a00530a020731f448db714f73bbec750120a8c..f270fb42ccd11d420172c38283cbabe4beda4625 100644 (file)
@@ -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
index 29209e4d7be9863d324dab64f450b5a11887d18c..46c7efef258d3dc33dcc0541bb09a79dcb2a093e 100644 (file)
@@ -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
index b2f79ceea08845dfedff9492224f694a0d7e35e1..2fdb4ba919303961e5618904618b579b7eceb7c6 100644 (file)
@@ -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
index 59d60ac07728c16284ad9d3c8ed40e03d6d66037..29e2d92c92c5b569087613270c6a41e54bebc072 100644 (file)
@@ -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
index 865309c252b786e9adf9a94c33d0bb27a9f0c435..a1354f60c19ac8a44dec2984df67f4d485566747 100644 (file)
@@ -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
index f2b31d9da5232d578086ed5a0b2a26e6ac3ce1c1..b3ef4cdf2e029a69ab625a0f3c945191c6bd5b57 100644 (file)
@@ -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
index 59c91046d464576e1c85c7984a57c36cbed6d304..d34f146a5b666dbfe9aa630a7ecf75e0ac8b11a6 100644 (file)
@@ -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
index 564e3c480a96acb5854c1fb7dc66eb2c34812965..061cac837c6be55093bb52e9083c932cdf3c8179 100644 (file)
@@ -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
index 39352b0c13690c350307719f8b5c9bb2e24d5569..f406566fa16944a8cdac38909f960a86afc88821 100644 (file)
@@ -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
index 7d189b927b4e66b062ce569ac1e45fce2147d611..f19e9116d9882633ecd5d94f714bed674d989299 100644 (file)
@@ -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
index 37e339907a68f9c920b7f37c6a121aa047d0404c..762a95db313861455d608eb405d2d83d2494cc48 100644 (file)
@@ -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
index 62210f82d625b24404ca7cf4382b1d7b7ffddc06..99f22c694e149a33bc9884a26a4c46266287d604 100644 (file)
@@ -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_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math);
 }
+#endif
 
-bool SOLID_REACTIVE_CROSS(effect_params_t* params) {
-  return rgb_matrix_solid_reactive_multicross_range(qsub8(g_last_hit_tracker.count, 1), params);
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
+bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) {
+    return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math);
 }
+#endif
 
 #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 #endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS)
index 33f478ac704f7067215fc8e6a7c8dde7b5d29c41..8bebd042d2d49072b1eb682a1733a5c3963e0366 100644 (file)
@@ -11,43 +11,29 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS)
 
 #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static bool rgb_matrix_solid_reactive_multinexus_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 = 8;
-      uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist;
-      if (effect > 255)
+static void SOLID_REACTIVE_NEXUS_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+    uint16_t effect = tick - dist;
+    if (effect > 255)
         effect = 255;
-      if (dist > 72)
+    if (dist > 72)
         effect = 255;
-      if ((dx > dist2 || dx < -dist2) && (dy > dist2 || dy < -dist2))
+    if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8))
         effect = 255;
-      hsv.v = qadd8(hsv.v, 255 - effect);
-      hsv.h = rgb_matrix_config.hue + dy / 4;
-    }
-    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);
+    hsv->h = rgb_matrix_config.hue + dy / 4;
 }
 
-bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) {
-  return rgb_matrix_solid_reactive_multinexus_range(0, params);
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
+bool SOLID_REACTIVE_NEXUS(effect_params_t* params) {
+    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math);
 }
+#endif
 
-bool SOLID_REACTIVE_NEXUS(effect_params_t* params) {
-  return rgb_matrix_solid_reactive_multinexus_range(qsub8(g_last_hit_tracker.count, 1), params);
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
+bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) {
+    return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math);
 }
+#endif
 
 #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 #endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS)
index f235824e271e47cb2cfdb351ce9328ec3e7c1cb8..36c6ec5277608aecc98a826fb5174fa07e4b509b 100644 (file)
@@ -3,29 +3,12 @@
 RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE)
 #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
-
-  HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
-  // 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;
-  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_SIMPLE_math(HSV* hsv, uint16_t offset) {
+    hsv->v = scale8(255 - offset, rgb_matrix_config.val);
+}
 
-    uint16_t  offset = scale16by8(tick, rgb_matrix_config.speed);
-    hsv.v = scale8(255 - offset, 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;
+bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) {
+    return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math);
 }
 
 #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
index ff0f6f5ecab7e704fe0a5d7b254e3b9879c34a58..36edc475c872a0014f7e2b9b7468b1f8f56bbbcd 100644 (file)
@@ -11,37 +11,24 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE)
 
 #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static bool rgb_matrix_solid_reactive_multiwide_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);
-      uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist * 5;
-      if (effect > 255)
+static void SOLID_REACTIVE_WIDE_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+    uint16_t effect = tick + dist * 5;
+    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_MULTIWIDE(effect_params_t* params) {
-  return rgb_matrix_solid_reactive_multiwide_range(0, params);
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
+bool SOLID_REACTIVE_WIDE(effect_params_t* params) {
+    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math);
 }
+#endif
 
-bool SOLID_REACTIVE_WIDE(effect_params_t* params) {
-  return rgb_matrix_solid_reactive_multiwide_range(qsub8(g_last_hit_tracker.count, 1), params);
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
+bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) {
+    return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math);
 }
+#endif
 
 #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 #endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE)
index d439bd8880d1425590c17307bd79096ab3122831..84c99ff00c9d038b569fb58e3dd48c0b94bda8b7 100644 (file)
@@ -11,37 +11,24 @@ RGB_MATRIX_EFFECT(SOLID_MULTISPLASH)
 
 #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-static bool rgb_matrix_solid_multisplash_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++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    hsv.v = 0;
-    for (uint8_t j = start; j < count; j++) {
-      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);
-      uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist;
-      if (effect > 255)
+void SOLID_SPLASH_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+    uint16_t effect = tick - dist;
+    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_MULTISPLASH(effect_params_t* params) {
-  return rgb_matrix_solid_multisplash_range(0, params);
+#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
+bool SOLID_SPLASH(effect_params_t* params) {
+    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math);
 }
+#endif
 
-bool SOLID_SPLASH(effect_params_t* params) {
-  return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params);
+#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
+bool SOLID_MULTISPLASH(effect_params_t* params) {
+    return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math);
 }
+#endif
 
 #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
index 214dab68dad46bb433a10544c13fa5c0da9131cb..c4c05165359ac42caa393eeea127f82d7e3e32d9 100644 (file)
@@ -11,40 +11,25 @@ RGB_MATRIX_EFFECT(MULTISPLASH)
 
 #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 
-
-static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) {
-  RGB_MATRIX_USE_LIMITS(led_min, led_max);
-
-  HSV hsv = { 0, rgb_matrix_config.sat, 0 };
-  uint8_t count = g_last_hit_tracker.count;
-  for (uint8_t i = led_min; i < led_max; i++) {
-    RGB_MATRIX_TEST_LED_FLAGS();
-    hsv.h = rgb_matrix_config.hue;
-    hsv.v = 0;
-    for (uint8_t j = start; j < count; j++) {
-      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);
-      uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist;
+void SPLASH_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
+    uint16_t effect = tick - dist;
       if (effect > 255)
         effect = 255;
-      hsv.h += effect;
-      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->h += effect;
+      hsv->v = qadd8(hsv->v, 255 - effect);
 }
 
-bool MULTISPLASH(effect_params_t* params) {
-  return rgb_matrix_multisplash_range(0, params);
+#ifndef DISABLE_RGB_MATRIX_SPLASH
+bool SPLASH(effect_params_t* params) {
+    return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math);
 }
+#endif
 
-bool SPLASH(effect_params_t* params) {
-  return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params);
+#ifndef DISABLE_RGB_MATRIX_MULTISPLASH
+bool MULTISPLASH(effect_params_t* params) {
+    return effect_runner_reactive_splash(0, params, &SPLASH_math);
 }
+#endif
 
 #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
 #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
diff --git a/quantum/rgb_matrix_runners/effect_runner_dx_dy.h b/quantum/rgb_matrix_runners/effect_runner_dx_dy.h
new file mode 100644 (file)
index 0000000..4331262
--- /dev/null
@@ -0,0 +1,19 @@
+#pragma once
+
+typedef void (*dx_dy_f)(HSV* hsv, int16_t dx, int16_t dy, uint8_t time);
+
+bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) {
+  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+  HSV hsv = { rgb_matrix_config.hue, 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 - k_rgb_matrix_center.x;
+    int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
+    effect_func(&hsv, dx, dy, time);
+    RGB rgb = hsv_to_rgb(hsv);
+    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+  }
+  return led_max < DRIVER_LED_TOTAL;
+}
diff --git a/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h b/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h
new file mode 100644 (file)
index 0000000..a7310c8
--- /dev/null
@@ -0,0 +1,20 @@
+#pragma once
+
+typedef void (*dx_dy_dist_f)(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time);
+
+bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) {
+  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+  HSV hsv = { rgb_matrix_config.hue, 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 - 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);
+    effect_func(&hsv, dx, dy, 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;
+}
diff --git a/quantum/rgb_matrix_runners/effect_runner_i.h b/quantum/rgb_matrix_runners/effect_runner_i.h
new file mode 100644 (file)
index 0000000..85405ba
--- /dev/null
@@ -0,0 +1,17 @@
+#pragma once
+
+typedef void (*i_f)(HSV* hsv, uint8_t i, uint8_t time);
+
+bool effect_runner_i(effect_params_t* params, i_f effect_func) {
+  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+  HSV hsv = { rgb_matrix_config.hue, 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();
+    effect_func(&hsv, i, time);
+    RGB rgb = hsv_to_rgb(hsv);
+    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+  }
+  return led_max < DRIVER_LED_TOTAL;
+}
diff --git a/quantum/rgb_matrix_runners/effect_runner_reactive.h b/quantum/rgb_matrix_runners/effect_runner_reactive.h
new file mode 100644 (file)
index 0000000..94cd7d5
--- /dev/null
@@ -0,0 +1,31 @@
+#pragma once
+
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+
+typedef void (*reactive_f)(HSV* hsv, uint16_t offset);
+
+bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) {
+    RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+  HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val };
+  uint16_t max_tick = 65535 / rgb_matrix_config.speed;
+  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;
+      }
+    }
+
+    uint16_t  offset = scale16by8(tick, rgb_matrix_config.speed);
+    effect_func(&hsv, offset);
+    RGB rgb = hsv_to_rgb(hsv);
+    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+  }
+  return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h b/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h
new file mode 100644 (file)
index 0000000..cb2b0d7
--- /dev/null
@@ -0,0 +1,30 @@
+#pragma once
+
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+
+typedef void (*reactive_splash_f)(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick);
+
+bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, reactive_splash_f effect_func) {
+  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+  HSV hsv = { 0, rgb_matrix_config.sat, 0 };
+  uint8_t count = g_last_hit_tracker.count;
+  for (uint8_t i = led_min; i < led_max; i++) {
+    RGB_MATRIX_TEST_LED_FLAGS();
+    hsv.h = rgb_matrix_config.hue;
+    hsv.v = 0;
+    for (uint8_t j = start; j < count; j++) {
+      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);
+      uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed);
+      effect_func(&hsv, dx, dy, dist, tick);
+    }
+    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;
+}
+
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h b/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h
new file mode 100644 (file)
index 0000000..54e4c6d
--- /dev/null
@@ -0,0 +1,19 @@
+#pragma once
+
+typedef void (*sin_cos_i_f)(HSV* hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time);
+
+bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) {
+  RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+  HSV hsv = { rgb_matrix_config.hue, 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();
+    effect_func(&hsv, cos_value, sin_value, i, time);
+    RGB rgb = hsv_to_rgb(hsv);
+    rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+  }
+  return led_max < DRIVER_LED_TOTAL;
+}