diff options
| author | XScorpion2 <rcalt2vt@gmail.com> | 2019-04-02 19:24:14 -0500 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-04-02 17:24:14 -0700 |
| commit | c98247e3dd2958bd2d8969dc75170e7e2757b895 (patch) | |
| tree | a566de223a9501809e1059c522b52adf7d37fe74 /quantum/rgb_matrix_animations | |
| parent | 68d8bb2b3fb8a35fda164539d27754b3f74e0819 (diff) | |
| download | qmk_firmware-c98247e3dd2958bd2d8969dc75170e7e2757b895.tar.gz qmk_firmware-c98247e3dd2958bd2d8969dc75170e7e2757b895.zip | |
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
Diffstat (limited to 'quantum/rgb_matrix_animations')
18 files changed, 535 insertions, 0 deletions
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 000000000..cc1914d7f --- /dev/null +++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS | ||
| 3 | |||
| 4 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | |||
| 7 | // alphas = color1, mods = color2 | ||
| 8 | bool rgb_matrix_alphas_mods(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | RGB rgb1 = hsv_to_rgb(hsv); | ||
| 13 | hsv.h += rgb_matrix_config.speed; | ||
| 14 | RGB rgb2 = hsv_to_rgb(hsv); | ||
| 15 | |||
| 16 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 17 | if (g_rgb_leds[i].modifier) { | ||
| 18 | rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b); | ||
| 19 | } else { | ||
| 20 | rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b); | ||
| 21 | } | ||
| 22 | } | ||
| 23 | return led_max < DRIVER_LED_TOTAL; | ||
| 24 | } | ||
| 25 | |||
| 26 | #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 000000000..fb90b66bd --- /dev/null +++ b/quantum/rgb_matrix_animations/breathing_anim.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_BREATHING | ||
| 3 | |||
| 4 | extern rgb_config_t rgb_matrix_config; | ||
| 5 | |||
| 6 | bool rgb_matrix_breathing(effect_params_t* params) { | ||
| 7 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 8 | |||
| 9 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 8); | ||
| 10 | uint8_t val = scale8(abs8(sin8(time) - 128) * 2, rgb_matrix_config.val); | ||
| 11 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, val }; | ||
| 12 | RGB rgb = hsv_to_rgb(hsv); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 15 | } | ||
| 16 | return led_max < DRIVER_LED_TOTAL; | ||
| 17 | } | ||
| 18 | |||
| 19 | #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 000000000..5c18cfa0c --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_cycle_all(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | hsv.h = time; | ||
| 15 | RGB rgb = hsv_to_rgb(hsv); | ||
| 16 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 17 | } | ||
| 18 | return led_max < DRIVER_LED_TOTAL; | ||
| 19 | } | ||
| 20 | |||
| 21 | #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 000000000..f519aeb47 --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_cycle_left_right(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | point_t point = g_rgb_leds[i].point; | ||
| 15 | hsv.h = point.x - time; | ||
| 16 | RGB rgb = hsv_to_rgb(hsv); | ||
| 17 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 18 | } | ||
| 19 | return led_max < DRIVER_LED_TOTAL; | ||
| 20 | } | ||
| 21 | |||
| 22 | #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 000000000..8b91d890d --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_cycle_up_down(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | point_t point = g_rgb_leds[i].point; | ||
| 15 | hsv.h = point.y - time; | ||
| 16 | RGB rgb = hsv_to_rgb(hsv); | ||
| 17 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 18 | } | ||
| 19 | return led_max < DRIVER_LED_TOTAL; | ||
| 20 | } | ||
| 21 | |||
| 22 | #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 000000000..4ba3c1c87 --- /dev/null +++ b/quantum/rgb_matrix_animations/digital_rain_anim.h | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN | ||
| 3 | |||
| 4 | #ifndef RGB_DIGITAL_RAIN_DROPS | ||
| 5 | // lower the number for denser effect/wider keyboard | ||
| 6 | #define RGB_DIGITAL_RAIN_DROPS 24 | ||
| 7 | #endif | ||
| 8 | |||
| 9 | bool rgb_matrix_digital_rain(effect_params_t* params) { | ||
| 10 | // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain | ||
| 11 | const uint8_t drop_ticks = 28; | ||
| 12 | const uint8_t pure_green_intensity = 0xd0; | ||
| 13 | const uint8_t max_brightness_boost = 0xc0; | ||
| 14 | const uint8_t max_intensity = 0xff; | ||
| 15 | |||
| 16 | static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}}; | ||
| 17 | static uint8_t drop = 0; | ||
| 18 | |||
| 19 | if (params->init) { | ||
| 20 | rgb_matrix_set_color_all(0, 0, 0); | ||
| 21 | memset(map, 0, sizeof map); | ||
| 22 | drop = 0; | ||
| 23 | } | ||
| 24 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 25 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 26 | if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { | ||
| 27 | // top row, pixels have just fallen and we're | ||
| 28 | // making a new rain drop in this column | ||
| 29 | map[col][row] = max_intensity; | ||
| 30 | } | ||
| 31 | else if (map[col][row] > 0 && map[col][row] < max_intensity) { | ||
| 32 | // neither fully bright nor dark, decay it | ||
| 33 | map[col][row]--; | ||
| 34 | } | ||
| 35 | // set the pixel colour | ||
| 36 | uint8_t led[LED_HITS_TO_REMEMBER]; | ||
| 37 | uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); | ||
| 38 | |||
| 39 | // TODO: multiple leds are supported mapped to the same row/column | ||
| 40 | if (led_count > 0) { | ||
| 41 | if (map[col][row] > pure_green_intensity) { | ||
| 42 | const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity)); | ||
| 43 | rgb_matrix_set_color(led[0], boost, max_intensity, boost); | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity); | ||
| 47 | rgb_matrix_set_color(led[0], 0, green, 0); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | if (++drop > drop_ticks) { | ||
| 53 | // reset drop timer | ||
| 54 | drop = 0; | ||
| 55 | for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { | ||
| 56 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 57 | // if ths is on the bottom row and bright allow decay | ||
| 58 | if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) { | ||
| 59 | map[col][row]--; | ||
| 60 | } | ||
| 61 | // check if the pixel above is bright | ||
| 62 | if (map[col][row - 1] == max_intensity) { | ||
| 63 | // allow old bright pixel to decay | ||
| 64 | map[col][row - 1]--; | ||
| 65 | // make this pixel bright | ||
| 66 | map[col][row] = max_intensity; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | return false; | ||
| 72 | } | ||
| 73 | |||
| 74 | #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 000000000..dda315780 --- /dev/null +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_dual_beacon(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | int8_t cos_value = cos8(time) - 128; | ||
| 14 | int8_t sin_value = sin8(time) - 128; | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * sin_value) / 128 + rgb_matrix_config.hue; | ||
| 18 | RGB rgb = hsv_to_rgb(hsv); | ||
| 19 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 20 | } | ||
| 21 | return led_max < DRIVER_LED_TOTAL; | ||
| 22 | } | ||
| 23 | |||
| 24 | #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 000000000..11498e22f --- /dev/null +++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN | ||
| 3 | |||
| 4 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | |||
| 7 | bool rgb_matrix_gradient_up_down(effect_params_t* params) { | ||
| 8 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 9 | |||
| 10 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 11 | uint8_t scale = scale8(64, rgb_matrix_config.speed); | ||
| 12 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 13 | point_t point = g_rgb_leds[i].point; | ||
| 14 | // The y range will be 0..64, map this to 0..4 | ||
| 15 | // Relies on hue being 8-bit and wrapping | ||
| 16 | hsv.h = rgb_matrix_config.hue + scale * (point.y >> 4); | ||
| 17 | RGB rgb = hsv_to_rgb(hsv); | ||
| 18 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 19 | } | ||
| 20 | return led_max < DRIVER_LED_TOTAL; | ||
| 21 | } | ||
| 22 | #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 000000000..01ff5c230 --- /dev/null +++ b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | static void jellybean_raindrops_set_color(int i) { | ||
| 9 | HSV hsv = { rand() & 0xFF , rand() & 0xFF, rgb_matrix_config.val }; | ||
| 10 | RGB rgb = hsv_to_rgb(hsv); | ||
| 11 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 12 | } | ||
| 13 | |||
| 14 | bool rgb_matrix_jellybean_raindrops(effect_params_t* params) { | ||
| 15 | if (!params->init) { | ||
| 16 | // Change one LED every tick, make sure speed is not 0 | ||
| 17 | if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { | ||
| 18 | jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL); | ||
| 19 | } | ||
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 24 | for (int i = led_min; i < led_max; i++) { | ||
| 25 | jellybean_raindrops_set_color(i); | ||
| 26 | } | ||
| 27 | return led_max < DRIVER_LED_TOTAL; | ||
| 28 | } | ||
| 29 | |||
| 30 | #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 000000000..3c15e64ab --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_rainbow_beacon(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | int16_t cos_value = 2 * (cos8(time) - 128); | ||
| 14 | int16_t sin_value = 2 * (sin8(time) - 128); | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * sin_value) / 128 + rgb_matrix_config.hue; | ||
| 18 | RGB rgb = hsv_to_rgb(hsv); | ||
| 19 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 20 | } | ||
| 21 | return led_max < DRIVER_LED_TOTAL; | ||
| 22 | } | ||
| 23 | |||
| 24 | #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 000000000..0d11d5280 --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | point_t point = g_rgb_leds[i].point; | ||
| 15 | hsv.h = abs8(point.y - 32) + (point.x - time) + rgb_matrix_config.hue; | ||
| 16 | RGB rgb = hsv_to_rgb(hsv); | ||
| 17 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 18 | } | ||
| 19 | return led_max < DRIVER_LED_TOTAL; | ||
| 20 | } | ||
| 21 | |||
| 22 | #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 000000000..d7cd42cbe --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | int16_t cos_value = 3 * (cos8(time) - 128); | ||
| 14 | int16_t sin_value = 3 * (sin8(time) - 128); | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | hsv.h = ((point.y - 32) * cos_value + (56 - abs8(point.x - 112)) * sin_value) / 128 + rgb_matrix_config.hue; | ||
| 18 | RGB rgb = hsv_to_rgb(hsv); | ||
| 19 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 20 | } | ||
| 21 | return led_max < DRIVER_LED_TOTAL; | ||
| 22 | } | ||
| 23 | |||
| 24 | #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 000000000..fc721375b --- /dev/null +++ b/quantum/rgb_matrix_animations/raindrops_anim.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS | ||
| 3 | #include "rgb_matrix_types.h" | ||
| 4 | |||
| 5 | extern rgb_counters_t g_rgb_counters; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | static void raindrops_set_color(int i) { | ||
| 9 | HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 10 | |||
| 11 | // Take the shortest path between hues | ||
| 12 | int16_t deltaH = ((rgb_matrix_config.hue + 180) % 360 - rgb_matrix_config.hue) / 4; | ||
| 13 | if (deltaH > 127) { | ||
| 14 | deltaH -= 256; | ||
| 15 | } else if (deltaH < -127) { | ||
| 16 | deltaH += 256; | ||
| 17 | } | ||
| 18 | |||
| 19 | hsv.h = rgb_matrix_config.hue + (deltaH * (rand() & 0x03)); | ||
| 20 | RGB rgb = hsv_to_rgb(hsv); | ||
| 21 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 22 | } | ||
| 23 | |||
| 24 | bool rgb_matrix_raindrops(effect_params_t* params) { | ||
| 25 | if (!params->init) { | ||
| 26 | // Change one LED every tick, make sure speed is not 0 | ||
| 27 | if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { | ||
| 28 | raindrops_set_color(rand() % DRIVER_LED_TOTAL); | ||
| 29 | } | ||
| 30 | return false; | ||
| 31 | } | ||
| 32 | |||
| 33 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 34 | for (int i = led_min; i < led_max; i++) { | ||
| 35 | raindrops_set_color(i); | ||
| 36 | } | ||
| 37 | return led_max < DRIVER_LED_TOTAL; | ||
| 38 | } | ||
| 39 | |||
| 40 | #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 000000000..24a197beb --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_color_anim.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | extern rgb_config_t rgb_matrix_config; | ||
| 4 | |||
| 5 | bool rgb_matrix_solid_color(effect_params_t* params) { | ||
| 6 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 7 | |||
| 8 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 9 | RGB rgb = hsv_to_rgb(hsv); | ||
| 10 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 11 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 12 | } | ||
| 13 | return led_max < DRIVER_LED_TOTAL; | ||
| 14 | } | ||
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 000000000..220e54233 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #pragma once | ||
| 2 | #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) | ||
| 3 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE | ||
| 4 | |||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | extern last_hit_t g_last_hit_tracker; | ||
| 7 | |||
| 8 | bool rgb_matrix_solid_reactive(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val }; | ||
| 12 | // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 | ||
| 13 | uint16_t max_tick = 65535 / rgb_matrix_config.speed; | ||
| 14 | // Relies on hue being 8-bit and wrapping | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | uint16_t tick = max_tick; | ||
| 17 | for(uint8_t j = 0; j < g_last_hit_tracker.count; j++) { | ||
| 18 | if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { | ||
| 19 | tick = g_last_hit_tracker.tick[j]; | ||
| 20 | break; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); | ||
| 25 | hsv.h = rgb_matrix_config.hue + qsub8(130, offset); | ||
| 26 | RGB rgb = hsv_to_rgb(hsv); | ||
| 27 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 28 | } | ||
| 29 | return led_max < DRIVER_LED_TOTAL; | ||
| 30 | } | ||
| 31 | |||
| 32 | #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 33 | #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 000000000..e84cd6939 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 3 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 4 | |||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | extern last_hit_t g_last_hit_tracker; | ||
| 7 | |||
| 8 | bool rgb_matrix_solid_reactive_simple(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; | ||
| 12 | // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 | ||
| 13 | uint16_t max_tick = 65535 / rgb_matrix_config.speed; | ||
| 14 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 15 | uint16_t tick = max_tick; | ||
| 16 | for(uint8_t j = 0; j < g_last_hit_tracker.count; j++) { | ||
| 17 | if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { | ||
| 18 | tick = g_last_hit_tracker.tick[j]; | ||
| 19 | break; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); | ||
| 24 | hsv.v = scale8(255 - offset, rgb_matrix_config.val); | ||
| 25 | RGB rgb = hsv_to_rgb(hsv); | ||
| 26 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 27 | } | ||
| 28 | return led_max < DRIVER_LED_TOTAL; | ||
| 29 | } | ||
| 30 | |||
| 31 | #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 32 | #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 000000000..82ac055b8 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_splash_anim.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 3 | #if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) | ||
| 4 | |||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | extern last_hit_t g_last_hit_tracker; | ||
| 8 | |||
| 9 | static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* params) { | ||
| 10 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 11 | |||
| 12 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; | ||
| 13 | uint8_t count = g_last_hit_tracker.count; | ||
| 14 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 15 | hsv.v = 0; | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | for (uint8_t j = start; j < count; j++) { | ||
| 18 | int16_t dx = point.x - g_last_hit_tracker.x[j]; | ||
| 19 | int16_t dy = point.y - g_last_hit_tracker.y[j]; | ||
| 20 | uint8_t dist = sqrt16(dx * dx + dy * dy); | ||
| 21 | uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; | ||
| 22 | if (effect > 255) | ||
| 23 | effect = 255; | ||
| 24 | hsv.v = qadd8(hsv.v, 255 - effect); | ||
| 25 | } | ||
| 26 | hsv.v = scale8(hsv.v, rgb_matrix_config.val); | ||
| 27 | RGB rgb = hsv_to_rgb(hsv); | ||
| 28 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 29 | } | ||
| 30 | return led_max < DRIVER_LED_TOTAL; | ||
| 31 | } | ||
| 32 | |||
| 33 | bool rgb_matrix_solid_multisplash(effect_params_t* params) { | ||
| 34 | return rgb_matrix_solid_multisplash_range(0, params); | ||
| 35 | } | ||
| 36 | |||
| 37 | bool rgb_matrix_solid_splash(effect_params_t* params) { | ||
| 38 | return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); | ||
| 39 | } | ||
| 40 | |||
| 41 | #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH) | ||
| 42 | #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 000000000..829d30eef --- /dev/null +++ b/quantum/rgb_matrix_animations/splash_anim.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 3 | #if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) | ||
| 4 | |||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | extern last_hit_t g_last_hit_tracker; | ||
| 8 | |||
| 9 | static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) { | ||
| 10 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 11 | |||
| 12 | HSV hsv = { 0, rgb_matrix_config.sat, 0 }; | ||
| 13 | uint8_t count = g_last_hit_tracker.count; | ||
| 14 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 15 | hsv.h = rgb_matrix_config.hue; | ||
| 16 | hsv.v = 0; | ||
| 17 | point_t point = g_rgb_leds[i].point; | ||
| 18 | for (uint8_t j = start; j < count; j++) { | ||
| 19 | int16_t dx = point.x - g_last_hit_tracker.x[j]; | ||
| 20 | int16_t dy = point.y - g_last_hit_tracker.y[j]; | ||
| 21 | uint8_t dist = sqrt16(dx * dx + dy * dy); | ||
| 22 | uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; | ||
| 23 | if (effect > 255) | ||
| 24 | effect = 255; | ||
| 25 | hsv.h += effect; | ||
| 26 | hsv.v = qadd8(hsv.v, 255 - effect); | ||
| 27 | } | ||
| 28 | hsv.v = scale8(hsv.v, rgb_matrix_config.val); | ||
| 29 | RGB rgb = hsv_to_rgb(hsv); | ||
| 30 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 31 | } | ||
| 32 | return led_max < DRIVER_LED_TOTAL; | ||
| 33 | } | ||
| 34 | |||
| 35 | bool rgb_matrix_multisplash(effect_params_t* params) { | ||
| 36 | return rgb_matrix_multisplash_range(0, params); | ||
| 37 | } | ||
| 38 | |||
| 39 | bool rgb_matrix_splash(effect_params_t* params) { | ||
| 40 | return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); | ||
| 41 | } | ||
| 42 | |||
| 43 | #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) | ||
| 44 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
