From c98247e3dd2958bd2d8969dc75170e7e2757b895 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Tue, 2 Apr 2019 19:24:14 -0500 Subject: RGB Matrix Overhaul (#5372) * RGB Matrix overhaul Breakout of animations to separate files Integration of optimized int based math lib Overhaul of rgb_matrix.c and animations for performance * Updating effect function api for future extensions * Combined the keypresses || keyreleases define checks into a single define so I stop forgetting it where necessary * Moving define RGB_MATRIX_KEYREACTIVE_ENABLED earlier in the include chain --- quantum/rgb_matrix_animations/alpha_mods_anim.h | 26 ++++++++ quantum/rgb_matrix_animations/breathing_anim.h | 19 ++++++ quantum/rgb_matrix_animations/cycle_all_anim.h | 21 ++++++ .../rgb_matrix_animations/cycle_left_right_anim.h | 22 +++++++ quantum/rgb_matrix_animations/cycle_up_down_anim.h | 22 +++++++ quantum/rgb_matrix_animations/digital_rain_anim.h | 74 ++++++++++++++++++++++ quantum/rgb_matrix_animations/dual_beacon_anim.h | 24 +++++++ .../rgb_matrix_animations/gradient_up_down_anim.h | 22 +++++++ .../jellybean_raindrops_anim.h | 30 +++++++++ .../rgb_matrix_animations/rainbow_beacon_anim.h | 24 +++++++ .../rainbow_moving_chevron_anim.h | 22 +++++++ .../rgb_matrix_animations/rainbow_pinwheels_anim.h | 24 +++++++ quantum/rgb_matrix_animations/raindrops_anim.h | 40 ++++++++++++ quantum/rgb_matrix_animations/solid_color_anim.h | 14 ++++ .../rgb_matrix_animations/solid_reactive_anim.h | 33 ++++++++++ .../solid_reactive_simple_anim.h | 32 ++++++++++ quantum/rgb_matrix_animations/solid_splash_anim.h | 42 ++++++++++++ quantum/rgb_matrix_animations/splash_anim.h | 44 +++++++++++++ 18 files changed, 535 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/cycle_all_anim.h create mode 100644 quantum/rgb_matrix_animations/cycle_left_right_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_up_down_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/solid_color_anim.h create mode 100644 quantum/rgb_matrix_animations/solid_reactive_anim.h create mode 100644 quantum/rgb_matrix_animations/solid_reactive_simple_anim.h create mode 100644 quantum/rgb_matrix_animations/solid_splash_anim.h create mode 100644 quantum/rgb_matrix_animations/splash_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..cc1914d7f4 --- /dev/null +++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h @@ -0,0 +1,26 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS + +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +// alphas = color1, mods = color2 +bool rgb_matrix_alphas_mods(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; + RGB rgb1 = hsv_to_rgb(hsv); + hsv.h += rgb_matrix_config.speed; + RGB rgb2 = hsv_to_rgb(hsv); + + for (uint8_t i = led_min; i < led_max; i++) { + if (g_rgb_leds[i].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 // 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..fb90b66bdf --- /dev/null +++ b/quantum/rgb_matrix_animations/breathing_anim.h @@ -0,0 +1,19 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_BREATHING + +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_breathing(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 8); + uint8_t val = scale8(abs8(sin8(time) - 128) * 2, rgb_matrix_config.val); + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, val }; + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = led_min; i < led_max; i++) { + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // DISABLE_RGB_MATRIX_BREATHING 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..5c18cfa0c9 --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h @@ -0,0 +1,21 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_cycle_all(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++) { + hsv.h = time; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#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..f519aeb476 --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_cycle_left_right(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++) { + point_t point = g_rgb_leds[i].point; + hsv.h = point.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; +} + +#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT 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..8b91d890de --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_cycle_up_down(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++) { + point_t point = g_rgb_leds[i].point; + hsv.h = point.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; +} + +#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..4ba3c1c87d --- /dev/null +++ b/quantum/rgb_matrix_animations/digital_rain_anim.h @@ -0,0 +1,74 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN + +#ifndef RGB_DIGITAL_RAIN_DROPS + // lower the number for denser effect/wider keyboard + #define RGB_DIGITAL_RAIN_DROPS 24 +#endif + +bool rgb_matrix_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 map[MATRIX_COLS][MATRIX_ROWS] = {{0}}; + static uint8_t drop = 0; + + if (params->init) { + rgb_matrix_set_color_all(0, 0, 0); + memset(map, 0, sizeof map); + 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 + map[col][row] = max_intensity; + } + else if (map[col][row] > 0 && map[col][row] < max_intensity) { + // neither fully bright nor dark, decay it + map[col][row]--; + } + // 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 (map[col][row] > pure_green_intensity) { + const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (map[col][row] - 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 * map[col][row] / 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 && map[col][row] == max_intensity) { + map[col][row]--; + } + // check if the pixel above is bright + if (map[col][row - 1] == max_intensity) { + // allow old bright pixel to decay + map[col][row - 1]--; + // make this pixel bright + map[col][row] = max_intensity; + } + } + } + } + return false; +} + +#endif // 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..dda3157809 --- /dev/null +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_dual_beacon(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + 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++) { + point_t point = g_rgb_leds[i].point; + hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * 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; +} + +#endif // DISABLE_RGB_MATRIX_DUAL_BEACON 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..11498e22f5 --- /dev/null +++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN + +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_gradient_up_down(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 scale = scale8(64, rgb_matrix_config.speed); + for (uint8_t i = led_min; i < led_max; i++) { + point_t point = g_rgb_leds[i].point; + // 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.hue + scale * (point.y >> 4); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} +#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN 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..01ff5c2306 --- /dev/null +++ b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h @@ -0,0 +1,30 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +static void jellybean_raindrops_set_color(int i) { + HSV hsv = { rand() & 0xFF , rand() & 0xFF, rgb_matrix_config.val }; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); +} + +bool rgb_matrix_jellybean_raindrops(effect_params_t* params) { + if (!params->init) { + // Change one LED every tick, make sure speed is not 0 + if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { + jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL); + } + return false; + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + for (int i = led_min; i < led_max; i++) { + jellybean_raindrops_set_color(i); + } + return led_max < DRIVER_LED_TOTAL; +} + +#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..3c15e64ab6 --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_rainbow_beacon(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + 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++) { + point_t point = g_rgb_leds[i].point; + hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * 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; +} + +#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..0d11d52802 --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h @@ -0,0 +1,22 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_rainbow_moving_chevron(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++) { + point_t point = g_rgb_leds[i].point; + hsv.h = abs8(point.y - 32) + (point.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; +} + +#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..d7cd42cbe8 --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h @@ -0,0 +1,24 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS + +extern rgb_counters_t g_rgb_counters; +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + 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++) { + point_t point = g_rgb_leds[i].point; + hsv.h = ((point.y - 32) * cos_value + (56 - abs8(point.x - 112)) * 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; +} + +#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..fc721375b0 --- /dev/null +++ b/quantum/rgb_matrix_animations/raindrops_anim.h @@ -0,0 +1,40 @@ +#pragma once +#ifndef DISABLE_RGB_MATRIX_RAINDROPS +#include "rgb_matrix_types.h" + +extern rgb_counters_t g_rgb_counters; +extern rgb_config_t rgb_matrix_config; + +static void raindrops_set_color(int i) { + HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val }; + + // Take the shortest path between hues + int16_t deltaH = ((rgb_matrix_config.hue + 180) % 360 - rgb_matrix_config.hue) / 4; + if (deltaH > 127) { + deltaH -= 256; + } else if (deltaH < -127) { + deltaH += 256; + } + + hsv.h = rgb_matrix_config.hue + (deltaH * (rand() & 0x03)); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); +} + +bool rgb_matrix_raindrops(effect_params_t* params) { + if (!params->init) { + // Change one LED every tick, make sure speed is not 0 + if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { + raindrops_set_color(rand() % DRIVER_LED_TOTAL); + } + return false; + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + for (int i = led_min; i < led_max; i++) { + raindrops_set_color(i); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // DISABLE_RGB_MATRIX_RAINDROPS 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..24a197beb3 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_color_anim.h @@ -0,0 +1,14 @@ +#pragma once + +extern rgb_config_t rgb_matrix_config; + +bool rgb_matrix_solid_color(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = led_min; i < led_max; i++) { + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} 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..220e542331 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h @@ -0,0 +1,33 @@ +#pragma once +#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE + +extern rgb_config_t rgb_matrix_config; +extern last_hit_t g_last_hit_tracker; + +bool rgb_matrix_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++) { + uint16_t tick = max_tick; + for(uint8_t j = 0; j < g_last_hit_tracker.count; 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); + 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; +} + +#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +#endif // defined(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..e84cd69392 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h @@ -0,0 +1,32 @@ +#pragma once +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE + +extern rgb_config_t rgb_matrix_config; +extern last_hit_t g_last_hit_tracker; + +bool rgb_matrix_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++) { + uint16_t tick = max_tick; + for(uint8_t j = 0; j < g_last_hit_tracker.count; 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); + 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; +} + +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +#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..82ac055b88 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_splash_anim.h @@ -0,0 +1,42 @@ +#pragma once +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +#if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) + +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; +extern last_hit_t g_last_hit_tracker; + +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++) { + hsv.v = 0; + point_t point = g_rgb_leds[i].point; + for (uint8_t j = start; j < count; j++) { + int16_t dx = point.x - g_last_hit_tracker.x[j]; + int16_t dy = point.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) + 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; +} + +bool rgb_matrix_solid_multisplash(effect_params_t* params) { + return rgb_matrix_solid_multisplash_range(0, params); +} + +bool rgb_matrix_solid_splash(effect_params_t* params) { + return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); +} + +#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..829d30eef5 --- /dev/null +++ b/quantum/rgb_matrix_animations/splash_anim.h @@ -0,0 +1,44 @@ +#pragma once +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +#if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) + +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; +extern last_hit_t g_last_hit_tracker; + +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++) { + hsv.h = rgb_matrix_config.hue; + hsv.v = 0; + point_t point = g_rgb_leds[i].point; + for (uint8_t j = start; j < count; j++) { + int16_t dx = point.x - g_last_hit_tracker.x[j]; + int16_t dy = point.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) + 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; +} + +bool rgb_matrix_multisplash(effect_params_t* params) { + return rgb_matrix_multisplash_range(0, params); +} + +bool rgb_matrix_splash(effect_params_t* params) { + return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); +} + +#endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED -- cgit v1.2.3