From d61e5c0027e289ccf48652afa4c442342e7ccf04 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 22 Jun 2021 18:26:23 +1000 Subject: Move LED/RGB Matrix code into their own directories (#13257) --- quantum/rgb_matrix/animations/alpha_mods_anim.h | 26 +++++++ quantum/rgb_matrix/animations/breathing_anim.h | 20 +++++ .../animations/colorband_pinwheel_sat_anim.h | 13 ++++ .../animations/colorband_pinwheel_val_anim.h | 13 ++++ quantum/rgb_matrix/animations/colorband_sat_anim.h | 14 ++++ .../animations/colorband_spiral_sat_anim.h | 13 ++++ .../animations/colorband_spiral_val_anim.h | 13 ++++ quantum/rgb_matrix/animations/colorband_val_anim.h | 14 ++++ quantum/rgb_matrix/animations/cycle_all_anim.h | 13 ++++ .../rgb_matrix/animations/cycle_left_right_anim.h | 13 ++++ quantum/rgb_matrix/animations/cycle_out_in_anim.h | 13 ++++ .../rgb_matrix/animations/cycle_out_in_dual_anim.h | 15 ++++ .../rgb_matrix/animations/cycle_pinwheel_anim.h | 13 ++++ quantum/rgb_matrix/animations/cycle_spiral_anim.h | 13 ++++ quantum/rgb_matrix/animations/cycle_up_down_anim.h | 13 ++++ quantum/rgb_matrix/animations/digital_rain_anim.h | 75 +++++++++++++++++++ quantum/rgb_matrix/animations/dual_beacon_anim.h | 13 ++++ .../animations/gradient_left_right_anim.h | 22 ++++++ .../rgb_matrix/animations/gradient_up_down_anim.h | 22 ++++++ quantum/rgb_matrix/animations/hue_breathing_anim.h | 22 ++++++ quantum/rgb_matrix/animations/hue_pendulum_anim.h | 17 +++++ quantum/rgb_matrix/animations/hue_wave_anim.h | 17 +++++ .../animations/jellybean_raindrops_anim.h | 29 ++++++++ .../rgb_matrix/animations/rainbow_beacon_anim.h | 13 ++++ .../animations/rainbow_moving_chevron_anim.h | 13 ++++ .../rgb_matrix/animations/rainbow_pinwheels_anim.h | 13 ++++ quantum/rgb_matrix/animations/raindrops_anim.h | 39 ++++++++++ .../rgb_matrix/animations/rgb_matrix_effects.inc | 37 ++++++++++ .../animations/runners/effect_runner_dx_dy.h | 17 +++++ .../animations/runners/effect_runner_dx_dy_dist.h | 18 +++++ .../animations/runners/effect_runner_i.h | 15 ++++ .../animations/runners/effect_runner_reactive.h | 29 ++++++++ .../runners/effect_runner_reactive_splash.h | 29 ++++++++ .../animations/runners/effect_runner_sin_cos_i.h | 17 +++++ .../animations/runners/rgb_matrix_runners.inc | 6 ++ quantum/rgb_matrix/animations/solid_color_anim.h | 15 ++++ .../rgb_matrix/animations/solid_reactive_anim.h | 15 ++++ .../rgb_matrix/animations/solid_reactive_cross.h | 36 +++++++++ .../rgb_matrix/animations/solid_reactive_nexus.h | 34 +++++++++ .../animations/solid_reactive_simple_anim.h | 15 ++++ .../rgb_matrix/animations/solid_reactive_wide.h | 31 ++++++++ quantum/rgb_matrix/animations/solid_splash_anim.h | 31 ++++++++ quantum/rgb_matrix/animations/splash_anim.h | 32 ++++++++ .../rgb_matrix/animations/typing_heatmap_anim.h | 86 ++++++++++++++++++++++ 44 files changed, 977 insertions(+) create mode 100644 quantum/rgb_matrix/animations/alpha_mods_anim.h create mode 100644 quantum/rgb_matrix/animations/breathing_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_sat_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_spiral_val_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_val_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_all_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_left_right_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_out_in_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_pinwheel_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_spiral_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_up_down_anim.h create mode 100644 quantum/rgb_matrix/animations/digital_rain_anim.h create mode 100644 quantum/rgb_matrix/animations/dual_beacon_anim.h create mode 100644 quantum/rgb_matrix/animations/gradient_left_right_anim.h create mode 100644 quantum/rgb_matrix/animations/gradient_up_down_anim.h create mode 100644 quantum/rgb_matrix/animations/hue_breathing_anim.h create mode 100644 quantum/rgb_matrix/animations/hue_pendulum_anim.h create mode 100644 quantum/rgb_matrix/animations/hue_wave_anim.h create mode 100644 quantum/rgb_matrix/animations/jellybean_raindrops_anim.h create mode 100644 quantum/rgb_matrix/animations/rainbow_beacon_anim.h create mode 100644 quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h create mode 100644 quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h create mode 100644 quantum/rgb_matrix/animations/raindrops_anim.h create mode 100644 quantum/rgb_matrix/animations/rgb_matrix_effects.inc create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_i.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_reactive.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h create mode 100644 quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc create mode 100644 quantum/rgb_matrix/animations/solid_color_anim.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_anim.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_cross.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_nexus.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_simple_anim.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_wide.h create mode 100644 quantum/rgb_matrix/animations/solid_splash_anim.h create mode 100644 quantum/rgb_matrix/animations/splash_anim.h create mode 100644 quantum/rgb_matrix/animations/typing_heatmap_anim.h (limited to 'quantum/rgb_matrix/animations') diff --git a/quantum/rgb_matrix/animations/alpha_mods_anim.h b/quantum/rgb_matrix/animations/alpha_mods_anim.h new file mode 100644 index 0000000000..426d88ef35 --- /dev/null +++ b/quantum/rgb_matrix/animations/alpha_mods_anim.h @@ -0,0 +1,26 @@ +#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS +RGB_MATRIX_EFFECT(ALPHAS_MODS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// alphas = color1, mods = color2 +bool ALPHAS_MODS(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + RGB rgb1 = rgb_matrix_hsv_to_rgb(hsv); + hsv.h += rgb_matrix_config.speed; + RGB rgb2 = rgb_matrix_hsv_to_rgb(hsv); + + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) { + rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b); + } else { + rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b); + } + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS diff --git a/quantum/rgb_matrix/animations/breathing_anim.h b/quantum/rgb_matrix/animations/breathing_anim.h new file mode 100644 index 0000000000..340bd93e5d --- /dev/null +++ b/quantum/rgb_matrix/animations/breathing_anim.h @@ -0,0 +1,20 @@ +#ifndef DISABLE_RGB_MATRIX_BREATHING +RGB_MATRIX_EFFECT(BREATHING) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BREATHING(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BREATHING diff --git a/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h b/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h new file mode 100644 index 0000000000..3df3cfda7d --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +RGB_MATRIX_EFFECT(BAND_PINWHEEL_SAT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_PINWHEEL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv.s = scale8(hsv.s - time - atan2_8(dy, dx) * 3, hsv.s); + return hsv; +} + +bool BAND_PINWHEEL_SAT(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT diff --git a/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h b/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h new file mode 100644 index 0000000000..7d80074fd5 --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +RGB_MATRIX_EFFECT(BAND_PINWHEEL_VAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_PINWHEEL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv.v = scale8(hsv.v - time - atan2_8(dy, dx) * 3, hsv.v); + return hsv; +} + +bool BAND_PINWHEEL_VAL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL diff --git a/quantum/rgb_matrix/animations/colorband_sat_anim.h b/quantum/rgb_matrix/animations/colorband_sat_anim.h new file mode 100644 index 0000000000..35b830af6b --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_sat_anim.h @@ -0,0 +1,14 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SAT +RGB_MATRIX_EFFECT(BAND_SAT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_SAT_math(HSV hsv, uint8_t i, uint8_t time) { + int16_t s = hsv.s - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; + hsv.s = scale8(s < 0 ? 0 : s, hsv.s); + return hsv; +} + +bool BAND_SAT(effect_params_t* params) { return effect_runner_i(params, &BAND_SAT_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_SAT diff --git a/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h b/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h new file mode 100644 index 0000000000..048157aa1b --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT +RGB_MATRIX_EFFECT(BAND_SPIRAL_SAT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_SPIRAL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv.s = scale8(hsv.s + dist - time - atan2_8(dy, dx), hsv.s); + return hsv; +} + +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 +#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT diff --git a/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h b/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h new file mode 100644 index 0000000000..bff2da1616 --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL +RGB_MATRIX_EFFECT(BAND_SPIRAL_VAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_SPIRAL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv.v = scale8(hsv.v + dist - time - atan2_8(dy, dx), hsv.v); + return hsv; +} + +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 +#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL diff --git a/quantum/rgb_matrix/animations/colorband_val_anim.h b/quantum/rgb_matrix/animations/colorband_val_anim.h new file mode 100644 index 0000000000..f1aaf1d067 --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_val_anim.h @@ -0,0 +1,14 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_VAL +RGB_MATRIX_EFFECT(BAND_VAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_VAL_math(HSV hsv, uint8_t i, uint8_t time) { + int16_t v = hsv.v - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; + hsv.v = scale8(v < 0 ? 0 : v, hsv.v); + return hsv; +} + +bool BAND_VAL(effect_params_t* params) { return effect_runner_i(params, &BAND_VAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_VAL diff --git a/quantum/rgb_matrix/animations/cycle_all_anim.h b/quantum/rgb_matrix/animations/cycle_all_anim.h new file mode 100644 index 0000000000..faf8598a39 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_all_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL +RGB_MATRIX_EFFECT(CYCLE_ALL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_ALL_math(HSV hsv, uint8_t i, uint8_t time) { + hsv.h = time; + return hsv; +} + +bool CYCLE_ALL(effect_params_t* params) { return effect_runner_i(params, &CYCLE_ALL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_ALL diff --git a/quantum/rgb_matrix/animations/cycle_left_right_anim.h b/quantum/rgb_matrix/animations/cycle_left_right_anim.h new file mode 100644 index 0000000000..cf911eb937 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_left_right_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +RGB_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_LEFT_RIGHT_math(HSV hsv, uint8_t i, uint8_t time) { + hsv.h = g_led_config.point[i].x - time; + return hsv; +} + +bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT diff --git a/quantum/rgb_matrix/animations/cycle_out_in_anim.h b/quantum/rgb_matrix/animations/cycle_out_in_anim.h new file mode 100644 index 0000000000..d66acd4b2b --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_out_in_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN +RGB_MATRIX_EFFECT(CYCLE_OUT_IN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_OUT_IN_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv.h = 3 * dist / 2 + time; + return hsv; +} + +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 +#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN diff --git a/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h b/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h new file mode 100644 index 0000000000..fe8396140f --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h @@ -0,0 +1,15 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +RGB_MATRIX_EFFECT(CYCLE_OUT_IN_DUAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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; + return hsv; +} + +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 +#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL diff --git a/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h b/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h new file mode 100644 index 0000000000..7799887099 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_PINWHEEL +RGB_MATRIX_EFFECT(CYCLE_PINWHEEL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_PINWHEEL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv.h = atan2_8(dy, dx) + time; + return hsv; +} + +bool CYCLE_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_PINWHEEL diff --git a/quantum/rgb_matrix/animations/cycle_spiral_anim.h b/quantum/rgb_matrix/animations/cycle_spiral_anim.h new file mode 100644 index 0000000000..80cfb0dbc7 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_spiral_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_SPIRAL +RGB_MATRIX_EFFECT(CYCLE_SPIRAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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); + return hsv; +} + +bool CYCLE_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_SPIRAL diff --git a/quantum/rgb_matrix/animations/cycle_up_down_anim.h b/quantum/rgb_matrix/animations/cycle_up_down_anim.h new file mode 100644 index 0000000000..5016f739d6 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_up_down_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN +RGB_MATRIX_EFFECT(CYCLE_UP_DOWN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_UP_DOWN_math(HSV hsv, uint8_t i, uint8_t time) { + hsv.h = g_led_config.point[i].y - time; + return hsv; +} + +bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN diff --git a/quantum/rgb_matrix/animations/digital_rain_anim.h b/quantum/rgb_matrix/animations/digital_rain_anim.h new file mode 100644 index 0000000000..1de45f8e8d --- /dev/null +++ b/quantum/rgb_matrix/animations/digital_rain_anim.h @@ -0,0 +1,75 @@ +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) +RGB_MATRIX_EFFECT(DIGITAL_RAIN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +# ifndef RGB_DIGITAL_RAIN_DROPS +// lower the number for denser effect/wider keyboard +# define RGB_DIGITAL_RAIN_DROPS 24 +# endif + +bool DIGITAL_RAIN(effect_params_t* params) { + // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain + const uint8_t drop_ticks = 28; + const uint8_t pure_green_intensity = 0xd0; + const uint8_t max_brightness_boost = 0xc0; + const uint8_t max_intensity = 0xff; + + static uint8_t drop = 0; + + if (params->init) { + rgb_matrix_set_color_all(0, 0, 0); + memset(g_rgb_frame_buffer, 0, sizeof(g_rgb_frame_buffer)); + drop = 0; + } + + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { + // top row, pixels have just fallen and we're + // making a new rain drop in this column + g_rgb_frame_buffer[row][col] = max_intensity; + } else if (g_rgb_frame_buffer[row][col] > 0 && g_rgb_frame_buffer[row][col] < max_intensity) { + // neither fully bright nor dark, decay it + g_rgb_frame_buffer[row][col]--; + } + // set the pixel colour + uint8_t led[LED_HITS_TO_REMEMBER]; + uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); + + // TODO: multiple leds are supported mapped to the same row/column + if (led_count > 0) { + if (g_rgb_frame_buffer[row][col] > pure_green_intensity) { + const uint8_t boost = (uint8_t)((uint16_t)max_brightness_boost * (g_rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity)); + rgb_matrix_set_color(led[0], boost, max_intensity, boost); + } else { + const uint8_t green = (uint8_t)((uint16_t)max_intensity * g_rgb_frame_buffer[row][col] / pure_green_intensity); + rgb_matrix_set_color(led[0], 0, green, 0); + } + } + } + } + + if (++drop > drop_ticks) { + // reset drop timer + drop = 0; + for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + // if ths is on the bottom row and bright allow decay + if (row == MATRIX_ROWS - 1 && g_rgb_frame_buffer[row][col] == max_intensity) { + g_rgb_frame_buffer[row][col]--; + } + // check if the pixel above is bright + if (g_rgb_frame_buffer[row - 1][col] == max_intensity) { + // allow old bright pixel to decay + g_rgb_frame_buffer[row - 1][col]--; + // make this pixel bright + g_rgb_frame_buffer[row][col] = max_intensity; + } + } + } + } + return false; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) diff --git a/quantum/rgb_matrix/animations/dual_beacon_anim.h b/quantum/rgb_matrix/animations/dual_beacon_anim.h new file mode 100644 index 0000000000..ce94871681 --- /dev/null +++ b/quantum/rgb_matrix/animations/dual_beacon_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON +RGB_MATRIX_EFFECT(DUAL_BEACON) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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; + return hsv; +} + +bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_DUAL_BEACON diff --git a/quantum/rgb_matrix/animations/gradient_left_right_anim.h b/quantum/rgb_matrix/animations/gradient_left_right_anim.h new file mode 100644 index 0000000000..53dfd04e2c --- /dev/null +++ b/quantum/rgb_matrix/animations/gradient_left_right_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT +RGB_MATRIX_EFFECT(GRADIENT_LEFT_RIGHT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool GRADIENT_LEFT_RIGHT(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + uint8_t scale = scale8(64, rgb_matrix_config.speed); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + // The x range will be 0..224, map this to 0..7 + // Relies on hue being 8-bit and wrapping + hsv.h = rgb_matrix_config.hsv.h + (scale * g_led_config.point[i].x >> 5); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT diff --git a/quantum/rgb_matrix/animations/gradient_up_down_anim.h b/quantum/rgb_matrix/animations/gradient_up_down_anim.h new file mode 100644 index 0000000000..7e0d2898cf --- /dev/null +++ b/quantum/rgb_matrix/animations/gradient_up_down_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN +RGB_MATRIX_EFFECT(GRADIENT_UP_DOWN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool GRADIENT_UP_DOWN(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + uint8_t scale = scale8(64, rgb_matrix_config.speed); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + // The y range will be 0..64, map this to 0..4 + // Relies on hue being 8-bit and wrapping + hsv.h = rgb_matrix_config.hsv.h + scale * (g_led_config.point[i].y >> 4); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN diff --git a/quantum/rgb_matrix/animations/hue_breathing_anim.h b/quantum/rgb_matrix/animations/hue_breathing_anim.h new file mode 100644 index 0000000000..54dea958af --- /dev/null +++ b/quantum/rgb_matrix/animations/hue_breathing_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_HUE_BREATHING +RGB_MATRIX_EFFECT(HUE_BREATHING) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// Change huedelta to adjust range of hue change. 0-255. +// Hue Breathing - All LED's light up +bool HUE_BREATHING(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + uint8_t huedelta = 12; + HSV hsv = rgb_matrix_config.hsv; + uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + hsv.h = hsv.h + scale8(abs8(sin8(time) - 128) * 2, huedelta); + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_BREATHING diff --git a/quantum/rgb_matrix/animations/hue_pendulum_anim.h b/quantum/rgb_matrix/animations/hue_pendulum_anim.h new file mode 100644 index 0000000000..2d8d36174f --- /dev/null +++ b/quantum/rgb_matrix/animations/hue_pendulum_anim.h @@ -0,0 +1,17 @@ +#ifndef DISABLE_RGB_MATRIX_HUE_PENDULUM +RGB_MATRIX_EFFECT(HUE_PENDULUM) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// Change huedelta to adjust range of hue change. 0-255. +// Looks better with a low value and slow speed for subtle change. +// Hue Pendulum - color changes in a wave to the right before reversing direction +static HSV HUE_PENDULUM_math(HSV hsv, uint8_t i, uint8_t time) { + uint8_t huedelta = 12; + hsv.h = hsv.h + scale8(abs8(sin8(time) + (g_led_config.point[i].x) - 128) * 2, huedelta); + return hsv; +} + +bool HUE_PENDULUM(effect_params_t* params) { return effect_runner_i(params, &HUE_PENDULUM_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_PENDULUM diff --git a/quantum/rgb_matrix/animations/hue_wave_anim.h b/quantum/rgb_matrix/animations/hue_wave_anim.h new file mode 100644 index 0000000000..fd9026fc90 --- /dev/null +++ b/quantum/rgb_matrix/animations/hue_wave_anim.h @@ -0,0 +1,17 @@ +#ifndef DISABLE_RGB_MATRIX_HUE_WAVE +RGB_MATRIX_EFFECT(HUE_WAVE) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// Change huedelta to adjust range of hue change. 0-255. +// Looks better with a low value and slow speed for subtle change. +// Hue Wave - color changes in a wave to the right +static HSV HUE_WAVE_math(HSV hsv, uint8_t i, uint8_t time) { + uint8_t huedelta = 24; + hsv.h = hsv.h + scale8(abs8(g_led_config.point[i].x - time), huedelta); + return hsv; +} + +bool HUE_WAVE(effect_params_t* params) { return effect_runner_i(params, &HUE_WAVE_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_WAVE diff --git a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h new file mode 100644 index 0000000000..a17e954b1b --- /dev/null +++ b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h @@ -0,0 +1,29 @@ +#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +RGB_MATRIX_EFFECT(JELLYBEAN_RAINDROPS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static void jellybean_raindrops_set_color(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; + HSV hsv = {rand() & 0xFF, qadd8(rand() & 0x7F, 0x80), rgb_matrix_config.hsv.v}; + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); +} + +bool JELLYBEAN_RAINDROPS(effect_params_t* params) { + if (!params->init) { + // Change one LED every tick, make sure speed is not 0 + if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { + jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL, params); + } + return false; + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + for (int i = led_min; i < led_max; i++) { + jellybean_raindrops_set_color(i, params); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS diff --git a/quantum/rgb_matrix/animations/rainbow_beacon_anim.h b/quantum/rgb_matrix/animations/rainbow_beacon_anim.h new file mode 100644 index 0000000000..977261182f --- /dev/null +++ b/quantum/rgb_matrix/animations/rainbow_beacon_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON +RGB_MATRIX_EFFECT(RAINBOW_BEACON) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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; + return hsv; +} + +bool RAINBOW_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON diff --git a/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h new file mode 100644 index 0000000000..e51e7b2516 --- /dev/null +++ b/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +RGB_MATRIX_EFFECT(RAINBOW_MOVING_CHEVRON) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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); + return hsv; +} + +bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON diff --git a/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h new file mode 100644 index 0000000000..1cd4ed2acf --- /dev/null +++ b/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS +RGB_MATRIX_EFFECT(RAINBOW_PINWHEELS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV RAINBOW_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; + return hsv; +} + +bool RAINBOW_PINWHEELS(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_PINWHEELS_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS diff --git a/quantum/rgb_matrix/animations/raindrops_anim.h b/quantum/rgb_matrix/animations/raindrops_anim.h new file mode 100644 index 0000000000..38359cdca7 --- /dev/null +++ b/quantum/rgb_matrix/animations/raindrops_anim.h @@ -0,0 +1,39 @@ +#ifndef DISABLE_RGB_MATRIX_RAINDROPS +RGB_MATRIX_EFFECT(RAINDROPS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static void raindrops_set_color(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; + HSV hsv = {0, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v}; + + // Take the shortest path between hues + int16_t deltaH = ((rgb_matrix_config.hsv.h + 180) % 360 - rgb_matrix_config.hsv.h) / 4; + if (deltaH > 127) { + deltaH -= 256; + } else if (deltaH < -127) { + deltaH += 256; + } + + hsv.h = rgb_matrix_config.hsv.h + (deltaH * (rand() & 0x03)); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); +} + +bool RAINDROPS(effect_params_t* params) { + if (!params->init) { + // Change one LED every tick, make sure speed is not 0 + if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { + raindrops_set_color(rand() % DRIVER_LED_TOTAL, params); + } + return false; + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + for (int i = led_min; i < led_max; i++) { + raindrops_set_color(i, params); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINDROPS diff --git a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc new file mode 100644 index 0000000000..302ad79c04 --- /dev/null +++ b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc @@ -0,0 +1,37 @@ +// Add your new core rgb matrix effect here, order determines enum order +#include "solid_color_anim.h" +#include "alpha_mods_anim.h" +#include "gradient_up_down_anim.h" +#include "gradient_left_right_anim.h" +#include "breathing_anim.h" +#include "colorband_sat_anim.h" +#include "colorband_val_anim.h" +#include "colorband_pinwheel_sat_anim.h" +#include "colorband_pinwheel_val_anim.h" +#include "colorband_spiral_sat_anim.h" +#include "colorband_spiral_val_anim.h" +#include "cycle_all_anim.h" +#include "cycle_left_right_anim.h" +#include "cycle_up_down_anim.h" +#include "rainbow_moving_chevron_anim.h" +#include "cycle_out_in_anim.h" +#include "cycle_out_in_dual_anim.h" +#include "cycle_pinwheel_anim.h" +#include "cycle_spiral_anim.h" +#include "dual_beacon_anim.h" +#include "rainbow_beacon_anim.h" +#include "rainbow_pinwheels_anim.h" +#include "raindrops_anim.h" +#include "jellybean_raindrops_anim.h" +#include "hue_breathing_anim.h" +#include "hue_pendulum_anim.h" +#include "hue_wave_anim.h" +#include "typing_heatmap_anim.h" +#include "digital_rain_anim.h" +#include "solid_reactive_simple_anim.h" +#include "solid_reactive_anim.h" +#include "solid_reactive_wide.h" +#include "solid_reactive_cross.h" +#include "solid_reactive_nexus.h" +#include "splash_anim.h" +#include "solid_splash_anim.h" diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h new file mode 100644 index 0000000000..4867609c81 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h @@ -0,0 +1,17 @@ +#pragma once + +typedef HSV (*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); + + uint8_t time = scale16by8(g_rgb_timer, 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; + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h new file mode 100644 index 0000000000..9545b418d9 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h @@ -0,0 +1,18 @@ +#pragma once + +typedef HSV (*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); + + uint8_t time = scale16by8(g_rgb_timer, 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); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, dist, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_i.h b/quantum/rgb_matrix/animations/runners/effect_runner_i.h new file mode 100644 index 0000000000..95bfe8b390 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_i.h @@ -0,0 +1,15 @@ +#pragma once + +typedef HSV (*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); + + uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h new file mode 100644 index 0000000000..8485b61f3d --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h @@ -0,0 +1,29 @@ +#pragma once + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + +typedef HSV (*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); + + 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); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset)); + 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/animations/runners/effect_runner_reactive_splash.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h new file mode 100644 index 0000000000..5c69d0fbb9 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h @@ -0,0 +1,29 @@ +#pragma once + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + +typedef HSV (*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); + + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + HSV hsv = rgb_matrix_config.hsv; + 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); + hsv = effect_func(hsv, dx, dy, dist, tick); + } + hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v); + RGB rgb = rgb_matrix_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/animations/runners/effect_runner_sin_cos_i.h b/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h new file mode 100644 index 0000000000..02351de51e --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h @@ -0,0 +1,17 @@ +#pragma once + +typedef HSV (*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); + + uint16_t time = scale16by8(g_rgb_timer, 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(); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, cos_value, sin_value, i, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc b/quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc new file mode 100644 index 0000000000..c09022bb0f --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc @@ -0,0 +1,6 @@ +#include "effect_runner_dx_dy_dist.h" +#include "effect_runner_dx_dy.h" +#include "effect_runner_i.h" +#include "effect_runner_sin_cos_i.h" +#include "effect_runner_reactive.h" +#include "effect_runner_reactive_splash.h" diff --git a/quantum/rgb_matrix/animations/solid_color_anim.h b/quantum/rgb_matrix/animations/solid_color_anim.h new file mode 100644 index 0000000000..79d63cf133 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_color_anim.h @@ -0,0 +1,15 @@ +RGB_MATRIX_EFFECT(SOLID_COLOR) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool SOLID_COLOR(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#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 new file mode 100644 index 0000000000..d45bb961bc --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_anim.h @@ -0,0 +1,15 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE +RGB_MATRIX_EFFECT(SOLID_REACTIVE) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV SOLID_REACTIVE_math(HSV hsv, uint16_t offset) { + hsv.h += qsub8(130, offset); + return hsv; +} + +bool SOLID_REACTIVE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_cross.h b/quantum/rgb_matrix/animations/solid_reactive_cross.h new file mode 100644 index 0000000000..f76c68e8c7 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_cross.h @@ -0,0 +1,36 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_CROSS) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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); + return hsv; +} + +# 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 + +# 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) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_nexus.h b/quantum/rgb_matrix/animations/solid_reactive_nexus.h new file mode 100644 index 0000000000..17f94e3c18 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_nexus.h @@ -0,0 +1,34 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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) effect = 255; + if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + hsv.h = rgb_matrix_config.hsv.h + dy / 4; + return hsv; +} + +# 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 + +# 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) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h new file mode 100644 index 0000000000..12eb248cc0 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h @@ -0,0 +1,15 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv, uint16_t offset) { + hsv.v = scale8(255 - offset, hsv.v); + return hsv; +} + +bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_wide.h b/quantum/rgb_matrix/animations/solid_reactive_wide.h new file mode 100644 index 0000000000..1cc4dca728 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_wide.h @@ -0,0 +1,31 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +RGB_MATRIX_EFFECT(SOLID_REACTIVE_WIDE) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV 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); + return hsv; +} + +# 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 + +# 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) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_splash_anim.h b/quantum/rgb_matrix/animations/solid_splash_anim.h new file mode 100644 index 0000000000..99efb4996a --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_splash_anim.h @@ -0,0 +1,31 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) + +# ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH +RGB_MATRIX_EFFECT(SOLID_SPLASH) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH +RGB_MATRIX_EFFECT(SOLID_MULTISPLASH) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +HSV 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); + return hsv; +} + +# 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 + +# 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) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/splash_anim.h b/quantum/rgb_matrix/animations/splash_anim.h new file mode 100644 index 0000000000..1415bcc0fa --- /dev/null +++ b/quantum/rgb_matrix/animations/splash_anim.h @@ -0,0 +1,32 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) + +# ifndef DISABLE_RGB_MATRIX_SPLASH +RGB_MATRIX_EFFECT(SPLASH) +# endif + +# ifndef DISABLE_RGB_MATRIX_MULTISPLASH +RGB_MATRIX_EFFECT(MULTISPLASH) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +HSV 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); + return hsv; +} + +# 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 + +# 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) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/typing_heatmap_anim.h b/quantum/rgb_matrix/animations/typing_heatmap_anim.h new file mode 100644 index 0000000000..e7dda11a2f --- /dev/null +++ b/quantum/rgb_matrix/animations/typing_heatmap_anim.h @@ -0,0 +1,86 @@ +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) +RGB_MATRIX_EFFECT(TYPING_HEATMAP) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +# ifndef RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS +# define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 25 +# endif + +void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { + uint8_t m_row = row - 1; + uint8_t p_row = row + 1; + uint8_t m_col = col - 1; + uint8_t p_col = col + 1; + + if (m_col < col) g_rgb_frame_buffer[row][m_col] = qadd8(g_rgb_frame_buffer[row][m_col], 16); + g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32); + if (p_col < MATRIX_COLS) g_rgb_frame_buffer[row][p_col] = qadd8(g_rgb_frame_buffer[row][p_col], 16); + + if (p_row < MATRIX_ROWS) { + if (m_col < col) g_rgb_frame_buffer[p_row][m_col] = qadd8(g_rgb_frame_buffer[p_row][m_col], 13); + g_rgb_frame_buffer[p_row][col] = qadd8(g_rgb_frame_buffer[p_row][col], 16); + if (p_col < MATRIX_COLS) g_rgb_frame_buffer[p_row][p_col] = qadd8(g_rgb_frame_buffer[p_row][p_col], 13); + } + + if (m_row < row) { + if (m_col < col) g_rgb_frame_buffer[m_row][m_col] = qadd8(g_rgb_frame_buffer[m_row][m_col], 13); + g_rgb_frame_buffer[m_row][col] = qadd8(g_rgb_frame_buffer[m_row][col], 16); + if (p_col < MATRIX_COLS) g_rgb_frame_buffer[m_row][p_col] = qadd8(g_rgb_frame_buffer[m_row][p_col], 13); + } +} + +// A timer to track the last time we decremented all heatmap values. +static uint16_t heatmap_decrease_timer; +// Whether we should decrement the heatmap values during the next update. +static bool decrease_heatmap_values; + +bool TYPING_HEATMAP(effect_params_t* params) { + // Modified version of RGB_MATRIX_USE_LIMITS to work off of matrix row / col size + uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; + uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT; + if (led_max > sizeof(g_rgb_frame_buffer)) led_max = sizeof(g_rgb_frame_buffer); + + if (params->init) { + rgb_matrix_set_color_all(0, 0, 0); + memset(g_rgb_frame_buffer, 0, sizeof g_rgb_frame_buffer); + } + + // The heatmap animation might run in several iterations depending on + // `RGB_MATRIX_LED_PROCESS_LIMIT`, therefore we only want to update the + // timer when the animation starts. + if (params->iter == 0) { + decrease_heatmap_values = timer_elapsed(heatmap_decrease_timer) >= RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS; + + // Restart the timer if we are going to decrease the heatmap this frame. + if (decrease_heatmap_values) { + heatmap_decrease_timer = timer_read(); + } + } + + // Render heatmap & decrease + for (int i = led_min; i < led_max; i++) { + uint8_t row = i % MATRIX_ROWS; + uint8_t col = i / MATRIX_ROWS; + uint8_t val = g_rgb_frame_buffer[row][col]; + + // set the pixel colour + uint8_t led[LED_HITS_TO_REMEMBER]; + uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); + for (uint8_t j = 0; j < led_count; ++j) { + if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags)) continue; + + HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)}; + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b); + } + + if (decrease_heatmap_values) { + g_rgb_frame_buffer[row][col] = qsub8(val, 1); + } + } + + return led_max < sizeof(g_rgb_frame_buffer); +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) -- cgit v1.2.3