From 4b5a0375d462b85e6777881039d14c078b287b47 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Mon, 6 May 2019 17:06:43 -0500 Subject: [PATCH 01/19] Fix issuse with OLED Driver and Split Keyboard code --- changelog.md | 1 + quantum/quantum.c | 16 ---------------- quantum/split_common/matrix.c | 2 +- tmk_core/common/keyboard.c | 19 +++++++++++++++++++ 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index cdebe64f43..badca9920f 100644 --- a/changelog.md +++ b/changelog.md @@ -16,3 +16,4 @@ 05-05-2019 - New keycode macro (XP) for shifted character pairs using UNICODEMAP, and bugfixes/improvements 05-05-2019 - Add `LINK_TIME_OPTIMIZATION_ENABLE` to enable LTO and disable problematic features that cause LTO to fail 05-05-2019 - Fix issue with Space Cadet +05-06-2019 - Changes to Split Common and OLED code diff --git a/quantum/quantum.c b/quantum/quantum.c index 2d21bf0773..20762b1126 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -247,12 +247,6 @@ bool process_record_quantum(keyrecord_t *record) { preprocess_tap_dance(keycode, record); #endif - #if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT) - // Wake up oled if user is using those fabulous keys! - if (record->event.pressed) - oled_on(); - #endif - if (!( #if defined(KEY_LOCK_ENABLE) // Must run first to be able to mask key_up events. @@ -976,9 +970,6 @@ void matrix_init_quantum() { #ifdef OUTPUT_AUTO_ENABLE set_output(OUTPUT_AUTO); #endif - #ifdef OLED_DRIVER_ENABLE - oled_init(OLED_ROTATION_0); - #endif matrix_init_kb(); } @@ -1015,10 +1006,6 @@ void matrix_scan_quantum() { haptic_task(); #endif - #ifdef OLED_DRIVER_ENABLE - oled_task(); - #endif - matrix_scan_kb(); } #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN) @@ -1109,9 +1096,7 @@ void backlight_task(void) { #endif #endif -#else // pwm through timer -#define TIMER_TOP 0xFFFFU // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { @@ -1158,7 +1143,6 @@ void backlight_task(void) {} #define BREATHING_NO_HALT 0 #define BREATHING_HALT_OFF 1 -#define BREATHING_HALT_ON 2 #define BREATHING_STEPS 128 static uint8_t breathing_period = BREATHING_PERIOD; diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index eb110bd23a..3c3daf3d3b 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c @@ -299,7 +299,7 @@ uint8_t _matrix_scan(void) { debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); - return 1; + return (uint8_t)changed; } uint8_t matrix_scan(void) { diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 52546866eb..85d2525480 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -75,6 +75,9 @@ along with this program. If not, see . #ifdef QWIIC_ENABLE # include "qwiic.h" #endif +#ifdef OLED_DRIVER_ENABLE + #include "oled_driver.h" +#endif #ifdef VELOCIKEY_ENABLE #include "velocikey.h" #endif @@ -205,6 +208,9 @@ void keyboard_init(void) { #ifdef QWIIC_ENABLE qwiic_init(); #endif +#ifdef OLED_DRIVER_ENABLE + oled_init(OLED_ROTATION_0); +#endif #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif @@ -262,7 +268,11 @@ void keyboard_task(void) uint8_t keys_processed = 0; #endif +#if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT) + uint8_t ret = matrix_scan(); +#else matrix_scan(); +#endif if (is_keyboard_master()) { for (uint8_t r = 0; r < MATRIX_ROWS; r++) { @@ -306,6 +316,15 @@ MATRIX_LOOP_END: qwiic_task(); #endif +#ifdef OLED_DRIVER_ENABLE + oled_task(); +#ifndef OLED_DISABLE_TIMEOUT + // Wake up oled if user is using those fabulous keys! + if (ret) + oled_on(); +#endif +#endif + #ifdef MOUSEKEY_ENABLE // mousekey repeat & acceleration mousekey_task(); From be58a6847364a9a8243a77b5398e9c209628d1ef Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 6 May 2019 08:35:01 -0700 Subject: [PATCH 02/19] Re-fix Mousekey Movements (#5740) * Re-fix Mousekey Movements After the new movement model was instroduced, it broke diagonal momement, again. Reapplying fix from #3147 to both old and new acceleration method. * Make diagonal mouse report checks more readable Co-Authored-By: drashna --- changelog.md | 1 + tmk_core/common/mousekey.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index cdebe64f43..053d554125 100644 --- a/changelog.md +++ b/changelog.md @@ -16,3 +16,4 @@ 05-05-2019 - New keycode macro (XP) for shifted character pairs using UNICODEMAP, and bugfixes/improvements 05-05-2019 - Add `LINK_TIME_OPTIMIZATION_ENABLE` to enable LTO and disable problematic features that cause LTO to fail 05-05-2019 - Fix issue with Space Cadet +05-06-2019 - More readable fix of Mousekeys issue diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c index 5b85268a03..bb08576b9f 100644 --- a/tmk_core/common/mousekey.c +++ b/tmk_core/common/mousekey.c @@ -114,9 +114,9 @@ void mousekey_task(void) { /* diagonal move [1/sqrt(2)] */ if (mouse_report.x && mouse_report.y) { mouse_report.x = times_inv_sqrt2(mouse_report.x); - mouse_report.x = mouse_report.x == 0 ? 1 : mouse_report.x; + if (mouse_report.x == 0) { mouse_report.x = 1; } mouse_report.y = times_inv_sqrt2(mouse_report.y); - mouse_report.y = mouse_report.y == 0 ? 1 : mouse_report.y; + if (mouse_report.y == 0) { mouse_report.y = 1; } } if (mouse_report.v > 0) mouse_report.v = wheel_unit(); if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1; @@ -234,9 +234,9 @@ void adjust_speed(void) { // adjust for diagonals if (mouse_report.x && mouse_report.y) { mouse_report.x = times_inv_sqrt2(mouse_report.x); - mouse_report.x = mouse_report.x == 0 ? 1 : mouse_report.x; + if (mouse_report.x == 0) { mouse_report.x = 1; } mouse_report.y = times_inv_sqrt2(mouse_report.y); - mouse_report.y = mouse_report.y == 0 ? 1 : mouse_report.y; + if (mouse_report.y == 0) { mouse_report.y = 1; } } if (mouse_report.h && mouse_report.v) { mouse_report.h = times_inv_sqrt2(mouse_report.h); From 9ab77d760cf309bb8b6ec17742c96ceae4de8965 Mon Sep 17 00:00:00 2001 From: skullydazed Date: Mon, 6 May 2019 10:56:34 -0700 Subject: [PATCH 03/19] Make python a required build dependency (#5784) * Make python a required build dependency * Add missing color * fixup sabayon linux per @BlitzKraft --- Makefile | 2 ++ changelog.md | 1 + message.mk | 4 ++++ util/freebsd_install.sh | 3 ++- util/linux_install.sh | 9 ++++++++- util/macos_install.sh | 2 +- util/msys2_install.sh | 2 +- 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index bf3abbe528..a6c3ee35b7 100644 --- a/Makefile +++ b/Makefile @@ -534,6 +534,8 @@ endef %: # Check if we have the CMP tool installed cmp $(ROOT_DIR)/Makefile $(ROOT_DIR)/Makefile >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; + # Ensure that python3 is installed. This check can be removed after python is used in more places. + if ! python3 --version 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; fi # Check if the submodules are dirty, and display a warning if they are ifndef SKIP_GIT if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 1 --init lib/chibios; fi diff --git a/changelog.md b/changelog.md index cdebe64f43..c550b5f3b6 100644 --- a/changelog.md +++ b/changelog.md @@ -16,3 +16,4 @@ 05-05-2019 - New keycode macro (XP) for shifted character pairs using UNICODEMAP, and bugfixes/improvements 05-05-2019 - Add `LINK_TIME_OPTIMIZATION_ENABLE` to enable LTO and disable problematic features that cause LTO to fail 05-05-2019 - Fix issue with Space Cadet +05-06-2019 - Add Python dependency to build scripts diff --git a/message.mk b/message.mk index 71f37be0b5..734de86457 100644 --- a/message.mk +++ b/message.mk @@ -81,3 +81,7 @@ MSG_FILE_TOO_BIG = $(ERROR_COLOR)The firmware is too large!$(NO_COLOR) $(CURRENT MSG_FILE_TOO_SMALL = The firmware is too small! $(CURRENT_SIZE)/$(MAX_SIZE)\n MSG_FILE_JUST_RIGHT = The firmware size is fine - $(CURRENT_SIZE)/$(MAX_SIZE) ($(FREE_SIZE) bytes free)\n MSG_FILE_NEAR_LIMIT = The firmware size is approaching the maximum - $(CURRENT_SIZE)/$(MAX_SIZE) ($(FREE_SIZE) bytes free)\n +MSG_PYTHON_MISSING = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \ + Python 3 is not installed. It will be required by a future version\n\ + of qmk_firmware.\n\n\ + Please run $(BOLD)util/qmk_install.sh$(NO_COLOR) to install all the dependencies QMK requires.\n\n diff --git a/util/freebsd_install.sh b/util/freebsd_install.sh index 25ea80a7fc..c8696e8cc7 100755 --- a/util/freebsd_install.sh +++ b/util/freebsd_install.sh @@ -15,4 +15,5 @@ pkg install -y \ arm-none-eabi-gcc \ arm-none-eabi-binutils \ arm-none-eabi-newlib \ - diffutils + diffutils \ + python3 diff --git a/util/linux_install.sh b/util/linux_install.sh index d6e6b86cdc..53f50d7f18 100755 --- a/util/linux_install.sh +++ b/util/linux_install.sh @@ -25,6 +25,7 @@ if grep ID /etc/os-release | grep -qE "fedora"; then kernel-headers \ make \ perl \ + python3 \ unzip \ wget \ zip @@ -47,6 +48,7 @@ elif grep ID /etc/os-release | grep -qE 'debian|ubuntu'; then gcc-avr \ git \ libnewlib-arm-none-eabi \ + python3 \ unzip \ wget \ zip @@ -66,6 +68,7 @@ elif grep ID /etc/os-release | grep -q 'arch\|manjaro'; then diffutils \ gcc \ git \ + python \ unzip \ wget \ zip @@ -87,6 +90,7 @@ elif grep ID /etc/os-release | grep -q gentoo; then app-arch/zip \ app-mobilephone/dfu-util \ dev-embedded/avrdude \ + dev-lang/python:3.5 \ net-misc/wget \ sys-devel/gcc \ sys-devel/crossdev @@ -102,6 +106,7 @@ elif grep ID /etc/os-release | grep -q sabayon; then app-arch/zip \ app-mobilephone/dfu-util \ dev-embedded/avrdude \ + dev-lang/python \ net-misc/wget \ sys-devel/gcc \ sys-devel/crossdev @@ -125,6 +130,7 @@ elif grep ID /etc/os-release | grep -qE "opensuse|tumbleweed"; then dfu-tool \ dfu-programmer \ gcc \ + python3 \ unzip \ wget \ zip @@ -143,7 +149,8 @@ elif grep ID /etc/os-release | grep -q slackware; then dfu-util \ arm-binutils \ arm-gcc \ - newlib + newlib \ + python3 echo "Done!" else echo "Quitting..." diff --git a/util/macos_install.sh b/util/macos_install.sh index d2629a8cb4..93f3ed0b96 100755 --- a/util/macos_install.sh +++ b/util/macos_install.sh @@ -22,5 +22,5 @@ fi brew tap osx-cross/avr brew tap PX4/homebrew-px4 brew update -brew install avr-gcc@7 gcc-arm-none-eabi dfu-programmer avrdude dfu-util +brew install avr-gcc@7 gcc-arm-none-eabi dfu-programmer avrdude dfu-util python3 brew link --force avr-gcc@7 diff --git a/util/msys2_install.sh b/util/msys2_install.sh index fcb4882494..bcb628ab21 100755 --- a/util/msys2_install.sh +++ b/util/msys2_install.sh @@ -7,7 +7,7 @@ armtools=gcc-arm-none-eabi installflip=false echo "Installing dependencies needed for the installation (quazip)" -pacman --needed -S msys/unzip msys/p7zip base-devel msys/git mingw-w64-x86_64-toolchain +pacman --needed -S base-devel mingw-w64-x86_64-toolchain msys/git msys/p7zip msys/python3 msys/unzip source "$dir/win_shared_install.sh" From 6364fe4efb3c2ac402d3d189a246e4428394840c Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Tue, 30 Apr 2019 00:18:50 +0200 Subject: [PATCH 04/19] Updated rgb_led struct field modifier to flags (#5619) Updated effects to test led flags Updated massdrop to use new flags field for led toggle --- keyboards/ergodox_ez/ergodox_ez.c | 96 +++++++++---------- keyboards/planck/ez/ez.c | 66 ++++++------- quantum/rgb_matrix.c | 48 ++++------ quantum/rgb_matrix.h | 6 +- .../rgb_matrix_animations/alpha_mods_anim.h | 5 +- .../rgb_matrix_animations/breathing_anim.h | 1 + .../rgb_matrix_animations/cycle_all_anim.h | 6 +- .../cycle_left_right_anim.h | 3 +- .../cycle_up_down_anim.h | 3 +- .../rgb_matrix_animations/dual_beacon_anim.h | 3 +- .../gradient_up_down_anim.h | 3 +- .../jellybean_raindrops_anim.h | 9 +- .../rainbow_beacon_anim.h | 3 +- .../rainbow_moving_chevron_anim.h | 3 +- .../rainbow_pinwheels_anim.h | 3 +- .../rgb_matrix_animations/raindrops_anim.h | 7 +- .../rgb_matrix_animations/solid_color_anim.h | 1 + .../solid_reactive_anim.h | 1 + .../solid_reactive_cross.h | 3 +- .../solid_reactive_nexus.h | 3 +- .../solid_reactive_simple_anim.h | 1 + .../solid_reactive_wide.h | 3 +- .../rgb_matrix_animations/solid_splash_anim.h | 3 +- quantum/rgb_matrix_animations/splash_anim.h | 3 +- quantum/rgb_matrix_types.h | 22 +++-- tmk_core/protocol/arm_atsam/led_matrix.c | 4 +- 26 files changed, 161 insertions(+), 148 deletions(-) diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c index 6f4ae9fed1..13ea843022 100644 --- a/keyboards/ergodox_ez/ergodox_ez.c +++ b/keyboards/ergodox_ez/ergodox_ez.c @@ -269,64 +269,64 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { }; -const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { +rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { /*{row | col << 4} | {x=0..224, y=0..64} - | | modifier + | | flags | | | */ - {{ 8|(0<<4)}, {17.2* 8, 12.8*0}, 0}, // LED 1 on right > Key 6 - {{ 9|(0<<4)}, {17.2* 9, 12.8*0}, 0}, // LED 2 > Key 7 - {{10|(0<<4)}, {17.2*10, 12.8*0}, 0}, // LED 3 > Key 8 - {{11|(0<<4)}, {17.2*11, 12.8*0}, 0}, // LED 4 > Key 9 - {{12|(0<<4)}, {17.2*12, 12.8*0}, 0}, // LED 5 > Key 0 - - {{ 8|(1<<4)}, {17.2* 8, 12.8*1}, 0}, // LED 6 - {{ 9|(1<<4)}, {17.2* 9, 12.8*1}, 0}, // LED 7 - {{10|(1<<4)}, {17.2*10, 12.8*1}, 0}, // LED 8 - {{11|(1<<4)}, {17.2*11, 12.8*1}, 0}, // LED 9 - {{12|(1<<4)}, {17.2*12, 12.8*1}, 0}, // LED 10 - - {{ 8|(2<<4)}, {17.2* 8, 12.8*2}, 0}, // LED 11 - {{ 9|(2<<4)}, {17.2* 9, 12.8*2}, 0}, // LED 12 - {{10|(2<<4)}, {17.2*10, 12.8*2}, 0}, // LED 13 - {{11|(2<<4)}, {17.2*11, 12.8*2}, 0}, // LED 14 - {{12|(2<<4)}, {17.2*12, 12.8*2}, 0}, // LED 15 - - {{ 8|(3<<4)}, {17.2* 8, 12.8*3}, 0}, // LED 16 - {{ 9|(3<<4)}, {17.2* 9, 12.8*3}, 0}, // LED 17 - {{10|(3<<4)}, {17.2*10, 12.8*3}, 0}, // LED 18 - {{11|(3<<4)}, {17.2*11, 12.8*3}, 0}, // LED 19 - {{12|(3<<4)}, {17.2*12, 12.8*3}, 0}, // LED 20 + {{ 8|(0<<4)}, {17.2* 8, 12.8*0}, 4}, // LED 1 on right > Key 6 + {{ 9|(0<<4)}, {17.2* 9, 12.8*0}, 4}, // LED 2 > Key 7 + {{10|(0<<4)}, {17.2*10, 12.8*0}, 4}, // LED 3 > Key 8 + {{11|(0<<4)}, {17.2*11, 12.8*0}, 4}, // LED 4 > Key 9 + {{12|(0<<4)}, {17.2*12, 12.8*0}, 4}, // LED 5 > Key 0 + + {{ 8|(1<<4)}, {17.2* 8, 12.8*1}, 4}, // LED 6 + {{ 9|(1<<4)}, {17.2* 9, 12.8*1}, 4}, // LED 7 + {{10|(1<<4)}, {17.2*10, 12.8*1}, 4}, // LED 8 + {{11|(1<<4)}, {17.2*11, 12.8*1}, 4}, // LED 9 + {{12|(1<<4)}, {17.2*12, 12.8*1}, 4}, // LED 10 + + {{ 8|(2<<4)}, {17.2* 8, 12.8*2}, 4}, // LED 11 + {{ 9|(2<<4)}, {17.2* 9, 12.8*2}, 4}, // LED 12 + {{10|(2<<4)}, {17.2*10, 12.8*2}, 4}, // LED 13 + {{11|(2<<4)}, {17.2*11, 12.8*2}, 4}, // LED 14 + {{12|(2<<4)}, {17.2*12, 12.8*2}, 4}, // LED 15 + + {{ 8|(3<<4)}, {17.2* 8, 12.8*3}, 4}, // LED 16 + {{ 9|(3<<4)}, {17.2* 9, 12.8*3}, 4}, // LED 17 + {{10|(3<<4)}, {17.2*10, 12.8*3}, 4}, // LED 18 + {{11|(3<<4)}, {17.2*11, 12.8*3}, 4}, // LED 19 + {{12|(3<<4)}, {17.2*12, 12.8*3}, 4}, // LED 20 {{ 9|(4<<4)}, {17.2* 9, 12.8*4}, 1}, // LED 21 {{10|(4<<4)}, {17.2*10, 12.8*4}, 1}, // LED 22 {{11|(4<<4)}, {17.2*11, 12.8*4}, 1}, // LED 23 {{12|(4<<4)}, {17.2*12, 12.8*4}, 1}, // LED 24 - {{ 5|(0<<4)}, {17.2* 5, 12.8*0}, 0}, // LED 1 on left > Key 5 - {{ 4|(0<<4)}, {17.2* 4, 12.8*0}, 0}, // LED 2 > Key 4 - {{ 3|(0<<4)}, {17.2* 3, 12.8*0}, 0}, // LED 3 > Key 3 - {{ 2|(0<<4)}, {17.2* 2, 12.8*0}, 0}, // LED 4 > Key 2 - {{ 1|(0<<4)}, {17.2* 1, 12.8*0}, 0}, // LED 5 > Key 1 - - {{ 5|(1<<4)}, {17.2* 5, 12.8*1}, 0}, // LED 6 - {{ 4|(1<<4)}, {17.2* 4, 12.8*1}, 0}, // LED 7 - {{ 3|(1<<4)}, {17.2* 3, 12.8*1}, 0}, // LED 8 - {{ 2|(1<<4)}, {17.2* 2, 12.8*1}, 0}, // LED 9 - {{ 1|(1<<4)}, {17.2* 1, 12.8*1}, 0}, // LED 10 - - {{ 5|(2<<4)}, {17.2* 5, 12.8*2}, 0}, // LED 11 - {{ 4|(2<<4)}, {17.2* 4, 12.8*2}, 0}, // LED 12 - {{ 3|(2<<4)}, {17.2* 3, 12.8*2}, 0}, // LED 13 - {{ 2|(2<<4)}, {17.2* 2, 12.8*2}, 0}, // LED 14 - {{ 1|(2<<4)}, {17.2* 1, 12.8*2}, 0}, // LED 15 - - {{ 5|(3<<4)}, {17.2* 5, 12.8*3}, 0}, // LED 16 - {{ 4|(3<<4)}, {17.2* 4, 12.8*3}, 0}, // LED 17 - {{ 3|(3<<4)}, {17.2* 3, 12.8*3}, 0}, // LED 18 - {{ 2|(3<<4)}, {17.2* 2, 12.8*3}, 0}, // LED 19 - {{ 1|(3<<4)}, {17.2* 1, 12.8*3}, 0}, // LED 20 + {{ 5|(0<<4)}, {17.2* 5, 12.8*0}, 4}, // LED 1 on left > Key 5 + {{ 4|(0<<4)}, {17.2* 4, 12.8*0}, 4}, // LED 2 > Key 4 + {{ 3|(0<<4)}, {17.2* 3, 12.8*0}, 4}, // LED 3 > Key 3 + {{ 2|(0<<4)}, {17.2* 2, 12.8*0}, 4}, // LED 4 > Key 2 + {{ 1|(0<<4)}, {17.2* 1, 12.8*0}, 4}, // LED 5 > Key 1 + + {{ 5|(1<<4)}, {17.2* 5, 12.8*1}, 4}, // LED 6 + {{ 4|(1<<4)}, {17.2* 4, 12.8*1}, 4}, // LED 7 + {{ 3|(1<<4)}, {17.2* 3, 12.8*1}, 4}, // LED 8 + {{ 2|(1<<4)}, {17.2* 2, 12.8*1}, 4}, // LED 9 + {{ 1|(1<<4)}, {17.2* 1, 12.8*1}, 4}, // LED 10 + + {{ 5|(2<<4)}, {17.2* 5, 12.8*2}, 4}, // LED 11 + {{ 4|(2<<4)}, {17.2* 4, 12.8*2}, 4}, // LED 12 + {{ 3|(2<<4)}, {17.2* 3, 12.8*2}, 4}, // LED 13 + {{ 2|(2<<4)}, {17.2* 2, 12.8*2}, 4}, // LED 14 + {{ 1|(2<<4)}, {17.2* 1, 12.8*2}, 4}, // LED 15 + + {{ 5|(3<<4)}, {17.2* 5, 12.8*3}, 4}, // LED 16 + {{ 4|(3<<4)}, {17.2* 4, 12.8*3}, 4}, // LED 17 + {{ 3|(3<<4)}, {17.2* 3, 12.8*3}, 4}, // LED 18 + {{ 2|(3<<4)}, {17.2* 2, 12.8*3}, 4}, // LED 19 + {{ 1|(3<<4)}, {17.2* 1, 12.8*3}, 4}, // LED 20 {{ 4|(4<<4)}, {17.2* 4, 12.8*4}, 1}, // LED 21 {{ 3|(4<<4)}, {17.2* 3, 12.8*4}, 1}, // LED 22 diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c index c3b7e26170..94f5071896 100644 --- a/keyboards/planck/ez/ez.c +++ b/keyboards/planck/ez/ez.c @@ -79,49 +79,49 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { }; -const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { +rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { /*{row | col << 4} | {x=0..224, y=0..64} - | | modifier + | | flags | | | */ {{0|(0<<4)}, {20.36*0, 21.33*0}, 1}, - {{0|(1<<4)}, {20.36*1, 21.33*0}, 0}, - {{0|(2<<4)}, {20.36*2, 21.33*0}, 0}, - {{0|(3<<4)}, {20.36*3, 21.33*0}, 0}, - {{0|(4<<4)}, {20.36*4, 21.33*0}, 0}, - {{0|(5<<4)}, {20.36*5, 21.33*0}, 0}, - {{4|(0<<4)}, {20.36*6, 21.33*0}, 0}, - {{4|(1<<4)}, {20.36*7, 21.33*0}, 0}, - {{4|(2<<4)}, {20.36*8, 21.33*0}, 0}, - {{4|(3<<4)}, {20.36*9, 21.33*0}, 0}, - {{4|(4<<4)}, {20.36*10,21.33*0}, 0}, + {{0|(1<<4)}, {20.36*1, 21.33*0}, 4}, + {{0|(2<<4)}, {20.36*2, 21.33*0}, 4}, + {{0|(3<<4)}, {20.36*3, 21.33*0}, 4}, + {{0|(4<<4)}, {20.36*4, 21.33*0}, 4}, + {{0|(5<<4)}, {20.36*5, 21.33*0}, 4}, + {{4|(0<<4)}, {20.36*6, 21.33*0}, 4}, + {{4|(1<<4)}, {20.36*7, 21.33*0}, 4}, + {{4|(2<<4)}, {20.36*8, 21.33*0}, 4}, + {{4|(3<<4)}, {20.36*9, 21.33*0}, 4}, + {{4|(4<<4)}, {20.36*10,21.33*0}, 4}, {{4|(5<<4)}, {20.36*11,21.33*0}, 1}, {{1|(0<<4)}, {20.36*0, 21.33*1}, 1}, - {{1|(1<<4)}, {20.36*1, 21.33*1}, 0}, - {{1|(2<<4)}, {20.36*2, 21.33*1}, 0}, - {{1|(3<<4)}, {20.36*3, 21.33*1}, 0}, - {{1|(4<<4)}, {20.36*4, 21.33*1}, 0}, - {{1|(5<<4)}, {20.36*5, 21.33*1}, 0}, - {{5|(0<<4)}, {20.36*6, 21.33*1}, 0}, - {{5|(1<<4)}, {20.36*7, 21.33*1}, 0}, - {{5|(2<<4)}, {20.36*8, 21.33*1}, 0}, - {{5|(3<<4)}, {20.36*9, 21.33*1}, 0}, - {{5|(4<<4)}, {20.36*10,21.33*1}, 0}, + {{1|(1<<4)}, {20.36*1, 21.33*1}, 4}, + {{1|(2<<4)}, {20.36*2, 21.33*1}, 4}, + {{1|(3<<4)}, {20.36*3, 21.33*1}, 4}, + {{1|(4<<4)}, {20.36*4, 21.33*1}, 4}, + {{1|(5<<4)}, {20.36*5, 21.33*1}, 4}, + {{5|(0<<4)}, {20.36*6, 21.33*1}, 4}, + {{5|(1<<4)}, {20.36*7, 21.33*1}, 4}, + {{5|(2<<4)}, {20.36*8, 21.33*1}, 4}, + {{5|(3<<4)}, {20.36*9, 21.33*1}, 4}, + {{5|(4<<4)}, {20.36*10,21.33*1}, 4}, {{5|(5<<4)}, {20.36*11,21.33*1}, 1}, {{2|(0<<4)}, {20.36*0, 21.33*2}, 1}, - {{2|(1<<4)}, {20.36*1, 21.33*2}, 0}, - {{2|(2<<4)}, {20.36*2, 21.33*2}, 0}, - {{2|(3<<4)}, {20.36*3, 21.33*2}, 0}, - {{2|(4<<4)}, {20.36*4, 21.33*2}, 0}, - {{2|(5<<4)}, {20.36*5, 21.33*2}, 0}, - {{6|(0<<4)}, {20.36*6, 21.33*2}, 0}, - {{6|(1<<4)}, {20.36*7, 21.33*2}, 0}, - {{6|(2<<4)}, {20.36*8, 21.33*2}, 0}, - {{6|(3<<4)}, {20.36*9, 21.33*2}, 0}, - {{6|(4<<4)}, {20.36*10,21.33*2}, 0}, + {{2|(1<<4)}, {20.36*1, 21.33*2}, 4}, + {{2|(2<<4)}, {20.36*2, 21.33*2}, 4}, + {{2|(3<<4)}, {20.36*3, 21.33*2}, 4}, + {{2|(4<<4)}, {20.36*4, 21.33*2}, 4}, + {{2|(5<<4)}, {20.36*5, 21.33*2}, 4}, + {{6|(0<<4)}, {20.36*6, 21.33*2}, 4}, + {{6|(1<<4)}, {20.36*7, 21.33*2}, 4}, + {{6|(2<<4)}, {20.36*8, 21.33*2}, 4}, + {{6|(3<<4)}, {20.36*9, 21.33*2}, 4}, + {{6|(4<<4)}, {20.36*10,21.33*2}, 4}, {{6|(5<<4)}, {20.36*11,21.33*2}, 1}, {{3|(0<<4)}, {20.36*0, 21.33*3}, 1}, @@ -129,7 +129,7 @@ const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { {{3|(2<<4)}, {20.36*2, 21.33*3}, 1}, {{7|(3<<4)}, {20.36*3, 21.33*3}, 1}, {{7|(4<<4)}, {20.36*4, 21.33*3}, 1}, - {{7|(5<<4)}, {20.36*5.5,21.33*3}, 0}, + {{7|(5<<4)}, {20.36*5.5,21.33*3}, 4}, {{7|(0<<4)}, {20.36*7, 21.33*3}, 1}, {{7|(1<<4)}, {20.36*8, 21.33*3}, 1}, {{7|(2<<4)}, {20.36*9, 21.33*3}, 1}, diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 3c83463146..5528a08347 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -167,28 +167,11 @@ void rgb_matrix_update_pwm_buffers(void) { } void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { -#ifdef RGB_MATRIX_EXTRA_TOG - const bool is_key = g_rgb_leds[index].matrix_co.raw != 0xff; - if ( - (rgb_matrix_config.enable == RGB_ZONE_KEYS && !is_key) || - (rgb_matrix_config.enable == RGB_ZONE_UNDER && is_key) - ) { - rgb_matrix_driver.set_color(index, 0, 0, 0); - return; - } -#endif - rgb_matrix_driver.set_color(index, red, green, blue); } void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { -#ifdef RGB_MATRIX_EXTRA_TOG - for (int i = 0; i < DRIVER_LED_TOTAL; i++) { - rgb_matrix_set_color(i, red, green, blue); - } -#else rgb_matrix_driver.set_color_all(red, green, blue); -#endif } bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { @@ -267,7 +250,7 @@ static bool rgb_matrix_none(effect_params_t* params) { static uint8_t rgb_last_enable = UINT8_MAX; static uint8_t rgb_last_effect = UINT8_MAX; -static effect_params_t rgb_effect_params = { 0, 0 }; +static effect_params_t rgb_effect_params = { 0, 0xFF }; static rgb_task_states rgb_task_state = SYNCING; static void rgb_task_timers(void) { @@ -580,34 +563,31 @@ void rgb_matrix_set_suspend_state(bool state) { } void rgb_matrix_toggle(void) { -#ifdef RGB_MATRIX_EXTRA_TOG - rgb_matrix_config.enable++; -#else rgb_matrix_config.enable ^= 1; - if (rgb_matrix_config.enable > 1) { rgb_matrix_config.enable = 0; } // make sure that if we are treating this as a bool, that it is only 1 or 0. -#endif - if (!rgb_matrix_config.enable) { - rgb_task_state = STARTING; - } + rgb_task_state = STARTING; eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgb_matrix_enable(void) { - rgb_matrix_config.enable = 1; + rgb_matrix_enable_noeeprom(); eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgb_matrix_enable_noeeprom(void) { - rgb_matrix_config.enable = 1; + if (!rgb_matrix_config.enable) + rgb_task_state = STARTING; + rgb_matrix_config.enable = 1; } void rgb_matrix_disable(void) { - rgb_matrix_config.enable = 0; + rgb_matrix_disable_noeeprom(); eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgb_matrix_disable_noeeprom(void) { - rgb_matrix_config.enable = 0; + if (rgb_matrix_config.enable) + rgb_task_state = STARTING; + rgb_matrix_config.enable = 0; } void rgb_matrix_step(void) { @@ -668,6 +648,14 @@ void rgb_matrix_decrease_speed(void) { eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this } +led_flags_t rgb_matrix_get_flags(void) { + return rgb_effect_params.flags; +} + +void rgb_matrix_set_flags(led_flags_t flags) { + rgb_effect_params.flags = flags; +} + void rgb_matrix_mode(uint8_t mode) { rgb_matrix_config.mode = mode; rgb_task_state = STARTING; diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 775cbeac03..33665ffff2 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -54,7 +54,9 @@ uint8_t max = DRIVER_LED_TOTAL; #endif -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +#define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) continue + +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; typedef struct { @@ -209,6 +211,8 @@ void rgb_matrix_increase_val(void); void rgb_matrix_decrease_val(void); void rgb_matrix_increase_speed(void); void rgb_matrix_decrease_speed(void); +led_flags_t rgb_matrix_get_flags(void); +void rgb_matrix_set_flags(led_flags_t flags); void rgb_matrix_mode(uint8_t mode); void rgb_matrix_mode_noeeprom(uint8_t mode); uint8_t rgb_matrix_get_mode(void); diff --git a/quantum/rgb_matrix_animations/alpha_mods_anim.h b/quantum/rgb_matrix_animations/alpha_mods_anim.h index cc1914d7f4..4bd01c4fc8 100644 --- a/quantum/rgb_matrix_animations/alpha_mods_anim.h +++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h @@ -1,7 +1,7 @@ #pragma once #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; // alphas = color1, mods = color2 @@ -14,7 +14,8 @@ bool rgb_matrix_alphas_mods(effect_params_t* params) { RGB rgb2 = hsv_to_rgb(hsv); for (uint8_t i = led_min; i < led_max; i++) { - if (g_rgb_leds[i].modifier) { + RGB_MATRIX_TEST_LED_FLAGS(); + if (HAS_FLAGS(g_rgb_leds[i].flags, 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); diff --git a/quantum/rgb_matrix_animations/breathing_anim.h b/quantum/rgb_matrix_animations/breathing_anim.h index 4a9a1dcdb2..54d60f927d 100644 --- a/quantum/rgb_matrix_animations/breathing_anim.h +++ b/quantum/rgb_matrix_animations/breathing_anim.h @@ -12,6 +12,7 @@ bool rgb_matrix_breathing(effect_params_t* params) { 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_TEST_LED_FLAGS(); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } return led_max < DRIVER_LED_TOTAL; diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h index 5c18cfa0c9..513dff1281 100644 --- a/quantum/rgb_matrix_animations/cycle_all_anim.h +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h @@ -2,16 +2,16 @@ #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_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); + hsv.h = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { - hsv.h = time; + RGB_MATRIX_TEST_LED_FLAGS(); RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h index f519aeb476..428adea223 100644 --- a/quantum/rgb_matrix_animations/cycle_left_right_anim.h +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_left_right(effect_params_t* params) { @@ -11,6 +11,7 @@ bool rgb_matrix_cycle_left_right(effect_params_t* params) { HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); point_t point = g_rgb_leds[i].point; hsv.h = point.x - time; RGB rgb = hsv_to_rgb(hsv); diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h index 8b91d890de..ea63095d2e 100644 --- a/quantum/rgb_matrix_animations/cycle_up_down_anim.h +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_up_down(effect_params_t* params) { @@ -11,6 +11,7 @@ bool rgb_matrix_cycle_up_down(effect_params_t* params) { HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); point_t point = g_rgb_leds[i].point; hsv.h = point.y - time; RGB rgb = hsv_to_rgb(hsv); diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h index dda3157809..00f6e50880 100644 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_dual_beacon(effect_params_t* params) { @@ -13,6 +13,7 @@ bool rgb_matrix_dual_beacon(effect_params_t* params) { 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(); 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); diff --git a/quantum/rgb_matrix_animations/gradient_up_down_anim.h b/quantum/rgb_matrix_animations/gradient_up_down_anim.h index 11498e22f5..05117540ae 100644 --- a/quantum/rgb_matrix_animations/gradient_up_down_anim.h +++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h @@ -1,7 +1,7 @@ #pragma once #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern 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) { @@ -10,6 +10,7 @@ bool rgb_matrix_gradient_up_down(effect_params_t* params) { 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++) { + RGB_MATRIX_TEST_LED_FLAGS(); 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 diff --git a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h index 01ff5c2306..dffa532643 100644 --- a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h +++ b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h @@ -2,10 +2,11 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; -static void jellybean_raindrops_set_color(int i) { +static void jellybean_raindrops_set_color(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) return; 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); @@ -15,14 +16,14 @@ 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); + 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); + jellybean_raindrops_set_color(i, params); } return led_max < DRIVER_LED_TOTAL; } diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h index 3c15e64ab6..89f6965c33 100644 --- a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_rainbow_beacon(effect_params_t* params) { @@ -13,6 +13,7 @@ bool rgb_matrix_rainbow_beacon(effect_params_t* params) { int16_t cos_value = 2 * (cos8(time) - 128); int16_t sin_value = 2 * (sin8(time) - 128); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); 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); diff --git a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h index 0d11d52802..0d57aef57b 100644 --- a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { @@ -11,6 +11,7 @@ bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); 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); diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h index d7cd42cbe8..03652758c6 100644 --- a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { @@ -13,6 +13,7 @@ bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { int16_t cos_value = 3 * (cos8(time) - 128); int16_t sin_value = 3 * (sin8(time) - 128); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); 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); diff --git a/quantum/rgb_matrix_animations/raindrops_anim.h b/quantum/rgb_matrix_animations/raindrops_anim.h index fc721375b0..0e3a878642 100644 --- a/quantum/rgb_matrix_animations/raindrops_anim.h +++ b/quantum/rgb_matrix_animations/raindrops_anim.h @@ -5,7 +5,8 @@ extern rgb_counters_t g_rgb_counters; extern rgb_config_t rgb_matrix_config; -static void raindrops_set_color(int i) { +static void raindrops_set_color(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) return; HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val }; // Take the shortest path between hues @@ -25,14 +26,14 @@ 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); + 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); + raindrops_set_color(i, params); } return led_max < DRIVER_LED_TOTAL; } diff --git a/quantum/rgb_matrix_animations/solid_color_anim.h b/quantum/rgb_matrix_animations/solid_color_anim.h index 24a197beb3..033c1f9333 100644 --- a/quantum/rgb_matrix_animations/solid_color_anim.h +++ b/quantum/rgb_matrix_animations/solid_color_anim.h @@ -8,6 +8,7 @@ bool rgb_matrix_solid_color(effect_params_t* params) { 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_TEST_LED_FLAGS(); 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 index 1116bb055c..82483653ae 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h @@ -13,6 +13,7 @@ bool rgb_matrix_solid_reactive(effect_params_t* params) { uint16_t max_tick = 65535 / rgb_matrix_config.speed; // Relies on hue being 8-bit and wrapping for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); uint16_t tick = max_tick; // Reverse search to find most recent key hit for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { diff --git a/quantum/rgb_matrix_animations/solid_reactive_cross.h b/quantum/rgb_matrix_animations/solid_reactive_cross.h index af602cba15..1dec1886d1 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_cross.h +++ b/quantum/rgb_matrix_animations/solid_reactive_cross.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -15,6 +15,7 @@ static bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, effect_par hsv.v = 0; point_t point = g_rgb_leds[i].point; for (uint8_t j = start; j < count; j++) { + RGB_MATRIX_TEST_LED_FLAGS(); 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); diff --git a/quantum/rgb_matrix_animations/solid_reactive_nexus.h b/quantum/rgb_matrix_animations/solid_reactive_nexus.h index 8b4a139dc9..8952a1e2bf 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_nexus.h +++ b/quantum/rgb_matrix_animations/solid_reactive_nexus.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -15,6 +15,7 @@ static bool rgb_matrix_solid_reactive_multinexus_range(uint8_t start, effect_par hsv.v = 0; point_t point = g_rgb_leds[i].point; for (uint8_t j = start; j < count; j++) { + RGB_MATRIX_TEST_LED_FLAGS(); 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); diff --git a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h index a2d3f242c1..9fc4d527a8 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h @@ -12,6 +12,7 @@ bool rgb_matrix_solid_reactive_simple(effect_params_t* params) { // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 uint16_t max_tick = 65535 / rgb_matrix_config.speed; for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); uint16_t tick = max_tick; // Reverse search to find most recent key hit for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { diff --git a/quantum/rgb_matrix_animations/solid_reactive_wide.h b/quantum/rgb_matrix_animations/solid_reactive_wide.h index abb01892ed..d86cb12844 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_wide.h +++ b/quantum/rgb_matrix_animations/solid_reactive_wide.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -15,6 +15,7 @@ static bool rgb_matrix_solid_reactive_multiwide_range(uint8_t start, effect_para hsv.v = 0; point_t point = g_rgb_leds[i].point; for (uint8_t j = start; j < count; j++) { + RGB_MATRIX_TEST_LED_FLAGS(); 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); diff --git a/quantum/rgb_matrix_animations/solid_splash_anim.h b/quantum/rgb_matrix_animations/solid_splash_anim.h index 82ac055b88..14312f33da 100644 --- a/quantum/rgb_matrix_animations/solid_splash_anim.h +++ b/quantum/rgb_matrix_animations/solid_splash_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -12,6 +12,7 @@ static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* p HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; uint8_t count = g_last_hit_tracker.count; for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); hsv.v = 0; point_t point = g_rgb_leds[i].point; for (uint8_t j = start; j < count; j++) { diff --git a/quantum/rgb_matrix_animations/splash_anim.h b/quantum/rgb_matrix_animations/splash_anim.h index 829d30eef5..3c96d451e1 100644 --- a/quantum/rgb_matrix_animations/splash_anim.h +++ b/quantum/rgb_matrix_animations/splash_anim.h @@ -2,7 +2,7 @@ #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_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -12,6 +12,7 @@ static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) HSV hsv = { 0, rgb_matrix_config.sat, 0 }; uint8_t count = g_last_hit_tracker.count; for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); hsv.h = rgb_matrix_config.hue; hsv.v = 0; point_t point = g_rgb_leds[i].point; diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h index 908e96da56..7a3bc6714f 100644 --- a/quantum/rgb_matrix_types.h +++ b/quantum/rgb_matrix_types.h @@ -67,19 +67,21 @@ typedef union { }; } matrix_co_t; +#define HAS_FLAGS(bits, flags) ((bits & flags) == flags) +#define HAS_ANY_FLAGS(bits, flags) ((bits & flags) != 0x00) + +#define LED_FLAG_ALL 0xFF +#define LED_FLAG_NONE 0x00 +#define LED_FLAG_MODIFIER 0x01 +#define LED_FLAG_UNDERGLOW 0x02 +#define LED_FLAG_KEYLIGHT 0x04 + typedef struct PACKED { - matrix_co_t matrix_co; - point_t point; - uint8_t modifier:1; + matrix_co_t matrix_co; + point_t point; + uint8_t flags; } rgb_led; -typedef enum { - RGB_ZONE_OFF = 0, - RGB_ZONE_ALL, - RGB_ZONE_KEYS, - RGB_ZONE_UNDER, -} rgb_zone_t; - typedef union { uint32_t raw; struct PACKED { diff --git a/tmk_core/protocol/arm_atsam/led_matrix.c b/tmk_core/protocol/arm_atsam/led_matrix.c index e29fb6587c..a2eab1b563 100644 --- a/tmk_core/protocol/arm_atsam/led_matrix.c +++ b/tmk_core/protocol/arm_atsam/led_matrix.c @@ -443,9 +443,9 @@ static void led_matrix_massdrop_config_override(int i) uint8_t highest_active_layer = biton32(layer_state); - if (led_lighting_mode == LED_MODE_KEYS_ONLY && g_rgb_leds[i].matrix_co.raw == 0xff) { + if (led_lighting_mode == LED_MODE_KEYS_ONLY && HAS_FLAGS(g_rgb_leds[i].flags, LED_FLAG_UNDERGLOW)) { //Do not act on this LED - } else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && g_rgb_leds[i].matrix_co.raw != 0xff) { + } else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && !HAS_FLAGS(g_rgb_leds[i].flags, LED_FLAG_UNDERGLOW)) { //Do not act on this LED } else if (led_lighting_mode == LED_MODE_INDICATORS_ONLY) { //Do not act on this LED (Only show indicators) From 4d57a049b5b04354f7d83ba97b172db22236f5c8 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Tue, 7 May 2019 18:22:46 -0500 Subject: [PATCH 05/19] rgb_led struct conversion (aka: Per led (key) type rgb matrix effects - part 2) (#5783) * Initial conversion of the rgb_led struct * Converting last keyboard & updating effects to take advantage of the new structure * New struct should not be const * Updated docs * Changing define ___ for no led to NO_LED * Missed converting some keymap usages of the old struct layout --- keyboards/ergodox_ez/ergodox_ez.c | 99 +++++++------------ keyboards/planck/ez/ez.c | 78 ++++----------- quantum/rgb_matrix.c | 16 ++- quantum/rgb_matrix.h | 4 +- .../rgb_matrix_animations/alpha_mods_anim.h | 4 +- .../rgb_matrix_animations/cycle_all_anim.h | 2 +- .../cycle_left_right_anim.h | 5 +- .../cycle_up_down_anim.h | 5 +- .../rgb_matrix_animations/dual_beacon_anim.h | 5 +- .../gradient_up_down_anim.h | 5 +- .../jellybean_raindrops_anim.h | 4 +- .../rainbow_beacon_anim.h | 5 +- .../rainbow_moving_chevron_anim.h | 5 +- .../rainbow_pinwheels_anim.h | 5 +- .../rgb_matrix_animations/raindrops_anim.h | 3 +- .../rgb_matrix_animations/solid_color_anim.h | 1 + .../solid_reactive_anim.h | 1 + .../solid_reactive_cross.h | 7 +- .../solid_reactive_nexus.h | 7 +- .../solid_reactive_simple_anim.h | 1 + .../solid_reactive_wide.h | 7 +- .../rgb_matrix_animations/solid_splash_anim.h | 7 +- quantum/rgb_matrix_animations/splash_anim.h | 7 +- quantum/rgb_matrix_types.h | 18 ++-- tmk_core/protocol/arm_atsam/led_matrix.c | 9 +- 25 files changed, 114 insertions(+), 196 deletions(-) diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c index 13ea843022..09443cf725 100644 --- a/keyboards/ergodox_ez/ergodox_ez.c +++ b/keyboards/ergodox_ez/ergodox_ez.c @@ -269,68 +269,39 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { }; -rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { - - /*{row | col << 4} - | {x=0..224, y=0..64} - | | flags - | | | */ - {{ 8|(0<<4)}, {17.2* 8, 12.8*0}, 4}, // LED 1 on right > Key 6 - {{ 9|(0<<4)}, {17.2* 9, 12.8*0}, 4}, // LED 2 > Key 7 - {{10|(0<<4)}, {17.2*10, 12.8*0}, 4}, // LED 3 > Key 8 - {{11|(0<<4)}, {17.2*11, 12.8*0}, 4}, // LED 4 > Key 9 - {{12|(0<<4)}, {17.2*12, 12.8*0}, 4}, // LED 5 > Key 0 - - {{ 8|(1<<4)}, {17.2* 8, 12.8*1}, 4}, // LED 6 - {{ 9|(1<<4)}, {17.2* 9, 12.8*1}, 4}, // LED 7 - {{10|(1<<4)}, {17.2*10, 12.8*1}, 4}, // LED 8 - {{11|(1<<4)}, {17.2*11, 12.8*1}, 4}, // LED 9 - {{12|(1<<4)}, {17.2*12, 12.8*1}, 4}, // LED 10 - - {{ 8|(2<<4)}, {17.2* 8, 12.8*2}, 4}, // LED 11 - {{ 9|(2<<4)}, {17.2* 9, 12.8*2}, 4}, // LED 12 - {{10|(2<<4)}, {17.2*10, 12.8*2}, 4}, // LED 13 - {{11|(2<<4)}, {17.2*11, 12.8*2}, 4}, // LED 14 - {{12|(2<<4)}, {17.2*12, 12.8*2}, 4}, // LED 15 - - {{ 8|(3<<4)}, {17.2* 8, 12.8*3}, 4}, // LED 16 - {{ 9|(3<<4)}, {17.2* 9, 12.8*3}, 4}, // LED 17 - {{10|(3<<4)}, {17.2*10, 12.8*3}, 4}, // LED 18 - {{11|(3<<4)}, {17.2*11, 12.8*3}, 4}, // LED 19 - {{12|(3<<4)}, {17.2*12, 12.8*3}, 4}, // LED 20 - - {{ 9|(4<<4)}, {17.2* 9, 12.8*4}, 1}, // LED 21 - {{10|(4<<4)}, {17.2*10, 12.8*4}, 1}, // LED 22 - {{11|(4<<4)}, {17.2*11, 12.8*4}, 1}, // LED 23 - {{12|(4<<4)}, {17.2*12, 12.8*4}, 1}, // LED 24 - - {{ 5|(0<<4)}, {17.2* 5, 12.8*0}, 4}, // LED 1 on left > Key 5 - {{ 4|(0<<4)}, {17.2* 4, 12.8*0}, 4}, // LED 2 > Key 4 - {{ 3|(0<<4)}, {17.2* 3, 12.8*0}, 4}, // LED 3 > Key 3 - {{ 2|(0<<4)}, {17.2* 2, 12.8*0}, 4}, // LED 4 > Key 2 - {{ 1|(0<<4)}, {17.2* 1, 12.8*0}, 4}, // LED 5 > Key 1 - - {{ 5|(1<<4)}, {17.2* 5, 12.8*1}, 4}, // LED 6 - {{ 4|(1<<4)}, {17.2* 4, 12.8*1}, 4}, // LED 7 - {{ 3|(1<<4)}, {17.2* 3, 12.8*1}, 4}, // LED 8 - {{ 2|(1<<4)}, {17.2* 2, 12.8*1}, 4}, // LED 9 - {{ 1|(1<<4)}, {17.2* 1, 12.8*1}, 4}, // LED 10 - - {{ 5|(2<<4)}, {17.2* 5, 12.8*2}, 4}, // LED 11 - {{ 4|(2<<4)}, {17.2* 4, 12.8*2}, 4}, // LED 12 - {{ 3|(2<<4)}, {17.2* 3, 12.8*2}, 4}, // LED 13 - {{ 2|(2<<4)}, {17.2* 2, 12.8*2}, 4}, // LED 14 - {{ 1|(2<<4)}, {17.2* 1, 12.8*2}, 4}, // LED 15 - - {{ 5|(3<<4)}, {17.2* 5, 12.8*3}, 4}, // LED 16 - {{ 4|(3<<4)}, {17.2* 4, 12.8*3}, 4}, // LED 17 - {{ 3|(3<<4)}, {17.2* 3, 12.8*3}, 4}, // LED 18 - {{ 2|(3<<4)}, {17.2* 2, 12.8*3}, 4}, // LED 19 - {{ 1|(3<<4)}, {17.2* 1, 12.8*3}, 4}, // LED 20 - - {{ 4|(4<<4)}, {17.2* 4, 12.8*4}, 1}, // LED 21 - {{ 3|(4<<4)}, {17.2* 3, 12.8*4}, 1}, // LED 22 - {{ 2|(4<<4)}, {17.2* 2, 12.8*4}, 1}, // LED 23 - {{ 1|(4<<4)}, {17.2* 1, 12.8*4}, 1}, // LED 24 > Key Hack -}; +led_config_t g_led_config = { { + { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED }, + { 28, 33, 38, 43, 47, NO_LED }, + { 27, 32, 37, 42, 46, NO_LED }, + { 26, 31, 36, 41, 45, NO_LED }, + { 25, 30, 35, 40, 44, NO_LED }, + { 24, 29, 34, 39, NO_LED, NO_LED }, + { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED }, + { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED }, + { 0, 5, 10, 15, NO_LED, NO_LED }, + { 1, 6, 11, 16, 20, NO_LED }, + { 2, 7, 12, 17, 21, NO_LED }, + { 3, 8, 13, 18, 22, NO_LED }, + { 4, 9, 14, 19, 23, NO_LED }, + { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED } +}, { + { 137, 0 }, { 154, 0 }, { 172, 0 }, { 189, 0 }, { 206, 0 }, { 137, 12 }, + { 154, 12 }, { 172, 12 }, { 189, 12 }, { 206, 12 }, { 137, 25 }, { 154, 25 }, + { 172, 25 }, { 189, 25 }, { 206, 25 }, { 137, 38 }, { 154, 38 }, { 172, 38 }, + { 189, 38 }, { 206, 38 }, { 154, 51 }, { 172, 51 }, { 189, 51 }, { 206, 51 }, + { 86, 0 }, { 68, 0 }, { 51, 0 }, { 34, 0 }, { 17, 0 }, { 86, 12 }, + { 68, 12 }, { 51, 12 }, { 34, 12 }, { 17, 12 }, { 86, 25 }, { 68, 25 }, + { 51, 25 }, { 34, 25 }, { 17, 25 }, { 86, 38 }, { 68, 38 }, { 51, 38 }, + { 34, 38 }, { 17, 38 }, { 68, 51 }, { 51, 51 }, { 34, 51 }, { 17, 51 } +}, { + 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, + 4, 4, 1, 1, 1, 1, + 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, + 4, 4, 1, 1, 1, 1 +} }; + #endif diff --git a/keyboards/planck/ez/ez.c b/keyboards/planck/ez/ez.c index 94f5071896..3ad694c4a3 100644 --- a/keyboards/planck/ez/ez.c +++ b/keyboards/planck/ez/ez.c @@ -79,63 +79,27 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { }; -rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { - - /*{row | col << 4} - | {x=0..224, y=0..64} - | | flags - | | | */ - {{0|(0<<4)}, {20.36*0, 21.33*0}, 1}, - {{0|(1<<4)}, {20.36*1, 21.33*0}, 4}, - {{0|(2<<4)}, {20.36*2, 21.33*0}, 4}, - {{0|(3<<4)}, {20.36*3, 21.33*0}, 4}, - {{0|(4<<4)}, {20.36*4, 21.33*0}, 4}, - {{0|(5<<4)}, {20.36*5, 21.33*0}, 4}, - {{4|(0<<4)}, {20.36*6, 21.33*0}, 4}, - {{4|(1<<4)}, {20.36*7, 21.33*0}, 4}, - {{4|(2<<4)}, {20.36*8, 21.33*0}, 4}, - {{4|(3<<4)}, {20.36*9, 21.33*0}, 4}, - {{4|(4<<4)}, {20.36*10,21.33*0}, 4}, - {{4|(5<<4)}, {20.36*11,21.33*0}, 1}, - - {{1|(0<<4)}, {20.36*0, 21.33*1}, 1}, - {{1|(1<<4)}, {20.36*1, 21.33*1}, 4}, - {{1|(2<<4)}, {20.36*2, 21.33*1}, 4}, - {{1|(3<<4)}, {20.36*3, 21.33*1}, 4}, - {{1|(4<<4)}, {20.36*4, 21.33*1}, 4}, - {{1|(5<<4)}, {20.36*5, 21.33*1}, 4}, - {{5|(0<<4)}, {20.36*6, 21.33*1}, 4}, - {{5|(1<<4)}, {20.36*7, 21.33*1}, 4}, - {{5|(2<<4)}, {20.36*8, 21.33*1}, 4}, - {{5|(3<<4)}, {20.36*9, 21.33*1}, 4}, - {{5|(4<<4)}, {20.36*10,21.33*1}, 4}, - {{5|(5<<4)}, {20.36*11,21.33*1}, 1}, - - {{2|(0<<4)}, {20.36*0, 21.33*2}, 1}, - {{2|(1<<4)}, {20.36*1, 21.33*2}, 4}, - {{2|(2<<4)}, {20.36*2, 21.33*2}, 4}, - {{2|(3<<4)}, {20.36*3, 21.33*2}, 4}, - {{2|(4<<4)}, {20.36*4, 21.33*2}, 4}, - {{2|(5<<4)}, {20.36*5, 21.33*2}, 4}, - {{6|(0<<4)}, {20.36*6, 21.33*2}, 4}, - {{6|(1<<4)}, {20.36*7, 21.33*2}, 4}, - {{6|(2<<4)}, {20.36*8, 21.33*2}, 4}, - {{6|(3<<4)}, {20.36*9, 21.33*2}, 4}, - {{6|(4<<4)}, {20.36*10,21.33*2}, 4}, - {{6|(5<<4)}, {20.36*11,21.33*2}, 1}, - - {{3|(0<<4)}, {20.36*0, 21.33*3}, 1}, - {{3|(1<<4)}, {20.36*1, 21.33*3}, 1}, - {{3|(2<<4)}, {20.36*2, 21.33*3}, 1}, - {{7|(3<<4)}, {20.36*3, 21.33*3}, 1}, - {{7|(4<<4)}, {20.36*4, 21.33*3}, 1}, - {{7|(5<<4)}, {20.36*5.5,21.33*3}, 4}, - {{7|(0<<4)}, {20.36*7, 21.33*3}, 1}, - {{7|(1<<4)}, {20.36*8, 21.33*3}, 1}, - {{7|(2<<4)}, {20.36*9, 21.33*3}, 1}, - {{3|(3<<4)}, {20.36*10,21.33*3}, 1}, - {{3|(4<<4)}, {20.36*11,21.33*3}, 1} -}; +led_config_t g_led_config = { { + { 0, 1, 2, 3, 4, 5 }, + { 12, 13, 14, 15, 16, 17 }, + { 24, 25, 26, 27, 28, 29 }, + { 36, 37, 38, 45, 46, NO_LED }, + { 6, 7, 8, 9, 10, 11 }, + { 18, 19, 20, 21, 22, 23 }, + { 30, 31, 32, 33, 34, 35 }, + { 42, 43, 44, 39, 40, 41 } +}, { + { 0, 0 }, { 20, 0 }, { 40, 0 }, { 61, 0 }, { 81, 0 }, { 101, 0 }, { 122, 0 }, { 142, 0 }, { 162, 0 }, { 183, 0 }, { 203, 0 }, { 223, 0 }, + { 0, 21 }, { 20, 21 }, { 40, 21 }, { 61, 21 }, { 81, 21 }, { 101, 21 }, { 122, 21 }, { 142, 21 }, { 162, 21 }, { 183, 21 }, { 203, 21 }, { 223, 21 }, + { 0, 42 }, { 20, 42 }, { 40, 42 }, { 61, 42 }, { 81, 42 }, { 101, 42 }, { 122, 42 }, { 142, 42 }, { 162, 42 }, { 183, 42 }, { 203, 42 }, { 223, 42 }, + { 0, 63 }, { 20, 63 }, { 40, 63 }, { 61, 63 }, { 81, 63 }, { 111, 63 }, { 142, 63 }, { 162, 63 }, { 183, 63 }, { 203, 63 }, { 223, 63 } +}, { + 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, + 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, + 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, + 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1 +} }; + void matrix_init_kb(void) { matrix_init_user(); diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 5528a08347..edbcee9cd1 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -105,6 +105,7 @@ bool g_suspend_state = false; +extern led_config_t g_led_config; rgb_config_t rgb_matrix_config; rgb_counters_t g_rgb_counters; @@ -150,14 +151,11 @@ uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t } uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { - // TODO: This is kinda expensive, fix this soonish uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i); - for (uint8_t i = 0; i < DRIVER_LED_TOTAL && led_count < LED_HITS_TO_REMEMBER; i++) { - matrix_co_t matrix_co = g_rgb_leds[i].matrix_co; - if (row == matrix_co.row && column == matrix_co.col) { - led_i[led_count] = i; - led_count++; - } + uint8_t led_index = g_led_config.matrix_co[row][column]; + if (led_index != NO_LED) { + led_i[led_count] = led_index; + led_count++; } return led_count; } @@ -201,8 +199,8 @@ bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { for(uint8_t i = 0; i < led_count; i++) { uint8_t index = last_hit_buffer.count; - last_hit_buffer.x[index] = g_rgb_leds[led[i]].point.x; - last_hit_buffer.y[index] = g_rgb_leds[led[i]].point.y; + last_hit_buffer.x[index] = g_led_config.point[led[i]].x; + last_hit_buffer.y[index] = g_led_config.point[led[i]].y; last_hit_buffer.index[index] = led[i]; last_hit_buffer.tick[index] = 0; last_hit_buffer.count++; diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 33665ffff2..365a92bbf6 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -54,9 +54,7 @@ uint8_t max = DRIVER_LED_TOTAL; #endif -#define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) continue - -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +#define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue typedef struct { diff --git a/quantum/rgb_matrix_animations/alpha_mods_anim.h b/quantum/rgb_matrix_animations/alpha_mods_anim.h index 4bd01c4fc8..d7f6f4655b 100644 --- a/quantum/rgb_matrix_animations/alpha_mods_anim.h +++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h @@ -1,7 +1,7 @@ #pragma once #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; // alphas = color1, mods = color2 @@ -15,7 +15,7 @@ bool rgb_matrix_alphas_mods(effect_params_t* params) { for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - if (HAS_FLAGS(g_rgb_leds[i].flags, LED_FLAG_MODIFIER)) { + 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); diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h index 513dff1281..e93798f900 100644 --- a/quantum/rgb_matrix_animations/cycle_all_anim.h +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_all(effect_params_t* params) { diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h index 428adea223..4b09d5826b 100644 --- a/quantum/rgb_matrix_animations/cycle_left_right_anim.h +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_left_right(effect_params_t* params) { @@ -12,8 +12,7 @@ bool rgb_matrix_cycle_left_right(effect_params_t* params) { uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - point_t point = g_rgb_leds[i].point; - hsv.h = point.x - time; + hsv.h = g_led_config.point[i].x - time; RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h index ea63095d2e..403214bb73 100644 --- a/quantum/rgb_matrix_animations/cycle_up_down_anim.h +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_up_down(effect_params_t* params) { @@ -12,8 +12,7 @@ bool rgb_matrix_cycle_up_down(effect_params_t* params) { uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - point_t point = g_rgb_leds[i].point; - hsv.h = point.y - time; + hsv.h = g_led_config.point[i].y - time; RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h index 00f6e50880..dcb594029e 100644 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_dual_beacon(effect_params_t* params) { @@ -14,8 +14,7 @@ bool rgb_matrix_dual_beacon(effect_params_t* params) { int8_t sin_value = sin8(time) - 128; for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - 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; + hsv.h = ((g_led_config.point[i].y - 32) * cos_value + (g_led_config.point[i].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); } diff --git a/quantum/rgb_matrix_animations/gradient_up_down_anim.h b/quantum/rgb_matrix_animations/gradient_up_down_anim.h index 05117540ae..7a6ed14219 100644 --- a/quantum/rgb_matrix_animations/gradient_up_down_anim.h +++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h @@ -1,7 +1,7 @@ #pragma once #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_gradient_up_down(effect_params_t* params) { @@ -11,10 +11,9 @@ bool rgb_matrix_gradient_up_down(effect_params_t* params) { uint8_t scale = scale8(64, rgb_matrix_config.speed); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - 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); + hsv.h = rgb_matrix_config.hue + scale * (g_led_config.point[i].y >> 4); RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h index dffa532643..5ea971435e 100644 --- a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h +++ b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h @@ -2,11 +2,11 @@ #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; static void jellybean_raindrops_set_color(int i, effect_params_t* params) { - if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) return; + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; 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); diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h index 89f6965c33..d462880731 100644 --- a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_rainbow_beacon(effect_params_t* params) { @@ -14,8 +14,7 @@ bool rgb_matrix_rainbow_beacon(effect_params_t* params) { int16_t sin_value = 2 * (sin8(time) - 128); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - 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; + hsv.h = ((g_led_config.point[i].y - 32) * cos_value + (g_led_config.point[i].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); } diff --git a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h index 0d57aef57b..3b7d9689f8 100644 --- a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { @@ -12,8 +12,7 @@ bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - point_t point = g_rgb_leds[i].point; - hsv.h = abs8(point.y - 32) + (point.x - time) + rgb_matrix_config.hue; + hsv.h = abs8(g_led_config.point[i].y - 32) + (g_led_config.point[i].x - time) + rgb_matrix_config.hue; RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h index 03652758c6..e92f351765 100644 --- a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS extern rgb_counters_t g_rgb_counters; -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { @@ -14,8 +14,7 @@ bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { int16_t sin_value = 3 * (sin8(time) - 128); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - 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; + hsv.h = ((g_led_config.point[i].y - 32) * cos_value + (56 - abs8(g_led_config.point[i].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); } diff --git a/quantum/rgb_matrix_animations/raindrops_anim.h b/quantum/rgb_matrix_animations/raindrops_anim.h index 0e3a878642..4ce1d65e57 100644 --- a/quantum/rgb_matrix_animations/raindrops_anim.h +++ b/quantum/rgb_matrix_animations/raindrops_anim.h @@ -3,10 +3,11 @@ #include "rgb_matrix_types.h" extern rgb_counters_t g_rgb_counters; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; static void raindrops_set_color(int i, effect_params_t* params) { - if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) return; + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val }; // Take the shortest path between hues diff --git a/quantum/rgb_matrix_animations/solid_color_anim.h b/quantum/rgb_matrix_animations/solid_color_anim.h index 033c1f9333..ba2cea15e3 100644 --- a/quantum/rgb_matrix_animations/solid_color_anim.h +++ b/quantum/rgb_matrix_animations/solid_color_anim.h @@ -1,5 +1,6 @@ #pragma once +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_solid_color(effect_params_t* params) { diff --git a/quantum/rgb_matrix_animations/solid_reactive_anim.h b/quantum/rgb_matrix_animations/solid_reactive_anim.h index 82483653ae..c3dba8a5af 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h @@ -2,6 +2,7 @@ #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; diff --git a/quantum/rgb_matrix_animations/solid_reactive_cross.h b/quantum/rgb_matrix_animations/solid_reactive_cross.h index 1dec1886d1..8858f71e60 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_cross.h +++ b/quantum/rgb_matrix_animations/solid_reactive_cross.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -13,11 +13,10 @@ static bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, effect_par 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++) { RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = point.x - g_last_hit_tracker.x[j]; - int16_t dy = point.y - g_last_hit_tracker.y[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); int16_t dist2 = 16; uint8_t dist3; diff --git a/quantum/rgb_matrix_animations/solid_reactive_nexus.h b/quantum/rgb_matrix_animations/solid_reactive_nexus.h index 8952a1e2bf..c0e3c24507 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_nexus.h +++ b/quantum/rgb_matrix_animations/solid_reactive_nexus.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -13,11 +13,10 @@ static bool rgb_matrix_solid_reactive_multinexus_range(uint8_t start, effect_par 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++) { RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = point.x - g_last_hit_tracker.x[j]; - int16_t dy = point.y - g_last_hit_tracker.y[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); int16_t dist2 = 8; uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; diff --git a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h index 9fc4d527a8..abc7e36a89 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h @@ -2,6 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; diff --git a/quantum/rgb_matrix_animations/solid_reactive_wide.h b/quantum/rgb_matrix_animations/solid_reactive_wide.h index d86cb12844..3d1d38e806 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_wide.h +++ b/quantum/rgb_matrix_animations/solid_reactive_wide.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -13,11 +13,10 @@ static bool rgb_matrix_solid_reactive_multiwide_range(uint8_t start, effect_para 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++) { RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = point.x - g_last_hit_tracker.x[j]; - int16_t dy = point.y - g_last_hit_tracker.y[j]; + int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; + int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; uint8_t dist = sqrt16(dx * dx + dy * dy); uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist * 5; if (effect > 255) diff --git a/quantum/rgb_matrix_animations/solid_splash_anim.h b/quantum/rgb_matrix_animations/solid_splash_anim.h index 14312f33da..4e5565d0d3 100644 --- a/quantum/rgb_matrix_animations/solid_splash_anim.h +++ b/quantum/rgb_matrix_animations/solid_splash_anim.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -14,10 +14,9 @@ static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* p for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); 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]; + int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; + int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; uint8_t dist = sqrt16(dx * dx + dy * dy); uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; if (effect > 255) diff --git a/quantum/rgb_matrix_animations/splash_anim.h b/quantum/rgb_matrix_animations/splash_anim.h index 3c96d451e1..fbe7761117 100644 --- a/quantum/rgb_matrix_animations/splash_anim.h +++ b/quantum/rgb_matrix_animations/splash_anim.h @@ -2,7 +2,7 @@ #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) -extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern led_config_t g_led_config; extern rgb_config_t rgb_matrix_config; extern last_hit_t g_last_hit_tracker; @@ -15,10 +15,9 @@ static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) RGB_MATRIX_TEST_LED_FLAGS(); 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]; + int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; + int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; uint8_t dist = sqrt16(dx * dx + dy * dy); uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; if (effect > 255) diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h index 7a3bc6714f..f890edd94f 100644 --- a/quantum/rgb_matrix_types.h +++ b/quantum/rgb_matrix_types.h @@ -59,14 +59,6 @@ typedef struct PACKED { uint8_t y; } point_t; -typedef union { - uint8_t raw; - struct { - uint8_t row:4; // 16 max - uint8_t col:4; // 16 max - }; -} matrix_co_t; - #define HAS_FLAGS(bits, flags) ((bits & flags) == flags) #define HAS_ANY_FLAGS(bits, flags) ((bits & flags) != 0x00) @@ -76,11 +68,13 @@ typedef union { #define LED_FLAG_UNDERGLOW 0x02 #define LED_FLAG_KEYLIGHT 0x04 +#define NO_LED 255 + typedef struct PACKED { - matrix_co_t matrix_co; - point_t point; - uint8_t flags; -} rgb_led; + uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; + point_t point[DRIVER_LED_TOTAL]; + uint8_t flags[DRIVER_LED_TOTAL]; +} led_config_t; typedef union { uint32_t raw; diff --git a/tmk_core/protocol/arm_atsam/led_matrix.c b/tmk_core/protocol/arm_atsam/led_matrix.c index a2eab1b563..ea067a7439 100644 --- a/tmk_core/protocol/arm_atsam/led_matrix.c +++ b/tmk_core/protocol/arm_atsam/led_matrix.c @@ -431,6 +431,7 @@ static void led_run_pattern(led_setup_t *f, float* ro, float* go, float* bo, flo } } +extern led_config_t g_led_config; static void led_matrix_massdrop_config_override(int i) { float ro = 0; @@ -438,14 +439,14 @@ static void led_matrix_massdrop_config_override(int i) float bo = 0; float po = (led_animation_orientation) - ? (float)g_rgb_leds[i].point.y / 64.f * 100 - : (float)g_rgb_leds[i].point.x / 224.f * 100; + ? (float)g_led_config.point[i].y / 64.f * 100 + : (float)g_led_config.point[i].x / 224.f * 100; uint8_t highest_active_layer = biton32(layer_state); - if (led_lighting_mode == LED_MODE_KEYS_ONLY && HAS_FLAGS(g_rgb_leds[i].flags, LED_FLAG_UNDERGLOW)) { + if (led_lighting_mode == LED_MODE_KEYS_ONLY && HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) { //Do not act on this LED - } else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && !HAS_FLAGS(g_rgb_leds[i].flags, LED_FLAG_UNDERGLOW)) { + } else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && !HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) { //Do not act on this LED } else if (led_lighting_mode == LED_MODE_INDICATORS_ONLY) { //Do not act on this LED (Only show indicators) From b4dab5b09b617c44213ed97123f8f3744f3ab9d6 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Tue, 7 May 2019 21:17:00 -0500 Subject: [PATCH 06/19] RGB Matrix Typing Heatmap (#5786) * RGB Matrix Typing Heatmap Effect * Fixing file name and effect init --- quantum/rgb_matrix.c | 21 ++++++ quantum/rgb_matrix.h | 5 ++ .../rgb_matrix_animations/digital_rain_anim.h | 33 ++++---- .../typing_heatmap_anim.h | 75 +++++++++++++++++++ 4 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 quantum/rgb_matrix_animations/typing_heatmap_anim.h diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index edbcee9cd1..92a94df80f 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -38,6 +38,7 @@ #include "rgb_matrix_animations/rainbow_pinwheels_anim.h" #include "rgb_matrix_animations/rainbow_moving_chevron_anim.h" #include "rgb_matrix_animations/jellybean_raindrops_anim.h" +#include "rgb_matrix_animations/typing_heatmap_anim.h" #include "rgb_matrix_animations/digital_rain_anim.h" #include "rgb_matrix_animations/solid_reactive_simple_anim.h" #include "rgb_matrix_animations/solid_reactive_anim.h" @@ -111,6 +112,10 @@ rgb_config_t rgb_matrix_config; rgb_counters_t g_rgb_counters; static uint32_t rgb_counters_buffer; +#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS +uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; +#endif + #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED last_hit_t g_last_hit_tracker; static last_hit_t last_hit_buffer; @@ -206,6 +211,13 @@ bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { last_hit_buffer.count++; } #endif // RGB_MATRIX_KEYREACTIVE_ENABLED + +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) + if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) { + process_rgb_matrix_typing_heatmap(record); + } +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) + return true; } @@ -370,11 +382,20 @@ static void rgb_task_render(uint8_t effect) { rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms break; #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS + +#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS +#ifndef DISABLE_RGB_MATRIX_TYPING_HEATMAP + case RGB_MATRIX_TYPING_HEATMAP: + rendering = rgb_matrix_typing_heatmap(&rgb_effect_params); // Max 4ms Avg 3ms + break; +#endif // DISABLE_RGB_MATRIX_TYPING_HEATMAP #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN case RGB_MATRIX_DIGITAL_RAIN: rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it break; #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN +#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS + #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE case RGB_MATRIX_SOLID_REACTIVE_SIMPLE: diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 365a92bbf6..add0715d9f 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -101,9 +101,14 @@ enum rgb_matrix_effects { #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS RGB_MATRIX_JELLYBEAN_RAINDROPS, #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS +#ifndef DISABLE_RGB_MATRIX_TYPING_HEATMAP + RGB_MATRIX_TYPING_HEATMAP, +#endif // DISABLE_RGB_MATRIX_TYPING_HEATMAP #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN RGB_MATRIX_DIGITAL_RAIN, #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN +#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE RGB_MATRIX_SOLID_REACTIVE_SIMPLE, diff --git a/quantum/rgb_matrix_animations/digital_rain_anim.h b/quantum/rgb_matrix_animations/digital_rain_anim.h index 4ba3c1c87d..6ccba392aa 100644 --- a/quantum/rgb_matrix_animations/digital_rain_anim.h +++ b/quantum/rgb_matrix_animations/digital_rain_anim.h @@ -1,11 +1,13 @@ #pragma once -#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(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 +extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; + 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; @@ -13,24 +15,24 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { 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); + memset(rgb_frame_buffer, 0, sizeof 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 - map[col][row] = max_intensity; + rgb_frame_buffer[col][row] = max_intensity; } - else if (map[col][row] > 0 && map[col][row] < max_intensity) { + else if (rgb_frame_buffer[col][row] > 0 && rgb_frame_buffer[col][row] < max_intensity) { // neither fully bright nor dark, decay it - map[col][row]--; + rgb_frame_buffer[col][row]--; } // set the pixel colour uint8_t led[LED_HITS_TO_REMEMBER]; @@ -38,32 +40,33 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { // 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)); + if (rgb_frame_buffer[col][row] > pure_green_intensity) { + const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (rgb_frame_buffer[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); + const uint8_t green = (uint8_t) ((uint16_t) max_intensity * rgb_frame_buffer[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]--; + if (row == MATRIX_ROWS - 1 && rgb_frame_buffer[col][row] == max_intensity) { + rgb_frame_buffer[col][row]--; } // check if the pixel above is bright - if (map[col][row - 1] == max_intensity) { + if (rgb_frame_buffer[col][row - 1] == max_intensity) { // allow old bright pixel to decay - map[col][row - 1]--; + rgb_frame_buffer[col][row - 1]--; // make this pixel bright - map[col][row] = max_intensity; + rgb_frame_buffer[col][row] = max_intensity; } } } @@ -71,4 +74,4 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { return false; } -#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) 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..aade53fccc --- /dev/null +++ b/quantum/rgb_matrix_animations/typing_heatmap_anim.h @@ -0,0 +1,75 @@ +#pragma once +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) + +extern rgb_config_t rgb_matrix_config; +extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; + +void process_rgb_matrix_typing_heatmap(keyrecord_t *record) { + uint8_t row = record->event.key.row; + uint8_t col = record->event.key.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) + rgb_frame_buffer[row][m_col] = qadd8(rgb_frame_buffer[row][m_col], 16); + rgb_frame_buffer[row][col] = qadd8(rgb_frame_buffer[row][col], 32); + if (p_col < MATRIX_COLS) + rgb_frame_buffer[row][p_col] = qadd8(rgb_frame_buffer[row][p_col], 16); + + if (p_row < MATRIX_ROWS) { + if (m_col < col) + rgb_frame_buffer[p_row][m_col] = qadd8(rgb_frame_buffer[p_row][m_col], 13); + rgb_frame_buffer[p_row][col] = qadd8(rgb_frame_buffer[p_row][col], 16); + if (p_col < MATRIX_COLS) + rgb_frame_buffer[p_row][p_col] = qadd8(rgb_frame_buffer[p_row][p_col], 13); + } + + if (m_row < row) { + if (m_col < col) + rgb_frame_buffer[m_row][m_col] = qadd8(rgb_frame_buffer[m_row][m_col], 13); + rgb_frame_buffer[m_row][col] = qadd8(rgb_frame_buffer[m_row][col], 16); + if (p_col < MATRIX_COLS) + rgb_frame_buffer[m_row][p_col] = qadd8(rgb_frame_buffer[m_row][p_col], 13); + } +} + +bool rgb_matrix_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(rgb_frame_buffer)) + led_max = sizeof(rgb_frame_buffer); + + if (params->init) { + rgb_matrix_set_color_all(0, 0, 0); + memset(rgb_frame_buffer, 0, sizeof rgb_frame_buffer); + } + + // 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 = 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.sat, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.val) }; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b); + } + + rgb_frame_buffer[row][col] = qsub8(val, 1); + } + + return led_max < sizeof(rgb_frame_buffer); +} + +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) From 5d9a4c4414b557ab6fb0d0ded35debeaf2c79a55 Mon Sep 17 00:00:00 2001 From: Rainer Clasen Date: Tue, 7 May 2019 19:45:10 +0200 Subject: [PATCH 07/19] [Split] fix split_common i2c backlight disabling (#3886) slave backlight was always on - as get_backlight_level() doesn't indicate if the backlight is enabled or not. also updated the corosponding code for serial transport to stop peeking directly at 'internal' backlight_config structure. --- changelog.md | 1 + quantum/split_common/transport.c | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index cdebe64f43..f176ff646d 100644 --- a/changelog.md +++ b/changelog.md @@ -16,3 +16,4 @@ 05-05-2019 - New keycode macro (XP) for shifted character pairs using UNICODEMAP, and bugfixes/improvements 05-05-2019 - Add `LINK_TIME_OPTIMIZATION_ENABLE` to enable LTO and disable problematic features that cause LTO to fail 05-05-2019 - Fix issue with Space Cadet +05-10-2019 - Split Common i2c Backlight fix diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 7ea1a9cec9..a3539576f5 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -13,7 +13,6 @@ #ifdef BACKLIGHT_ENABLE # include "backlight.h" -extern backlight_config_t backlight_config; #endif #ifdef ENCODER_ENABLE @@ -55,7 +54,7 @@ bool transport_master(matrix_row_t matrix[]) { // write backlight info # ifdef BACKLIGHT_ENABLE - uint8_t level = get_backlight_level(); + uint8_t level = is_backlight_enabled() ? get_backlight_level() : 0; if (level != i2c_buffer->backlight_level) { if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIGHT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) { i2c_buffer->backlight_level = level; @@ -223,7 +222,7 @@ bool transport_master(matrix_row_t matrix[]) { # ifdef BACKLIGHT_ENABLE // Write backlight level for slave to read - serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0; + serial_m2s_buffer.backlight_level = is_backlight_enabled() ? get_backlight_level() : 0; # endif # ifdef ENCODER_ENABLE From 665e719e31eda70f225f333e70cdba8197f58cf9 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Fri, 10 May 2019 18:55:02 -0500 Subject: [PATCH 08/19] Cleanup/rgb matrix (#5811) * clean up rgb matrix extern usage Moved rgb matrix boiler plate into macros Rebased onto typing heatmap pr * Fixing the reversed frame buffer access in digital rain * Fixing digital rain & typing heatmap if keyreactive effects are not enabled * Apply suggestions from code review Co-Authored-By: Drashna Jaelre * Adding parenthesizes to DRIVER_LED_TOTAL where necessary * Updated docs * added notes about parentheses --- keyboards/ergodox_ez/config.h | 2 +- quantum/quantum.c | 2 +- quantum/rgb_matrix.c | 196 +++--------------- quantum/rgb_matrix.h | 103 ++------- .../rgb_matrix_animations/alpha_mods_anim.h | 9 +- .../rgb_matrix_animations/breathing_anim.h | 9 +- .../rgb_matrix_animations/cycle_all_anim.h | 10 +- .../cycle_left_right_anim.h | 10 +- .../cycle_up_down_anim.h | 10 +- .../rgb_matrix_animations/digital_rain_anim.h | 32 +-- .../rgb_matrix_animations/dual_beacon_anim.h | 10 +- .../gradient_up_down_anim.h | 10 +- .../jellybean_raindrops_anim.h | 10 +- .../rainbow_beacon_anim.h | 10 +- .../rainbow_moving_chevron_anim.h | 10 +- .../rainbow_pinwheels_anim.h | 10 +- .../rgb_matrix_animations/raindrops_anim.h | 11 +- .../rgb_matrix_effects.inc | 23 ++ .../rgb_matrix_animations/solid_color_anim.h | 10 +- .../solid_reactive_anim.h | 16 +- .../solid_reactive_cross.h | 18 +- .../solid_reactive_nexus.h | 18 +- .../solid_reactive_simple_anim.h | 9 +- .../solid_reactive_wide.h | 18 +- .../rgb_matrix_animations/solid_splash_anim.h | 18 +- quantum/rgb_matrix_animations/splash_anim.h | 19 +- .../typing_heatmap_anim.h | 9 +- tmk_core/protocol/arm_atsam/led_matrix.c | 3 - 28 files changed, 215 insertions(+), 400 deletions(-) create mode 100644 quantum/rgb_matrix_animations/rgb_matrix_effects.inc diff --git a/keyboards/ergodox_ez/config.h b/keyboards/ergodox_ez/config.h index cbf7f8aaa2..d22836bd86 100644 --- a/keyboards/ergodox_ez/config.h +++ b/keyboards/ergodox_ez/config.h @@ -107,7 +107,7 @@ along with this program. If not, see . #define DRIVER_COUNT 2 #define DRIVER_1_LED_TOTAL 24 #define DRIVER_2_LED_TOTAL 24 -#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL +#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) // #define RGBLIGHT_COLOR_LAYER_0 0x00, 0x00, 0xFF /* #define RGBLIGHT_COLOR_LAYER_1 0x00, 0x00, 0xFF */ diff --git a/quantum/quantum.c b/quantum/quantum.c index 2d21bf0773..43d7be7b87 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -264,7 +264,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef HAPTIC_ENABLE process_haptic(keycode, record) && #endif //HAPTIC_ENABLE - #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYREACTIVE_ENABLED) + #if defined(RGB_MATRIX_ENABLE) process_rgb_matrix(keycode, record) && #endif process_record_kb(keycode, record) && diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 92a94df80f..9b9932df52 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -26,41 +26,23 @@ #include "lib/lib8tion/lib8tion.h" -#include "rgb_matrix_animations/solid_color_anim.h" -#include "rgb_matrix_animations/alpha_mods_anim.h" -#include "rgb_matrix_animations/dual_beacon_anim.h" -#include "rgb_matrix_animations/gradient_up_down_anim.h" -#include "rgb_matrix_animations/raindrops_anim.h" -#include "rgb_matrix_animations/cycle_all_anim.h" -#include "rgb_matrix_animations/cycle_left_right_anim.h" -#include "rgb_matrix_animations/cycle_up_down_anim.h" -#include "rgb_matrix_animations/rainbow_beacon_anim.h" -#include "rgb_matrix_animations/rainbow_pinwheels_anim.h" -#include "rgb_matrix_animations/rainbow_moving_chevron_anim.h" -#include "rgb_matrix_animations/jellybean_raindrops_anim.h" -#include "rgb_matrix_animations/typing_heatmap_anim.h" -#include "rgb_matrix_animations/digital_rain_anim.h" -#include "rgb_matrix_animations/solid_reactive_simple_anim.h" -#include "rgb_matrix_animations/solid_reactive_anim.h" -#include "rgb_matrix_animations/solid_reactive_wide.h" -#include "rgb_matrix_animations/solid_reactive_cross.h" -#include "rgb_matrix_animations/solid_reactive_nexus.h" -#include "rgb_matrix_animations/splash_anim.h" -#include "rgb_matrix_animations/solid_splash_anim.h" -#include "rgb_matrix_animations/breathing_anim.h" +// ------------------------------------------ +// -----Begin rgb effect includes macros----- +#define RGB_MATRIX_EFFECT(name) +#define RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) - #define RGB_MATRIX_CUSTOM_EFFECT_IMPLS - #define RGB_MATRIX_EFFECT(name, ...) - #ifdef RGB_MATRIX_CUSTOM_KB - #include "rgb_matrix_kb.inc" - #endif - #ifdef RGB_MATRIX_CUSTOM_USER - #include "rgb_matrix_user.inc" - #endif - #undef RGB_MATRIX_EFFECT - #undef RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#include "rgb_matrix_animations/rgb_matrix_effects.inc" +#ifdef RGB_MATRIX_CUSTOM_KB + #include "rgb_matrix_kb.inc" #endif +#ifdef RGB_MATRIX_CUSTOM_USER + #include "rgb_matrix_user.inc" +#endif + +#undef RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#undef RGB_MATRIX_EFFECT +// -----End rgb effect includes macros------- +// ------------------------------------------ #ifndef RGB_DISABLE_AFTER_TIMEOUT #define RGB_DISABLE_AFTER_TIMEOUT 0 @@ -106,7 +88,6 @@ bool g_suspend_state = false; -extern led_config_t g_led_config; rgb_config_t rgb_matrix_config; rgb_counters_t g_rgb_counters; @@ -319,145 +300,14 @@ static void rgb_task_render(uint8_t effect) { rendering = rgb_matrix_none(&rgb_effect_params); break; - case RGB_MATRIX_SOLID_COLOR: - rendering = rgb_matrix_solid_color(&rgb_effect_params); // Max 1ms Avg 0ms - break; -#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS - case RGB_MATRIX_ALPHAS_MODS: - rendering = rgb_matrix_alphas_mods(&rgb_effect_params); // Max 2ms Avg 1ms - break; -#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS -#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN - case RGB_MATRIX_GRADIENT_UP_DOWN: - rendering = rgb_matrix_gradient_up_down(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN -#ifndef DISABLE_RGB_MATRIX_BREATHING - case RGB_MATRIX_BREATHING: - rendering = rgb_matrix_breathing(&rgb_effect_params); // Max 1ms Avg 0ms - break; -#endif // DISABLE_RGB_MATRIX_BREATHING -#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL - case RGB_MATRIX_CYCLE_ALL: - rendering = rgb_matrix_cycle_all(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_CYCLE_ALL -#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT - case RGB_MATRIX_CYCLE_LEFT_RIGHT: - rendering = rgb_matrix_cycle_left_right(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT -#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN - case RGB_MATRIX_CYCLE_UP_DOWN: - rendering = rgb_matrix_cycle_up_down(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN -#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON - case RGB_MATRIX_RAINBOW_MOVING_CHEVRON: - rendering = rgb_matrix_rainbow_moving_chevron(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON -#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON - case RGB_MATRIX_DUAL_BEACON: - rendering = rgb_matrix_dual_beacon(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_DUAL_BEACON -#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON - case RGB_MATRIX_RAINBOW_BEACON: - rendering = rgb_matrix_rainbow_beacon(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON -#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS - case RGB_MATRIX_RAINBOW_PINWHEELS: - rendering = rgb_matrix_rainbow_pinwheels(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS -#ifndef DISABLE_RGB_MATRIX_RAINDROPS - case RGB_MATRIX_RAINDROPS: - rendering = rgb_matrix_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms - break; -#endif // DISABLE_RGB_MATRIX_RAINDROPS -#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS - case RGB_MATRIX_JELLYBEAN_RAINDROPS: - rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms - break; -#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS - -#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS -#ifndef DISABLE_RGB_MATRIX_TYPING_HEATMAP - case RGB_MATRIX_TYPING_HEATMAP: - rendering = rgb_matrix_typing_heatmap(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_TYPING_HEATMAP -#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN - case RGB_MATRIX_DIGITAL_RAIN: - rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it - break; -#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN -#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS - -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE - case RGB_MATRIX_SOLID_REACTIVE_SIMPLE: - rendering = rgb_matrix_solid_reactive_simple(&rgb_effect_params);// Max 4ms Avg 3ms - break; -#endif -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE - case RGB_MATRIX_SOLID_REACTIVE: - rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE - case RGB_MATRIX_SOLID_REACTIVE_WIDE: - rendering = rgb_matrix_solid_reactive_wide(&rgb_effect_params); // Max ?? ms Avg ?? ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE - case RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE: - rendering = rgb_matrix_solid_reactive_multiwide(&rgb_effect_params); // Max ?? ms Avg ?? ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS - case RGB_MATRIX_SOLID_REACTIVE_CROSS: - rendering = rgb_matrix_solid_reactive_cross(&rgb_effect_params); // Max ?? ms Avg ?? ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS - case RGB_MATRIX_SOLID_REACTIVE_MULTICROSS: - rendering = rgb_matrix_solid_reactive_multicross(&rgb_effect_params); // Max ?? ms Avg ?? ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS - case RGB_MATRIX_SOLID_REACTIVE_NEXUS: - rendering = rgb_matrix_solid_reactive_nexus(&rgb_effect_params); // Max ?? ms Avg ?? ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS - case RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS: - rendering = rgb_matrix_solid_reactive_multinexus(&rgb_effect_params); // Max ?? ms Avg ?? ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS -#ifndef DISABLE_RGB_MATRIX_SPLASH - case RGB_MATRIX_SPLASH: - rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_SPLASH -#ifndef DISABLE_RGB_MATRIX_MULTISPLASH - case RGB_MATRIX_MULTISPLASH: - rendering = rgb_matrix_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms - break; -#endif // DISABLE_RGB_MATRIX_MULTISPLASH -#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH - case RGB_MATRIX_SOLID_SPLASH: - rendering = rgb_matrix_solid_splash(&rgb_effect_params); // Max 5ms Avg 3ms - break; -#endif // DISABLE_RGB_MATRIX_SOLID_SPLASH -#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH - case RGB_MATRIX_SOLID_MULTISPLASH: - rendering = rgb_matrix_solid_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms +// --------------------------------------------- +// -----Begin rgb effect switch case macros----- +#define RGB_MATRIX_EFFECT(name, ...) \ + case RGB_MATRIX_##name: \ + rendering = name(&rgb_effect_params); \ break; -#endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#include "rgb_matrix_animations/rgb_matrix_effects.inc" +#undef RGB_MATRIX_EFFECT #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) #define RGB_MATRIX_EFFECT(name, ...) \ @@ -472,6 +322,8 @@ static void rgb_task_render(uint8_t effect) { #endif #undef RGB_MATRIX_EFFECT #endif +// -----End rgb effect switch case macros------- +// --------------------------------------------- // Factory default magic value case UINT8_MAX: { diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index add0715d9f..96a8b76627 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -64,89 +64,12 @@ typedef struct enum rgb_matrix_effects { RGB_MATRIX_NONE = 0, - RGB_MATRIX_SOLID_COLOR = 1, -#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS - RGB_MATRIX_ALPHAS_MODS, -#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS -#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN - RGB_MATRIX_GRADIENT_UP_DOWN, -#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN -#ifndef DISABLE_RGB_MATRIX_BREATHING - RGB_MATRIX_BREATHING, -#endif // DISABLE_RGB_MATRIX_BREATHING -#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL - RGB_MATRIX_CYCLE_ALL, -#endif // DISABLE_RGB_MATRIX_CYCLE_ALL -#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT - RGB_MATRIX_CYCLE_LEFT_RIGHT, -#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT -#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN - RGB_MATRIX_CYCLE_UP_DOWN, -#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN -#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON - RGB_MATRIX_RAINBOW_MOVING_CHEVRON, -#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON -#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON - RGB_MATRIX_DUAL_BEACON, -#endif // DISABLE_RGB_MATRIX_DUAL_BEACON -#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON - RGB_MATRIX_RAINBOW_BEACON, -#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON -#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS - RGB_MATRIX_RAINBOW_PINWHEELS, -#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS -#ifndef DISABLE_RGB_MATRIX_RAINDROPS - RGB_MATRIX_RAINDROPS, -#endif // DISABLE_RGB_MATRIX_RAINDROPS -#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS - RGB_MATRIX_JELLYBEAN_RAINDROPS, -#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS -#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS -#ifndef DISABLE_RGB_MATRIX_TYPING_HEATMAP - RGB_MATRIX_TYPING_HEATMAP, -#endif // DISABLE_RGB_MATRIX_TYPING_HEATMAP -#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN - RGB_MATRIX_DIGITAL_RAIN, -#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN -#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE - RGB_MATRIX_SOLID_REACTIVE_SIMPLE, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE - RGB_MATRIX_SOLID_REACTIVE, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE - RGB_MATRIX_SOLID_REACTIVE_WIDE, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE - RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS - RGB_MATRIX_SOLID_REACTIVE_CROSS, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS - RGB_MATRIX_SOLID_REACTIVE_MULTICROSS, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS - RGB_MATRIX_SOLID_REACTIVE_NEXUS, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS -#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS - RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS, -#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS -#ifndef DISABLE_RGB_MATRIX_SPLASH - RGB_MATRIX_SPLASH, -#endif // DISABLE_RGB_MATRIX_SPLASH -#ifndef DISABLE_RGB_MATRIX_MULTISPLASH - RGB_MATRIX_MULTISPLASH, -#endif // DISABLE_RGB_MATRIX_MULTISPLASH -#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH - RGB_MATRIX_SOLID_SPLASH, -#endif // DISABLE_RGB_MATRIX_SOLID_SPLASH -#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH - RGB_MATRIX_SOLID_MULTISPLASH, -#endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED + +// -------------------------------------- +// -----Begin rgb effect enum macros----- +#define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name, +#include "rgb_matrix_animations/rgb_matrix_effects.inc" +#undef RGB_MATRIX_EFFECT #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name, @@ -158,6 +81,8 @@ enum rgb_matrix_effects { #endif #undef RGB_MATRIX_EFFECT #endif +// -------------------------------------- +// -----End rgb effect enum macros------- RGB_MATRIX_EFFECT_MAX }; @@ -257,4 +182,16 @@ typedef struct { extern const rgb_matrix_driver_t rgb_matrix_driver; +extern rgb_config_t rgb_matrix_config; + +extern bool g_suspend_state; +extern rgb_counters_t g_rgb_counters; +extern led_config_t g_led_config; +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +extern last_hit_t g_last_hit_tracker; +#endif +#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS +extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; +#endif + #endif diff --git a/quantum/rgb_matrix_animations/alpha_mods_anim.h b/quantum/rgb_matrix_animations/alpha_mods_anim.h index d7f6f4655b..0fee19aefc 100644 --- a/quantum/rgb_matrix_animations/alpha_mods_anim.h +++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h @@ -1,11 +1,9 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS - -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; +RGB_MATRIX_EFFECT(ALPHAS_MODS) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS // alphas = color1, mods = color2 -bool rgb_matrix_alphas_mods(effect_params_t* params) { +bool 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 }; @@ -24,4 +22,5 @@ bool rgb_matrix_alphas_mods(effect_params_t* params) { 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 index 54d60f927d..c357b53031 100644 --- a/quantum/rgb_matrix_animations/breathing_anim.h +++ b/quantum/rgb_matrix_animations/breathing_anim.h @@ -1,10 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_BREATHING +RGB_MATRIX_EFFECT(BREATHING) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_breathing(effect_params_t* params) { +bool 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); @@ -18,4 +16,5 @@ bool rgb_matrix_breathing(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #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 index e93798f900..e6319cad7f 100644 --- a/quantum/rgb_matrix_animations/cycle_all_anim.h +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h @@ -1,11 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL +RGB_MATRIX_EFFECT(CYCLE_ALL) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_cycle_all(effect_params_t* params) { +bool 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 }; @@ -18,4 +15,5 @@ bool rgb_matrix_cycle_all(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#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 index 4b09d5826b..d9a00530a0 100644 --- a/quantum/rgb_matrix_animations/cycle_left_right_anim.h +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h @@ -1,11 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +RGB_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_cycle_left_right(effect_params_t* params) { +bool 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 }; @@ -19,4 +16,5 @@ bool rgb_matrix_cycle_left_right(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #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 index 403214bb73..f2b31d9da5 100644 --- a/quantum/rgb_matrix_animations/cycle_up_down_anim.h +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h @@ -1,11 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN +RGB_MATRIX_EFFECT(CYCLE_UP_DOWN) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_cycle_up_down(effect_params_t* params) { +bool 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 }; @@ -19,4 +16,5 @@ bool rgb_matrix_cycle_up_down(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#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 index 6ccba392aa..982399cbde 100644 --- a/quantum/rgb_matrix_animations/digital_rain_anim.h +++ b/quantum/rgb_matrix_animations/digital_rain_anim.h @@ -1,14 +1,13 @@ -#pragma once #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 -extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; - -bool rgb_matrix_digital_rain(effect_params_t* params) { +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; @@ -19,7 +18,7 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { if (params->init) { rgb_matrix_set_color_all(0, 0, 0); - memset(rgb_frame_buffer, 0, sizeof rgb_frame_buffer); + memset(rgb_frame_buffer, 0, sizeof(rgb_frame_buffer)); drop = 0; } @@ -28,11 +27,11 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { 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 - rgb_frame_buffer[col][row] = max_intensity; + rgb_frame_buffer[row][col] = max_intensity; } - else if (rgb_frame_buffer[col][row] > 0 && rgb_frame_buffer[col][row] < max_intensity) { + else if (rgb_frame_buffer[row][col] > 0 && rgb_frame_buffer[row][col] < max_intensity) { // neither fully bright nor dark, decay it - rgb_frame_buffer[col][row]--; + rgb_frame_buffer[row][col]--; } // set the pixel colour uint8_t led[LED_HITS_TO_REMEMBER]; @@ -40,12 +39,12 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { // TODO: multiple leds are supported mapped to the same row/column if (led_count > 0) { - if (rgb_frame_buffer[col][row] > pure_green_intensity) { - const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (rgb_frame_buffer[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity)); + if (rgb_frame_buffer[row][col] > pure_green_intensity) { + const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (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 * rgb_frame_buffer[col][row] / pure_green_intensity); + const uint8_t green = (uint8_t) ((uint16_t) max_intensity * rgb_frame_buffer[row][col] / pure_green_intensity); rgb_matrix_set_color(led[0], 0, green, 0); } } @@ -58,15 +57,15 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { 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 && rgb_frame_buffer[col][row] == max_intensity) { - rgb_frame_buffer[col][row]--; + if (row == MATRIX_ROWS - 1 && rgb_frame_buffer[row][col] == max_intensity) { + rgb_frame_buffer[row][col]--; } // check if the pixel above is bright - if (rgb_frame_buffer[col][row - 1] == max_intensity) { + if (rgb_frame_buffer[row - 1][col] == max_intensity) { // allow old bright pixel to decay - rgb_frame_buffer[col][row - 1]--; + rgb_frame_buffer[row - 1][col]--; // make this pixel bright - rgb_frame_buffer[col][row] = max_intensity; + rgb_frame_buffer[row][col] = max_intensity; } } } @@ -74,4 +73,5 @@ bool rgb_matrix_digital_rain(effect_params_t* params) { 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 index dcb594029e..f853f71ecc 100644 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -1,11 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON +RGB_MATRIX_EFFECT(DUAL_BEACON) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_dual_beacon(effect_params_t* params) { +bool 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 }; @@ -21,4 +18,5 @@ bool rgb_matrix_dual_beacon(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #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 index 7a6ed14219..d9fcd4d988 100644 --- a/quantum/rgb_matrix_animations/gradient_up_down_anim.h +++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h @@ -1,10 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN +RGB_MATRIX_EFFECT(GRADIENT_UP_DOWN) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_gradient_up_down(effect_params_t* params) { +bool 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 }; @@ -19,4 +17,6 @@ bool rgb_matrix_gradient_up_down(effect_params_t* params) { } 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/jellybean_raindrops_anim.h b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h index 5ea971435e..8f0b1bd914 100644 --- a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h +++ b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h @@ -1,9 +1,6 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS - -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; +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; @@ -12,7 +9,7 @@ static void jellybean_raindrops_set_color(int i, effect_params_t* params) { rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } -bool rgb_matrix_jellybean_raindrops(effect_params_t* params) { +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_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { @@ -28,4 +25,5 @@ bool rgb_matrix_jellybean_raindrops(effect_params_t* 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 index d462880731..a0e0f814c5 100644 --- a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h @@ -1,11 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON +RGB_MATRIX_EFFECT(RAINBOW_BEACON) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_rainbow_beacon(effect_params_t* params) { +bool 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 }; @@ -21,4 +18,5 @@ bool rgb_matrix_rainbow_beacon(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#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 index 3b7d9689f8..39352b0c13 100644 --- a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h @@ -1,11 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +RGB_MATRIX_EFFECT(RAINBOW_MOVING_CHEVRON) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { +bool 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 }; @@ -19,4 +16,5 @@ bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#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 index e92f351765..275aaa48d9 100644 --- a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h @@ -1,11 +1,8 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS +RGB_MATRIX_EFFECT(PINWHEELS) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { +bool PINWHEELS(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; @@ -21,4 +18,5 @@ bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#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 index 4ce1d65e57..09d0d1df87 100644 --- a/quantum/rgb_matrix_animations/raindrops_anim.h +++ b/quantum/rgb_matrix_animations/raindrops_anim.h @@ -1,10 +1,6 @@ -#pragma once #ifndef DISABLE_RGB_MATRIX_RAINDROPS -#include "rgb_matrix_types.h" - -extern rgb_counters_t g_rgb_counters; -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; +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; @@ -23,7 +19,7 @@ static void raindrops_set_color(int i, effect_params_t* params) { rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } -bool rgb_matrix_raindrops(effect_params_t* params) { +bool 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) { @@ -39,4 +35,5 @@ bool rgb_matrix_raindrops(effect_params_t* 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..9bc6454613 --- /dev/null +++ b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc @@ -0,0 +1,23 @@ +// Add your new core rgb matrix effect here, order determins enum order, requires "rgb_matrix_animations/ directory +#include "rgb_matrix_animations/solid_color_anim.h" +#include "rgb_matrix_animations/alpha_mods_anim.h" +#include "rgb_matrix_animations/gradient_up_down_anim.h" +#include "rgb_matrix_animations/breathing_anim.h" +#include "rgb_matrix_animations/cycle_all_anim.h" +#include "rgb_matrix_animations/cycle_left_right_anim.h" +#include "rgb_matrix_animations/cycle_up_down_anim.h" +#include "rgb_matrix_animations/rainbow_moving_chevron_anim.h" +#include "rgb_matrix_animations/dual_beacon_anim.h" +#include "rgb_matrix_animations/rainbow_beacon_anim.h" +#include "rgb_matrix_animations/rainbow_pinwheels_anim.h" +#include "rgb_matrix_animations/raindrops_anim.h" +#include "rgb_matrix_animations/jellybean_raindrops_anim.h" +#include "rgb_matrix_animations/typing_heatmap_anim.h" +#include "rgb_matrix_animations/digital_rain_anim.h" +#include "rgb_matrix_animations/solid_reactive_simple_anim.h" +#include "rgb_matrix_animations/solid_reactive_anim.h" +#include "rgb_matrix_animations/solid_reactive_wide.h" +#include "rgb_matrix_animations/solid_reactive_cross.h" +#include "rgb_matrix_animations/solid_reactive_nexus.h" +#include "rgb_matrix_animations/splash_anim.h" +#include "rgb_matrix_animations/solid_splash_anim.h" diff --git a/quantum/rgb_matrix_animations/solid_color_anim.h b/quantum/rgb_matrix_animations/solid_color_anim.h index ba2cea15e3..9376425598 100644 --- a/quantum/rgb_matrix_animations/solid_color_anim.h +++ b/quantum/rgb_matrix_animations/solid_color_anim.h @@ -1,9 +1,7 @@ -#pragma once +RGB_MATRIX_EFFECT(SOLID_COLOR) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; - -bool rgb_matrix_solid_color(effect_params_t* params) { +bool 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 }; @@ -14,3 +12,5 @@ bool rgb_matrix_solid_color(effect_params_t* params) { } 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 index c3dba8a5af..37e339907a 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h @@ -1,12 +1,9 @@ -#pragma once -#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE +RGB_MATRIX_EFFECT(SOLID_REACTIVE) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; -extern last_hit_t g_last_hit_tracker; - -bool rgb_matrix_solid_reactive(effect_params_t* params) { +bool SOLID_REACTIVE(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val }; @@ -32,5 +29,6 @@ bool rgb_matrix_solid_reactive(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } -#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON -#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) +#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 index 8858f71e60..62210f82d6 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_cross.h +++ b/quantum/rgb_matrix_animations/solid_reactive_cross.h @@ -1,10 +1,15 @@ -#pragma once #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; -extern last_hit_t g_last_hit_tracker; +#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 bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); @@ -38,13 +43,14 @@ static bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, effect_par return led_max < DRIVER_LED_TOTAL; } -bool rgb_matrix_solid_reactive_multicross(effect_params_t* params) { +bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return rgb_matrix_solid_reactive_multicross_range(0, params); } -bool rgb_matrix_solid_reactive_cross(effect_params_t* params) { +bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return rgb_matrix_solid_reactive_multicross_range(qsub8(g_last_hit_tracker.count, 1), params); } +#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 index c0e3c24507..33f478ac70 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_nexus.h +++ b/quantum/rgb_matrix_animations/solid_reactive_nexus.h @@ -1,10 +1,15 @@ -#pragma once #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; -extern last_hit_t g_last_hit_tracker; +#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 bool rgb_matrix_solid_reactive_multinexus_range(uint8_t start, effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); @@ -36,13 +41,14 @@ static bool rgb_matrix_solid_reactive_multinexus_range(uint8_t start, effect_par return led_max < DRIVER_LED_TOTAL; } -bool rgb_matrix_solid_reactive_multinexus(effect_params_t* params) { +bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return rgb_matrix_solid_reactive_multinexus_range(0, params); } -bool rgb_matrix_solid_reactive_nexus(effect_params_t* params) { +bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return rgb_matrix_solid_reactive_multinexus_range(qsub8(g_last_hit_tracker.count, 1), params); } +#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 index abc7e36a89..a568a54386 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h @@ -1,12 +1,10 @@ #pragma once #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -extern led_config_t g_led_config; -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) { +bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; @@ -31,5 +29,6 @@ bool rgb_matrix_solid_reactive_simple(effect_params_t* params) { return led_max < DRIVER_LED_TOTAL; } +#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 index 3d1d38e806..ff0f6f5eca 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_wide.h +++ b/quantum/rgb_matrix_animations/solid_reactive_wide.h @@ -1,10 +1,15 @@ -#pragma once #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; -extern last_hit_t g_last_hit_tracker; +#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 bool rgb_matrix_solid_reactive_multiwide_range(uint8_t start, effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); @@ -30,13 +35,14 @@ static bool rgb_matrix_solid_reactive_multiwide_range(uint8_t start, effect_para return led_max < DRIVER_LED_TOTAL; } -bool rgb_matrix_solid_reactive_multiwide(effect_params_t* params) { +bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return rgb_matrix_solid_reactive_multiwide_range(0, params); } -bool rgb_matrix_solid_reactive_wide(effect_params_t* params) { +bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return rgb_matrix_solid_reactive_multiwide_range(qsub8(g_last_hit_tracker.count, 1), params); } +#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 index 4e5565d0d3..d439bd8880 100644 --- a/quantum/rgb_matrix_animations/solid_splash_anim.h +++ b/quantum/rgb_matrix_animations/solid_splash_anim.h @@ -1,10 +1,15 @@ -#pragma once #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; -extern last_hit_t g_last_hit_tracker; +#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 static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); @@ -30,13 +35,14 @@ static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* p return led_max < DRIVER_LED_TOTAL; } -bool rgb_matrix_solid_multisplash(effect_params_t* params) { +bool SOLID_MULTISPLASH(effect_params_t* params) { return rgb_matrix_solid_multisplash_range(0, params); } -bool rgb_matrix_solid_splash(effect_params_t* params) { +bool SOLID_SPLASH(effect_params_t* params) { return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); } +#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 index fbe7761117..214dab68da 100644 --- a/quantum/rgb_matrix_animations/splash_anim.h +++ b/quantum/rgb_matrix_animations/splash_anim.h @@ -1,10 +1,16 @@ -#pragma once #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) -extern led_config_t g_led_config; -extern rgb_config_t rgb_matrix_config; -extern last_hit_t g_last_hit_tracker; +#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 + static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); @@ -32,13 +38,14 @@ static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) return led_max < DRIVER_LED_TOTAL; } -bool rgb_matrix_multisplash(effect_params_t* params) { +bool MULTISPLASH(effect_params_t* params) { return rgb_matrix_multisplash_range(0, params); } -bool rgb_matrix_splash(effect_params_t* params) { +bool SPLASH(effect_params_t* params) { return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); } +#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 index aade53fccc..e6b34717b2 100644 --- a/quantum/rgb_matrix_animations/typing_heatmap_anim.h +++ b/quantum/rgb_matrix_animations/typing_heatmap_anim.h @@ -1,8 +1,6 @@ -#pragma once #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) - -extern rgb_config_t rgb_matrix_config; -extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; +RGB_MATRIX_EFFECT(TYPING_HEATMAP) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS void process_rgb_matrix_typing_heatmap(keyrecord_t *record) { uint8_t row = record->event.key.row; @@ -35,7 +33,7 @@ void process_rgb_matrix_typing_heatmap(keyrecord_t *record) { } } -bool rgb_matrix_typing_heatmap(effect_params_t* params) { +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; @@ -72,4 +70,5 @@ bool rgb_matrix_typing_heatmap(effect_params_t* params) { return led_max < sizeof(rgb_frame_buffer); } +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) diff --git a/tmk_core/protocol/arm_atsam/led_matrix.c b/tmk_core/protocol/arm_atsam/led_matrix.c index ea067a7439..42dfccbc50 100644 --- a/tmk_core/protocol/arm_atsam/led_matrix.c +++ b/tmk_core/protocol/arm_atsam/led_matrix.c @@ -27,8 +27,6 @@ led_instruction_t led_instructions[] = { { .end = 1 } }; static void led_matrix_massdrop_config_override(int i); #endif // USE_MASSDROP_CONFIGURATOR -extern rgb_config_t rgb_matrix_config; -extern rgb_counters_t g_rgb_counters; void SERCOM1_0_Handler( void ) { @@ -431,7 +429,6 @@ static void led_run_pattern(led_setup_t *f, float* ro, float* go, float* bo, flo } } -extern led_config_t g_led_config; static void led_matrix_massdrop_config_override(int i) { float ro = 0; From a8ed2608b5c9bbe39531661496449b1096db2ee7 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Fri, 10 May 2019 21:56:16 -0500 Subject: [PATCH 09/19] RGB Matrix Effects: Cycle Out to In & Cycle Out to In Dual (#5812) --- .../rgb_matrix_animations/cycle_out_in_anim.h | 23 +++++++++++++++++++ .../cycle_out_in_dual_anim.h | 23 +++++++++++++++++++ .../rgb_matrix_effects.inc | 2 ++ 3 files changed, 48 insertions(+) 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 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..dc9d09fd3f --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_out_in_anim.h @@ -0,0 +1,23 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN +RGB_MATRIX_EFFECT(CYCLE_OUT_IN) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool CYCLE_OUT_IN(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - 112; + int16_t dy = g_led_config.point[i].y - 32; + uint8_t dist = sqrt16(dx * dx + dy * dy); + hsv.h = 3 * dist / 2 + time; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#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..941e6b9a8a --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h @@ -0,0 +1,23 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +RGB_MATRIX_EFFECT(CYCLE_OUT_IN_DUAL) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = 56 - abs8(g_led_config.point[i].x - 112); + int16_t dy = g_led_config.point[i].y - 32; + uint8_t dist = sqrt16(dx * dx + dy * dy); + hsv.h = 3 * dist + time; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL diff --git a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc index 9bc6454613..f05a415a58 100644 --- a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc +++ b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc @@ -7,6 +7,8 @@ #include "rgb_matrix_animations/cycle_left_right_anim.h" #include "rgb_matrix_animations/cycle_up_down_anim.h" #include "rgb_matrix_animations/rainbow_moving_chevron_anim.h" +#include "rgb_matrix_animations/cycle_out_in_anim.h" +#include "rgb_matrix_animations/cycle_out_in_dual_anim.h" #include "rgb_matrix_animations/dual_beacon_anim.h" #include "rgb_matrix_animations/rainbow_beacon_anim.h" #include "rgb_matrix_animations/rainbow_pinwheels_anim.h" From c4f2f95db8e1b3c09e41ab1f02b8233171007fa0 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 7 May 2019 21:52:46 -0700 Subject: [PATCH 10/19] Enable additional animation modes for the Glow keyboards --- keyboards/ergodox_ez/keymaps/glow/rules.mk | 2 ++ keyboards/ergodox_ez/keymaps/reactive/config.h | 6 ++++++ keyboards/ergodox_ez/keymaps/reactive/rules.mk | 3 +++ keyboards/planck/ez/config.h | 1 + 4 files changed, 12 insertions(+) diff --git a/keyboards/ergodox_ez/keymaps/glow/rules.mk b/keyboards/ergodox_ez/keymaps/glow/rules.mk index 360c3c51b8..3c1b984562 100644 --- a/keyboards/ergodox_ez/keymaps/glow/rules.mk +++ b/keyboards/ergodox_ez/keymaps/glow/rules.mk @@ -2,3 +2,5 @@ RGBLIGHT_ENABLE = no RGB_MATRIX_ENABLE = yes # enable later SRC += ../default/keymap.c + +LINK_TIME_OPTIMIZATION_ENABLE = yes \ No newline at end of file diff --git a/keyboards/ergodox_ez/keymaps/reactive/config.h b/keyboards/ergodox_ez/keymaps/reactive/config.h index 458ca9a8d4..6e86f8d9d0 100644 --- a/keyboards/ergodox_ez/keymaps/reactive/config.h +++ b/keyboards/ergodox_ez/keymaps/reactive/config.h @@ -1,6 +1,12 @@ #pragma once #define RGB_MATRIX_KEYPRESSES +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS #define DISABLE_RGB_MATRIX_DIGITAL_RAIN #define DISABLE_RGB_MATRIX_ALPHAS_MODS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#define DISABLE_RGB_MATRIX_SPLASH +#define DISABLE_RGB_MATRIX_SOLID_SPLASH diff --git a/keyboards/ergodox_ez/keymaps/reactive/rules.mk b/keyboards/ergodox_ez/keymaps/reactive/rules.mk index 360c3c51b8..b1be2c921b 100644 --- a/keyboards/ergodox_ez/keymaps/reactive/rules.mk +++ b/keyboards/ergodox_ez/keymaps/reactive/rules.mk @@ -2,3 +2,6 @@ RGBLIGHT_ENABLE = no RGB_MATRIX_ENABLE = yes # enable later SRC += ../default/keymap.c + +LINK_TIME_OPTIMIZATION_ENABLE = yes +COMMAND_ENABLE = no diff --git a/keyboards/planck/ez/config.h b/keyboards/planck/ez/config.h index c449d17192..d4adf881e4 100644 --- a/keyboards/planck/ez/config.h +++ b/keyboards/planck/ez/config.h @@ -139,3 +139,4 @@ #define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL #define RGB_MATRIX_KEYPRESSES +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS From 95e4c8a461b328a33baf7d4576bad39fe0dfadfe Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sat, 11 May 2019 14:31:31 -0500 Subject: [PATCH 11/19] Fix for Solid Reactive mode bug (#5846) derp, forgot to remove the pragma once --- quantum/rgb_matrix_animations/solid_reactive_simple_anim.h | 1 - 1 file changed, 1 deletion(-) diff --git a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h index a568a54386..f235824e27 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h @@ -1,4 +1,3 @@ -#pragma once #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) From cf1b36bf83bf5dfd8bda86dcd0a2d946b298e0b6 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Thu, 16 May 2019 13:11:28 +0900 Subject: [PATCH 12/19] Add effect range to rgblight.c (#5856) * add rgblight_set_effect_range() * implement effect range * Arrange the order of function list in rgblight.h . * update docs/feature_rgblight.md * fix RGBLIGHT_RAINBOW_SWIRL_RANGE default value * add example code about Utility Functions * add example code about direct operation functions * When RGBLIGHT_SPLIT is defined, the following function has no meaning and is invalidated. * rgblight_setrgb_master(r, g, b) * rgblight_setrgb_slave(r, g, b) * rgblight_sethsv_master(h, s, v) * rgblight_sethsv_slave(h, s, v) * add temporary test code for rgblight_set_effect_range * fix rgblight_effect_knight() bug * Test End. Revert "add temporary test code for rgblight_set_effect_range" This reverts commit 5680cddd012d68b2db75a532862a7fef250f8973. --- changelog.md | 1 + quantum/rgblight.c | 117 ++++++++++++++++++++++++------------------ quantum/rgblight.h | 123 ++++++++++++++++++++++++++------------------- 3 files changed, 139 insertions(+), 102 deletions(-) diff --git a/changelog.md b/changelog.md index cdebe64f43..59518791ec 100644 --- a/changelog.md +++ b/changelog.md @@ -16,3 +16,4 @@ 05-05-2019 - New keycode macro (XP) for shifted character pairs using UNICODEMAP, and bugfixes/improvements 05-05-2019 - Add `LINK_TIME_OPTIMIZATION_ENABLE` to enable LTO and disable problematic features that cause LTO to fail 05-05-2019 - Fix issue with Space Cadet +05-16-2019 - Add RGB Light Effect Range functionality diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 77772e2925..75e4ef0d86 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -101,19 +101,35 @@ LED_TYPE led[RGBLED_NUM]; static uint8_t clipping_start_pos = 0; static uint8_t clipping_num_leds = RGBLED_NUM; +static uint8_t effect_start_pos = 0; +static uint8_t effect_end_pos = RGBLED_NUM; +static uint8_t effect_num_leds = RGBLED_NUM; void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { clipping_start_pos = start_pos; clipping_num_leds = num_leds; } +void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { + if (start_pos >= RGBLED_NUM) return; + if (start_pos + num_leds > RGBLED_NUM) return; + effect_start_pos = start_pos; + effect_end_pos = start_pos + num_leds; + effect_num_leds = num_leds; +} -void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { - HSV hsv = { hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val }; +void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { + HSV hsv = { hue, sat, val }; RGB rgb = hsv_to_rgb(hsv); setrgb(rgb.r, rgb.g, rgb.b, led1); } +void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { + sethsv_raw( hue, sat, + val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, + led1); +} + void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { (*led1).r = r; (*led1).g = g; @@ -501,15 +517,15 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w #else uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; #endif - for (uint8_t i = 0; i < RGBLED_NUM; i++) { - uint8_t _hue = ((uint16_t)i * (uint16_t)range) / RGBLED_NUM; + for (uint8_t i = 0; i < effect_num_leds; i++) { + uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; if (direction) { _hue = hue + _hue; } else { _hue = hue - _hue; } dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); - sethsv(_hue, sat, val, (LED_TYPE *)&led[i]); + sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); } rgblight_set(); } @@ -557,7 +573,7 @@ uint8_t rgblight_get_val(void) { void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { if (!rgblight_config.enable) { return; } - for (uint8_t i = 0; i < RGBLED_NUM; i++) { + for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { led[i].r = r; led[i].g = g; led[i].b = b; @@ -615,6 +631,7 @@ void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); } +#ifndef RGBLIGHT_SPLIT void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, 0 , (uint8_t) RGBLED_NUM/2); } @@ -630,36 +647,34 @@ void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); } +#endif // ifndef RGBLIGHT_SPLIT #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { - LED_TYPE *start_led = led + clipping_start_pos; + LED_TYPE *start_led; uint16_t num_leds = clipping_num_leds; - if (rgblight_config.enable) { - #ifdef RGBLIGHT_LED_MAP - LED_TYPE led0[RGBLED_NUM]; - for(uint8_t i = 0; i < RGBLED_NUM; i++) { - led0[i] = led[pgm_read_byte(&led_map[i])]; - } - start_led = led0 + clipping_start_pos; - #endif - #ifdef RGBW - ws2812_setleds_rgbw(start_led, num_leds); - #else - ws2812_setleds(start_led, num_leds); - #endif - } else { - for (uint8_t i = 0; i < RGBLED_NUM; i++) { + + if (!rgblight_config.enable) { + for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; } - #ifdef RGBW - ws2812_setleds_rgbw(start_led, num_leds); - #else - ws2812_setleds(start_led, num_leds); - #endif } +#ifdef RGBLIGHT_LED_MAP + LED_TYPE led0[RGBLED_NUM]; + for(uint8_t i = 0; i < RGBLED_NUM; i++) { + led0[i] = led[pgm_read_byte(&led_map[i])]; + } + start_led = led0 + clipping_start_pos; +#else + start_led = led + clipping_start_pos; +#endif +#ifdef RGBW + ws2812_setleds_rgbw(start_led, num_leds); +#else + ws2812_setleds(start_led, num_leds); +#endif } #endif @@ -926,9 +941,9 @@ void rgblight_effect_rainbow_swirl(animation_status_t *anim) { uint8_t hue; uint8_t i; - for (i = 0; i < RGBLED_NUM; i++) { - hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue); - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); + for (i = 0; i < effect_num_leds; i++) { + hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); } rgblight_set(); @@ -957,7 +972,7 @@ void rgblight_effect_snake(animation_status_t *anim) { #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) if (anim->pos == 0) { // restart signal if (increment == 1) { - pos = RGBLED_NUM - 1; + pos = effect_num_leds - 1; } else { pos = 0; } @@ -965,26 +980,27 @@ void rgblight_effect_snake(animation_status_t *anim) { } #endif - for (i = 0; i < RGBLED_NUM; i++) { - led[i].r = 0; - led[i].g = 0; - led[i].b = 0; + for (i = 0; i < effect_num_leds; i++) { + LED_TYPE *ledp = led + i + effect_start_pos; + ledp->r = 0; + ledp->g = 0; + ledp->b = 0; for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { k = pos + j * increment; if (k < 0) { - k = k + RGBLED_NUM; + k = k + effect_num_leds; } if (i == k) { sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), - (LED_TYPE *)&led[i]); + ledp); } } } rgblight_set(); if (increment == 1) { if (pos - 1 < 0) { - pos = RGBLED_NUM - 1; + pos = effect_num_leds - 1; #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) anim->pos = 0; #endif @@ -995,7 +1011,7 @@ void rgblight_effect_snake(animation_status_t *anim) { #endif } } else { - pos = (pos + 1) % RGBLED_NUM; + pos = (pos + 1) % effect_num_leds; #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) anim->pos = pos; #endif @@ -1023,14 +1039,14 @@ void rgblight_effect_knight(animation_status_t *anim) { } #endif // Set all the LEDs to 0 - for (i = 0; i < RGBLED_NUM; i++) { + for (i = effect_start_pos; i < effect_end_pos; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; } // Determine which LEDs should be lit up for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { - cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM; + cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; if (i >= low_bound && i <= high_bound) { sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); @@ -1064,9 +1080,9 @@ void rgblight_effect_christmas(animation_status_t *anim) { uint8_t i; anim->current_offset = (anim->current_offset + 1) % 2; - for (i = 0; i < RGBLED_NUM; i++) { + for (i = 0; i < effect_num_leds; i++) { hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); } rgblight_set(); } @@ -1099,13 +1115,14 @@ void rgblight_effect_rgbtest(animation_status_t *anim) { #ifdef RGBLIGHT_EFFECT_ALTERNATING void rgblight_effect_alternating(animation_status_t *anim) { - for(int i = 0; ipos){ - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); - }else if (i>=RGBLED_NUM/2 && !anim->pos){ - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); - }else{ - sethsv(rgblight_config.hue, rgblight_config.sat, 0, (LED_TYPE *)&led[i]); + for (int i = 0; i < effect_num_leds; i++) { + LED_TYPE *ledp = led + i + effect_start_pos; + if (ipos) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); + } else if (i>=effect_num_leds/2 && !anim->pos) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); + } else { + sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); } } rgblight_set(); diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 35d7942ca6..064522a2b0 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -99,7 +99,7 @@ enum RGBLIGHT_EFFECT_MODE { #endif #ifndef RGBLIGHT_EFFECT_KNIGHT_LED_NUM -#define RGBLIGHT_EFFECT_KNIGHT_LED_NUM RGBLED_NUM +#define RGBLIGHT_EFFECT_KNIGHT_LED_NUM (effect_num_leds) #endif #ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL @@ -170,61 +170,79 @@ typedef struct _rgblight_status_t { #endif } rgblight_status_t; -#ifdef RGBLIGHT_SPLIT - #define RGBLIGHT_STATUS_CHANGE_MODE (1<<0) - #define RGBLIGHT_STATUS_CHANGE_HSVS (1<<1) - #define RGBLIGHT_STATUS_CHANGE_TIMER (1<<2) - #define RGBLIGHT_STATUS_ANIMATION_TICK (1<<3) +/* === Utility Functions ===*/ +void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); +void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check +void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); - typedef struct _rgblight_syncinfo_t { - rgblight_config_t config; - rgblight_status_t status; - } rgblight_syncinfo_t; +/* === Low level Functions === */ +void rgblight_set(void); +void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds); - /* for split keyboard master side */ - uint8_t rgblight_get_change_flags(void); - void rgblight_clear_change_flags(void); - void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo); - /* for split keyboard slave side */ - void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom); +/* === Effects and Animations Functions === */ +/* effect range setting */ +void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds); + +/* direct operation */ +void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index); +void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index); +void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end); +void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end); +void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b); + +#ifndef RGBLIGHT_SPLIT +void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b); +void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b); +void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val); +void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val); #endif -void rgblight_init(void); +/* effect mode change */ +void rgblight_mode(uint8_t mode); +void rgblight_mode_noeeprom(uint8_t mode); void rgblight_increase(void); void rgblight_decrease(void); +void rgblight_step(void); +void rgblight_step_noeeprom(void); +void rgblight_step_reverse(void); +void rgblight_step_reverse_noeeprom(void); + +/* effects mode disable/enable */ void rgblight_toggle(void); +void rgblight_toggle_noeeprom(void); void rgblight_enable(void); +void rgblight_enable_noeeprom(void); void rgblight_disable(void); -void rgblight_step(void); -void rgblight_step_reverse(void); -uint8_t rgblight_get_mode(void); -void rgblight_mode(uint8_t mode); -void rgblight_set(void); -uint32_t rgblight_read_dword(void); -void rgblight_update_dword(uint32_t dword); +void rgblight_disable_noeeprom(void); + +/* hue, sat, val change */ void rgblight_increase_hue(void); +void rgblight_increase_hue_noeeprom(void); void rgblight_decrease_hue(void); +void rgblight_decrease_hue_noeeprom(void); void rgblight_increase_sat(void); +void rgblight_increase_sat_noeeprom(void); void rgblight_decrease_sat(void); +void rgblight_decrease_sat_noeeprom(void); void rgblight_increase_val(void); +void rgblight_increase_val_noeeprom(void); void rgblight_decrease_val(void); +void rgblight_decrease_val_noeeprom(void); void rgblight_increase_speed(void); void rgblight_decrease_speed(void); void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val); +void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val); + +/* query */ +uint8_t rgblight_get_mode(void); uint8_t rgblight_get_hue(void); uint8_t rgblight_get_sat(void); uint8_t rgblight_get_val(void); -void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b); -void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index); -void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index); -void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end); -void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end); -void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b); -void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b); -void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val); -void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val); -void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds); +/* === qmk_firmware (core)internal Functions === */ +void rgblight_init(void); +uint32_t rgblight_read_dword(void); +void rgblight_update_dword(uint32_t dword); uint32_t eeconfig_read_rgblight(void); void eeconfig_update_rgblight(uint32_t val); void eeconfig_update_rgblight_default(void); @@ -233,27 +251,9 @@ void eeconfig_debug_rgblight(void); void rgb_matrix_increase(void); void rgb_matrix_decrease(void); -void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); -void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); - -void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val); -void rgblight_mode_noeeprom(uint8_t mode); -void rgblight_toggle_noeeprom(void); -void rgblight_enable_noeeprom(void); -void rgblight_disable_noeeprom(void); -void rgblight_step_noeeprom(void); -void rgblight_step_reverse_noeeprom(void); -void rgblight_increase_hue_noeeprom(void); -void rgblight_decrease_hue_noeeprom(void); -void rgblight_increase_sat_noeeprom(void); -void rgblight_decrease_sat_noeeprom(void); -void rgblight_increase_val_noeeprom(void); -void rgblight_decrease_val_noeeprom(void); - void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom); void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom); - #define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF) void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b); @@ -264,6 +264,25 @@ void rgblight_timer_enable(void); void rgblight_timer_disable(void); void rgblight_timer_toggle(void); +#ifdef RGBLIGHT_SPLIT + #define RGBLIGHT_STATUS_CHANGE_MODE (1<<0) + #define RGBLIGHT_STATUS_CHANGE_HSVS (1<<1) + #define RGBLIGHT_STATUS_CHANGE_TIMER (1<<2) + #define RGBLIGHT_STATUS_ANIMATION_TICK (1<<3) + + typedef struct _rgblight_syncinfo_t { + rgblight_config_t config; + rgblight_status_t status; + } rgblight_syncinfo_t; + + /* for split keyboard master side */ + uint8_t rgblight_get_change_flags(void); + void rgblight_clear_change_flags(void); + void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo); + /* for split keyboard slave side */ + void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom); +#endif + #ifdef RGBLIGHT_USE_TIMER typedef struct _animation_status_t { From 1724b515b57e0ec07fcd518bddbc995d13f4e3b6 Mon Sep 17 00:00:00 2001 From: yiancar Date: Thu, 16 May 2019 05:09:36 +0100 Subject: [PATCH 13/19] NK65 Addition (#5865) * Nk65 initial commit * Minor fix for compatibility * Make everything pretty * Update keyboards/nk65/config.h Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update keyboards/nk65/readme.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Chmod Dummy * Update getting_started_introduction.md * Revert "Update getting_started_introduction.md" This reverts commit daf446acf7ae4ae00488b389ce04f2cfca708d44. --- drivers/issi/is31fl3733.c | 38 ++++++++++++++++++------------------ drivers/issi/is31fl3733.h | 6 +++--- quantum/led_matrix_drivers.c | 8 ++++---- quantum/rgb_matrix_drivers.c | 8 +++++--- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/issi/is31fl3733.c b/drivers/issi/is31fl3733.c index c18ed7ca30..aa247f4e8a 100644 --- a/drivers/issi/is31fl3733.c +++ b/drivers/issi/is31fl3733.c @@ -75,10 +75,10 @@ uint8_t g_twi_transfer_buffer[20]; // buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][192]; -bool g_pwm_buffer_update_required = false; +bool g_pwm_buffer_update_required[DRIVER_COUNT] = { false }; uint8_t g_led_control_registers[DRIVER_COUNT][24] = { { 0 }, { 0 } }; -bool g_led_control_registers_update_required = false; +bool g_led_control_registers_update_required[DRIVER_COUNT] = { false }; void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data ) { @@ -123,12 +123,13 @@ void IS31FL3733_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ) } } -void IS31FL3733_init( uint8_t addr ) +void IS31FL3733_init( uint8_t addr, uint8_t sync) { // In order to avoid the LEDs being driven with garbage data // in the LED driver's PWM registers, shutdown is enabled last. // Set up the mode and other settings, clear the PWM registers, // then disable software shutdown. + // Sync is passed so set it according to the datasheet. // Unlock the command register. IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); @@ -161,7 +162,7 @@ void IS31FL3733_init( uint8_t addr ) // Set global current to maximum. IS31FL3733_write_register( addr, ISSI_REG_GLOBALCURRENT, 0xFF ); // Disable software shutdown. - IS31FL3733_write_register( addr, ISSI_REG_CONFIGURATION, 0x01 ); + IS31FL3733_write_register( addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01 ); // Wait 10ms to ensure the device has woken up. #ifdef __AVR__ @@ -179,7 +180,7 @@ void IS31FL3733_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.g] = green; g_pwm_buffer[led.driver][led.b] = blue; - g_pwm_buffer_update_required = true; + g_pwm_buffer_update_required[led.driver] = true; } } @@ -218,35 +219,34 @@ void IS31FL3733_set_led_control_register( uint8_t index, bool red, bool green, b g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b); } - g_led_control_registers_update_required = true; + g_led_control_registers_update_required[led.driver] = true; } -void IS31FL3733_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ) +void IS31FL3733_update_pwm_buffers( uint8_t addr, uint8_t index ) { - if ( g_pwm_buffer_update_required ) + if ( g_pwm_buffer_update_required[index] ) { // Firstly we need to unlock the command register and select PG1 - IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); - IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM ); + IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); + IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM ); - IS31FL3733_write_pwm_buffer( addr1, g_pwm_buffer[0] ); - //IS31FL3733_write_pwm_buffer( addr2, g_pwm_buffer[1] ); + IS31FL3733_write_pwm_buffer( addr, g_pwm_buffer[index] ); } - g_pwm_buffer_update_required = false; + g_pwm_buffer_update_required[index] = false; } -void IS31FL3733_update_led_control_registers( uint8_t addr1, uint8_t addr2 ) +void IS31FL3733_update_led_control_registers( uint8_t addr, uint8_t index ) { - if ( g_led_control_registers_update_required ) + if ( g_led_control_registers_update_required[index] ) { // Firstly we need to unlock the command register and select PG0 - IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); - IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL ); + IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); + IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL ); for ( int i=0; i<24; i++ ) { - IS31FL3733_write_register(addr1, i, g_led_control_registers[0][i] ); - //IS31FL3733_write_register(addr2, i, g_led_control_registers[1][i] ); + IS31FL3733_write_register(addr, i, g_led_control_registers[index][i] ); } } + g_led_control_registers_update_required[index] = false; } diff --git a/drivers/issi/is31fl3733.h b/drivers/issi/is31fl3733.h index 3d23b188aa..e117b25460 100644 --- a/drivers/issi/is31fl3733.h +++ b/drivers/issi/is31fl3733.h @@ -32,7 +32,7 @@ typedef struct is31_led { extern const is31_led g_is31_leds[DRIVER_LED_TOTAL]; -void IS31FL3733_init( uint8_t addr ); +void IS31FL3733_init( uint8_t addr, uint8_t sync ); void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data ); void IS31FL3733_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ); @@ -45,8 +45,8 @@ void IS31FL3733_set_led_control_register( uint8_t index, bool red, bool green, b // (eg. from a timer interrupt). // Call this while idle (in between matrix scans). // If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3733_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ); -void IS31FL3733_update_led_control_registers( uint8_t addr1, uint8_t addr2 ); +void IS31FL3733_update_pwm_buffers( uint8_t addr, uint8_t index ); +void IS31FL3733_update_led_control_registers( uint8_t addr, uint8_t index ); #define A_1 0x00 #define A_2 0x01 diff --git a/quantum/led_matrix_drivers.c b/quantum/led_matrix_drivers.c index 4ee509ee56..cb91821a40 100644 --- a/quantum/led_matrix_drivers.c +++ b/quantum/led_matrix_drivers.c @@ -53,16 +53,16 @@ static void init(void) { #endif #else #ifdef LED_DRIVER_ADDR_1 - IS31FL3733_init(LED_DRIVER_ADDR_1); + IS31FL3733_init(LED_DRIVER_ADDR_1, 0 ); #endif #ifdef LED_DRIVER_ADDR_2 - IS31FL3733_init(LED_DRIVER_ADDR_2); + IS31FL3733_init(LED_DRIVER_ADDR_2, 0 ); #endif #ifdef LED_DRIVER_ADDR_3 - IS31FL3733_init(LED_DRIVER_ADDR_3); + IS31FL3733_init(LED_DRIVER_ADDR_3, 0 ); #endif #ifdef LED_DRIVER_ADDR_4 - IS31FL3733_init(LED_DRIVER_ADDR_4); + IS31FL3733_init(LED_DRIVER_ADDR_4, 0 ); #endif #endif diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c index 1d64dc9093..2a3aa9a5e0 100644 --- a/quantum/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix_drivers.c @@ -34,7 +34,7 @@ static void init( void ) IS31FL3731_init( DRIVER_ADDR_1 ); IS31FL3731_init( DRIVER_ADDR_2 ); #elif defined(IS31FL3733) - IS31FL3733_init( DRIVER_ADDR_1 ); + IS31FL3733_init( DRIVER_ADDR_1, 0 ); #else IS31FL3737_init( DRIVER_ADDR_1 ); #endif @@ -53,7 +53,8 @@ static void init( void ) #ifdef IS31FL3731 IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); #elif defined(IS31FL3733) - IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); + IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, 0 ); + IS31FL3733_update_led_control_registers( DRIVER_ADDR_2, 1 ); #else IS31FL3737_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); #endif @@ -74,7 +75,8 @@ const rgb_matrix_driver_t rgb_matrix_driver = { #elif defined(IS31FL3733) static void flush( void ) { - IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); + IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, 0); + IS31FL3733_update_pwm_buffers( DRIVER_ADDR_2, 1); } const rgb_matrix_driver_t rgb_matrix_driver = { From 1e51f568ddb9a69231c4a5f9392d278231bfc849 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 16 May 2019 10:28:06 -0700 Subject: [PATCH 14/19] Make delay for Capslock in Hold-Tap functions configurable (#5497) * Increase delay for Hold-Tap register for CAPSLOCK Because it seems that the 80ms delay wasn't too much * Screw it, make the caps delay a define and make it configurable --- changelog.md | 1 + tmk_core/common/action.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index cdebe64f43..4a5567c21c 100644 --- a/changelog.md +++ b/changelog.md @@ -16,3 +16,4 @@ 05-05-2019 - New keycode macro (XP) for shifted character pairs using UNICODEMAP, and bugfixes/improvements 05-05-2019 - Add `LINK_TIME_OPTIMIZATION_ENABLE` to enable LTO and disable problematic features that cause LTO to fail 05-05-2019 - Fix issue with Space Cadet +05-17-2019 - Make delay for Capslock in Hold-Tap functions configurable diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index d4d4ac28da..bb4e66c9c8 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -44,6 +44,9 @@ int retro_tapping_counter = 0; #include #endif +#ifndef TAP_HOLD_CAPS_DELAY +# define TAP_HOLD_CAPS_DELAY 200 +#endif /** \brief Called to execute an action. * * FIXME: Needs documentation. @@ -518,7 +521,7 @@ void process_action(keyrecord_t *record, action_t action) if (tap_count > 0) { dprint("KEYMAP_TAP_KEY: Tap: unregister_code\n"); if (action.layer_tap.code == KC_CAPS) { - wait_ms(80); + wait_ms(TAP_HOLD_CAPS_DELAY); } unregister_code(action.layer_tap.code); } else { @@ -853,8 +856,13 @@ void unregister_code(uint8_t code) */ void tap_code(uint8_t code) { register_code(code); + if (code == KC_CAPS) { + wait_ms(TAP_HOLD_CAPS_DELAY); + } #if TAP_CODE_DELAY > 0 + else { wait_ms(TAP_CODE_DELAY); + } #endif unregister_code(code); } From 05e01eb565c1788187dbb8dac91371ae9f3f2cc8 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sun, 19 May 2019 11:09:06 -0500 Subject: [PATCH 15/19] Single Color Band scrolling left to right effects (#5867) --- .../colorband_sat_anim.h | 21 +++++++++++++++++++ .../colorband_val_anim.h | 21 +++++++++++++++++++ .../rgb_matrix_effects.inc | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 quantum/rgb_matrix_animations/colorband_sat_anim.h create mode 100644 quantum/rgb_matrix_animations/colorband_val_anim.h 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..89773b6ce6 --- /dev/null +++ b/quantum/rgb_matrix_animations/colorband_sat_anim.h @@ -0,0 +1,21 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SAT +RGB_MATRIX_EFFECT(BAND_SAT) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BAND_SAT(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t s = rgb_matrix_config.sat - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; + hsv.s = s < 0 ? 0 : s; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_SAT 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..bf41cec910 --- /dev/null +++ b/quantum/rgb_matrix_animations/colorband_val_anim.h @@ -0,0 +1,21 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_VAL +RGB_MATRIX_EFFECT(BAND_VAL) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BAND_VAL(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t v = rgb_matrix_config.val - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; + hsv.v = v < 0 ? 0 : v; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_VAL diff --git a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc index f05a415a58..4b01afaa35 100644 --- a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc +++ b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc @@ -3,6 +3,8 @@ #include "rgb_matrix_animations/alpha_mods_anim.h" #include "rgb_matrix_animations/gradient_up_down_anim.h" #include "rgb_matrix_animations/breathing_anim.h" +#include "rgb_matrix_animations/colorband_sat_anim.h" +#include "rgb_matrix_animations/colorband_val_anim.h" #include "rgb_matrix_animations/cycle_all_anim.h" #include "rgb_matrix_animations/cycle_left_right_anim.h" #include "rgb_matrix_animations/cycle_up_down_anim.h" From 5b69491bacc6b4520e3875fd3badf04fb20e77a0 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sun, 19 May 2019 11:11:08 -0500 Subject: [PATCH 16/19] Fixing hsv_to_rgb where s = 0 and v < 255 (#5915) * Fixing hsv to rgb where s is 0 and v is < 255 * Update color.c --- quantum/color.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/quantum/color.c b/quantum/color.c index 466e6edacb..a309da379a 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -27,9 +27,13 @@ RGB hsv_to_rgb( HSV hsv ) if ( hsv.s == 0 ) { +#ifdef USE_CIE1931_CURVE + rgb.r = rgb.g = rgb.b = pgm_read_byte( &CIE1931_CURVE[hsv.v] ); +#else rgb.r = hsv.v; rgb.g = hsv.v; rgb.b = hsv.v; +#endif return rgb; } From 2e08096ba636e1db29dbbb7fcf481dc0ee1a0bc7 Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sun, 19 May 2019 11:19:46 -0500 Subject: [PATCH 17/19] Spirals, Pinwheels, and Documentation....Oh My! RGB Matrix Effects (#5877) * Spirals, Pinwheels, and Documentation....Oh My! * Spiral effect band thickness adjustments * Fixing animation spin directions --- lib/lib8tion/trig8.h | 25 +++++++++++++++++++ .../colorband_pinwheel_sat_anim.h | 22 ++++++++++++++++ .../colorband_pinwheel_val_anim.h | 22 ++++++++++++++++ .../colorband_spiral_sat_anim.h | 23 +++++++++++++++++ .../colorband_spiral_val_anim.h | 23 +++++++++++++++++ .../cycle_pinwheel_anim.h | 22 ++++++++++++++++ .../rgb_matrix_animations/cycle_spiral_anim.h | 23 +++++++++++++++++ .../rgb_matrix_effects.inc | 6 +++++ 8 files changed, 166 insertions(+) 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_spiral_sat_anim.h create mode 100644 quantum/rgb_matrix_animations/colorband_spiral_val_anim.h create mode 100644 quantum/rgb_matrix_animations/cycle_pinwheel_anim.h create mode 100644 quantum/rgb_matrix_animations/cycle_spiral_anim.h diff --git a/lib/lib8tion/trig8.h b/lib/lib8tion/trig8.h index 6ef3ce625f..cfba6373fb 100644 --- a/lib/lib8tion/trig8.h +++ b/lib/lib8tion/trig8.h @@ -255,5 +255,30 @@ LIB8STATIC uint8_t cos8( uint8_t theta) return sin8( theta + 64); } +/// Fast 16-bit approximation of atan2(x). +/// @returns atan2, value between 0 and 255 +LIB8STATIC uint8_t atan2_8(int16_t dy, int16_t dx) +{ + if (dy == 0) + { + if (dx >= 0) + return 0; + else + return 128; + } + + int16_t abs_y = dy > 0 ? dy : -dy; + int8_t a; + + if (dx >= 0) + a = 32 - (32 * (dx - abs_y) / (dx + abs_y)); + else + a = 96 - (32 * (dx + abs_y) / (abs_y - dx)); + + if (dy < 0) + return -a; // negate if in quad III or IV + return a; +} + ///@} #endif 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..3e6df1fbeb --- /dev/null +++ b/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +RGB_MATRIX_EFFECT(BAND_PINWHEEL_SAT) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BAND_PINWHEEL_SAT(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - 112; + int16_t dy = g_led_config.point[i].y - 32; + hsv.s = rgb_matrix_config.sat - time - atan2_8(dy, dx) * 3; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#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..88cc7d1f23 --- /dev/null +++ b/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +RGB_MATRIX_EFFECT(BAND_PINWHEEL_VAL) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BAND_PINWHEEL_VAL(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - 112; + int16_t dy = g_led_config.point[i].y - 32; + hsv.v = rgb_matrix_config.val - time - atan2_8(dy, dx) * 3; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL 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..44955900a5 --- /dev/null +++ b/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h @@ -0,0 +1,23 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT +RGB_MATRIX_EFFECT(BAND_SPIRAL_SAT) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BAND_SPIRAL_SAT(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - 112; + int16_t dy = g_led_config.point[i].y - 32; + uint8_t dist = sqrt16(dx * dx + dy * dy); + hsv.s = rgb_matrix_config.sat + dist - time - atan2_8(dy, dx); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#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..5aea0c8da1 --- /dev/null +++ b/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h @@ -0,0 +1,23 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL +RGB_MATRIX_EFFECT(BAND_SPIRAL_VAL) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BAND_SPIRAL_VAL(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - 112; + int16_t dy = g_led_config.point[i].y - 32; + uint8_t dist = sqrt16(dx * dx + dy * dy); + hsv.v = rgb_matrix_config.val + dist - time - atan2_8(dy, dx); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL 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..59d60ac077 --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_PINWHEEL +RGB_MATRIX_EFFECT(CYCLE_PINWHEEL) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool CYCLE_PINWHEEL(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - 112; + int16_t dy = g_led_config.point[i].y - 32; + hsv.h = atan2_8(dy, dx) + time; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#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..865309c252 --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_spiral_anim.h @@ -0,0 +1,23 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_SPIRAL +RGB_MATRIX_EFFECT(CYCLE_SPIRAL) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool CYCLE_SPIRAL(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - 112; + int16_t dy = g_led_config.point[i].y - 32; + uint8_t dist = sqrt16(dx * dx + dy * dy); + hsv.h = dist - time - atan2_8(dy, dx); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_SPIRAL diff --git a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc index 4b01afaa35..01332ed0dd 100644 --- a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc +++ b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc @@ -5,12 +5,18 @@ #include "rgb_matrix_animations/breathing_anim.h" #include "rgb_matrix_animations/colorband_sat_anim.h" #include "rgb_matrix_animations/colorband_val_anim.h" +#include "rgb_matrix_animations/colorband_pinwheel_sat_anim.h" +#include "rgb_matrix_animations/colorband_pinwheel_val_anim.h" +#include "rgb_matrix_animations/colorband_spiral_sat_anim.h" +#include "rgb_matrix_animations/colorband_spiral_val_anim.h" #include "rgb_matrix_animations/cycle_all_anim.h" #include "rgb_matrix_animations/cycle_left_right_anim.h" #include "rgb_matrix_animations/cycle_up_down_anim.h" #include "rgb_matrix_animations/rainbow_moving_chevron_anim.h" #include "rgb_matrix_animations/cycle_out_in_anim.h" #include "rgb_matrix_animations/cycle_out_in_dual_anim.h" +#include "rgb_matrix_animations/cycle_pinwheel_anim.h" +#include "rgb_matrix_animations/cycle_spiral_anim.h" #include "rgb_matrix_animations/dual_beacon_anim.h" #include "rgb_matrix_animations/rainbow_beacon_anim.h" #include "rgb_matrix_animations/rainbow_pinwheels_anim.h" From 18e15a7077ed8a0ea31cc6f31824ca073717d724 Mon Sep 17 00:00:00 2001 From: Ryan Caltabiano Date: Wed, 15 May 2019 22:23:42 -0500 Subject: [PATCH 18/19] Added custom center point to rgb matrix --- quantum/rgb_matrix.c | 6 ++++++ quantum/rgb_matrix_animations/cycle_out_in_anim.h | 4 ++-- quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h | 4 ++-- quantum/rgb_matrix_animations/dual_beacon_anim.h | 2 +- quantum/rgb_matrix_animations/rainbow_beacon_anim.h | 2 +- quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 9b9932df52..a6a9549af4 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -26,6 +26,12 @@ #include "lib/lib8tion/lib8tion.h" +#ifndef RGB_MATRIX_CENTER + const point_t k_rgb_matrix_center = { 112, 32 }; +#else + const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; +#endif + // ------------------------------------------ // -----Begin rgb effect includes macros----- #define RGB_MATRIX_EFFECT(name) diff --git a/quantum/rgb_matrix_animations/cycle_out_in_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_anim.h index dc9d09fd3f..29209e4d7b 100644 --- a/quantum/rgb_matrix_animations/cycle_out_in_anim.h +++ b/quantum/rgb_matrix_animations/cycle_out_in_anim.h @@ -9,8 +9,8 @@ bool CYCLE_OUT_IN(effect_params_t* params) { uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - 112; - int16_t dy = g_led_config.point[i].y - 32; + int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; + int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; uint8_t dist = sqrt16(dx * dx + dy * dy); hsv.h = 3 * dist / 2 + time; RGB rgb = hsv_to_rgb(hsv); diff --git a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h index 941e6b9a8a..b2f79ceea0 100644 --- a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h +++ b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h @@ -9,8 +9,8 @@ bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = 56 - abs8(g_led_config.point[i].x - 112); - int16_t dy = g_led_config.point[i].y - 32; + int16_t dx = (k_rgb_matrix_center.x / 2) - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x); + int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; uint8_t dist = sqrt16(dx * dx + dy * dy); hsv.h = 3 * dist + time; RGB rgb = hsv_to_rgb(hsv); diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h index f853f71ecc..59c91046d4 100644 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -11,7 +11,7 @@ bool DUAL_BEACON(effect_params_t* params) { int8_t sin_value = sin8(time) - 128; for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = ((g_led_config.point[i].y - 32) * cos_value + (g_led_config.point[i].x - 112) * sin_value) / 128 + rgb_matrix_config.hue; + hsv.h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos_value + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin_value) / 128 + rgb_matrix_config.hue; RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h index a0e0f814c5..564e3c480a 100644 --- a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h @@ -11,7 +11,7 @@ bool RAINBOW_BEACON(effect_params_t* params) { int16_t sin_value = 2 * (sin8(time) - 128); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = ((g_led_config.point[i].y - 32) * cos_value + (g_led_config.point[i].x - 112) * sin_value) / 128 + rgb_matrix_config.hue; + hsv.h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos_value + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin_value) / 128 + rgb_matrix_config.hue; RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h index 275aaa48d9..7d189b927b 100644 --- a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h @@ -11,7 +11,7 @@ bool PINWHEELS(effect_params_t* params) { int16_t sin_value = 3 * (sin8(time) - 128); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = ((g_led_config.point[i].y - 32) * cos_value + (56 - abs8(g_led_config.point[i].x - 112)) * sin_value) / 128 + rgb_matrix_config.hue; + hsv.h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos_value + (56 - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x)) * sin_value) / 128 + rgb_matrix_config.hue; RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } From 0554bced7c71fd60263931dbe85e08ac421fb5d3 Mon Sep 17 00:00:00 2001 From: Ryan Caltabiano Date: Sun, 19 May 2019 08:34:25 -0500 Subject: [PATCH 19/19] Reduce rgb matrix firmware size --- quantum/rgb_matrix.c | 8 +++ .../colorband_pinwheel_sat_anim.h | 18 ++----- .../colorband_pinwheel_val_anim.h | 18 ++----- .../colorband_sat_anim.h | 18 +++---- .../colorband_spiral_sat_anim.h | 19 ++----- .../colorband_spiral_val_anim.h | 19 ++----- .../colorband_val_anim.h | 18 +++---- .../rgb_matrix_animations/cycle_all_anim.h | 16 +++--- .../cycle_left_right_anim.h | 16 ++---- .../rgb_matrix_animations/cycle_out_in_anim.h | 19 ++----- .../cycle_out_in_dual_anim.h | 21 +++----- .../cycle_pinwheel_anim.h | 18 ++----- .../rgb_matrix_animations/cycle_spiral_anim.h | 19 ++----- .../cycle_up_down_anim.h | 16 ++---- .../rgb_matrix_animations/dual_beacon_anim.h | 18 ++----- .../rainbow_beacon_anim.h | 18 ++----- .../rainbow_moving_chevron_anim.h | 16 ++---- .../rainbow_pinwheels_anim.h | 18 ++----- .../solid_reactive_anim.h | 28 ++--------- .../solid_reactive_cross.h | 50 +++++++------------ .../solid_reactive_nexus.h | 44 ++++++---------- .../solid_reactive_simple_anim.h | 27 ++-------- .../solid_reactive_wide.h | 37 +++++--------- .../rgb_matrix_animations/solid_splash_anim.h | 37 +++++--------- quantum/rgb_matrix_animations/splash_anim.h | 39 +++++---------- .../rgb_matrix_runners/effect_runner_dx_dy.h | 19 +++++++ .../effect_runner_dx_dy_dist.h | 20 ++++++++ quantum/rgb_matrix_runners/effect_runner_i.h | 17 +++++++ .../effect_runner_reactive.h | 31 ++++++++++++ .../effect_runner_reactive_splash.h | 30 +++++++++++ .../effect_runner_sin_cos_i.h | 19 +++++++ 31 files changed, 312 insertions(+), 399 deletions(-) create mode 100644 quantum/rgb_matrix_runners/effect_runner_dx_dy.h create mode 100644 quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h create mode 100644 quantum/rgb_matrix_runners/effect_runner_i.h create mode 100644 quantum/rgb_matrix_runners/effect_runner_reactive.h create mode 100644 quantum/rgb_matrix_runners/effect_runner_reactive_splash.h create mode 100644 quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index a6a9549af4..98baf5cb58 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -32,6 +32,14 @@ const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; #endif +// Generic effect runners +#include "rgb_matrix_runners/effect_runner_dx_dy_dist.h" +#include "rgb_matrix_runners/effect_runner_dx_dy.h" +#include "rgb_matrix_runners/effect_runner_i.h" +#include "rgb_matrix_runners/effect_runner_sin_cos_i.h" +#include "rgb_matrix_runners/effect_runner_reactive.h" +#include "rgb_matrix_runners/effect_runner_reactive_splash.h" + // ------------------------------------------ // -----Begin rgb effect includes macros----- #define RGB_MATRIX_EFFECT(name) diff --git a/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h b/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h index 3e6df1fbeb..cf9c0784a8 100644 --- a/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h +++ b/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(BAND_PINWHEEL_SAT) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool BAND_PINWHEEL_SAT(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void BAND_PINWHEEL_SAT_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv->s = rgb_matrix_config.sat - time - atan2_8(dy, dx) * 3; +} - HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - 112; - int16_t dy = g_led_config.point[i].y - 32; - hsv.s = rgb_matrix_config.sat - time - atan2_8(dy, dx) * 3; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool BAND_PINWHEEL_SAT(effect_params_t* params) { + return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h b/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h index 88cc7d1f23..05ad0ee323 100644 --- a/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h +++ b/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(BAND_PINWHEEL_VAL) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool BAND_PINWHEEL_VAL(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void BAND_PINWHEEL_VAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv->v = rgb_matrix_config.val - time - atan2_8(dy, dx) * 3; +} - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - 112; - int16_t dy = g_led_config.point[i].y - 32; - hsv.v = rgb_matrix_config.val - time - atan2_8(dy, dx) * 3; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool BAND_PINWHEEL_VAL(effect_params_t* params) { + return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/colorband_sat_anim.h b/quantum/rgb_matrix_animations/colorband_sat_anim.h index 89773b6ce6..8a40473e4a 100644 --- a/quantum/rgb_matrix_animations/colorband_sat_anim.h +++ b/quantum/rgb_matrix_animations/colorband_sat_anim.h @@ -2,19 +2,13 @@ RGB_MATRIX_EFFECT(BAND_SAT) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool BAND_SAT(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); +static void BAND_SAT_math(HSV* hsv, uint8_t i, uint8_t time) { int16_t s = rgb_matrix_config.sat - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; - hsv.s = s < 0 ? 0 : s; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->s = s < 0 ? 0 : s; +} + +bool BAND_SAT(effect_params_t* params) { + return effect_runner_i(params, &BAND_SAT_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h b/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h index 44955900a5..4af6c60b0d 100644 --- a/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h +++ b/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h @@ -2,21 +2,12 @@ RGB_MATRIX_EFFECT(BAND_SPIRAL_SAT) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool BAND_SPIRAL_SAT(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void BAND_SPIRAL_SAT_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv->s = rgb_matrix_config.sat + dist - time - atan2_8(dy, dx); +} - HSV hsv = { rgb_matrix_config.hue, 0, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - 112; - int16_t dy = g_led_config.point[i].y - 32; - uint8_t dist = sqrt16(dx * dx + dy * dy); - hsv.s = rgb_matrix_config.sat + dist - time - atan2_8(dy, dx); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool BAND_SPIRAL_SAT(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h b/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h index 5aea0c8da1..e787956a7a 100644 --- a/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h +++ b/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h @@ -2,21 +2,12 @@ RGB_MATRIX_EFFECT(BAND_SPIRAL_VAL) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool BAND_SPIRAL_VAL(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void BAND_SPIRAL_VAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv->v = rgb_matrix_config.val + dist - time - atan2_8(dy, dx); +} - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - 112; - int16_t dy = g_led_config.point[i].y - 32; - uint8_t dist = sqrt16(dx * dx + dy * dy); - hsv.v = rgb_matrix_config.val + dist - time - atan2_8(dy, dx); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool BAND_SPIRAL_VAL(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/colorband_val_anim.h b/quantum/rgb_matrix_animations/colorband_val_anim.h index bf41cec910..1e3740cea4 100644 --- a/quantum/rgb_matrix_animations/colorband_val_anim.h +++ b/quantum/rgb_matrix_animations/colorband_val_anim.h @@ -2,19 +2,13 @@ RGB_MATRIX_EFFECT(BAND_VAL) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool BAND_VAL(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); +static void BAND_VAL_math(HSV* hsv, uint8_t i, uint8_t time) { int16_t v = rgb_matrix_config.val - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; - hsv.v = v < 0 ? 0 : v; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->v = v < 0 ? 0 : v; +} + +bool BAND_VAL(effect_params_t* params) { + return effect_runner_i(params, &BAND_VAL_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h index e6319cad7f..380dbe05a4 100644 --- a/quantum/rgb_matrix_animations/cycle_all_anim.h +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h @@ -2,17 +2,13 @@ RGB_MATRIX_EFFECT(CYCLE_ALL) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool CYCLE_ALL(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void CYCLE_ALL_math(HSV* hsv, uint8_t i, uint8_t time) +{ + hsv->h = time; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - hsv.h = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool CYCLE_ALL(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_ALL_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h index d9a00530a0..f270fb42cc 100644 --- a/quantum/rgb_matrix_animations/cycle_left_right_anim.h +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h @@ -2,18 +2,12 @@ RGB_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool CYCLE_LEFT_RIGHT(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void CYCLE_LEFT_RIGHT_math(HSV* hsv, uint8_t i, uint8_t time) { + hsv->h = g_led_config.point[i].x - time; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = g_led_config.point[i].x - time; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool CYCLE_LEFT_RIGHT(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/cycle_out_in_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_anim.h index 29209e4d7b..46c7efef25 100644 --- a/quantum/rgb_matrix_animations/cycle_out_in_anim.h +++ b/quantum/rgb_matrix_animations/cycle_out_in_anim.h @@ -2,21 +2,12 @@ RGB_MATRIX_EFFECT(CYCLE_OUT_IN) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool CYCLE_OUT_IN(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void CYCLE_OUT_IN_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv->h = 3 * dist / 2 + time; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; - int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; - uint8_t dist = sqrt16(dx * dx + dy * dy); - hsv.h = 3 * dist / 2 + time; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool CYCLE_OUT_IN(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h index b2f79ceea0..2fdb4ba919 100644 --- a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h +++ b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h @@ -2,21 +2,14 @@ RGB_MATRIX_EFFECT(CYCLE_OUT_IN_DUAL) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = (k_rgb_matrix_center.x / 2) - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x); - int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; +static void CYCLE_OUT_IN_DUAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) { + dx = (k_rgb_matrix_center.x / 2) - abs8(dx); uint8_t dist = sqrt16(dx * dx + dy * dy); - hsv.h = 3 * dist + time; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->h = 3 * dist + time; +} + +bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { + return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h b/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h index 59d60ac077..29e2d92c92 100644 --- a/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h +++ b/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(CYCLE_PINWHEEL) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool CYCLE_PINWHEEL(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void CYCLE_PINWHEEL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv->h = atan2_8(dy, dx) + time; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - 112; - int16_t dy = g_led_config.point[i].y - 32; - hsv.h = atan2_8(dy, dx) + time; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool CYCLE_PINWHEEL(effect_params_t* params) { + return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/cycle_spiral_anim.h b/quantum/rgb_matrix_animations/cycle_spiral_anim.h index 865309c252..a1354f60c1 100644 --- a/quantum/rgb_matrix_animations/cycle_spiral_anim.h +++ b/quantum/rgb_matrix_animations/cycle_spiral_anim.h @@ -2,21 +2,12 @@ RGB_MATRIX_EFFECT(CYCLE_SPIRAL) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool CYCLE_SPIRAL(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void CYCLE_SPIRAL_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv->h = dist - time - atan2_8(dy, dx); +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - 112; - int16_t dy = g_led_config.point[i].y - 32; - uint8_t dist = sqrt16(dx * dx + dy * dy); - hsv.h = dist - time - atan2_8(dy, dx); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool CYCLE_SPIRAL(effect_params_t* params) { + return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h index f2b31d9da5..b3ef4cdf2e 100644 --- a/quantum/rgb_matrix_animations/cycle_up_down_anim.h +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h @@ -2,18 +2,12 @@ RGB_MATRIX_EFFECT(CYCLE_UP_DOWN) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool CYCLE_UP_DOWN(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void CYCLE_UP_DOWN_math(HSV* hsv, uint8_t i, uint8_t time) { + hsv->h = g_led_config.point[i].y - time; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = g_led_config.point[i].y - time; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool CYCLE_UP_DOWN(effect_params_t* params) { + return effect_runner_i(params, &CYCLE_UP_DOWN_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h index 59c91046d4..d34f146a5b 100644 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(DUAL_BEACON) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool DUAL_BEACON(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void DUAL_BEACON_math(HSV* hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { + hsv->h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin) / 128 + rgb_matrix_config.hue; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - int8_t cos_value = cos8(time) - 128; - int8_t sin_value = sin8(time) - 128; - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos_value + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin_value) / 128 + rgb_matrix_config.hue; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool DUAL_BEACON(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h index 564e3c480a..061cac837c 100644 --- a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(RAINBOW_BEACON) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool RAINBOW_BEACON(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void RAINBOW_BEACON_math(HSV* hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { + hsv->h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 2 * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * 2 * sin) / 128 + rgb_matrix_config.hue; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - int16_t cos_value = 2 * (cos8(time) - 128); - int16_t sin_value = 2 * (sin8(time) - 128); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos_value + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin_value) / 128 + rgb_matrix_config.hue; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool RAINBOW_BEACON(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h index 39352b0c13..f406566fa1 100644 --- a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h @@ -2,18 +2,12 @@ RGB_MATRIX_EFFECT(RAINBOW_MOVING_CHEVRON) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void RAINBOW_MOVING_CHEVRON_math(HSV* hsv, uint8_t i, uint8_t time) { + hsv->h = abs8(g_led_config.point[i].y - k_rgb_matrix_center.y) + (g_led_config.point[i].x - time) + rgb_matrix_config.hue; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = abs8(g_led_config.point[i].y - 32) + (g_led_config.point[i].x - time) + rgb_matrix_config.hue; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { + return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h index 7d189b927b..f19e9116d9 100644 --- a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h @@ -2,20 +2,12 @@ RGB_MATRIX_EFFECT(PINWHEELS) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool PINWHEELS(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); +static void PINWHEELS_math(HSV* hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { + hsv->h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 3 * cos + (56 - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x)) * 3 * sin) / 128 + rgb_matrix_config.hue; +} - HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); - int16_t cos_value = 3 * (cos8(time) - 128); - int16_t sin_value = 3 * (sin8(time) - 128); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos_value + (56 - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x)) * sin_value) / 128 + rgb_matrix_config.hue; - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool PINWHEELS(effect_params_t* params) { + return effect_runner_sin_cos_i(params, &PINWHEELS_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/solid_reactive_anim.h b/quantum/rgb_matrix_animations/solid_reactive_anim.h index 37e339907a..762a95db31 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h @@ -3,30 +3,12 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool SOLID_REACTIVE(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val }; - // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 - uint16_t max_tick = 65535 / rgb_matrix_config.speed; - // Relies on hue being 8-bit and wrapping - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - uint16_t tick = max_tick; - // Reverse search to find most recent key hit - for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { - if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { - tick = g_last_hit_tracker.tick[j]; - break; - } - } +static void SOLID_REACTIVE_math(HSV* hsv, uint16_t offset) { + hsv->h = rgb_matrix_config.hue + qsub8(130, offset); +} - uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); - hsv.h = rgb_matrix_config.hue + qsub8(130, offset); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool SOLID_REACTIVE(effect_params_t* params) { + return effect_runner_reactive(params, &SOLID_REACTIVE_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/solid_reactive_cross.h b/quantum/rgb_matrix_animations/solid_reactive_cross.h index 62210f82d6..99f22c694e 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_cross.h +++ b/quantum/rgb_matrix_animations/solid_reactive_cross.h @@ -11,45 +11,29 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -static bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - uint8_t count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - hsv.v = 0; - for (uint8_t j = start; j < count; j++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; - int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; - uint8_t dist = sqrt16(dx * dx + dy * dy); - int16_t dist2 = 16; - uint8_t dist3; - uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist; - dx = dx < 0 ? dx * -1 : dx; - dy = dy < 0 ? dy * -1 : dy; - dx = dx * dist2 > 255 ? 255 : dx * dist2; - dy = dy * dist2 > 255 ? 255 : dy * dist2; - dist3 = dx > dy ? dy : dx; - effect += dist3; - if (effect > 255) +static void SOLID_REACTIVE_CROSS_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick + dist; + dx = dx < 0 ? dx * -1 : dx; + dy = dy < 0 ? dy * -1 : dy; + dx = dx * 16 > 255 ? 255 : dx * 16; + dy = dy * 16 > 255 ? 255 : dy * 16; + effect += dx > dy ? dy : dx; + if (effect > 255) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - } - hsv.v = scale8(hsv.v, rgb_matrix_config.val); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->v = qadd8(hsv->v, 255 - effect); } -bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { - return rgb_matrix_solid_reactive_multicross_range(0, params); +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +bool SOLID_REACTIVE_CROSS(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } +#endif -bool SOLID_REACTIVE_CROSS(effect_params_t* params) { - return rgb_matrix_solid_reactive_multicross_range(qsub8(g_last_hit_tracker.count, 1), params); +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); } +#endif #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) diff --git a/quantum/rgb_matrix_animations/solid_reactive_nexus.h b/quantum/rgb_matrix_animations/solid_reactive_nexus.h index 33f478ac70..8bebd042d2 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_nexus.h +++ b/quantum/rgb_matrix_animations/solid_reactive_nexus.h @@ -11,43 +11,29 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -static bool rgb_matrix_solid_reactive_multinexus_range(uint8_t start, effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - uint8_t count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - hsv.v = 0; - for (uint8_t j = start; j < count; j++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; - int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; - uint8_t dist = sqrt16(dx * dx + dy * dy); - int16_t dist2 = 8; - uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; - if (effect > 255) +static void SOLID_REACTIVE_NEXUS_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; - if (dist > 72) + if (dist > 72) effect = 255; - if ((dx > dist2 || dx < -dist2) && (dy > dist2 || dy < -dist2)) + if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - hsv.h = rgb_matrix_config.hue + dy / 4; - } - hsv.v = scale8(hsv.v, rgb_matrix_config.val); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->v = qadd8(hsv->v, 255 - effect); + hsv->h = rgb_matrix_config.hue + dy / 4; } -bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { - return rgb_matrix_solid_reactive_multinexus_range(0, params); +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } +#endif -bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { - return rgb_matrix_solid_reactive_multinexus_range(qsub8(g_last_hit_tracker.count, 1), params); +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); } +#endif #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) diff --git a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h index f235824e27..36c6ec5277 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h @@ -3,29 +3,12 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 - uint16_t max_tick = 65535 / rgb_matrix_config.speed; - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - uint16_t tick = max_tick; - // Reverse search to find most recent key hit - for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { - if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { - tick = g_last_hit_tracker.tick[j]; - break; - } - } +static void SOLID_REACTIVE_SIMPLE_math(HSV* hsv, uint16_t offset) { + hsv->v = scale8(255 - offset, rgb_matrix_config.val); +} - uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); - hsv.v = scale8(255 - offset, rgb_matrix_config.val); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; +bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { + return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/solid_reactive_wide.h b/quantum/rgb_matrix_animations/solid_reactive_wide.h index ff0f6f5eca..36edc475c8 100644 --- a/quantum/rgb_matrix_animations/solid_reactive_wide.h +++ b/quantum/rgb_matrix_animations/solid_reactive_wide.h @@ -11,37 +11,24 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -static bool rgb_matrix_solid_reactive_multiwide_range(uint8_t start, effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - uint8_t count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - hsv.v = 0; - for (uint8_t j = start; j < count; j++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; - int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; - uint8_t dist = sqrt16(dx * dx + dy * dy); - uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist * 5; - if (effect > 255) +static void SOLID_REACTIVE_WIDE_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick + dist * 5; + if (effect > 255) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - } - hsv.v = scale8(hsv.v, rgb_matrix_config.val); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->v = qadd8(hsv->v, 255 - effect); } -bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { - return rgb_matrix_solid_reactive_multiwide_range(0, params); +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +bool SOLID_REACTIVE_WIDE(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } +#endif -bool SOLID_REACTIVE_WIDE(effect_params_t* params) { - return rgb_matrix_solid_reactive_multiwide_range(qsub8(g_last_hit_tracker.count, 1), params); +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); } +#endif #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) diff --git a/quantum/rgb_matrix_animations/solid_splash_anim.h b/quantum/rgb_matrix_animations/solid_splash_anim.h index d439bd8880..84c99ff00c 100644 --- a/quantum/rgb_matrix_animations/solid_splash_anim.h +++ b/quantum/rgb_matrix_animations/solid_splash_anim.h @@ -11,37 +11,24 @@ RGB_MATRIX_EFFECT(SOLID_MULTISPLASH) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS -static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; - uint8_t count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.v = 0; - for (uint8_t j = start; j < count; j++) { - int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; - int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; - uint8_t dist = sqrt16(dx * dx + dy * dy); - uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; - if (effect > 255) +void SOLID_SPLASH_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - } - hsv.v = scale8(hsv.v, rgb_matrix_config.val); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->v = qadd8(hsv->v, 255 - effect); } -bool SOLID_MULTISPLASH(effect_params_t* params) { - return rgb_matrix_solid_multisplash_range(0, params); +#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH +bool SOLID_SPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } +#endif -bool SOLID_SPLASH(effect_params_t* params) { - return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); +#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH +bool SOLID_MULTISPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } +#endif #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH) diff --git a/quantum/rgb_matrix_animations/splash_anim.h b/quantum/rgb_matrix_animations/splash_anim.h index 214dab68da..c4c0516535 100644 --- a/quantum/rgb_matrix_animations/splash_anim.h +++ b/quantum/rgb_matrix_animations/splash_anim.h @@ -11,40 +11,25 @@ RGB_MATRIX_EFFECT(MULTISPLASH) #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = { 0, rgb_matrix_config.sat, 0 }; - uint8_t count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - hsv.h = rgb_matrix_config.hue; - hsv.v = 0; - for (uint8_t j = start; j < count; j++) { - int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; - int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; - uint8_t dist = sqrt16(dx * dx + dy * dy); - uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; +void SPLASH_math(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; if (effect > 255) effect = 255; - hsv.h += effect; - hsv.v = qadd8(hsv.v, 255 - effect); - } - hsv.v = scale8(hsv.v, rgb_matrix_config.val); - RGB rgb = hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; + hsv->h += effect; + hsv->v = qadd8(hsv->v, 255 - effect); } -bool MULTISPLASH(effect_params_t* params) { - return rgb_matrix_multisplash_range(0, params); +#ifndef DISABLE_RGB_MATRIX_SPLASH +bool SPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math); } +#endif -bool SPLASH(effect_params_t* params) { - return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); +#ifndef DISABLE_RGB_MATRIX_MULTISPLASH +bool MULTISPLASH(effect_params_t* params) { + return effect_runner_reactive_splash(0, params, &SPLASH_math); } +#endif #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) diff --git a/quantum/rgb_matrix_runners/effect_runner_dx_dy.h b/quantum/rgb_matrix_runners/effect_runner_dx_dy.h new file mode 100644 index 0000000000..43312629de --- /dev/null +++ b/quantum/rgb_matrix_runners/effect_runner_dx_dy.h @@ -0,0 +1,19 @@ +#pragma once + +typedef void (*dx_dy_f)(HSV* hsv, int16_t dx, int16_t dy, uint8_t time); + +bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; + int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; + effect_func(&hsv, dx, dy, time); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h b/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h new file mode 100644 index 0000000000..a7310c8537 --- /dev/null +++ b/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h @@ -0,0 +1,20 @@ +#pragma once + +typedef void (*dx_dy_dist_f)(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time); + +bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; + int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; + uint8_t dist = sqrt16(dx * dx + dy * dy); + effect_func(&hsv, dx, dy, dist, time); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix_runners/effect_runner_i.h b/quantum/rgb_matrix_runners/effect_runner_i.h new file mode 100644 index 0000000000..85405ba1b6 --- /dev/null +++ b/quantum/rgb_matrix_runners/effect_runner_i.h @@ -0,0 +1,17 @@ +#pragma once + +typedef void (*i_f)(HSV* hsv, uint8_t i, uint8_t time); + +bool effect_runner_i(effect_params_t* params, i_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + effect_func(&hsv, i, time); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix_runners/effect_runner_reactive.h b/quantum/rgb_matrix_runners/effect_runner_reactive.h new file mode 100644 index 0000000000..94cd7d5452 --- /dev/null +++ b/quantum/rgb_matrix_runners/effect_runner_reactive.h @@ -0,0 +1,31 @@ +#pragma once + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + +typedef void (*reactive_f)(HSV* hsv, uint16_t offset); + +bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint16_t max_tick = 65535 / rgb_matrix_config.speed; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + uint16_t tick = max_tick; + // Reverse search to find most recent key hit + for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { + if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { + tick = g_last_hit_tracker.tick[j]; + break; + } + } + + uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); + effect_func(&hsv, offset); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h b/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h new file mode 100644 index 0000000000..cb2b0d7943 --- /dev/null +++ b/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h @@ -0,0 +1,30 @@ +#pragma once + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + +typedef void (*reactive_splash_f)(HSV* hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick); + +bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, reactive_splash_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { 0, rgb_matrix_config.sat, 0 }; + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + hsv.h = rgb_matrix_config.hue; + hsv.v = 0; + for (uint8_t j = start; j < count; j++) { + int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; + int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; + uint8_t dist = sqrt16(dx * dx + dy * dy); + uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed); + effect_func(&hsv, dx, dy, dist, tick); + } + hsv.v = scale8(hsv.v, rgb_matrix_config.val); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h b/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h new file mode 100644 index 0000000000..54e4c6d866 --- /dev/null +++ b/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h @@ -0,0 +1,19 @@ +#pragma once + +typedef void (*sin_cos_i_f)(HSV* hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time); + +bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; + uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + int8_t cos_value = cos8(time) - 128; + int8_t sin_value = sin8(time) - 128; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + effect_func(&hsv, cos_value, sin_value, i, time); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +}