From d61e5c0027e289ccf48652afa4c442342e7ccf04 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 22 Jun 2021 18:26:23 +1000 Subject: Move LED/RGB Matrix code into their own directories (#13257) --- common_features.mk | 18 +- quantum/led_matrix.c | 582 ------------------- quantum/led_matrix.h | 160 ----- quantum/led_matrix/animations/alpha_mods_anim.h | 24 + quantum/led_matrix/animations/band_anim.h | 13 + quantum/led_matrix/animations/band_pinwheel_anim.h | 10 + quantum/led_matrix/animations/band_spiral_anim.h | 10 + quantum/led_matrix/animations/breathing_anim.h | 19 + .../led_matrix/animations/cycle_left_right_anim.h | 10 + quantum/led_matrix/animations/cycle_out_in_anim.h | 10 + quantum/led_matrix/animations/cycle_up_down_anim.h | 10 + quantum/led_matrix/animations/dual_beacon_anim.h | 10 + .../led_matrix/animations/led_matrix_effects.inc | 18 + .../animations/runners/effect_runner_dx_dy.h | 16 + .../animations/runners/effect_runner_dx_dy_dist.h | 17 + .../animations/runners/effect_runner_i.h | 14 + .../animations/runners/effect_runner_reactive.h | 28 + .../runners/effect_runner_reactive_splash.h | 26 + .../animations/runners/effect_runner_sin_cos_i.h | 16 + .../animations/runners/led_matrix_runners.inc | 6 + quantum/led_matrix/animations/solid_anim.h | 15 + .../led_matrix/animations/solid_reactive_cross.h | 35 ++ .../led_matrix/animations/solid_reactive_nexus.h | 32 + .../animations/solid_reactive_simple_anim.h | 12 + .../led_matrix/animations/solid_reactive_wide.h | 30 + quantum/led_matrix/animations/solid_splash_anim.h | 30 + .../led_matrix/animations/wave_left_right_anim.h | 10 + quantum/led_matrix/animations/wave_up_down_anim.h | 10 + quantum/led_matrix/led_matrix.c | 577 ++++++++++++++++++ quantum/led_matrix/led_matrix.h | 160 +++++ quantum/led_matrix/led_matrix_drivers.c | 153 +++++ quantum/led_matrix/led_matrix_types.h | 97 ++++ quantum/led_matrix_animations/alpha_mods_anim.h | 24 - quantum/led_matrix_animations/band_anim.h | 13 - quantum/led_matrix_animations/band_pinwheel_anim.h | 10 - quantum/led_matrix_animations/band_spiral_anim.h | 10 - quantum/led_matrix_animations/breathing_anim.h | 19 - .../led_matrix_animations/cycle_left_right_anim.h | 10 - quantum/led_matrix_animations/cycle_out_in_anim.h | 10 - quantum/led_matrix_animations/cycle_up_down_anim.h | 10 - quantum/led_matrix_animations/dual_beacon_anim.h | 10 - .../led_matrix_animations/led_matrix_effects.inc | 18 - quantum/led_matrix_animations/solid_anim.h | 15 - .../led_matrix_animations/solid_reactive_cross.h | 35 -- .../led_matrix_animations/solid_reactive_nexus.h | 32 - .../solid_reactive_simple_anim.h | 12 - .../led_matrix_animations/solid_reactive_wide.h | 30 - quantum/led_matrix_animations/solid_splash_anim.h | 30 - .../led_matrix_animations/wave_left_right_anim.h | 10 - quantum/led_matrix_animations/wave_up_down_anim.h | 10 - quantum/led_matrix_drivers.c | 153 ----- quantum/led_matrix_runners/effect_runner_dx_dy.h | 16 - .../led_matrix_runners/effect_runner_dx_dy_dist.h | 17 - quantum/led_matrix_runners/effect_runner_i.h | 14 - .../led_matrix_runners/effect_runner_reactive.h | 28 - .../effect_runner_reactive_splash.h | 26 - .../led_matrix_runners/effect_runner_sin_cos_i.h | 16 - quantum/led_matrix_types.h | 97 ---- quantum/rgb_matrix.c | 645 --------------------- quantum/rgb_matrix.h | 228 -------- quantum/rgb_matrix/animations/alpha_mods_anim.h | 26 + quantum/rgb_matrix/animations/breathing_anim.h | 20 + .../animations/colorband_pinwheel_sat_anim.h | 13 + .../animations/colorband_pinwheel_val_anim.h | 13 + quantum/rgb_matrix/animations/colorband_sat_anim.h | 14 + .../animations/colorband_spiral_sat_anim.h | 13 + .../animations/colorband_spiral_val_anim.h | 13 + quantum/rgb_matrix/animations/colorband_val_anim.h | 14 + quantum/rgb_matrix/animations/cycle_all_anim.h | 13 + .../rgb_matrix/animations/cycle_left_right_anim.h | 13 + quantum/rgb_matrix/animations/cycle_out_in_anim.h | 13 + .../rgb_matrix/animations/cycle_out_in_dual_anim.h | 15 + .../rgb_matrix/animations/cycle_pinwheel_anim.h | 13 + quantum/rgb_matrix/animations/cycle_spiral_anim.h | 13 + quantum/rgb_matrix/animations/cycle_up_down_anim.h | 13 + quantum/rgb_matrix/animations/digital_rain_anim.h | 75 +++ quantum/rgb_matrix/animations/dual_beacon_anim.h | 13 + .../animations/gradient_left_right_anim.h | 22 + .../rgb_matrix/animations/gradient_up_down_anim.h | 22 + quantum/rgb_matrix/animations/hue_breathing_anim.h | 22 + quantum/rgb_matrix/animations/hue_pendulum_anim.h | 17 + quantum/rgb_matrix/animations/hue_wave_anim.h | 17 + .../animations/jellybean_raindrops_anim.h | 29 + .../rgb_matrix/animations/rainbow_beacon_anim.h | 13 + .../animations/rainbow_moving_chevron_anim.h | 13 + .../rgb_matrix/animations/rainbow_pinwheels_anim.h | 13 + quantum/rgb_matrix/animations/raindrops_anim.h | 39 ++ .../rgb_matrix/animations/rgb_matrix_effects.inc | 37 ++ .../animations/runners/effect_runner_dx_dy.h | 17 + .../animations/runners/effect_runner_dx_dy_dist.h | 18 + .../animations/runners/effect_runner_i.h | 15 + .../animations/runners/effect_runner_reactive.h | 29 + .../runners/effect_runner_reactive_splash.h | 29 + .../animations/runners/effect_runner_sin_cos_i.h | 17 + .../animations/runners/rgb_matrix_runners.inc | 6 + quantum/rgb_matrix/animations/solid_color_anim.h | 15 + .../rgb_matrix/animations/solid_reactive_anim.h | 15 + .../rgb_matrix/animations/solid_reactive_cross.h | 36 ++ .../rgb_matrix/animations/solid_reactive_nexus.h | 34 ++ .../animations/solid_reactive_simple_anim.h | 15 + .../rgb_matrix/animations/solid_reactive_wide.h | 31 + quantum/rgb_matrix/animations/solid_splash_anim.h | 31 + quantum/rgb_matrix/animations/splash_anim.h | 32 + .../rgb_matrix/animations/typing_heatmap_anim.h | 86 +++ quantum/rgb_matrix/rgb_matrix.c | 640 ++++++++++++++++++++ quantum/rgb_matrix/rgb_matrix.h | 228 ++++++++ quantum/rgb_matrix/rgb_matrix_drivers.c | 228 ++++++++ quantum/rgb_matrix/rgb_matrix_types.h | 98 ++++ quantum/rgb_matrix_animations/alpha_mods_anim.h | 26 - quantum/rgb_matrix_animations/breathing_anim.h | 20 - .../colorband_pinwheel_sat_anim.h | 13 - .../colorband_pinwheel_val_anim.h | 13 - quantum/rgb_matrix_animations/colorband_sat_anim.h | 14 - .../colorband_spiral_sat_anim.h | 13 - .../colorband_spiral_val_anim.h | 13 - quantum/rgb_matrix_animations/colorband_val_anim.h | 14 - quantum/rgb_matrix_animations/cycle_all_anim.h | 13 - .../rgb_matrix_animations/cycle_left_right_anim.h | 13 - quantum/rgb_matrix_animations/cycle_out_in_anim.h | 13 - .../rgb_matrix_animations/cycle_out_in_dual_anim.h | 15 - .../rgb_matrix_animations/cycle_pinwheel_anim.h | 13 - quantum/rgb_matrix_animations/cycle_spiral_anim.h | 13 - quantum/rgb_matrix_animations/cycle_up_down_anim.h | 13 - quantum/rgb_matrix_animations/digital_rain_anim.h | 75 --- quantum/rgb_matrix_animations/dual_beacon_anim.h | 13 - .../gradient_left_right_anim.h | 22 - .../rgb_matrix_animations/gradient_up_down_anim.h | 22 - quantum/rgb_matrix_animations/hue_breathing_anim.h | 22 - quantum/rgb_matrix_animations/hue_pendulum_anim.h | 17 - quantum/rgb_matrix_animations/hue_wave_anim.h | 17 - .../jellybean_raindrops_anim.h | 29 - .../rgb_matrix_animations/rainbow_beacon_anim.h | 13 - .../rainbow_moving_chevron_anim.h | 13 - .../rgb_matrix_animations/rainbow_pinwheels_anim.h | 13 - quantum/rgb_matrix_animations/raindrops_anim.h | 39 -- .../rgb_matrix_animations/rgb_matrix_effects.inc | 37 -- quantum/rgb_matrix_animations/solid_color_anim.h | 15 - .../rgb_matrix_animations/solid_reactive_anim.h | 15 - .../rgb_matrix_animations/solid_reactive_cross.h | 36 -- .../rgb_matrix_animations/solid_reactive_nexus.h | 34 -- .../solid_reactive_simple_anim.h | 15 - .../rgb_matrix_animations/solid_reactive_wide.h | 31 - quantum/rgb_matrix_animations/solid_splash_anim.h | 31 - quantum/rgb_matrix_animations/splash_anim.h | 32 - .../rgb_matrix_animations/typing_heatmap_anim.h | 86 --- quantum/rgb_matrix_drivers.c | 228 -------- quantum/rgb_matrix_runners/effect_runner_dx_dy.h | 17 - .../rgb_matrix_runners/effect_runner_dx_dy_dist.h | 18 - quantum/rgb_matrix_runners/effect_runner_i.h | 15 - .../rgb_matrix_runners/effect_runner_reactive.h | 29 - .../effect_runner_reactive_splash.h | 29 - .../rgb_matrix_runners/effect_runner_sin_cos_i.h | 17 - quantum/rgb_matrix_types.h | 98 ---- 153 files changed, 3601 insertions(+), 3593 deletions(-) delete mode 100644 quantum/led_matrix.c delete mode 100644 quantum/led_matrix.h create mode 100644 quantum/led_matrix/animations/alpha_mods_anim.h create mode 100644 quantum/led_matrix/animations/band_anim.h create mode 100644 quantum/led_matrix/animations/band_pinwheel_anim.h create mode 100644 quantum/led_matrix/animations/band_spiral_anim.h create mode 100644 quantum/led_matrix/animations/breathing_anim.h create mode 100644 quantum/led_matrix/animations/cycle_left_right_anim.h create mode 100644 quantum/led_matrix/animations/cycle_out_in_anim.h create mode 100644 quantum/led_matrix/animations/cycle_up_down_anim.h create mode 100644 quantum/led_matrix/animations/dual_beacon_anim.h create mode 100644 quantum/led_matrix/animations/led_matrix_effects.inc create mode 100644 quantum/led_matrix/animations/runners/effect_runner_dx_dy.h create mode 100644 quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h create mode 100644 quantum/led_matrix/animations/runners/effect_runner_i.h create mode 100644 quantum/led_matrix/animations/runners/effect_runner_reactive.h create mode 100644 quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h create mode 100644 quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h create mode 100644 quantum/led_matrix/animations/runners/led_matrix_runners.inc create mode 100644 quantum/led_matrix/animations/solid_anim.h create mode 100644 quantum/led_matrix/animations/solid_reactive_cross.h create mode 100644 quantum/led_matrix/animations/solid_reactive_nexus.h create mode 100644 quantum/led_matrix/animations/solid_reactive_simple_anim.h create mode 100644 quantum/led_matrix/animations/solid_reactive_wide.h create mode 100644 quantum/led_matrix/animations/solid_splash_anim.h create mode 100644 quantum/led_matrix/animations/wave_left_right_anim.h create mode 100644 quantum/led_matrix/animations/wave_up_down_anim.h create mode 100644 quantum/led_matrix/led_matrix.c create mode 100644 quantum/led_matrix/led_matrix.h create mode 100644 quantum/led_matrix/led_matrix_drivers.c create mode 100644 quantum/led_matrix/led_matrix_types.h delete mode 100644 quantum/led_matrix_animations/alpha_mods_anim.h delete mode 100644 quantum/led_matrix_animations/band_anim.h delete mode 100644 quantum/led_matrix_animations/band_pinwheel_anim.h delete mode 100644 quantum/led_matrix_animations/band_spiral_anim.h delete mode 100644 quantum/led_matrix_animations/breathing_anim.h delete mode 100644 quantum/led_matrix_animations/cycle_left_right_anim.h delete mode 100644 quantum/led_matrix_animations/cycle_out_in_anim.h delete mode 100644 quantum/led_matrix_animations/cycle_up_down_anim.h delete mode 100644 quantum/led_matrix_animations/dual_beacon_anim.h delete mode 100644 quantum/led_matrix_animations/led_matrix_effects.inc delete mode 100644 quantum/led_matrix_animations/solid_anim.h delete mode 100644 quantum/led_matrix_animations/solid_reactive_cross.h delete mode 100644 quantum/led_matrix_animations/solid_reactive_nexus.h delete mode 100644 quantum/led_matrix_animations/solid_reactive_simple_anim.h delete mode 100644 quantum/led_matrix_animations/solid_reactive_wide.h delete mode 100644 quantum/led_matrix_animations/solid_splash_anim.h delete mode 100644 quantum/led_matrix_animations/wave_left_right_anim.h delete mode 100644 quantum/led_matrix_animations/wave_up_down_anim.h delete mode 100644 quantum/led_matrix_drivers.c delete mode 100644 quantum/led_matrix_runners/effect_runner_dx_dy.h delete mode 100644 quantum/led_matrix_runners/effect_runner_dx_dy_dist.h delete mode 100644 quantum/led_matrix_runners/effect_runner_i.h delete mode 100644 quantum/led_matrix_runners/effect_runner_reactive.h delete mode 100644 quantum/led_matrix_runners/effect_runner_reactive_splash.h delete mode 100644 quantum/led_matrix_runners/effect_runner_sin_cos_i.h delete mode 100644 quantum/led_matrix_types.h delete mode 100644 quantum/rgb_matrix.c delete mode 100644 quantum/rgb_matrix.h create mode 100644 quantum/rgb_matrix/animations/alpha_mods_anim.h create mode 100644 quantum/rgb_matrix/animations/breathing_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_sat_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_spiral_val_anim.h create mode 100644 quantum/rgb_matrix/animations/colorband_val_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_all_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_left_right_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_out_in_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_pinwheel_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_spiral_anim.h create mode 100644 quantum/rgb_matrix/animations/cycle_up_down_anim.h create mode 100644 quantum/rgb_matrix/animations/digital_rain_anim.h create mode 100644 quantum/rgb_matrix/animations/dual_beacon_anim.h create mode 100644 quantum/rgb_matrix/animations/gradient_left_right_anim.h create mode 100644 quantum/rgb_matrix/animations/gradient_up_down_anim.h create mode 100644 quantum/rgb_matrix/animations/hue_breathing_anim.h create mode 100644 quantum/rgb_matrix/animations/hue_pendulum_anim.h create mode 100644 quantum/rgb_matrix/animations/hue_wave_anim.h create mode 100644 quantum/rgb_matrix/animations/jellybean_raindrops_anim.h create mode 100644 quantum/rgb_matrix/animations/rainbow_beacon_anim.h create mode 100644 quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h create mode 100644 quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h create mode 100644 quantum/rgb_matrix/animations/raindrops_anim.h create mode 100644 quantum/rgb_matrix/animations/rgb_matrix_effects.inc create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_i.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_reactive.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h create mode 100644 quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h create mode 100644 quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc create mode 100644 quantum/rgb_matrix/animations/solid_color_anim.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_anim.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_cross.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_nexus.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_simple_anim.h create mode 100644 quantum/rgb_matrix/animations/solid_reactive_wide.h create mode 100644 quantum/rgb_matrix/animations/solid_splash_anim.h create mode 100644 quantum/rgb_matrix/animations/splash_anim.h create mode 100644 quantum/rgb_matrix/animations/typing_heatmap_anim.h create mode 100644 quantum/rgb_matrix/rgb_matrix.c create mode 100644 quantum/rgb_matrix/rgb_matrix.h create mode 100644 quantum/rgb_matrix/rgb_matrix_drivers.c create mode 100644 quantum/rgb_matrix/rgb_matrix_types.h delete mode 100644 quantum/rgb_matrix_animations/alpha_mods_anim.h delete mode 100644 quantum/rgb_matrix_animations/breathing_anim.h delete mode 100644 quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h delete mode 100644 quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h delete mode 100644 quantum/rgb_matrix_animations/colorband_sat_anim.h delete mode 100644 quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h delete mode 100644 quantum/rgb_matrix_animations/colorband_spiral_val_anim.h delete mode 100644 quantum/rgb_matrix_animations/colorband_val_anim.h delete mode 100644 quantum/rgb_matrix_animations/cycle_all_anim.h delete mode 100644 quantum/rgb_matrix_animations/cycle_left_right_anim.h delete mode 100644 quantum/rgb_matrix_animations/cycle_out_in_anim.h delete mode 100644 quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h delete mode 100644 quantum/rgb_matrix_animations/cycle_pinwheel_anim.h delete mode 100644 quantum/rgb_matrix_animations/cycle_spiral_anim.h delete mode 100644 quantum/rgb_matrix_animations/cycle_up_down_anim.h delete mode 100644 quantum/rgb_matrix_animations/digital_rain_anim.h delete mode 100644 quantum/rgb_matrix_animations/dual_beacon_anim.h delete mode 100644 quantum/rgb_matrix_animations/gradient_left_right_anim.h delete mode 100644 quantum/rgb_matrix_animations/gradient_up_down_anim.h delete mode 100644 quantum/rgb_matrix_animations/hue_breathing_anim.h delete mode 100644 quantum/rgb_matrix_animations/hue_pendulum_anim.h delete mode 100644 quantum/rgb_matrix_animations/hue_wave_anim.h delete mode 100644 quantum/rgb_matrix_animations/jellybean_raindrops_anim.h delete mode 100644 quantum/rgb_matrix_animations/rainbow_beacon_anim.h delete mode 100644 quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h delete mode 100644 quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h delete mode 100644 quantum/rgb_matrix_animations/raindrops_anim.h delete mode 100644 quantum/rgb_matrix_animations/rgb_matrix_effects.inc delete mode 100644 quantum/rgb_matrix_animations/solid_color_anim.h delete mode 100644 quantum/rgb_matrix_animations/solid_reactive_anim.h delete mode 100644 quantum/rgb_matrix_animations/solid_reactive_cross.h delete mode 100644 quantum/rgb_matrix_animations/solid_reactive_nexus.h delete mode 100644 quantum/rgb_matrix_animations/solid_reactive_simple_anim.h delete mode 100644 quantum/rgb_matrix_animations/solid_reactive_wide.h delete mode 100644 quantum/rgb_matrix_animations/solid_splash_anim.h delete mode 100644 quantum/rgb_matrix_animations/splash_anim.h delete mode 100644 quantum/rgb_matrix_animations/typing_heatmap_anim.h delete mode 100644 quantum/rgb_matrix_drivers.c delete mode 100644 quantum/rgb_matrix_runners/effect_runner_dx_dy.h delete mode 100644 quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h delete mode 100644 quantum/rgb_matrix_runners/effect_runner_i.h delete mode 100644 quantum/rgb_matrix_runners/effect_runner_reactive.h delete mode 100644 quantum/rgb_matrix_runners/effect_runner_reactive_splash.h delete mode 100644 quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h delete mode 100644 quantum/rgb_matrix_types.h diff --git a/common_features.mk b/common_features.mk index 9c6fc9cdf8..33a8da23d7 100644 --- a/common_features.mk +++ b/common_features.mk @@ -230,9 +230,12 @@ ifneq (,$(filter $(MCU), atmega16u2 atmega32u2 at90usb162)) # ATmegaxxU2 does not have hardware MUL instruction - lib8tion must be told to use software multiplication routines OPT_DEFS += -DLIB8_ATTINY endif - SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c - SRC += $(QUANTUM_DIR)/led_matrix.c - SRC += $(QUANTUM_DIR)/led_matrix_drivers.c + COMMON_VPATH += $(QUANTUM_DIR)/led_matrix + COMMON_VPATH += $(QUANTUM_DIR)/led_matrix/animations + COMMON_VPATH += $(QUANTUM_DIR)/led_matrix/animations/runners + SRC += process_backlight.c + SRC += led_matrix.c + SRC += led_matrix_drivers.c CIE1931_CURVE := yes ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731) @@ -255,9 +258,12 @@ ifneq (,$(filter $(MCU), atmega16u2 atmega32u2 at90usb162)) # ATmegaxxU2 does not have hardware MUL instruction - lib8tion must be told to use software multiplication routines OPT_DEFS += -DLIB8_ATTINY endif - SRC += $(QUANTUM_DIR)/color.c - SRC += $(QUANTUM_DIR)/rgb_matrix.c - SRC += $(QUANTUM_DIR)/rgb_matrix_drivers.c + COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix + COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations + COMMON_VPATH += $(QUANTUM_DIR)/rgb_matrix/animations/runners + SRC += color.c + SRC += rgb_matrix.c + SRC += rgb_matrix_drivers.c CIE1931_CURVE := yes RGB_KEYCODES_ENABLE := yes diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c deleted file mode 100644 index 9b6151604f..0000000000 --- a/quantum/led_matrix.c +++ /dev/null @@ -1,582 +0,0 @@ -/* Copyright 2017 Jason Williams - * Copyright 2017 Jack Humbert - * Copyright 2018 Yiancar - * Copyright 2019 Clueboard - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "led_matrix.h" -#include "progmem.h" -#include "config.h" -#include "eeprom.h" -#include -#include -#include "led_tables.h" - -#include - -#ifndef LED_MATRIX_CENTER -const led_point_t k_led_matrix_center = {112, 32}; -#else -const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; -#endif - -// clang-format off -#ifndef LED_MATRIX_IMMEDIATE_EEPROM -# define led_eeconfig_update(v) led_update_eeprom |= v -#else -# define led_eeconfig_update(v) if (v) eeconfig_update_led_matrix() -#endif -// clang-format on - -// Generic effect runners -#include "led_matrix_runners/effect_runner_dx_dy_dist.h" -#include "led_matrix_runners/effect_runner_dx_dy.h" -#include "led_matrix_runners/effect_runner_i.h" -#include "led_matrix_runners/effect_runner_sin_cos_i.h" -#include "led_matrix_runners/effect_runner_reactive.h" -#include "led_matrix_runners/effect_runner_reactive_splash.h" - -// ------------------------------------------ -// -----Begin led effect includes macros----- -#define LED_MATRIX_EFFECT(name) -#define LED_MATRIX_CUSTOM_EFFECT_IMPLS - -#include "led_matrix_animations/led_matrix_effects.inc" -#ifdef LED_MATRIX_CUSTOM_KB -# include "led_matrix_kb.inc" -#endif -#ifdef LED_MATRIX_CUSTOM_USER -# include "led_matrix_user.inc" -#endif - -#undef LED_MATRIX_CUSTOM_EFFECT_IMPLS -#undef LED_MATRIX_EFFECT -// -----End led effect includes macros------- -// ------------------------------------------ - -#if defined(LED_DISABLE_AFTER_TIMEOUT) && !defined(LED_DISABLE_TIMEOUT) -# define LED_DISABLE_TIMEOUT (LED_DISABLE_AFTER_TIMEOUT * 1200UL) -#endif - -#ifndef LED_DISABLE_TIMEOUT -# define LED_DISABLE_TIMEOUT 0 -#endif - -#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX -# undef LED_MATRIX_MAXIMUM_BRIGHTNESS -# define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX -#endif - -#if !defined(LED_MATRIX_VAL_STEP) -# define LED_MATRIX_VAL_STEP 8 -#endif - -#if !defined(LED_MATRIX_SPD_STEP) -# define LED_MATRIX_SPD_STEP 16 -#endif - -#if !defined(LED_MATRIX_STARTUP_MODE) -# define LED_MATRIX_STARTUP_MODE LED_MATRIX_SOLID -#endif - -#if !defined(LED_MATRIX_STARTUP_VAL) -# define LED_MATRIX_STARTUP_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS -#endif - -#if !defined(LED_MATRIX_STARTUP_SPD) -# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2 -#endif - -// globals -led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr -uint32_t g_led_timer; -#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS -uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; -#endif // LED_MATRIX_FRAMEBUFFER_EFFECTS -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -last_hit_t g_last_hit_tracker; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED - -// internals -static bool suspend_state = false; -static bool led_update_eeprom = false; -static uint8_t led_last_enable = UINT8_MAX; -static uint8_t led_last_effect = UINT8_MAX; -static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; -static led_task_states led_task_state = SYNCING; -#if LED_DISABLE_TIMEOUT > 0 -static uint32_t led_anykey_timer; -#endif // LED_DISABLE_TIMEOUT > 0 - -// double buffers -static uint32_t led_timer_buffer; -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -static last_hit_t last_hit_buffer; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED - -// split led matrix -#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) -const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; -#endif - -void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } - -void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } - -void eeconfig_update_led_matrix_default(void) { - dprintf("eeconfig_update_led_matrix_default\n"); - led_matrix_eeconfig.enable = 1; - led_matrix_eeconfig.mode = LED_MATRIX_STARTUP_MODE; - led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL; - led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD; - led_matrix_eeconfig.flags = LED_FLAG_ALL; - eeconfig_update_led_matrix(); -} - -void eeconfig_debug_led_matrix(void) { - dprintf("led_matrix_eeconfig EEPROM\n"); - dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable); - dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode); - dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val); - dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed); - dprintf("led_matrix_eeconfig.flags = %d\n", led_matrix_eeconfig.flags); -} - -__attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } - -uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { - uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i); - 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; -} - -void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } - -void led_matrix_set_value(int index, uint8_t value) { -#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) - if (!is_keyboard_left() && index >= k_led_matrix_split[0]) -# ifdef USE_CIE1931_CURVE - led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value])); -# else - led_matrix_driver.set_value(index - k_led_matrix_split[0], value); -# endif - else if (is_keyboard_left() && index < k_led_matrix_split[0]) -#endif -#ifdef USE_CIE1931_CURVE - led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value])); -#else - led_matrix_driver.set_value(index, value); -#endif -} - -void led_matrix_set_value_all(uint8_t value) { -#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) led_matrix_set_value(i, value); -#else -# ifdef USE_CIE1931_CURVE - led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value])); -# else - led_matrix_driver.set_value_all(value); -# endif -#endif -} - -void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { -#ifndef LED_MATRIX_SPLIT - if (!is_keyboard_master()) return; -#endif -#if LED_DISABLE_TIMEOUT > 0 - led_anykey_timer = 0; -#endif // LED_DISABLE_TIMEOUT > 0 - -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED - uint8_t led[LED_HITS_TO_REMEMBER]; - uint8_t led_count = 0; - -# if defined(LED_MATRIX_KEYRELEASES) - if (!pressed) -# elif defined(LED_MATRIX_KEYPRESSES) - if (pressed) -# endif // defined(LED_MATRIX_KEYRELEASES) - { - led_count = led_matrix_map_row_column_to_led(row, col, led); - } - - if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { - memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); - memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); - memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit - memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); - last_hit_buffer.count--; - } - - for (uint8_t i = 0; i < led_count; i++) { - uint8_t index = last_hit_buffer.count; - 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++; - } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED - -#if defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP) - if (led_matrix_eeconfig.mode == LED_MATRIX_TYPING_HEATMAP) { - process_led_matrix_typing_heatmap(row, col); - } -#endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP) -} - -static bool led_matrix_none(effect_params_t *params) { - if (!params->init) { - return false; - } - - led_matrix_set_value_all(0); - return false; -} - -static void led_task_timers(void) { -#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 - uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer); -#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 - led_timer_buffer = sync_timer_read32(); - - // Update double buffer timers -#if LED_DISABLE_TIMEOUT > 0 - if (led_anykey_timer < UINT32_MAX) { - if (UINT32_MAX - deltaTime < led_anykey_timer) { - led_anykey_timer = UINT32_MAX; - } else { - led_anykey_timer += deltaTime; - } - } -#endif // LED_DISABLE_TIMEOUT > 0 - - // Update double buffer last hit timers -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED - uint8_t count = last_hit_buffer.count; - for (uint8_t i = 0; i < count; ++i) { - if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { - last_hit_buffer.count--; - continue; - } - last_hit_buffer.tick[i] += deltaTime; - } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED -} - -static void led_task_sync(void) { - // next task - if (led_update_eeprom) eeconfig_update_led_matrix(); - led_update_eeprom = false; - if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING; -} - -static void led_task_start(void) { - // reset iter - led_effect_params.iter = 0; - - // update double buffers - g_led_timer = led_timer_buffer; -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED - g_last_hit_tracker = last_hit_buffer; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED - - // next task - led_task_state = RENDERING; -} - -static void led_task_render(uint8_t effect) { - bool rendering = false; - led_effect_params.init = (effect != led_last_effect) || (led_matrix_eeconfig.enable != led_last_enable); - if (led_effect_params.flags != led_matrix_eeconfig.flags) { - led_effect_params.flags = led_matrix_eeconfig.flags; - led_matrix_set_value_all(0); - } - - // each effect can opt to do calculations - // and/or request PWM buffer updates. - switch (effect) { - case LED_MATRIX_NONE: - rendering = led_matrix_none(&led_effect_params); - break; - -// --------------------------------------------- -// -----Begin led effect switch case macros----- -#define LED_MATRIX_EFFECT(name, ...) \ - case LED_MATRIX_##name: \ - rendering = name(&led_effect_params); \ - break; -#include "led_matrix_animations/led_matrix_effects.inc" -#undef LED_MATRIX_EFFECT - -#if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER) -# define LED_MATRIX_EFFECT(name, ...) \ - case LED_MATRIX_CUSTOM_##name: \ - rendering = name(&led_effect_params); \ - break; -# ifdef LED_MATRIX_CUSTOM_KB -# include "led_matrix_kb.inc" -# endif -# ifdef LED_MATRIX_CUSTOM_USER -# include "led_matrix_user.inc" -# endif -# undef LED_MATRIX_EFFECT -#endif - // -----End led effect switch case macros------- - // --------------------------------------------- - } - - led_effect_params.iter++; - - // next task - if (!rendering) { - led_task_state = FLUSHING; - if (!led_effect_params.init && effect == LED_MATRIX_NONE) { - // We only need to flush once if we are LED_MATRIX_NONE - led_task_state = SYNCING; - } - } -} - -static void led_task_flush(uint8_t effect) { - // update last trackers after the first full render so we can init over several frames - led_last_effect = effect; - led_last_enable = led_matrix_eeconfig.enable; - - // update pwm buffers - led_matrix_update_pwm_buffers(); - - // next task - led_task_state = SYNCING; -} - -void led_matrix_task(void) { - led_task_timers(); - - // Ideally we would also stop sending zeros to the LED driver PWM buffers - // while suspended and just do a software shutdown. This is a cheap hack for now. - bool suspend_backlight = suspend_state || -#if LED_DISABLE_TIMEOUT > 0 - (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || -#endif // LED_DISABLE_TIMEOUT > 0 - false; - - uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode; - - switch (led_task_state) { - case STARTING: - led_task_start(); - break; - case RENDERING: - led_task_render(effect); - if (effect) { - led_matrix_indicators(); - led_matrix_indicators_advanced(&led_effect_params); - } - break; - case FLUSHING: - led_task_flush(effect); - break; - case SYNCING: - led_task_sync(); - break; - } -} - -void led_matrix_indicators(void) { - led_matrix_indicators_kb(); - led_matrix_indicators_user(); -} - -__attribute__((weak)) void led_matrix_indicators_kb(void) {} - -__attribute__((weak)) void led_matrix_indicators_user(void) {} - -void led_matrix_indicators_advanced(effect_params_t *params) { - /* special handling is needed for "params->iter", since it's already been incremented. - * Could move the invocations to led_task_render, but then it's missing a few checks - * and not sure which would be better. Otherwise, this should be called from - * led_task_render, right before the iter++ line. - */ -#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL - uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); - uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; -#else - uint8_t min = 0; - uint8_t max = DRIVER_LED_TOTAL; -#endif - led_matrix_indicators_advanced_kb(min, max); - led_matrix_indicators_advanced_user(min, max); -} - -__attribute__((weak)) void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {} - -__attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {} - -void led_matrix_init(void) { - led_matrix_driver.init(); - -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED - g_last_hit_tracker.count = 0; - for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { - g_last_hit_tracker.tick[i] = UINT16_MAX; - } - - last_hit_buffer.count = 0; - for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { - last_hit_buffer.tick[i] = UINT16_MAX; - } -#endif // LED_MATRIX_KEYREACTIVE_ENABLED - - if (!eeconfig_is_enabled()) { - dprintf("led_matrix_init_drivers eeconfig is not enabled.\n"); - eeconfig_init(); - eeconfig_update_led_matrix_default(); - } - - eeconfig_read_led_matrix(); - if (!led_matrix_eeconfig.mode) { - dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); - eeconfig_update_led_matrix_default(); - } - eeconfig_debug_led_matrix(); // display current eeprom values -} - -void led_matrix_set_suspend_state(bool state) { -#ifdef LED_DISABLE_WHEN_USB_SUSPENDED - if (state) { - led_matrix_set_value_all(0); // turn off all LEDs when suspending - } - suspend_state = state; -#endif -} - -bool led_matrix_get_suspend_state(void) { return suspend_state; } - -void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { - led_matrix_eeconfig.enable ^= 1; - led_task_state = STARTING; - led_eeconfig_update(write_to_eeprom); - dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); -} -void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } -void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); } - -void led_matrix_enable(void) { - led_matrix_enable_noeeprom(); - led_eeconfig_update(true); -} - -void led_matrix_enable_noeeprom(void) { - if (!led_matrix_eeconfig.enable) led_task_state = STARTING; - led_matrix_eeconfig.enable = 1; -} - -void led_matrix_disable(void) { - led_matrix_disable_noeeprom(); - led_eeconfig_update(true); -} - -void led_matrix_disable_noeeprom(void) { - if (led_matrix_eeconfig.enable) led_task_state = STARTING; - led_matrix_eeconfig.enable = 0; -} - -uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; } - -void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { - if (!led_matrix_eeconfig.enable) { - return; - } - if (mode < 1) { - led_matrix_eeconfig.mode = 1; - } else if (mode >= LED_MATRIX_EFFECT_MAX) { - led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1; - } else { - led_matrix_eeconfig.mode = mode; - } - led_task_state = STARTING; - led_eeconfig_update(write_to_eeprom); - dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); -} -void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } -void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); } - -uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } - -void led_matrix_step_helper(bool write_to_eeprom) { - uint8_t mode = led_matrix_eeconfig.mode + 1; - led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); -} -void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); } -void led_matrix_step(void) { led_matrix_step_helper(true); } - -void led_matrix_step_reverse_helper(bool write_to_eeprom) { - uint8_t mode = led_matrix_eeconfig.mode - 1; - led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); -} -void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); } -void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); } - -void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) { - if (!led_matrix_eeconfig.enable) { - return; - } - led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; - led_eeconfig_update(write_to_eeprom); - dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); -} -void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } -void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); } - -uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; } - -void led_matrix_increase_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } -void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); } -void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); } - -void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } -void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); } -void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); } - -void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { - led_matrix_eeconfig.speed = speed; - led_eeconfig_update(write_to_eeprom); - dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); -} -void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } -void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); } - -uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; } - -void led_matrix_increase_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } -void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); } -void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); } - -void led_matrix_decrease_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } -void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); } -void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); } - -led_flags_t led_matrix_get_flags(void) { return led_matrix_eeconfig.flags; } - -void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; } diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h deleted file mode 100644 index 0984de73b3..0000000000 --- a/quantum/led_matrix.h +++ /dev/null @@ -1,160 +0,0 @@ -/* Copyright 2017 Jason Williams - * Copyright 2017 Jack Humbert - * Copyright 2018 Yiancar - * Copyright 2019 Clueboard - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include "led_matrix_types.h" -#include "quantum.h" - -#ifdef IS31FL3731 -# include "is31fl3731-simple.h" -#endif - -#ifndef LED_MATRIX_LED_FLUSH_LIMIT -# define LED_MATRIX_LED_FLUSH_LIMIT 16 -#endif - -#ifndef LED_MATRIX_LED_PROCESS_LIMIT -# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 -#endif - -#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL -# define LED_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \ - uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \ - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; -#else -# define LED_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = 0; \ - uint8_t max = DRIVER_LED_TOTAL; -#endif - -#define LED_MATRIX_TEST_LED_FLAGS() \ - if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue - -enum led_matrix_effects { - LED_MATRIX_NONE = 0, - -// -------------------------------------- -// -----Begin led effect enum macros----- -#define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name, -#include "led_matrix_animations/led_matrix_effects.inc" -#undef LED_MATRIX_EFFECT - -#if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER) -# define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name, -# ifdef LED_MATRIX_CUSTOM_KB -# include "led_matrix_kb.inc" -# endif -# ifdef LED_MATRIX_CUSTOM_USER -# include "led_matrix_user.inc" -# endif -# undef LED_MATRIX_EFFECT -#endif - // -------------------------------------- - // -----End led effect enum macros------- - - LED_MATRIX_EFFECT_MAX -}; - -void eeconfig_update_led_matrix_default(void); -void eeconfig_update_led_matrix(void); -void eeconfig_debug_led_matrix(void); - -uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); -uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i); - -void led_matrix_set_value(int index, uint8_t value); -void led_matrix_set_value_all(uint8_t value); - -void process_led_matrix(uint8_t row, uint8_t col, bool pressed); - -void led_matrix_task(void); - -// This runs after another backlight effect and replaces -// values already set -void led_matrix_indicators(void); -void led_matrix_indicators_kb(void); -void led_matrix_indicators_user(void); - -void led_matrix_indicators_advanced(effect_params_t *params); -void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max); -void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max); - -void led_matrix_init(void); - -void led_matrix_set_suspend_state(bool state); -bool led_matrix_get_suspend_state(void); -void led_matrix_toggle(void); -void led_matrix_toggle_noeeprom(void); -void led_matrix_enable(void); -void led_matrix_enable_noeeprom(void); -void led_matrix_disable(void); -void led_matrix_disable_noeeprom(void); -uint8_t led_matrix_is_enabled(void); -void led_matrix_mode(uint8_t mode); -void led_matrix_mode_noeeprom(uint8_t mode); -uint8_t led_matrix_get_mode(void); -void led_matrix_step(void); -void led_matrix_step_noeeprom(void); -void led_matrix_step_reverse(void); -void led_matrix_step_reverse_noeeprom(void); -void led_matrix_set_val(uint8_t val); -void led_matrix_set_val_noeeprom(uint8_t val); -uint8_t led_matrix_get_val(void); -void led_matrix_increase_val(void); -void led_matrix_increase_val_noeeprom(void); -void led_matrix_decrease_val(void); -void led_matrix_decrease_val_noeeprom(void); -void led_matrix_set_speed(uint8_t speed); -void led_matrix_set_speed_noeeprom(uint8_t speed); -uint8_t led_matrix_get_speed(void); -void led_matrix_increase_speed(void); -void led_matrix_increase_speed_noeeprom(void); -void led_matrix_decrease_speed(void); -void led_matrix_decrease_speed_noeeprom(void); -led_flags_t led_matrix_get_flags(void); -void led_matrix_set_flags(led_flags_t flags); - -typedef struct { - /* Perform any initialisation required for the other driver functions to work. */ - void (*init)(void); - - /* Set the brightness of a single LED in the buffer. */ - void (*set_value)(int index, uint8_t value); - /* Set the brightness of all LEDS on the keyboard in the buffer. */ - void (*set_value_all)(uint8_t value); - /* Flush any buffered changes to the hardware. */ - void (*flush)(void); -} led_matrix_driver_t; - -extern const led_matrix_driver_t led_matrix_driver; - -extern led_eeconfig_t led_matrix_eeconfig; - -extern uint32_t g_led_timer; -extern led_config_t g_led_config; -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -extern last_hit_t g_last_hit_tracker; -#endif -#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS -extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; -#endif diff --git a/quantum/led_matrix/animations/alpha_mods_anim.h b/quantum/led_matrix/animations/alpha_mods_anim.h new file mode 100644 index 0000000000..a4638fde69 --- /dev/null +++ b/quantum/led_matrix/animations/alpha_mods_anim.h @@ -0,0 +1,24 @@ +#ifndef DISABLE_LED_MATRIX_ALPHAS_MODS +LED_MATRIX_EFFECT(ALPHAS_MODS) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +// alphas = val1, mods = val2 +bool ALPHAS_MODS(effect_params_t* params) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t val1 = led_matrix_eeconfig.val; + uint8_t val2 = val1 + led_matrix_eeconfig.speed; + + for (uint8_t i = led_min; i < led_max; i++) { + LED_MATRIX_TEST_LED_FLAGS(); + if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) { + led_matrix_set_value(i, val2); + } else { + led_matrix_set_value(i, val1); + } + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_ALPHAS_MODS diff --git a/quantum/led_matrix/animations/band_anim.h b/quantum/led_matrix/animations/band_anim.h new file mode 100644 index 0000000000..f9cb85dc4f --- /dev/null +++ b/quantum/led_matrix/animations/band_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_LED_MATRIX_BAND +LED_MATRIX_EFFECT(BAND) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t BAND_math(uint8_t val, uint8_t i, uint8_t time) { + int16_t v = val - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; + return scale8(v < 0 ? 0 : v, val); +} + +bool BAND(effect_params_t* params) { return effect_runner_i(params, &BAND_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_BAND diff --git a/quantum/led_matrix/animations/band_pinwheel_anim.h b/quantum/led_matrix/animations/band_pinwheel_anim.h new file mode 100644 index 0000000000..d3144bffbf --- /dev/null +++ b/quantum/led_matrix/animations/band_pinwheel_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_BAND_PINWHEEL +LED_MATRIX_EFFECT(BAND_PINWHEEL) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) { return scale8(val - time - atan2_8(dy, dx) * 3, val); } + +bool BAND_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_BAND_PINWHEEL diff --git a/quantum/led_matrix/animations/band_spiral_anim.h b/quantum/led_matrix/animations/band_spiral_anim.h new file mode 100644 index 0000000000..defbe69676 --- /dev/null +++ b/quantum/led_matrix/animations/band_spiral_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_BAND_SPIRAL +LED_MATRIX_EFFECT(BAND_SPIRAL) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(val + dist - time - atan2_8(dy, dx), val); } + +bool BAND_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_BAND_SPIRAL diff --git a/quantum/led_matrix/animations/breathing_anim.h b/quantum/led_matrix/animations/breathing_anim.h new file mode 100644 index 0000000000..4f49f50690 --- /dev/null +++ b/quantum/led_matrix/animations/breathing_anim.h @@ -0,0 +1,19 @@ +#ifndef DISABLE_LED_MATRIX_BREATHING +LED_MATRIX_EFFECT(BREATHING) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BREATHING(effect_params_t* params) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t val = led_matrix_eeconfig.val; + uint16_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 8); + val = scale8(abs8(sin8(time) - 128) * 2, val); + for (uint8_t i = led_min; i < led_max; i++) { + LED_MATRIX_TEST_LED_FLAGS(); + led_matrix_set_value(i, val); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_BREATHING diff --git a/quantum/led_matrix/animations/cycle_left_right_anim.h b/quantum/led_matrix/animations/cycle_left_right_anim.h new file mode 100644 index 0000000000..c426d02fd5 --- /dev/null +++ b/quantum/led_matrix/animations/cycle_left_right_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT +LED_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].x - time, val); } + +bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT diff --git a/quantum/led_matrix/animations/cycle_out_in_anim.h b/quantum/led_matrix/animations/cycle_out_in_anim.h new file mode 100644 index 0000000000..55527556fd --- /dev/null +++ b/quantum/led_matrix/animations/cycle_out_in_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_CYCLE_OUT_IN +LED_MATRIX_EFFECT(CYCLE_OUT_IN) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(3 * dist / 2 + time, val); } + +bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_CYCLE_OUT_IN diff --git a/quantum/led_matrix/animations/cycle_up_down_anim.h b/quantum/led_matrix/animations/cycle_up_down_anim.h new file mode 100644 index 0000000000..d97de0d1ec --- /dev/null +++ b/quantum/led_matrix/animations/cycle_up_down_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_CYCLE_UP_DOWN +LED_MATRIX_EFFECT(CYCLE_UP_DOWN) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].y - time, val); } + +bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_CYCLE_UP_DOWN diff --git a/quantum/led_matrix/animations/dual_beacon_anim.h b/quantum/led_matrix/animations/dual_beacon_anim.h new file mode 100644 index 0000000000..e1bc5ae464 --- /dev/null +++ b/quantum/led_matrix/animations/dual_beacon_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_DUAL_BEACON +LED_MATRIX_EFFECT(DUAL_BEACON) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val); } + +bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_DUAL_BEACON diff --git a/quantum/led_matrix/animations/led_matrix_effects.inc b/quantum/led_matrix/animations/led_matrix_effects.inc new file mode 100644 index 0000000000..ad1f46b242 --- /dev/null +++ b/quantum/led_matrix/animations/led_matrix_effects.inc @@ -0,0 +1,18 @@ +// Add your new core led matrix effect here, order determines enum order +#include "solid_anim.h" +#include "alpha_mods_anim.h" +#include "breathing_anim.h" +#include "band_anim.h" +#include "band_pinwheel_anim.h" +#include "band_spiral_anim.h" +#include "cycle_left_right_anim.h" +#include "cycle_up_down_anim.h" +#include "cycle_out_in_anim.h" +#include "dual_beacon_anim.h" +#include "solid_reactive_simple_anim.h" +#include "solid_reactive_wide.h" +#include "solid_reactive_cross.h" +#include "solid_reactive_nexus.h" +#include "solid_splash_anim.h" +#include "wave_left_right_anim.h" +#include "wave_up_down_anim.h" diff --git a/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h b/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h new file mode 100644 index 0000000000..ef97631b90 --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h @@ -0,0 +1,16 @@ +#pragma once + +typedef uint8_t (*dx_dy_f)(uint8_t val, int16_t dx, int16_t dy, uint8_t time); + +bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + LED_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x; + int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y; + led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, time)); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h b/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h new file mode 100644 index 0000000000..5ef5938be0 --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h @@ -0,0 +1,17 @@ +#pragma once + +typedef uint8_t (*dx_dy_dist_f)(uint8_t val, 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) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + LED_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x; + int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y; + uint8_t dist = sqrt16(dx * dx + dy * dy); + led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, dist, time)); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/led_matrix/animations/runners/effect_runner_i.h b/quantum/led_matrix/animations/runners/effect_runner_i.h new file mode 100644 index 0000000000..b3015759be --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_i.h @@ -0,0 +1,14 @@ +#pragma once + +typedef uint8_t (*i_f)(uint8_t val, uint8_t i, uint8_t time); + +bool effect_runner_i(effect_params_t* params, i_f effect_func) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + LED_MATRIX_TEST_LED_FLAGS(); + led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, i, time)); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive.h b/quantum/led_matrix/animations/runners/effect_runner_reactive.h new file mode 100644 index 0000000000..4369ea8c49 --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_reactive.h @@ -0,0 +1,28 @@ +#pragma once + +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED + +typedef uint8_t (*reactive_f)(uint8_t val, uint16_t offset); + +bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint16_t max_tick = 65535 / led_matrix_eeconfig.speed; + for (uint8_t i = led_min; i < led_max; i++) { + LED_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, led_matrix_eeconfig.speed); + led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, offset)); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h new file mode 100644 index 0000000000..d6eb9731ee --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h @@ -0,0 +1,26 @@ +#pragma once + +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED + +typedef uint8_t (*reactive_splash_f)(uint8_t val, 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) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + LED_MATRIX_TEST_LED_FLAGS(); + uint8_t val = 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], led_matrix_eeconfig.speed); + val = effect_func(val, dx, dy, dist, tick); + } + led_matrix_set_value(i, scale8(val, led_matrix_eeconfig.val)); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h b/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h new file mode 100644 index 0000000000..4a5219abd1 --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h @@ -0,0 +1,16 @@ +#pragma once + +typedef uint8_t (*sin_cos_i_f)(uint8_t val, 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) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint16_t time = scale16by8(g_led_timer, led_matrix_eeconfig.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++) { + LED_MATRIX_TEST_LED_FLAGS(); + led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, cos_value, sin_value, i, time)); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/led_matrix/animations/runners/led_matrix_runners.inc b/quantum/led_matrix/animations/runners/led_matrix_runners.inc new file mode 100644 index 0000000000..c09022bb0f --- /dev/null +++ b/quantum/led_matrix/animations/runners/led_matrix_runners.inc @@ -0,0 +1,6 @@ +#include "effect_runner_dx_dy_dist.h" +#include "effect_runner_dx_dy.h" +#include "effect_runner_i.h" +#include "effect_runner_sin_cos_i.h" +#include "effect_runner_reactive.h" +#include "effect_runner_reactive_splash.h" diff --git a/quantum/led_matrix/animations/solid_anim.h b/quantum/led_matrix/animations/solid_anim.h new file mode 100644 index 0000000000..4c9e43c581 --- /dev/null +++ b/quantum/led_matrix/animations/solid_anim.h @@ -0,0 +1,15 @@ +LED_MATRIX_EFFECT(SOLID) +#ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +bool SOLID(effect_params_t* params) { + LED_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t val = led_matrix_eeconfig.val; + for (uint8_t i = led_min; i < led_max; i++) { + LED_MATRIX_TEST_LED_FLAGS(); + led_matrix_set_value(i, val); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/led_matrix/animations/solid_reactive_cross.h b/quantum/led_matrix/animations/solid_reactive_cross.h new file mode 100644 index 0000000000..94425c959f --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_cross.h @@ -0,0 +1,35 @@ +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS +LED_MATRIX_EFFECT(SOLID_REACTIVE_CROSS) +# endif + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS +LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) +# endif + +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t SOLID_REACTIVE_CROSS_math(uint8_t val, 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; + return qadd8(val, 255 - effect); +} + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS +bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } +# endif + +# ifndef DISABLE_LED_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 // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_reactive_nexus.h b/quantum/led_matrix/animations/solid_reactive_nexus.h new file mode 100644 index 0000000000..504b1104f1 --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_nexus.h @@ -0,0 +1,32 @@ +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS +LED_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS) +# endif + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS +LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS) +# endif + +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t SOLID_REACTIVE_NEXUS_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; + if (dist > 72) effect = 255; + if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; + return qadd8(val, 255 - effect); +} + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS +bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } +# endif + +# ifndef DISABLE_LED_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 // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_reactive_simple_anim.h b/quantum/led_matrix/animations/solid_reactive_simple_anim.h new file mode 100644 index 0000000000..4752a84162 --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_simple_anim.h @@ -0,0 +1,12 @@ +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE +LED_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) { return scale8(255 - offset, val); } + +bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_reactive_wide.h b/quantum/led_matrix/animations/solid_reactive_wide.h new file mode 100644 index 0000000000..922e32fe5f --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_wide.h @@ -0,0 +1,30 @@ +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE +LED_MATRIX_EFFECT(SOLID_REACTIVE_WIDE) +# endif + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE +LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE) +# endif + +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t SOLID_REACTIVE_WIDE_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick + dist * 5; + if (effect > 255) effect = 255; + return qadd8(val, 255 - effect); +} + +# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE +bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } +# endif + +# ifndef DISABLE_LED_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 // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/solid_splash_anim.h b/quantum/led_matrix/animations/solid_splash_anim.h new file mode 100644 index 0000000000..d95889b813 --- /dev/null +++ b/quantum/led_matrix/animations/solid_splash_anim.h @@ -0,0 +1,30 @@ +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_LED_MATRIX_SOLID_SPLASH) || !defined(DISABLE_LED_MATRIX_SOLID_MULTISPLASH) + +# ifndef DISABLE_LED_MATRIX_SOLID_SPLASH +LED_MATRIX_EFFECT(SOLID_SPLASH) +# endif + +# ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH +LED_MATRIX_EFFECT(SOLID_MULTISPLASH) +# endif + +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +uint8_t SOLID_SPLASH_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; + return qadd8(val, 255 - effect); +} + +# ifndef DISABLE_LED_MATRIX_SOLID_SPLASH +bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } +# endif + +# ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH +bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } +# endif + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_LED_MATRIX_SPLASH) && !defined(DISABLE_LED_MATRIX_MULTISPLASH) +#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix/animations/wave_left_right_anim.h b/quantum/led_matrix/animations/wave_left_right_anim.h new file mode 100644 index 0000000000..8579f1b45f --- /dev/null +++ b/quantum/led_matrix/animations/wave_left_right_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT +LED_MATRIX_EFFECT(WAVE_LEFT_RIGHT) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].x - time), val); } + +bool WAVE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &WAVE_LEFT_RIGHT_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT diff --git a/quantum/led_matrix/animations/wave_up_down_anim.h b/quantum/led_matrix/animations/wave_up_down_anim.h new file mode 100644 index 0000000000..635c608414 --- /dev/null +++ b/quantum/led_matrix/animations/wave_up_down_anim.h @@ -0,0 +1,10 @@ +#ifndef DISABLE_LED_MATRIX_WAVE_UP_DOWN +LED_MATRIX_EFFECT(WAVE_UP_DOWN) +# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS + +static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].y - time), val); } + +bool WAVE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &WAVE_UP_DOWN_math); } + +# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_LED_MATRIX_WAVE_UP_DOWN diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c new file mode 100644 index 0000000000..32788866c5 --- /dev/null +++ b/quantum/led_matrix/led_matrix.c @@ -0,0 +1,577 @@ +/* Copyright 2017 Jason Williams + * Copyright 2017 Jack Humbert + * Copyright 2018 Yiancar + * Copyright 2019 Clueboard + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "led_matrix.h" +#include "progmem.h" +#include "config.h" +#include "eeprom.h" +#include +#include +#include "led_tables.h" + +#include + +#ifndef LED_MATRIX_CENTER +const led_point_t k_led_matrix_center = {112, 32}; +#else +const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; +#endif + +// clang-format off +#ifndef LED_MATRIX_IMMEDIATE_EEPROM +# define led_eeconfig_update(v) led_update_eeprom |= v +#else +# define led_eeconfig_update(v) if (v) eeconfig_update_led_matrix() +#endif +// clang-format on + +// Generic effect runners +#include "led_matrix_runners.inc" + +// ------------------------------------------ +// -----Begin led effect includes macros----- +#define LED_MATRIX_EFFECT(name) +#define LED_MATRIX_CUSTOM_EFFECT_IMPLS + +#include "led_matrix_effects.inc" +#ifdef LED_MATRIX_CUSTOM_KB +# include "led_matrix_kb.inc" +#endif +#ifdef LED_MATRIX_CUSTOM_USER +# include "led_matrix_user.inc" +#endif + +#undef LED_MATRIX_CUSTOM_EFFECT_IMPLS +#undef LED_MATRIX_EFFECT +// -----End led effect includes macros------- +// ------------------------------------------ + +#if defined(LED_DISABLE_AFTER_TIMEOUT) && !defined(LED_DISABLE_TIMEOUT) +# define LED_DISABLE_TIMEOUT (LED_DISABLE_AFTER_TIMEOUT * 1200UL) +#endif + +#ifndef LED_DISABLE_TIMEOUT +# define LED_DISABLE_TIMEOUT 0 +#endif + +#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX +# undef LED_MATRIX_MAXIMUM_BRIGHTNESS +# define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX +#endif + +#if !defined(LED_MATRIX_VAL_STEP) +# define LED_MATRIX_VAL_STEP 8 +#endif + +#if !defined(LED_MATRIX_SPD_STEP) +# define LED_MATRIX_SPD_STEP 16 +#endif + +#if !defined(LED_MATRIX_STARTUP_MODE) +# define LED_MATRIX_STARTUP_MODE LED_MATRIX_SOLID +#endif + +#if !defined(LED_MATRIX_STARTUP_VAL) +# define LED_MATRIX_STARTUP_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS +#endif + +#if !defined(LED_MATRIX_STARTUP_SPD) +# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2 +#endif + +// globals +led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr +uint32_t g_led_timer; +#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS +uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; +#endif // LED_MATRIX_FRAMEBUFFER_EFFECTS +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +last_hit_t g_last_hit_tracker; +#endif // LED_MATRIX_KEYREACTIVE_ENABLED + +// internals +static bool suspend_state = false; +static bool led_update_eeprom = false; +static uint8_t led_last_enable = UINT8_MAX; +static uint8_t led_last_effect = UINT8_MAX; +static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; +static led_task_states led_task_state = SYNCING; +#if LED_DISABLE_TIMEOUT > 0 +static uint32_t led_anykey_timer; +#endif // LED_DISABLE_TIMEOUT > 0 + +// double buffers +static uint32_t led_timer_buffer; +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +static last_hit_t last_hit_buffer; +#endif // LED_MATRIX_KEYREACTIVE_ENABLED + +// split led matrix +#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; +#endif + +void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } + +void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } + +void eeconfig_update_led_matrix_default(void) { + dprintf("eeconfig_update_led_matrix_default\n"); + led_matrix_eeconfig.enable = 1; + led_matrix_eeconfig.mode = LED_MATRIX_STARTUP_MODE; + led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL; + led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD; + led_matrix_eeconfig.flags = LED_FLAG_ALL; + eeconfig_update_led_matrix(); +} + +void eeconfig_debug_led_matrix(void) { + dprintf("led_matrix_eeconfig EEPROM\n"); + dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable); + dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode); + dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val); + dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed); + dprintf("led_matrix_eeconfig.flags = %d\n", led_matrix_eeconfig.flags); +} + +__attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } + +uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { + uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i); + 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; +} + +void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } + +void led_matrix_set_value(int index, uint8_t value) { +#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) + if (!is_keyboard_left() && index >= k_led_matrix_split[0]) +# ifdef USE_CIE1931_CURVE + led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value])); +# else + led_matrix_driver.set_value(index - k_led_matrix_split[0], value); +# endif + else if (is_keyboard_left() && index < k_led_matrix_split[0]) +#endif +#ifdef USE_CIE1931_CURVE + led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value])); +#else + led_matrix_driver.set_value(index, value); +#endif +} + +void led_matrix_set_value_all(uint8_t value) { +#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) led_matrix_set_value(i, value); +#else +# ifdef USE_CIE1931_CURVE + led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value])); +# else + led_matrix_driver.set_value_all(value); +# endif +#endif +} + +void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { +#ifndef LED_MATRIX_SPLIT + if (!is_keyboard_master()) return; +#endif +#if LED_DISABLE_TIMEOUT > 0 + led_anykey_timer = 0; +#endif // LED_DISABLE_TIMEOUT > 0 + +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED + uint8_t led[LED_HITS_TO_REMEMBER]; + uint8_t led_count = 0; + +# if defined(LED_MATRIX_KEYRELEASES) + if (!pressed) +# elif defined(LED_MATRIX_KEYPRESSES) + if (pressed) +# endif // defined(LED_MATRIX_KEYRELEASES) + { + led_count = led_matrix_map_row_column_to_led(row, col, led); + } + + if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { + memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); + memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); + memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit + memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); + last_hit_buffer.count--; + } + + for (uint8_t i = 0; i < led_count; i++) { + uint8_t index = last_hit_buffer.count; + 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++; + } +#endif // LED_MATRIX_KEYREACTIVE_ENABLED + +#if defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP) + if (led_matrix_eeconfig.mode == LED_MATRIX_TYPING_HEATMAP) { + process_led_matrix_typing_heatmap(row, col); + } +#endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP) +} + +static bool led_matrix_none(effect_params_t *params) { + if (!params->init) { + return false; + } + + led_matrix_set_value_all(0); + return false; +} + +static void led_task_timers(void) { +#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 + uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer); +#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 + led_timer_buffer = sync_timer_read32(); + + // Update double buffer timers +#if LED_DISABLE_TIMEOUT > 0 + if (led_anykey_timer < UINT32_MAX) { + if (UINT32_MAX - deltaTime < led_anykey_timer) { + led_anykey_timer = UINT32_MAX; + } else { + led_anykey_timer += deltaTime; + } + } +#endif // LED_DISABLE_TIMEOUT > 0 + + // Update double buffer last hit timers +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED + uint8_t count = last_hit_buffer.count; + for (uint8_t i = 0; i < count; ++i) { + if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { + last_hit_buffer.count--; + continue; + } + last_hit_buffer.tick[i] += deltaTime; + } +#endif // LED_MATRIX_KEYREACTIVE_ENABLED +} + +static void led_task_sync(void) { + // next task + if (led_update_eeprom) eeconfig_update_led_matrix(); + led_update_eeprom = false; + if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING; +} + +static void led_task_start(void) { + // reset iter + led_effect_params.iter = 0; + + // update double buffers + g_led_timer = led_timer_buffer; +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED + g_last_hit_tracker = last_hit_buffer; +#endif // LED_MATRIX_KEYREACTIVE_ENABLED + + // next task + led_task_state = RENDERING; +} + +static void led_task_render(uint8_t effect) { + bool rendering = false; + led_effect_params.init = (effect != led_last_effect) || (led_matrix_eeconfig.enable != led_last_enable); + if (led_effect_params.flags != led_matrix_eeconfig.flags) { + led_effect_params.flags = led_matrix_eeconfig.flags; + led_matrix_set_value_all(0); + } + + // each effect can opt to do calculations + // and/or request PWM buffer updates. + switch (effect) { + case LED_MATRIX_NONE: + rendering = led_matrix_none(&led_effect_params); + break; + +// --------------------------------------------- +// -----Begin led effect switch case macros----- +#define LED_MATRIX_EFFECT(name, ...) \ + case LED_MATRIX_##name: \ + rendering = name(&led_effect_params); \ + break; +#include "led_matrix_effects.inc" +#undef LED_MATRIX_EFFECT + +#if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER) +# define LED_MATRIX_EFFECT(name, ...) \ + case LED_MATRIX_CUSTOM_##name: \ + rendering = name(&led_effect_params); \ + break; +# ifdef LED_MATRIX_CUSTOM_KB +# include "led_matrix_kb.inc" +# endif +# ifdef LED_MATRIX_CUSTOM_USER +# include "led_matrix_user.inc" +# endif +# undef LED_MATRIX_EFFECT +#endif + // -----End led effect switch case macros------- + // --------------------------------------------- + } + + led_effect_params.iter++; + + // next task + if (!rendering) { + led_task_state = FLUSHING; + if (!led_effect_params.init && effect == LED_MATRIX_NONE) { + // We only need to flush once if we are LED_MATRIX_NONE + led_task_state = SYNCING; + } + } +} + +static void led_task_flush(uint8_t effect) { + // update last trackers after the first full render so we can init over several frames + led_last_effect = effect; + led_last_enable = led_matrix_eeconfig.enable; + + // update pwm buffers + led_matrix_update_pwm_buffers(); + + // next task + led_task_state = SYNCING; +} + +void led_matrix_task(void) { + led_task_timers(); + + // Ideally we would also stop sending zeros to the LED driver PWM buffers + // while suspended and just do a software shutdown. This is a cheap hack for now. + bool suspend_backlight = suspend_state || +#if LED_DISABLE_TIMEOUT > 0 + (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || +#endif // LED_DISABLE_TIMEOUT > 0 + false; + + uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode; + + switch (led_task_state) { + case STARTING: + led_task_start(); + break; + case RENDERING: + led_task_render(effect); + if (effect) { + led_matrix_indicators(); + led_matrix_indicators_advanced(&led_effect_params); + } + break; + case FLUSHING: + led_task_flush(effect); + break; + case SYNCING: + led_task_sync(); + break; + } +} + +void led_matrix_indicators(void) { + led_matrix_indicators_kb(); + led_matrix_indicators_user(); +} + +__attribute__((weak)) void led_matrix_indicators_kb(void) {} + +__attribute__((weak)) void led_matrix_indicators_user(void) {} + +void led_matrix_indicators_advanced(effect_params_t *params) { + /* special handling is needed for "params->iter", since it's already been incremented. + * Could move the invocations to led_task_render, but then it's missing a few checks + * and not sure which would be better. Otherwise, this should be called from + * led_task_render, right before the iter++ line. + */ +#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL + uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); + uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; + if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; +#else + uint8_t min = 0; + uint8_t max = DRIVER_LED_TOTAL; +#endif + led_matrix_indicators_advanced_kb(min, max); + led_matrix_indicators_advanced_user(min, max); +} + +__attribute__((weak)) void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {} + +__attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {} + +void led_matrix_init(void) { + led_matrix_driver.init(); + +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED + g_last_hit_tracker.count = 0; + for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { + g_last_hit_tracker.tick[i] = UINT16_MAX; + } + + last_hit_buffer.count = 0; + for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { + last_hit_buffer.tick[i] = UINT16_MAX; + } +#endif // LED_MATRIX_KEYREACTIVE_ENABLED + + if (!eeconfig_is_enabled()) { + dprintf("led_matrix_init_drivers eeconfig is not enabled.\n"); + eeconfig_init(); + eeconfig_update_led_matrix_default(); + } + + eeconfig_read_led_matrix(); + if (!led_matrix_eeconfig.mode) { + dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); + eeconfig_update_led_matrix_default(); + } + eeconfig_debug_led_matrix(); // display current eeprom values +} + +void led_matrix_set_suspend_state(bool state) { +#ifdef LED_DISABLE_WHEN_USB_SUSPENDED + if (state) { + led_matrix_set_value_all(0); // turn off all LEDs when suspending + } + suspend_state = state; +#endif +} + +bool led_matrix_get_suspend_state(void) { return suspend_state; } + +void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { + led_matrix_eeconfig.enable ^= 1; + led_task_state = STARTING; + led_eeconfig_update(write_to_eeprom); + dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); +} +void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } +void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); } + +void led_matrix_enable(void) { + led_matrix_enable_noeeprom(); + led_eeconfig_update(true); +} + +void led_matrix_enable_noeeprom(void) { + if (!led_matrix_eeconfig.enable) led_task_state = STARTING; + led_matrix_eeconfig.enable = 1; +} + +void led_matrix_disable(void) { + led_matrix_disable_noeeprom(); + led_eeconfig_update(true); +} + +void led_matrix_disable_noeeprom(void) { + if (led_matrix_eeconfig.enable) led_task_state = STARTING; + led_matrix_eeconfig.enable = 0; +} + +uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; } + +void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { + if (!led_matrix_eeconfig.enable) { + return; + } + if (mode < 1) { + led_matrix_eeconfig.mode = 1; + } else if (mode >= LED_MATRIX_EFFECT_MAX) { + led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1; + } else { + led_matrix_eeconfig.mode = mode; + } + led_task_state = STARTING; + led_eeconfig_update(write_to_eeprom); + dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); +} +void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } +void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); } + +uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } + +void led_matrix_step_helper(bool write_to_eeprom) { + uint8_t mode = led_matrix_eeconfig.mode + 1; + led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); +} +void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); } +void led_matrix_step(void) { led_matrix_step_helper(true); } + +void led_matrix_step_reverse_helper(bool write_to_eeprom) { + uint8_t mode = led_matrix_eeconfig.mode - 1; + led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); +} +void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); } +void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); } + +void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) { + if (!led_matrix_eeconfig.enable) { + return; + } + led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; + led_eeconfig_update(write_to_eeprom); + dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); +} +void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } +void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); } + +uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; } + +void led_matrix_increase_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } +void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); } +void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); } + +void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } +void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); } +void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); } + +void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { + led_matrix_eeconfig.speed = speed; + led_eeconfig_update(write_to_eeprom); + dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); +} +void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } +void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); } + +uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; } + +void led_matrix_increase_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } +void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); } +void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); } + +void led_matrix_decrease_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } +void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); } +void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); } + +led_flags_t led_matrix_get_flags(void) { return led_matrix_eeconfig.flags; } + +void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; } diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h new file mode 100644 index 0000000000..6f85854fbe --- /dev/null +++ b/quantum/led_matrix/led_matrix.h @@ -0,0 +1,160 @@ +/* Copyright 2017 Jason Williams + * Copyright 2017 Jack Humbert + * Copyright 2018 Yiancar + * Copyright 2019 Clueboard + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include "led_matrix_types.h" +#include "quantum.h" + +#ifdef IS31FL3731 +# include "is31fl3731-simple.h" +#endif + +#ifndef LED_MATRIX_LED_FLUSH_LIMIT +# define LED_MATRIX_LED_FLUSH_LIMIT 16 +#endif + +#ifndef LED_MATRIX_LED_PROCESS_LIMIT +# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 +#endif + +#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL +# define LED_MATRIX_USE_LIMITS(min, max) \ + uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \ + uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \ + if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; +#else +# define LED_MATRIX_USE_LIMITS(min, max) \ + uint8_t min = 0; \ + uint8_t max = DRIVER_LED_TOTAL; +#endif + +#define LED_MATRIX_TEST_LED_FLAGS() \ + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue + +enum led_matrix_effects { + LED_MATRIX_NONE = 0, + +// -------------------------------------- +// -----Begin led effect enum macros----- +#define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name, +#include "led_matrix_effects.inc" +#undef LED_MATRIX_EFFECT + +#if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER) +# define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name, +# ifdef LED_MATRIX_CUSTOM_KB +# include "led_matrix_kb.inc" +# endif +# ifdef LED_MATRIX_CUSTOM_USER +# include "led_matrix_user.inc" +# endif +# undef LED_MATRIX_EFFECT +#endif + // -------------------------------------- + // -----End led effect enum macros------- + + LED_MATRIX_EFFECT_MAX +}; + +void eeconfig_update_led_matrix_default(void); +void eeconfig_update_led_matrix(void); +void eeconfig_debug_led_matrix(void); + +uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); +uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i); + +void led_matrix_set_value(int index, uint8_t value); +void led_matrix_set_value_all(uint8_t value); + +void process_led_matrix(uint8_t row, uint8_t col, bool pressed); + +void led_matrix_task(void); + +// This runs after another backlight effect and replaces +// values already set +void led_matrix_indicators(void); +void led_matrix_indicators_kb(void); +void led_matrix_indicators_user(void); + +void led_matrix_indicators_advanced(effect_params_t *params); +void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max); +void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max); + +void led_matrix_init(void); + +void led_matrix_set_suspend_state(bool state); +bool led_matrix_get_suspend_state(void); +void led_matrix_toggle(void); +void led_matrix_toggle_noeeprom(void); +void led_matrix_enable(void); +void led_matrix_enable_noeeprom(void); +void led_matrix_disable(void); +void led_matrix_disable_noeeprom(void); +uint8_t led_matrix_is_enabled(void); +void led_matrix_mode(uint8_t mode); +void led_matrix_mode_noeeprom(uint8_t mode); +uint8_t led_matrix_get_mode(void); +void led_matrix_step(void); +void led_matrix_step_noeeprom(void); +void led_matrix_step_reverse(void); +void led_matrix_step_reverse_noeeprom(void); +void led_matrix_set_val(uint8_t val); +void led_matrix_set_val_noeeprom(uint8_t val); +uint8_t led_matrix_get_val(void); +void led_matrix_increase_val(void); +void led_matrix_increase_val_noeeprom(void); +void led_matrix_decrease_val(void); +void led_matrix_decrease_val_noeeprom(void); +void led_matrix_set_speed(uint8_t speed); +void led_matrix_set_speed_noeeprom(uint8_t speed); +uint8_t led_matrix_get_speed(void); +void led_matrix_increase_speed(void); +void led_matrix_increase_speed_noeeprom(void); +void led_matrix_decrease_speed(void); +void led_matrix_decrease_speed_noeeprom(void); +led_flags_t led_matrix_get_flags(void); +void led_matrix_set_flags(led_flags_t flags); + +typedef struct { + /* Perform any initialisation required for the other driver functions to work. */ + void (*init)(void); + + /* Set the brightness of a single LED in the buffer. */ + void (*set_value)(int index, uint8_t value); + /* Set the brightness of all LEDS on the keyboard in the buffer. */ + void (*set_value_all)(uint8_t value); + /* Flush any buffered changes to the hardware. */ + void (*flush)(void); +} led_matrix_driver_t; + +extern const led_matrix_driver_t led_matrix_driver; + +extern led_eeconfig_t led_matrix_eeconfig; + +extern uint32_t g_led_timer; +extern led_config_t g_led_config; +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +extern last_hit_t g_last_hit_tracker; +#endif +#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS +extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; +#endif diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c new file mode 100644 index 0000000000..1d46b2c506 --- /dev/null +++ b/quantum/led_matrix/led_matrix_drivers.c @@ -0,0 +1,153 @@ +/* Copyright 2018 James Laird-Wah + * Copyright 2019 Clueboard + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "led_matrix.h" + +/* Each driver needs to define a struct: + * + * const led_matrix_driver_t led_matrix_driver; + * + * All members must be provided. Keyboard custom drivers must define this + * in their own files. + */ + +#if defined(IS31FL3731) || defined(IS31FL3733) + +# include "i2c_master.h" + +static void init(void) { + i2c_init(); +# ifdef IS31FL3731 +# ifdef LED_DRIVER_ADDR_1 + IS31FL3731_init(LED_DRIVER_ADDR_1); +# endif +# ifdef LED_DRIVER_ADDR_2 + IS31FL3731_init(LED_DRIVER_ADDR_2); +# endif +# ifdef LED_DRIVER_ADDR_3 + IS31FL3731_init(LED_DRIVER_ADDR_3); +# endif +# ifdef LED_DRIVER_ADDR_4 + IS31FL3731_init(LED_DRIVER_ADDR_4); +# endif +# else +# ifdef LED_DRIVER_ADDR_1 +# ifndef LED_DRIVER_SYNC_1 +# define LED_DRIVER_SYNC_1 0 +# endif + IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1); +# endif +# ifdef LED_DRIVER_ADDR_2 +# ifndef LED_DRIVER_SYNC_2 +# define LED_DRIVER_SYNC_2 0 +# endif + IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2); +# endif +# ifdef LED_DRIVER_ADDR_3 +# ifndef LED_DRIVER_SYNC_3 +# define LED_DRIVER_SYNC_3 0 +# endif + IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3); +# endif +# ifdef LED_DRIVER_ADDR_4 +# ifndef LED_DRIVER_SYNC_4 +# define LED_DRIVER_SYNC_4 0 +# endif + IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4); +# endif +# endif + + for (int index = 0; index < DRIVER_LED_TOTAL; index++) { +# ifdef IS31FL3731 + IS31FL3731_set_led_control_register(index, true); +# else + IS31FL3733_set_led_control_register(index, true); +# endif + } +// This actually updates the LED drivers +# ifdef IS31FL3731 +# ifdef LED_DRIVER_ADDR_1 + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0); +# endif +# ifdef LED_DRIVER_ADDR_2 + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1); +# endif +# ifdef LED_DRIVER_ADDR_3 + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2); +# endif +# ifdef LED_DRIVER_ADDR_4 + IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3); +# endif +# else +# ifdef LED_DRIVER_ADDR_1 + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0); +# endif +# ifdef LED_DRIVER_ADDR_2 + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1); +# endif +# ifdef LED_DRIVER_ADDR_3 + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2); +# endif +# ifdef LED_DRIVER_ADDR_4 + IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3); +# endif +# endif +} + +static void flush(void) { +# ifdef IS31FL3731 +# ifdef LED_DRIVER_ADDR_1 + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); +# endif +# ifdef LED_DRIVER_ADDR_2 + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); +# endif +# ifdef LED_DRIVER_ADDR_3 + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); +# endif +# ifdef LED_DRIVER_ADDR_4 + IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); +# endif +# else +# ifdef LED_DRIVER_ADDR_1 + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); +# endif +# ifdef LED_DRIVER_ADDR_2 + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); +# endif +# ifdef LED_DRIVER_ADDR_3 + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); +# endif +# ifdef LED_DRIVER_ADDR_4 + IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); +# endif +# endif +} + +const led_matrix_driver_t led_matrix_driver = { + .init = init, + .flush = flush, +# ifdef IS31FL3731 + .set_value = IS31FL3731_set_value, + .set_value_all = IS31FL3731_set_value_all, +# else + .set_value = IS31FL3733_set_value, + .set_value_all = IS31FL3733_set_value_all, +# endif +}; + +#endif diff --git a/quantum/led_matrix/led_matrix_types.h b/quantum/led_matrix/led_matrix_types.h new file mode 100644 index 0000000000..61cdbd9b8e --- /dev/null +++ b/quantum/led_matrix/led_matrix_types.h @@ -0,0 +1,97 @@ +/* Copyright 2021 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +#if defined(__GNUC__) +# define PACKED __attribute__((__packed__)) +#else +# define PACKED +#endif + +#if defined(_MSC_VER) +# pragma pack(push, 1) +#endif + +#if defined(LED_MATRIX_KEYPRESSES) || defined(LED_MATRIX_KEYRELEASES) +# define LED_MATRIX_KEYREACTIVE_ENABLED +#endif + +// Last led hit +#ifndef LED_HITS_TO_REMEMBER +# define LED_HITS_TO_REMEMBER 8 +#endif // LED_HITS_TO_REMEMBER + +#ifdef LED_MATRIX_KEYREACTIVE_ENABLED +typedef struct PACKED { + uint8_t count; + uint8_t x[LED_HITS_TO_REMEMBER]; + uint8_t y[LED_HITS_TO_REMEMBER]; + uint8_t index[LED_HITS_TO_REMEMBER]; + uint16_t tick[LED_HITS_TO_REMEMBER]; +} last_hit_t; +#endif // LED_MATRIX_KEYREACTIVE_ENABLED + +typedef enum led_task_states { STARTING, RENDERING, FLUSHING, SYNCING } led_task_states; + +typedef uint8_t led_flags_t; + +typedef struct PACKED { + uint8_t iter; + led_flags_t flags; + bool init; +} effect_params_t; + +typedef struct PACKED { + uint8_t x; + uint8_t y; +} led_point_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_KEYLIGHT 0x04 +#define LED_FLAG_INDICATOR 0x08 + +#define NO_LED 255 + +typedef struct PACKED { + uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; + led_point_t point[DRIVER_LED_TOTAL]; + uint8_t flags[DRIVER_LED_TOTAL]; +} led_config_t; + +typedef union { + uint32_t raw; + struct PACKED { + uint8_t enable : 2; + uint8_t mode : 6; + uint16_t reserved; + uint8_t val; + uint8_t speed; // EECONFIG needs to be increased to support this + led_flags_t flags; + }; +} led_eeconfig_t; + +#if defined(_MSC_VER) +# pragma pack(pop) +#endif diff --git a/quantum/led_matrix_animations/alpha_mods_anim.h b/quantum/led_matrix_animations/alpha_mods_anim.h deleted file mode 100644 index 6f69f6892b..0000000000 --- a/quantum/led_matrix_animations/alpha_mods_anim.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_ALPHAS_MODS -LED_MATRIX_EFFECT(ALPHAS_MODS) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -// alphas = val1, mods = val2 -bool ALPHAS_MODS(effect_params_t* params) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t val1 = led_matrix_eeconfig.val; - uint8_t val2 = val1 + led_matrix_eeconfig.speed; - - for (uint8_t i = led_min; i < led_max; i++) { - LED_MATRIX_TEST_LED_FLAGS(); - if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) { - led_matrix_set_value(i, val2); - } else { - led_matrix_set_value(i, val1); - } - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_ALPHAS_MODS diff --git a/quantum/led_matrix_animations/band_anim.h b/quantum/led_matrix_animations/band_anim.h deleted file mode 100644 index 523dba1b78..0000000000 --- a/quantum/led_matrix_animations/band_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_BAND -LED_MATRIX_EFFECT(BAND) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t BAND_math(uint8_t val, uint8_t i, uint8_t time) { - int16_t v = val - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; - return scale8(v < 0 ? 0 : v, val); -} - -bool BAND(effect_params_t* params) { return effect_runner_i(params, &BAND_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_BAND diff --git a/quantum/led_matrix_animations/band_pinwheel_anim.h b/quantum/led_matrix_animations/band_pinwheel_anim.h deleted file mode 100644 index fb3b835cad..0000000000 --- a/quantum/led_matrix_animations/band_pinwheel_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_BAND_PINWHEEL -LED_MATRIX_EFFECT(BAND_PINWHEEL) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) { return scale8(val - time - atan2_8(dy, dx) * 3, val); } - -bool BAND_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_BAND_PINWHEEL diff --git a/quantum/led_matrix_animations/band_spiral_anim.h b/quantum/led_matrix_animations/band_spiral_anim.h deleted file mode 100644 index fca22aad9c..0000000000 --- a/quantum/led_matrix_animations/band_spiral_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_BAND_SPIRAL -LED_MATRIX_EFFECT(BAND_SPIRAL) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(val + dist - time - atan2_8(dy, dx), val); } - -bool BAND_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_BAND_SPIRAL diff --git a/quantum/led_matrix_animations/breathing_anim.h b/quantum/led_matrix_animations/breathing_anim.h deleted file mode 100644 index 00310e3f65..0000000000 --- a/quantum/led_matrix_animations/breathing_anim.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_BREATHING -LED_MATRIX_EFFECT(BREATHING) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -bool BREATHING(effect_params_t* params) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t val = led_matrix_eeconfig.val; - uint16_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 8); - val = scale8(abs8(sin8(time) - 128) * 2, val); - for (uint8_t i = led_min; i < led_max; i++) { - LED_MATRIX_TEST_LED_FLAGS(); - led_matrix_set_value(i, val); - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_BREATHING diff --git a/quantum/led_matrix_animations/cycle_left_right_anim.h b/quantum/led_matrix_animations/cycle_left_right_anim.h deleted file mode 100644 index 51e81d57ca..0000000000 --- a/quantum/led_matrix_animations/cycle_left_right_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT -LED_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].x - time, val); } - -bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT diff --git a/quantum/led_matrix_animations/cycle_out_in_anim.h b/quantum/led_matrix_animations/cycle_out_in_anim.h deleted file mode 100644 index f62061552c..0000000000 --- a/quantum/led_matrix_animations/cycle_out_in_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_CYCLE_OUT_IN -LED_MATRIX_EFFECT(CYCLE_OUT_IN) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(3 * dist / 2 + time, val); } - -bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_CYCLE_OUT_IN diff --git a/quantum/led_matrix_animations/cycle_up_down_anim.h b/quantum/led_matrix_animations/cycle_up_down_anim.h deleted file mode 100644 index bd1d125672..0000000000 --- a/quantum/led_matrix_animations/cycle_up_down_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_CYCLE_UP_DOWN -LED_MATRIX_EFFECT(CYCLE_UP_DOWN) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].y - time, val); } - -bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_CYCLE_UP_DOWN diff --git a/quantum/led_matrix_animations/dual_beacon_anim.h b/quantum/led_matrix_animations/dual_beacon_anim.h deleted file mode 100644 index 9b8a7877c9..0000000000 --- a/quantum/led_matrix_animations/dual_beacon_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_DUAL_BEACON -LED_MATRIX_EFFECT(DUAL_BEACON) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val); } - -bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_DUAL_BEACON diff --git a/quantum/led_matrix_animations/led_matrix_effects.inc b/quantum/led_matrix_animations/led_matrix_effects.inc deleted file mode 100644 index 67237c5683..0000000000 --- a/quantum/led_matrix_animations/led_matrix_effects.inc +++ /dev/null @@ -1,18 +0,0 @@ -// Add your new core led matrix effect here, order determins enum order, requires "led_matrix_animations/ directory -#include "led_matrix_animations/solid_anim.h" -#include "led_matrix_animations/alpha_mods_anim.h" -#include "led_matrix_animations/breathing_anim.h" -#include "led_matrix_animations/band_anim.h" -#include "led_matrix_animations/band_pinwheel_anim.h" -#include "led_matrix_animations/band_spiral_anim.h" -#include "led_matrix_animations/cycle_left_right_anim.h" -#include "led_matrix_animations/cycle_up_down_anim.h" -#include "led_matrix_animations/cycle_out_in_anim.h" -#include "led_matrix_animations/dual_beacon_anim.h" -#include "led_matrix_animations/solid_reactive_simple_anim.h" -#include "led_matrix_animations/solid_reactive_wide.h" -#include "led_matrix_animations/solid_reactive_cross.h" -#include "led_matrix_animations/solid_reactive_nexus.h" -#include "led_matrix_animations/solid_splash_anim.h" -#include "led_matrix_animations/wave_left_right_anim.h" -#include "led_matrix_animations/wave_up_down_anim.h" diff --git a/quantum/led_matrix_animations/solid_anim.h b/quantum/led_matrix_animations/solid_anim.h deleted file mode 100644 index 4c9e43c581..0000000000 --- a/quantum/led_matrix_animations/solid_anim.h +++ /dev/null @@ -1,15 +0,0 @@ -LED_MATRIX_EFFECT(SOLID) -#ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -bool SOLID(effect_params_t* params) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t val = led_matrix_eeconfig.val; - for (uint8_t i = led_min; i < led_max; i++) { - LED_MATRIX_TEST_LED_FLAGS(); - led_matrix_set_value(i, val); - } - return led_max < DRIVER_LED_TOTAL; -} - -#endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/led_matrix_animations/solid_reactive_cross.h b/quantum/led_matrix_animations/solid_reactive_cross.h deleted file mode 100644 index f402d99b37..0000000000 --- a/quantum/led_matrix_animations/solid_reactive_cross.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS -LED_MATRIX_EFFECT(SOLID_REACTIVE_CROSS) -# endif - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS -LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) -# endif - -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t SOLID_REACTIVE_CROSS_math(uint8_t val, 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; - return qadd8(val, 255 - effect); -} - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS -bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } -# endif - -# ifndef DISABLE_LED_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 // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix_animations/solid_reactive_nexus.h b/quantum/led_matrix_animations/solid_reactive_nexus.h deleted file mode 100644 index 4d0d252263..0000000000 --- a/quantum/led_matrix_animations/solid_reactive_nexus.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS -LED_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS) -# endif - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS -LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS) -# endif - -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t SOLID_REACTIVE_NEXUS_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick - dist; - if (effect > 255) effect = 255; - if (dist > 72) effect = 255; - if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; - return qadd8(val, 255 - effect); -} - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS -bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } -# endif - -# ifndef DISABLE_LED_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 // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix_animations/solid_reactive_simple_anim.h b/quantum/led_matrix_animations/solid_reactive_simple_anim.h deleted file mode 100644 index 30e2527f60..0000000000 --- a/quantum/led_matrix_animations/solid_reactive_simple_anim.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE -LED_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) { return scale8(255 - offset, val); } - -bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE -#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix_animations/solid_reactive_wide.h b/quantum/led_matrix_animations/solid_reactive_wide.h deleted file mode 100644 index 34a230c259..0000000000 --- a/quantum/led_matrix_animations/solid_reactive_wide.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE -LED_MATRIX_EFFECT(SOLID_REACTIVE_WIDE) -# endif - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE -LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE) -# endif - -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t SOLID_REACTIVE_WIDE_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick + dist * 5; - if (effect > 255) effect = 255; - return qadd8(val, 255 - effect); -} - -# ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE -bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } -# endif - -# ifndef DISABLE_LED_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 // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix_animations/solid_splash_anim.h b/quantum/led_matrix_animations/solid_splash_anim.h deleted file mode 100644 index 4f6ba3d343..0000000000 --- a/quantum/led_matrix_animations/solid_splash_anim.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_LED_MATRIX_SOLID_SPLASH) || !defined(DISABLE_LED_MATRIX_SOLID_MULTISPLASH) - -# ifndef DISABLE_LED_MATRIX_SOLID_SPLASH -LED_MATRIX_EFFECT(SOLID_SPLASH) -# endif - -# ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH -LED_MATRIX_EFFECT(SOLID_MULTISPLASH) -# endif - -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -uint8_t SOLID_SPLASH_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick - dist; - if (effect > 255) effect = 255; - return qadd8(val, 255 - effect); -} - -# ifndef DISABLE_LED_MATRIX_SOLID_SPLASH -bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } -# endif - -# ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH -bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } -# endif - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_LED_MATRIX_SPLASH) && !defined(DISABLE_LED_MATRIX_MULTISPLASH) -#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix_animations/wave_left_right_anim.h b/quantum/led_matrix_animations/wave_left_right_anim.h deleted file mode 100644 index 736f22ddc5..0000000000 --- a/quantum/led_matrix_animations/wave_left_right_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT -LED_MATRIX_EFFECT(WAVE_LEFT_RIGHT) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].x - time), val); } - -bool WAVE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &WAVE_LEFT_RIGHT_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT diff --git a/quantum/led_matrix_animations/wave_up_down_anim.h b/quantum/led_matrix_animations/wave_up_down_anim.h deleted file mode 100644 index 3cab0597d4..0000000000 --- a/quantum/led_matrix_animations/wave_up_down_anim.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DISABLE_LED_MATRIX_WAVE_UP_DOWN -LED_MATRIX_EFFECT(WAVE_UP_DOWN) -# ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS - -static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].y - time), val); } - -bool WAVE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &WAVE_UP_DOWN_math); } - -# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_LED_MATRIX_WAVE_UP_DOWN diff --git a/quantum/led_matrix_drivers.c b/quantum/led_matrix_drivers.c deleted file mode 100644 index 1d46b2c506..0000000000 --- a/quantum/led_matrix_drivers.c +++ /dev/null @@ -1,153 +0,0 @@ -/* Copyright 2018 James Laird-Wah - * Copyright 2019 Clueboard - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "led_matrix.h" - -/* Each driver needs to define a struct: - * - * const led_matrix_driver_t led_matrix_driver; - * - * All members must be provided. Keyboard custom drivers must define this - * in their own files. - */ - -#if defined(IS31FL3731) || defined(IS31FL3733) - -# include "i2c_master.h" - -static void init(void) { - i2c_init(); -# ifdef IS31FL3731 -# ifdef LED_DRIVER_ADDR_1 - IS31FL3731_init(LED_DRIVER_ADDR_1); -# endif -# ifdef LED_DRIVER_ADDR_2 - IS31FL3731_init(LED_DRIVER_ADDR_2); -# endif -# ifdef LED_DRIVER_ADDR_3 - IS31FL3731_init(LED_DRIVER_ADDR_3); -# endif -# ifdef LED_DRIVER_ADDR_4 - IS31FL3731_init(LED_DRIVER_ADDR_4); -# endif -# else -# ifdef LED_DRIVER_ADDR_1 -# ifndef LED_DRIVER_SYNC_1 -# define LED_DRIVER_SYNC_1 0 -# endif - IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1); -# endif -# ifdef LED_DRIVER_ADDR_2 -# ifndef LED_DRIVER_SYNC_2 -# define LED_DRIVER_SYNC_2 0 -# endif - IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2); -# endif -# ifdef LED_DRIVER_ADDR_3 -# ifndef LED_DRIVER_SYNC_3 -# define LED_DRIVER_SYNC_3 0 -# endif - IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3); -# endif -# ifdef LED_DRIVER_ADDR_4 -# ifndef LED_DRIVER_SYNC_4 -# define LED_DRIVER_SYNC_4 0 -# endif - IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4); -# endif -# endif - - for (int index = 0; index < DRIVER_LED_TOTAL; index++) { -# ifdef IS31FL3731 - IS31FL3731_set_led_control_register(index, true); -# else - IS31FL3733_set_led_control_register(index, true); -# endif - } -// This actually updates the LED drivers -# ifdef IS31FL3731 -# ifdef LED_DRIVER_ADDR_1 - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0); -# endif -# ifdef LED_DRIVER_ADDR_2 - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1); -# endif -# ifdef LED_DRIVER_ADDR_3 - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2); -# endif -# ifdef LED_DRIVER_ADDR_4 - IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3); -# endif -# else -# ifdef LED_DRIVER_ADDR_1 - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0); -# endif -# ifdef LED_DRIVER_ADDR_2 - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1); -# endif -# ifdef LED_DRIVER_ADDR_3 - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2); -# endif -# ifdef LED_DRIVER_ADDR_4 - IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3); -# endif -# endif -} - -static void flush(void) { -# ifdef IS31FL3731 -# ifdef LED_DRIVER_ADDR_1 - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); -# endif -# ifdef LED_DRIVER_ADDR_2 - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); -# endif -# ifdef LED_DRIVER_ADDR_3 - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); -# endif -# ifdef LED_DRIVER_ADDR_4 - IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); -# endif -# else -# ifdef LED_DRIVER_ADDR_1 - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); -# endif -# ifdef LED_DRIVER_ADDR_2 - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); -# endif -# ifdef LED_DRIVER_ADDR_3 - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); -# endif -# ifdef LED_DRIVER_ADDR_4 - IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); -# endif -# endif -} - -const led_matrix_driver_t led_matrix_driver = { - .init = init, - .flush = flush, -# ifdef IS31FL3731 - .set_value = IS31FL3731_set_value, - .set_value_all = IS31FL3731_set_value_all, -# else - .set_value = IS31FL3733_set_value, - .set_value_all = IS31FL3733_set_value_all, -# endif -}; - -#endif diff --git a/quantum/led_matrix_runners/effect_runner_dx_dy.h b/quantum/led_matrix_runners/effect_runner_dx_dy.h deleted file mode 100644 index ef97631b90..0000000000 --- a/quantum/led_matrix_runners/effect_runner_dx_dy.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -typedef uint8_t (*dx_dy_f)(uint8_t val, int16_t dx, int16_t dy, uint8_t time); - -bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - LED_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x; - int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y; - led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, time)); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/led_matrix_runners/effect_runner_dx_dy_dist.h b/quantum/led_matrix_runners/effect_runner_dx_dy_dist.h deleted file mode 100644 index 5ef5938be0..0000000000 --- a/quantum/led_matrix_runners/effect_runner_dx_dy_dist.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -typedef uint8_t (*dx_dy_dist_f)(uint8_t val, 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) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - LED_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x; - int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y; - uint8_t dist = sqrt16(dx * dx + dy * dy); - led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, dist, time)); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/led_matrix_runners/effect_runner_i.h b/quantum/led_matrix_runners/effect_runner_i.h deleted file mode 100644 index b3015759be..0000000000 --- a/quantum/led_matrix_runners/effect_runner_i.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -typedef uint8_t (*i_f)(uint8_t val, uint8_t i, uint8_t time); - -bool effect_runner_i(effect_params_t* params, i_f effect_func) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - LED_MATRIX_TEST_LED_FLAGS(); - led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, i, time)); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/led_matrix_runners/effect_runner_reactive.h b/quantum/led_matrix_runners/effect_runner_reactive.h deleted file mode 100644 index 4369ea8c49..0000000000 --- a/quantum/led_matrix_runners/effect_runner_reactive.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED - -typedef uint8_t (*reactive_f)(uint8_t val, uint16_t offset); - -bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint16_t max_tick = 65535 / led_matrix_eeconfig.speed; - for (uint8_t i = led_min; i < led_max; i++) { - LED_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, led_matrix_eeconfig.speed); - led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, offset)); - } - return led_max < DRIVER_LED_TOTAL; -} - -#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix_runners/effect_runner_reactive_splash.h b/quantum/led_matrix_runners/effect_runner_reactive_splash.h deleted file mode 100644 index d6eb9731ee..0000000000 --- a/quantum/led_matrix_runners/effect_runner_reactive_splash.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED - -typedef uint8_t (*reactive_splash_f)(uint8_t val, 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) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - LED_MATRIX_TEST_LED_FLAGS(); - uint8_t val = 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], led_matrix_eeconfig.speed); - val = effect_func(val, dx, dy, dist, tick); - } - led_matrix_set_value(i, scale8(val, led_matrix_eeconfig.val)); - } - return led_max < DRIVER_LED_TOTAL; -} - -#endif // LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/led_matrix_runners/effect_runner_sin_cos_i.h b/quantum/led_matrix_runners/effect_runner_sin_cos_i.h deleted file mode 100644 index 4a5219abd1..0000000000 --- a/quantum/led_matrix_runners/effect_runner_sin_cos_i.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -typedef uint8_t (*sin_cos_i_f)(uint8_t val, 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) { - LED_MATRIX_USE_LIMITS(led_min, led_max); - - uint16_t time = scale16by8(g_led_timer, led_matrix_eeconfig.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++) { - LED_MATRIX_TEST_LED_FLAGS(); - led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, cos_value, sin_value, i, time)); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/led_matrix_types.h b/quantum/led_matrix_types.h deleted file mode 100644 index 61cdbd9b8e..0000000000 --- a/quantum/led_matrix_types.h +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright 2021 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -#if defined(__GNUC__) -# define PACKED __attribute__((__packed__)) -#else -# define PACKED -#endif - -#if defined(_MSC_VER) -# pragma pack(push, 1) -#endif - -#if defined(LED_MATRIX_KEYPRESSES) || defined(LED_MATRIX_KEYRELEASES) -# define LED_MATRIX_KEYREACTIVE_ENABLED -#endif - -// Last led hit -#ifndef LED_HITS_TO_REMEMBER -# define LED_HITS_TO_REMEMBER 8 -#endif // LED_HITS_TO_REMEMBER - -#ifdef LED_MATRIX_KEYREACTIVE_ENABLED -typedef struct PACKED { - uint8_t count; - uint8_t x[LED_HITS_TO_REMEMBER]; - uint8_t y[LED_HITS_TO_REMEMBER]; - uint8_t index[LED_HITS_TO_REMEMBER]; - uint16_t tick[LED_HITS_TO_REMEMBER]; -} last_hit_t; -#endif // LED_MATRIX_KEYREACTIVE_ENABLED - -typedef enum led_task_states { STARTING, RENDERING, FLUSHING, SYNCING } led_task_states; - -typedef uint8_t led_flags_t; - -typedef struct PACKED { - uint8_t iter; - led_flags_t flags; - bool init; -} effect_params_t; - -typedef struct PACKED { - uint8_t x; - uint8_t y; -} led_point_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_KEYLIGHT 0x04 -#define LED_FLAG_INDICATOR 0x08 - -#define NO_LED 255 - -typedef struct PACKED { - uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; - led_point_t point[DRIVER_LED_TOTAL]; - uint8_t flags[DRIVER_LED_TOTAL]; -} led_config_t; - -typedef union { - uint32_t raw; - struct PACKED { - uint8_t enable : 2; - uint8_t mode : 6; - uint16_t reserved; - uint8_t val; - uint8_t speed; // EECONFIG needs to be increased to support this - led_flags_t flags; - }; -} led_eeconfig_t; - -#if defined(_MSC_VER) -# pragma pack(pop) -#endif diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c deleted file mode 100644 index 09803c72af..0000000000 --- a/quantum/rgb_matrix.c +++ /dev/null @@ -1,645 +0,0 @@ -/* Copyright 2017 Jason Williams - * Copyright 2017 Jack Humbert - * Copyright 2018 Yiancar - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "rgb_matrix.h" -#include "progmem.h" -#include "config.h" -#include "eeprom.h" -#include -#include - -#include - -#ifndef RGB_MATRIX_CENTER -const led_point_t k_rgb_matrix_center = {112, 32}; -#else -const led_point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; -#endif - -// clang-format off -#ifndef RGB_MATRIX_IMMEDIATE_EEPROM -# define rgb_eeconfig_update(v) rgb_update_eeprom |= v -#else -# define rgb_eeconfig_update(v) if (v) eeconfig_update_rgb_matrix() -#endif -// clang-format on - -__attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } - -// 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) -#define 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------- -// ------------------------------------------ - -#if defined(RGB_DISABLE_AFTER_TIMEOUT) && !defined(RGB_DISABLE_TIMEOUT) -# define RGB_DISABLE_TIMEOUT (RGB_DISABLE_AFTER_TIMEOUT * 1200UL) -#endif - -#ifndef RGB_DISABLE_TIMEOUT -# define RGB_DISABLE_TIMEOUT 0 -#endif - -#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX -# undef RGB_MATRIX_MAXIMUM_BRIGHTNESS -# define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX -#endif - -#if !defined(RGB_MATRIX_HUE_STEP) -# define RGB_MATRIX_HUE_STEP 8 -#endif - -#if !defined(RGB_MATRIX_SAT_STEP) -# define RGB_MATRIX_SAT_STEP 16 -#endif - -#if !defined(RGB_MATRIX_VAL_STEP) -# define RGB_MATRIX_VAL_STEP 16 -#endif - -#if !defined(RGB_MATRIX_SPD_STEP) -# define RGB_MATRIX_SPD_STEP 16 -#endif - -#if !defined(RGB_MATRIX_STARTUP_MODE) -# ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT -# define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT -# else -// fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace -# define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR -# endif -#endif - -#if !defined(RGB_MATRIX_STARTUP_HUE) -# define RGB_MATRIX_STARTUP_HUE 0 -#endif - -#if !defined(RGB_MATRIX_STARTUP_SAT) -# define RGB_MATRIX_STARTUP_SAT UINT8_MAX -#endif - -#if !defined(RGB_MATRIX_STARTUP_VAL) -# define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS -#endif - -#if !defined(RGB_MATRIX_STARTUP_SPD) -# define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2 -#endif - -// globals -rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr -uint32_t g_rgb_timer; -#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS -uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; -#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -last_hit_t g_last_hit_tracker; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED - -// internals -static bool suspend_state = false; -static bool rgb_update_eeprom = false; -static uint8_t rgb_last_enable = UINT8_MAX; -static uint8_t rgb_last_effect = UINT8_MAX; -static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; -static rgb_task_states rgb_task_state = SYNCING; -#if RGB_DISABLE_TIMEOUT > 0 -static uint32_t rgb_anykey_timer; -#endif // RGB_DISABLE_TIMEOUT > 0 - -// double buffers -static uint32_t rgb_timer_buffer; -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -static last_hit_t last_hit_buffer; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED - -// split rgb matrix -#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) -const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; -#endif - -void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } - -void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } - -void eeconfig_update_rgb_matrix_default(void) { - dprintf("eeconfig_update_rgb_matrix_default\n"); - rgb_matrix_config.enable = 1; - rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; - rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; - rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; - rgb_matrix_config.flags = LED_FLAG_ALL; - eeconfig_update_rgb_matrix(); -} - -void eeconfig_debug_rgb_matrix(void) { - dprintf("rgb_matrix_config EEPROM\n"); - dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); - dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); - dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); - dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); - dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); - dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); - dprintf("rgb_matrix_config.flags = %d\n", rgb_matrix_config.flags); -} - -__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } - -uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { - uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i); - 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; -} - -void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } - -void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { -#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) - if (!is_keyboard_left() && index >= k_rgb_matrix_split[0]) - rgb_matrix_driver.set_color(index - k_rgb_matrix_split[0], red, green, blue); - else if (is_keyboard_left() && index < k_rgb_matrix_split[0]) -#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) { -#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) - for (uint8_t 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 -} - -void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { -#ifndef RGB_MATRIX_SPLIT - if (!is_keyboard_master()) return; -#endif -#if RGB_DISABLE_TIMEOUT > 0 - rgb_anykey_timer = 0; -#endif // RGB_DISABLE_TIMEOUT > 0 - -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED - uint8_t led[LED_HITS_TO_REMEMBER]; - uint8_t led_count = 0; - -# if defined(RGB_MATRIX_KEYRELEASES) - if (!pressed) -# elif defined(RGB_MATRIX_KEYPRESSES) - if (pressed) -# endif // defined(RGB_MATRIX_KEYRELEASES) - { - led_count = rgb_matrix_map_row_column_to_led(row, col, led); - } - - if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { - memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); - memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); - memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit - memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); - last_hit_buffer.count--; - } - - for (uint8_t i = 0; i < led_count; i++) { - uint8_t index = last_hit_buffer.count; - 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++; - } -#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(row, col); - } -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) -} - -void rgb_matrix_test(void) { - // Mask out bits 4 and 5 - // Increase the factor to make the test animation slower (and reduce to make it faster) - uint8_t factor = 10; - switch ((g_rgb_timer & (0b11 << factor)) >> factor) { - case 0: { - rgb_matrix_set_color_all(20, 0, 0); - break; - } - case 1: { - rgb_matrix_set_color_all(0, 20, 0); - break; - } - case 2: { - rgb_matrix_set_color_all(0, 0, 20); - break; - } - case 3: { - rgb_matrix_set_color_all(20, 20, 20); - break; - } - } -} - -static bool rgb_matrix_none(effect_params_t *params) { - if (!params->init) { - return false; - } - - rgb_matrix_set_color_all(0, 0, 0); - return false; -} - -static void rgb_task_timers(void) { -#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 - uint32_t deltaTime = sync_timer_elapsed32(rgb_timer_buffer); -#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 - rgb_timer_buffer = sync_timer_read32(); - - // Update double buffer timers -#if RGB_DISABLE_TIMEOUT > 0 - if (rgb_anykey_timer < UINT32_MAX) { - if (UINT32_MAX - deltaTime < rgb_anykey_timer) { - rgb_anykey_timer = UINT32_MAX; - } else { - rgb_anykey_timer += deltaTime; - } - } -#endif // RGB_DISABLE_TIMEOUT > 0 - - // Update double buffer last hit timers -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED - uint8_t count = last_hit_buffer.count; - for (uint8_t i = 0; i < count; ++i) { - if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { - last_hit_buffer.count--; - continue; - } - last_hit_buffer.tick[i] += deltaTime; - } -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED -} - -static void rgb_task_sync(void) { - // next task - if (rgb_update_eeprom) eeconfig_update_rgb_matrix(); - rgb_update_eeprom = false; - if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; -} - -static void rgb_task_start(void) { - // reset iter - rgb_effect_params.iter = 0; - - // update double buffers - g_rgb_timer = rgb_timer_buffer; -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED - g_last_hit_tracker = last_hit_buffer; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED - - // next task - rgb_task_state = RENDERING; -} - -static void rgb_task_render(uint8_t effect) { - bool rendering = false; - rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); - if (rgb_effect_params.flags != rgb_matrix_config.flags) { - rgb_effect_params.flags = rgb_matrix_config.flags; - rgb_matrix_set_color_all(0, 0, 0); - } - - // each effect can opt to do calculations - // and/or request PWM buffer updates. - switch (effect) { - case RGB_MATRIX_NONE: - rendering = rgb_matrix_none(&rgb_effect_params); - break; - -// --------------------------------------------- -// -----Begin rgb effect switch case macros----- -#define RGB_MATRIX_EFFECT(name, ...) \ - case RGB_MATRIX_##name: \ - rendering = name(&rgb_effect_params); \ - break; -#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, ...) \ - case RGB_MATRIX_CUSTOM_##name: \ - rendering = name(&rgb_effect_params); \ - break; -# 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 -#endif - // -----End rgb effect switch case macros------- - // --------------------------------------------- - - // Factory default magic value - case UINT8_MAX: { - rgb_matrix_test(); - rgb_task_state = FLUSHING; - } - return; - } - - rgb_effect_params.iter++; - - // next task - if (!rendering) { - rgb_task_state = FLUSHING; - if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) { - // We only need to flush once if we are RGB_MATRIX_NONE - rgb_task_state = SYNCING; - } - } -} - -static void rgb_task_flush(uint8_t effect) { - // update last trackers after the first full render so we can init over several frames - rgb_last_effect = effect; - rgb_last_enable = rgb_matrix_config.enable; - - // update pwm buffers - rgb_matrix_update_pwm_buffers(); - - // next task - rgb_task_state = SYNCING; -} - -void rgb_matrix_task(void) { - rgb_task_timers(); - - // Ideally we would also stop sending zeros to the LED driver PWM buffers - // while suspended and just do a software shutdown. This is a cheap hack for now. - bool suspend_backlight = suspend_state || -#if RGB_DISABLE_TIMEOUT > 0 - (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || -#endif // RGB_DISABLE_TIMEOUT > 0 - false; - - uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; - - switch (rgb_task_state) { - case STARTING: - rgb_task_start(); - break; - case RENDERING: - rgb_task_render(effect); - if (effect) { - rgb_matrix_indicators(); - rgb_matrix_indicators_advanced(&rgb_effect_params); - } - break; - case FLUSHING: - rgb_task_flush(effect); - break; - case SYNCING: - rgb_task_sync(); - break; - } -} - -void rgb_matrix_indicators(void) { - rgb_matrix_indicators_kb(); - rgb_matrix_indicators_user(); -} - -__attribute__((weak)) void rgb_matrix_indicators_kb(void) {} - -__attribute__((weak)) void rgb_matrix_indicators_user(void) {} - -void rgb_matrix_indicators_advanced(effect_params_t *params) { - /* special handling is needed for "params->iter", since it's already been incremented. - * Could move the invocations to rgb_task_render, but then it's missing a few checks - * and not sure which would be better. Otherwise, this should be called from - * rgb_task_render, right before the iter++ line. - */ -#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; -#else - uint8_t min = 0; - uint8_t max = DRIVER_LED_TOTAL; -#endif - rgb_matrix_indicators_advanced_kb(min, max); - rgb_matrix_indicators_advanced_user(min, max); -} - -__attribute__((weak)) void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {} - -__attribute__((weak)) void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {} - -void rgb_matrix_init(void) { - rgb_matrix_driver.init(); - -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED - g_last_hit_tracker.count = 0; - for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { - g_last_hit_tracker.tick[i] = UINT16_MAX; - } - - last_hit_buffer.count = 0; - for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { - last_hit_buffer.tick[i] = UINT16_MAX; - } -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED - - if (!eeconfig_is_enabled()) { - dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); - eeconfig_init(); - eeconfig_update_rgb_matrix_default(); - } - - eeconfig_read_rgb_matrix(); - if (!rgb_matrix_config.mode) { - dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); - eeconfig_update_rgb_matrix_default(); - } - eeconfig_debug_rgb_matrix(); // display current eeprom values -} - -void rgb_matrix_set_suspend_state(bool state) { -#ifdef RGB_DISABLE_WHEN_USB_SUSPENDED - if (state) { - rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending - } - suspend_state = state; -#endif -} - -bool rgb_matrix_get_suspend_state(void) { return suspend_state; } - -void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { - rgb_matrix_config.enable ^= 1; - rgb_task_state = STARTING; - rgb_eeconfig_update(write_to_eeprom); - dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); -} -void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } -void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } - -void rgb_matrix_enable(void) { - rgb_matrix_enable_noeeprom(); - rgb_eeconfig_update(true); -} - -void rgb_matrix_enable_noeeprom(void) { - if (!rgb_matrix_config.enable) rgb_task_state = STARTING; - rgb_matrix_config.enable = 1; -} - -void rgb_matrix_disable(void) { - rgb_matrix_disable_noeeprom(); - rgb_eeconfig_update(true); -} - -void rgb_matrix_disable_noeeprom(void) { - if (rgb_matrix_config.enable) rgb_task_state = STARTING; - rgb_matrix_config.enable = 0; -} - -uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } - -void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { - if (!rgb_matrix_config.enable) { - return; - } - if (mode < 1) { - rgb_matrix_config.mode = 1; - } else if (mode >= RGB_MATRIX_EFFECT_MAX) { - rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; - } else { - rgb_matrix_config.mode = mode; - } - rgb_task_state = STARTING; - rgb_eeconfig_update(write_to_eeprom); - dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); -} -void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } -void rgb_matrix_mode(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, true); } - -uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } - -void rgb_matrix_step_helper(bool write_to_eeprom) { - uint8_t mode = rgb_matrix_config.mode + 1; - rgb_matrix_mode_eeprom_helper((mode < RGB_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); -} -void rgb_matrix_step_noeeprom(void) { rgb_matrix_step_helper(false); } -void rgb_matrix_step(void) { rgb_matrix_step_helper(true); } - -void rgb_matrix_step_reverse_helper(bool write_to_eeprom) { - uint8_t mode = rgb_matrix_config.mode - 1; - rgb_matrix_mode_eeprom_helper((mode < 1) ? RGB_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); -} -void rgb_matrix_step_reverse_noeeprom(void) { rgb_matrix_step_reverse_helper(false); } -void rgb_matrix_step_reverse(void) { rgb_matrix_step_reverse_helper(true); } - -void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { - if (!rgb_matrix_config.enable) { - return; - } - rgb_matrix_config.hsv.h = hue; - rgb_matrix_config.hsv.s = sat; - rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; - rgb_eeconfig_update(write_to_eeprom); - dprintf("rgb matrix set hsv [%s]: %u,%u,%u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v); -} -void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } -void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); } - -HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } -uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } -uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } -uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } - -void rgb_matrix_increase_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h + RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_increase_hue_noeeprom(void) { rgb_matrix_increase_hue_helper(false); } -void rgb_matrix_increase_hue(void) { rgb_matrix_increase_hue_helper(true); } - -void rgb_matrix_decrease_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h - RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_decrease_hue_noeeprom(void) { rgb_matrix_decrease_hue_helper(false); } -void rgb_matrix_decrease_hue(void) { rgb_matrix_decrease_hue_helper(true); } - -void rgb_matrix_increase_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_increase_sat_noeeprom(void) { rgb_matrix_increase_sat_helper(false); } -void rgb_matrix_increase_sat(void) { rgb_matrix_increase_sat_helper(true); } - -void rgb_matrix_decrease_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } -void rgb_matrix_decrease_sat_noeeprom(void) { rgb_matrix_decrease_sat_helper(false); } -void rgb_matrix_decrease_sat(void) { rgb_matrix_decrease_sat_helper(true); } - -void rgb_matrix_increase_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } -void rgb_matrix_increase_val_noeeprom(void) { rgb_matrix_increase_val_helper(false); } -void rgb_matrix_increase_val(void) { rgb_matrix_increase_val_helper(true); } - -void rgb_matrix_decrease_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } -void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); } -void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } - -void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { - rgb_matrix_config.speed = speed; - rgb_eeconfig_update(write_to_eeprom); - dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); -} -void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } -void rgb_matrix_set_speed(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, true); } - -uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } - -void rgb_matrix_increase_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } -void rgb_matrix_increase_speed_noeeprom(void) { rgb_matrix_increase_speed_helper(false); } -void rgb_matrix_increase_speed(void) { rgb_matrix_increase_speed_helper(true); } - -void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } -void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } -void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } - -led_flags_t rgb_matrix_get_flags(void) { return rgb_matrix_config.flags; } - -void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; } diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h deleted file mode 100644 index 741a2fe446..0000000000 --- a/quantum/rgb_matrix.h +++ /dev/null @@ -1,228 +0,0 @@ -/* Copyright 2017 Jason Williams - * Copyright 2017 Jack Humbert - * Copyright 2018 Yiancar - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include "rgb_matrix_types.h" -#include "color.h" -#include "quantum.h" -#include "rgblight_list.h" - -#ifdef IS31FL3731 -# include "is31fl3731.h" -#elif defined(IS31FL3733) -# include "is31fl3733.h" -#elif defined(IS31FL3737) -# include "is31fl3737.h" -#elif defined(IS31FL3741) -# include "is31fl3741.h" -#elif defined(AW20216) -# include "aw20216.h" -#elif defined(WS2812) -# include "ws2812.h" -#endif - -#ifndef RGB_MATRIX_LED_FLUSH_LIMIT -# define RGB_MATRIX_LED_FLUSH_LIMIT 16 -#endif - -#ifndef RGB_MATRIX_LED_PROCESS_LIMIT -# define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 -#endif - -#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; -#else -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = 0; \ - uint8_t max = DRIVER_LED_TOTAL; -#endif - -#define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \ - if (i >= led_min && i <= led_max) { \ - rgb_matrix_set_color(i, r, g, b); \ - } - -#define RGB_MATRIX_TEST_LED_FLAGS() \ - if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue - -enum rgb_matrix_effects { - RGB_MATRIX_NONE = 0, - -// -------------------------------------- -// -----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, -# 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 -#endif - // -------------------------------------- - // -----End rgb effect enum macros------- - - RGB_MATRIX_EFFECT_MAX -}; - -void eeconfig_update_rgb_matrix_default(void); -void eeconfig_update_rgb_matrix(void); - -uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); -uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i); - -void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); -void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); - -void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed); - -void rgb_matrix_task(void); - -// This runs after another backlight effect and replaces -// colors already set -void rgb_matrix_indicators(void); -void rgb_matrix_indicators_kb(void); -void rgb_matrix_indicators_user(void); - -void rgb_matrix_indicators_advanced(effect_params_t *params); -void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max); -void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max); - -void rgb_matrix_init(void); - -void rgb_matrix_set_suspend_state(bool state); -bool rgb_matrix_get_suspend_state(void); -void rgb_matrix_toggle(void); -void rgb_matrix_toggle_noeeprom(void); -void rgb_matrix_enable(void); -void rgb_matrix_enable_noeeprom(void); -void rgb_matrix_disable(void); -void rgb_matrix_disable_noeeprom(void); -uint8_t rgb_matrix_is_enabled(void); -void rgb_matrix_mode(uint8_t mode); -void rgb_matrix_mode_noeeprom(uint8_t mode); -uint8_t rgb_matrix_get_mode(void); -void rgb_matrix_step(void); -void rgb_matrix_step_noeeprom(void); -void rgb_matrix_step_reverse(void); -void rgb_matrix_step_reverse_noeeprom(void); -void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val); -void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); -HSV rgb_matrix_get_hsv(void); -uint8_t rgb_matrix_get_hue(void); -uint8_t rgb_matrix_get_sat(void); -uint8_t rgb_matrix_get_val(void); -void rgb_matrix_increase_hue(void); -void rgb_matrix_increase_hue_noeeprom(void); -void rgb_matrix_decrease_hue(void); -void rgb_matrix_decrease_hue_noeeprom(void); -void rgb_matrix_increase_sat(void); -void rgb_matrix_increase_sat_noeeprom(void); -void rgb_matrix_decrease_sat(void); -void rgb_matrix_decrease_sat_noeeprom(void); -void rgb_matrix_increase_val(void); -void rgb_matrix_increase_val_noeeprom(void); -void rgb_matrix_decrease_val(void); -void rgb_matrix_decrease_val_noeeprom(void); -void rgb_matrix_set_speed(uint8_t speed); -void rgb_matrix_set_speed_noeeprom(uint8_t speed); -uint8_t rgb_matrix_get_speed(void); -void rgb_matrix_increase_speed(void); -void rgb_matrix_increase_speed_noeeprom(void); -void rgb_matrix_decrease_speed(void); -void rgb_matrix_decrease_speed_noeeprom(void); -led_flags_t rgb_matrix_get_flags(void); -void rgb_matrix_set_flags(led_flags_t flags); - -#ifndef RGBLIGHT_ENABLE -# define eeconfig_update_rgblight_current eeconfig_update_rgb_matrix -# define rgblight_toggle rgb_matrix_toggle -# define rgblight_toggle_noeeprom rgb_matrix_toggle_noeeprom -# define rgblight_enable rgb_matrix_enable -# define rgblight_enable_noeeprom rgb_matrix_enable_noeeprom -# define rgblight_disable rgb_matrix_disable -# define rgblight_disable_noeeprom rgb_matrix_disable_noeeprom -# define rgblight_is_enabled rgb_matrix_is_enabled -# define rgblight_mode rgb_matrix_mode -# define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom -# define rgblight_get_mode rgb_matrix_get_mode -# define rgblight_get_hue rgb_matrix_get_hue -# define rgblight_get_sat rgb_matrix_get_sat -# define rgblight_get_val rgb_matrix_get_val -# define rgblight_get_hsv rgb_matrix_get_hsv -# define rgblight_step rgb_matrix_step -# define rgblight_step_noeeprom rgb_matrix_step_noeeprom -# define rgblight_step_reverse rgb_matrix_step_reverse -# define rgblight_step_reverse_noeeprom rgb_matrix_step_reverse_noeeprom -# define rgblight_sethsv rgb_matrix_sethsv -# define rgblight_sethsv_noeeprom rgb_matrix_sethsv_noeeprom -# define rgblight_increase_hue rgb_matrix_increase_hue -# define rgblight_increase_hue_noeeprom rgb_matrix_increase_hue_noeeprom -# define rgblight_decrease_hue rgb_matrix_decrease_hue -# define rgblight_decrease_hue_noeeprom rgb_matrix_decrease_hue_noeeprom -# define rgblight_increase_sat rgb_matrix_increase_sat -# define rgblight_increase_sat_noeeprom rgb_matrix_increase_sat_noeeprom -# define rgblight_decrease_sat rgb_matrix_decrease_sat -# define rgblight_decrease_sat_noeeprom rgb_matrix_decrease_sat_noeeprom -# define rgblight_increase_val rgb_matrix_increase_val -# define rgblight_increase_val_noeeprom rgb_matrix_increase_val_noeeprom -# define rgblight_decrease_val rgb_matrix_decrease_val -# define rgblight_decrease_val_noeeprom rgb_matrix_decrease_val_noeeprom -# define rgblight_set_speed rgb_matrix_set_speed -# define rgblight_set_speed_noeeprom rgb_matrix_set_speed_noeeprom -# define rgblight_get_speed rgb_matrix_get_speed -# define rgblight_increase_speed rgb_matrix_increase_speed -# define rgblight_increase_speed_noeeprom rgb_matrix_increase_speed_noeeprom -# define rgblight_decrease_speed rgb_matrix_decrease_speed -# define rgblight_decrease_speed_noeeprom rgb_matrix_decrease_speed_noeeprom -#endif - -typedef struct { - /* Perform any initialisation required for the other driver functions to work. */ - void (*init)(void); - /* Set the colour of a single LED in the buffer. */ - void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b); - /* Set the colour of all LEDS on the keyboard in the buffer. */ - void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b); - /* Flush any buffered changes to the hardware. */ - void (*flush)(void); -} rgb_matrix_driver_t; - -extern const rgb_matrix_driver_t rgb_matrix_driver; - -extern rgb_config_t rgb_matrix_config; - -extern uint32_t g_rgb_timer; -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 g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; -#endif diff --git a/quantum/rgb_matrix/animations/alpha_mods_anim.h b/quantum/rgb_matrix/animations/alpha_mods_anim.h new file mode 100644 index 0000000000..426d88ef35 --- /dev/null +++ b/quantum/rgb_matrix/animations/alpha_mods_anim.h @@ -0,0 +1,26 @@ +#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS +RGB_MATRIX_EFFECT(ALPHAS_MODS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// alphas = color1, mods = color2 +bool ALPHAS_MODS(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + RGB rgb1 = rgb_matrix_hsv_to_rgb(hsv); + hsv.h += rgb_matrix_config.speed; + RGB rgb2 = rgb_matrix_hsv_to_rgb(hsv); + + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) { + rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b); + } else { + rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b); + } + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS diff --git a/quantum/rgb_matrix/animations/breathing_anim.h b/quantum/rgb_matrix/animations/breathing_anim.h new file mode 100644 index 0000000000..340bd93e5d --- /dev/null +++ b/quantum/rgb_matrix/animations/breathing_anim.h @@ -0,0 +1,20 @@ +#ifndef DISABLE_RGB_MATRIX_BREATHING +RGB_MATRIX_EFFECT(BREATHING) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool BREATHING(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BREATHING diff --git a/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h b/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h new file mode 100644 index 0000000000..3df3cfda7d --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_pinwheel_sat_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +RGB_MATRIX_EFFECT(BAND_PINWHEEL_SAT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_PINWHEEL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv.s = scale8(hsv.s - time - atan2_8(dy, dx) * 3, hsv.s); + return hsv; +} + +bool BAND_PINWHEEL_SAT(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT diff --git a/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h b/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h new file mode 100644 index 0000000000..7d80074fd5 --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_pinwheel_val_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +RGB_MATRIX_EFFECT(BAND_PINWHEEL_VAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_PINWHEEL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv.v = scale8(hsv.v - time - atan2_8(dy, dx) * 3, hsv.v); + return hsv; +} + +bool BAND_PINWHEEL_VAL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL diff --git a/quantum/rgb_matrix/animations/colorband_sat_anim.h b/quantum/rgb_matrix/animations/colorband_sat_anim.h new file mode 100644 index 0000000000..35b830af6b --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_sat_anim.h @@ -0,0 +1,14 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SAT +RGB_MATRIX_EFFECT(BAND_SAT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_SAT_math(HSV hsv, uint8_t i, uint8_t time) { + int16_t s = hsv.s - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; + hsv.s = scale8(s < 0 ? 0 : s, hsv.s); + return hsv; +} + +bool BAND_SAT(effect_params_t* params) { return effect_runner_i(params, &BAND_SAT_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_SAT diff --git a/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h b/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h new file mode 100644 index 0000000000..048157aa1b --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_spiral_sat_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT +RGB_MATRIX_EFFECT(BAND_SPIRAL_SAT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_SPIRAL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv.s = scale8(hsv.s + dist - time - atan2_8(dy, dx), hsv.s); + return hsv; +} + +bool BAND_SPIRAL_SAT(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT diff --git a/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h b/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h new file mode 100644 index 0000000000..bff2da1616 --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_spiral_val_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL +RGB_MATRIX_EFFECT(BAND_SPIRAL_VAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_SPIRAL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv.v = scale8(hsv.v + dist - time - atan2_8(dy, dx), hsv.v); + return hsv; +} + +bool BAND_SPIRAL_VAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL diff --git a/quantum/rgb_matrix/animations/colorband_val_anim.h b/quantum/rgb_matrix/animations/colorband_val_anim.h new file mode 100644 index 0000000000..f1aaf1d067 --- /dev/null +++ b/quantum/rgb_matrix/animations/colorband_val_anim.h @@ -0,0 +1,14 @@ +#ifndef DISABLE_RGB_MATRIX_BAND_VAL +RGB_MATRIX_EFFECT(BAND_VAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV BAND_VAL_math(HSV hsv, uint8_t i, uint8_t time) { + int16_t v = hsv.v - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; + hsv.v = scale8(v < 0 ? 0 : v, hsv.v); + return hsv; +} + +bool BAND_VAL(effect_params_t* params) { return effect_runner_i(params, &BAND_VAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_BAND_VAL diff --git a/quantum/rgb_matrix/animations/cycle_all_anim.h b/quantum/rgb_matrix/animations/cycle_all_anim.h new file mode 100644 index 0000000000..faf8598a39 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_all_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL +RGB_MATRIX_EFFECT(CYCLE_ALL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_ALL_math(HSV hsv, uint8_t i, uint8_t time) { + hsv.h = time; + return hsv; +} + +bool CYCLE_ALL(effect_params_t* params) { return effect_runner_i(params, &CYCLE_ALL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_ALL diff --git a/quantum/rgb_matrix/animations/cycle_left_right_anim.h b/quantum/rgb_matrix/animations/cycle_left_right_anim.h new file mode 100644 index 0000000000..cf911eb937 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_left_right_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +RGB_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_LEFT_RIGHT_math(HSV hsv, uint8_t i, uint8_t time) { + hsv.h = g_led_config.point[i].x - time; + return hsv; +} + +bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT diff --git a/quantum/rgb_matrix/animations/cycle_out_in_anim.h b/quantum/rgb_matrix/animations/cycle_out_in_anim.h new file mode 100644 index 0000000000..d66acd4b2b --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_out_in_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN +RGB_MATRIX_EFFECT(CYCLE_OUT_IN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_OUT_IN_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv.h = 3 * dist / 2 + time; + return hsv; +} + +bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN diff --git a/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h b/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h new file mode 100644 index 0000000000..fe8396140f --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_out_in_dual_anim.h @@ -0,0 +1,15 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +RGB_MATRIX_EFFECT(CYCLE_OUT_IN_DUAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_OUT_IN_DUAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { + dx = (k_rgb_matrix_center.x / 2) - abs8(dx); + uint8_t dist = sqrt16(dx * dx + dy * dy); + hsv.h = 3 * dist + time; + return hsv; +} + +bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL diff --git a/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h b/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h new file mode 100644 index 0000000000..7799887099 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_pinwheel_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_PINWHEEL +RGB_MATRIX_EFFECT(CYCLE_PINWHEEL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_PINWHEEL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { + hsv.h = atan2_8(dy, dx) + time; + return hsv; +} + +bool CYCLE_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_PINWHEEL diff --git a/quantum/rgb_matrix/animations/cycle_spiral_anim.h b/quantum/rgb_matrix/animations/cycle_spiral_anim.h new file mode 100644 index 0000000000..80cfb0dbc7 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_spiral_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_SPIRAL +RGB_MATRIX_EFFECT(CYCLE_SPIRAL) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_SPIRAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { + hsv.h = dist - time - atan2_8(dy, dx); + return hsv; +} + +bool CYCLE_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_SPIRAL diff --git a/quantum/rgb_matrix/animations/cycle_up_down_anim.h b/quantum/rgb_matrix/animations/cycle_up_down_anim.h new file mode 100644 index 0000000000..5016f739d6 --- /dev/null +++ b/quantum/rgb_matrix/animations/cycle_up_down_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN +RGB_MATRIX_EFFECT(CYCLE_UP_DOWN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV CYCLE_UP_DOWN_math(HSV hsv, uint8_t i, uint8_t time) { + hsv.h = g_led_config.point[i].y - time; + return hsv; +} + +bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN diff --git a/quantum/rgb_matrix/animations/digital_rain_anim.h b/quantum/rgb_matrix/animations/digital_rain_anim.h new file mode 100644 index 0000000000..1de45f8e8d --- /dev/null +++ b/quantum/rgb_matrix/animations/digital_rain_anim.h @@ -0,0 +1,75 @@ +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) +RGB_MATRIX_EFFECT(DIGITAL_RAIN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +# ifndef RGB_DIGITAL_RAIN_DROPS +// lower the number for denser effect/wider keyboard +# define RGB_DIGITAL_RAIN_DROPS 24 +# endif + +bool DIGITAL_RAIN(effect_params_t* params) { + // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain + const uint8_t drop_ticks = 28; + const uint8_t pure_green_intensity = 0xd0; + const uint8_t max_brightness_boost = 0xc0; + const uint8_t max_intensity = 0xff; + + static uint8_t drop = 0; + + if (params->init) { + rgb_matrix_set_color_all(0, 0, 0); + memset(g_rgb_frame_buffer, 0, sizeof(g_rgb_frame_buffer)); + drop = 0; + } + + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { + // top row, pixels have just fallen and we're + // making a new rain drop in this column + g_rgb_frame_buffer[row][col] = max_intensity; + } else if (g_rgb_frame_buffer[row][col] > 0 && g_rgb_frame_buffer[row][col] < max_intensity) { + // neither fully bright nor dark, decay it + g_rgb_frame_buffer[row][col]--; + } + // set the pixel colour + uint8_t led[LED_HITS_TO_REMEMBER]; + uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); + + // TODO: multiple leds are supported mapped to the same row/column + if (led_count > 0) { + if (g_rgb_frame_buffer[row][col] > pure_green_intensity) { + const uint8_t boost = (uint8_t)((uint16_t)max_brightness_boost * (g_rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity)); + rgb_matrix_set_color(led[0], boost, max_intensity, boost); + } else { + const uint8_t green = (uint8_t)((uint16_t)max_intensity * g_rgb_frame_buffer[row][col] / pure_green_intensity); + rgb_matrix_set_color(led[0], 0, green, 0); + } + } + } + } + + if (++drop > drop_ticks) { + // reset drop timer + drop = 0; + for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + // if ths is on the bottom row and bright allow decay + if (row == MATRIX_ROWS - 1 && g_rgb_frame_buffer[row][col] == max_intensity) { + g_rgb_frame_buffer[row][col]--; + } + // check if the pixel above is bright + if (g_rgb_frame_buffer[row - 1][col] == max_intensity) { + // allow old bright pixel to decay + g_rgb_frame_buffer[row - 1][col]--; + // make this pixel bright + g_rgb_frame_buffer[row][col] = max_intensity; + } + } + } + } + return false; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) diff --git a/quantum/rgb_matrix/animations/dual_beacon_anim.h b/quantum/rgb_matrix/animations/dual_beacon_anim.h new file mode 100644 index 0000000000..ce94871681 --- /dev/null +++ b/quantum/rgb_matrix/animations/dual_beacon_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON +RGB_MATRIX_EFFECT(DUAL_BEACON) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV DUAL_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { + hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin) / 128; + return hsv; +} + +bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_DUAL_BEACON diff --git a/quantum/rgb_matrix/animations/gradient_left_right_anim.h b/quantum/rgb_matrix/animations/gradient_left_right_anim.h new file mode 100644 index 0000000000..53dfd04e2c --- /dev/null +++ b/quantum/rgb_matrix/animations/gradient_left_right_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT +RGB_MATRIX_EFFECT(GRADIENT_LEFT_RIGHT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool GRADIENT_LEFT_RIGHT(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + uint8_t scale = scale8(64, rgb_matrix_config.speed); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + // The x range will be 0..224, map this to 0..7 + // Relies on hue being 8-bit and wrapping + hsv.h = rgb_matrix_config.hsv.h + (scale * g_led_config.point[i].x >> 5); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT diff --git a/quantum/rgb_matrix/animations/gradient_up_down_anim.h b/quantum/rgb_matrix/animations/gradient_up_down_anim.h new file mode 100644 index 0000000000..7e0d2898cf --- /dev/null +++ b/quantum/rgb_matrix/animations/gradient_up_down_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN +RGB_MATRIX_EFFECT(GRADIENT_UP_DOWN) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool GRADIENT_UP_DOWN(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = rgb_matrix_config.hsv; + uint8_t scale = scale8(64, rgb_matrix_config.speed); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + // The y range will be 0..64, map this to 0..4 + // Relies on hue being 8-bit and wrapping + hsv.h = rgb_matrix_config.hsv.h + scale * (g_led_config.point[i].y >> 4); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN diff --git a/quantum/rgb_matrix/animations/hue_breathing_anim.h b/quantum/rgb_matrix/animations/hue_breathing_anim.h new file mode 100644 index 0000000000..54dea958af --- /dev/null +++ b/quantum/rgb_matrix/animations/hue_breathing_anim.h @@ -0,0 +1,22 @@ +#ifndef DISABLE_RGB_MATRIX_HUE_BREATHING +RGB_MATRIX_EFFECT(HUE_BREATHING) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// Change huedelta to adjust range of hue change. 0-255. +// Hue Breathing - All LED's light up +bool HUE_BREATHING(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + uint8_t huedelta = 12; + HSV hsv = rgb_matrix_config.hsv; + uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + hsv.h = hsv.h + scale8(abs8(sin8(time) - 128) * 2, huedelta); + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_BREATHING diff --git a/quantum/rgb_matrix/animations/hue_pendulum_anim.h b/quantum/rgb_matrix/animations/hue_pendulum_anim.h new file mode 100644 index 0000000000..2d8d36174f --- /dev/null +++ b/quantum/rgb_matrix/animations/hue_pendulum_anim.h @@ -0,0 +1,17 @@ +#ifndef DISABLE_RGB_MATRIX_HUE_PENDULUM +RGB_MATRIX_EFFECT(HUE_PENDULUM) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// Change huedelta to adjust range of hue change. 0-255. +// Looks better with a low value and slow speed for subtle change. +// Hue Pendulum - color changes in a wave to the right before reversing direction +static HSV HUE_PENDULUM_math(HSV hsv, uint8_t i, uint8_t time) { + uint8_t huedelta = 12; + hsv.h = hsv.h + scale8(abs8(sin8(time) + (g_led_config.point[i].x) - 128) * 2, huedelta); + return hsv; +} + +bool HUE_PENDULUM(effect_params_t* params) { return effect_runner_i(params, &HUE_PENDULUM_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_PENDULUM diff --git a/quantum/rgb_matrix/animations/hue_wave_anim.h b/quantum/rgb_matrix/animations/hue_wave_anim.h new file mode 100644 index 0000000000..fd9026fc90 --- /dev/null +++ b/quantum/rgb_matrix/animations/hue_wave_anim.h @@ -0,0 +1,17 @@ +#ifndef DISABLE_RGB_MATRIX_HUE_WAVE +RGB_MATRIX_EFFECT(HUE_WAVE) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +// Change huedelta to adjust range of hue change. 0-255. +// Looks better with a low value and slow speed for subtle change. +// Hue Wave - color changes in a wave to the right +static HSV HUE_WAVE_math(HSV hsv, uint8_t i, uint8_t time) { + uint8_t huedelta = 24; + hsv.h = hsv.h + scale8(abs8(g_led_config.point[i].x - time), huedelta); + return hsv; +} + +bool HUE_WAVE(effect_params_t* params) { return effect_runner_i(params, &HUE_WAVE_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_HUE_WAVE diff --git a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h new file mode 100644 index 0000000000..a17e954b1b --- /dev/null +++ b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h @@ -0,0 +1,29 @@ +#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +RGB_MATRIX_EFFECT(JELLYBEAN_RAINDROPS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static void jellybean_raindrops_set_color(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; + HSV hsv = {rand() & 0xFF, qadd8(rand() & 0x7F, 0x80), rgb_matrix_config.hsv.v}; + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); +} + +bool JELLYBEAN_RAINDROPS(effect_params_t* params) { + if (!params->init) { + // Change one LED every tick, make sure speed is not 0 + if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { + jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL, params); + } + return false; + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + for (int i = led_min; i < led_max; i++) { + jellybean_raindrops_set_color(i, params); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS diff --git a/quantum/rgb_matrix/animations/rainbow_beacon_anim.h b/quantum/rgb_matrix/animations/rainbow_beacon_anim.h new file mode 100644 index 0000000000..977261182f --- /dev/null +++ b/quantum/rgb_matrix/animations/rainbow_beacon_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON +RGB_MATRIX_EFFECT(RAINBOW_BEACON) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV RAINBOW_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { + hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 2 * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * 2 * sin) / 128; + return hsv; +} + +bool RAINBOW_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON diff --git a/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h new file mode 100644 index 0000000000..e51e7b2516 --- /dev/null +++ b/quantum/rgb_matrix/animations/rainbow_moving_chevron_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +RGB_MATRIX_EFFECT(RAINBOW_MOVING_CHEVRON) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV RAINBOW_MOVING_CHEVRON_math(HSV hsv, uint8_t i, uint8_t time) { + hsv.h += abs8(g_led_config.point[i].y - k_rgb_matrix_center.y) + (g_led_config.point[i].x - time); + return hsv; +} + +bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON diff --git a/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h new file mode 100644 index 0000000000..1cd4ed2acf --- /dev/null +++ b/quantum/rgb_matrix/animations/rainbow_pinwheels_anim.h @@ -0,0 +1,13 @@ +#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS +RGB_MATRIX_EFFECT(RAINBOW_PINWHEELS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV RAINBOW_PINWHEELS_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { + hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 3 * cos + (56 - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x)) * 3 * sin) / 128; + return hsv; +} + +bool RAINBOW_PINWHEELS(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_PINWHEELS_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS diff --git a/quantum/rgb_matrix/animations/raindrops_anim.h b/quantum/rgb_matrix/animations/raindrops_anim.h new file mode 100644 index 0000000000..38359cdca7 --- /dev/null +++ b/quantum/rgb_matrix/animations/raindrops_anim.h @@ -0,0 +1,39 @@ +#ifndef DISABLE_RGB_MATRIX_RAINDROPS +RGB_MATRIX_EFFECT(RAINDROPS) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static void raindrops_set_color(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; + HSV hsv = {0, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v}; + + // Take the shortest path between hues + int16_t deltaH = ((rgb_matrix_config.hsv.h + 180) % 360 - rgb_matrix_config.hsv.h) / 4; + if (deltaH > 127) { + deltaH -= 256; + } else if (deltaH < -127) { + deltaH += 256; + } + + hsv.h = rgb_matrix_config.hsv.h + (deltaH * (rand() & 0x03)); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); +} + +bool RAINDROPS(effect_params_t* params) { + if (!params->init) { + // Change one LED every tick, make sure speed is not 0 + if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { + raindrops_set_color(rand() % DRIVER_LED_TOTAL, params); + } + return false; + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + for (int i = led_min; i < led_max; i++) { + raindrops_set_color(i, params); + } + return led_max < DRIVER_LED_TOTAL; +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // DISABLE_RGB_MATRIX_RAINDROPS diff --git a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc new file mode 100644 index 0000000000..302ad79c04 --- /dev/null +++ b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc @@ -0,0 +1,37 @@ +// Add your new core rgb matrix effect here, order determines enum order +#include "solid_color_anim.h" +#include "alpha_mods_anim.h" +#include "gradient_up_down_anim.h" +#include "gradient_left_right_anim.h" +#include "breathing_anim.h" +#include "colorband_sat_anim.h" +#include "colorband_val_anim.h" +#include "colorband_pinwheel_sat_anim.h" +#include "colorband_pinwheel_val_anim.h" +#include "colorband_spiral_sat_anim.h" +#include "colorband_spiral_val_anim.h" +#include "cycle_all_anim.h" +#include "cycle_left_right_anim.h" +#include "cycle_up_down_anim.h" +#include "rainbow_moving_chevron_anim.h" +#include "cycle_out_in_anim.h" +#include "cycle_out_in_dual_anim.h" +#include "cycle_pinwheel_anim.h" +#include "cycle_spiral_anim.h" +#include "dual_beacon_anim.h" +#include "rainbow_beacon_anim.h" +#include "rainbow_pinwheels_anim.h" +#include "raindrops_anim.h" +#include "jellybean_raindrops_anim.h" +#include "hue_breathing_anim.h" +#include "hue_pendulum_anim.h" +#include "hue_wave_anim.h" +#include "typing_heatmap_anim.h" +#include "digital_rain_anim.h" +#include "solid_reactive_simple_anim.h" +#include "solid_reactive_anim.h" +#include "solid_reactive_wide.h" +#include "solid_reactive_cross.h" +#include "solid_reactive_nexus.h" +#include "splash_anim.h" +#include "solid_splash_anim.h" diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h new file mode 100644 index 0000000000..4867609c81 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h @@ -0,0 +1,17 @@ +#pragma once + +typedef HSV (*dx_dy_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t time); + +bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; + int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h new file mode 100644 index 0000000000..9545b418d9 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h @@ -0,0 +1,18 @@ +#pragma once + +typedef HSV (*dx_dy_dist_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time); + +bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 2); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; + int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; + uint8_t dist = sqrt16(dx * dx + dy * dy); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, dist, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_i.h b/quantum/rgb_matrix/animations/runners/effect_runner_i.h new file mode 100644 index 0000000000..95bfe8b390 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_i.h @@ -0,0 +1,15 @@ +#pragma once + +typedef HSV (*i_f)(HSV hsv, uint8_t i, uint8_t time); + +bool effect_runner_i(effect_params_t* params, i_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 4); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h new file mode 100644 index 0000000000..8485b61f3d --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h @@ -0,0 +1,29 @@ +#pragma once + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + +typedef HSV (*reactive_f)(HSV hsv, uint16_t offset); + +bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint16_t max_tick = 65535 / rgb_matrix_config.speed; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + uint16_t tick = max_tick; + // Reverse search to find most recent key hit + for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { + if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { + tick = g_last_hit_tracker.tick[j]; + break; + } + } + + uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h new file mode 100644 index 0000000000..5c69d0fbb9 --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h @@ -0,0 +1,29 @@ +#pragma once + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + +typedef HSV (*reactive_splash_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick); + +bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, reactive_splash_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + HSV hsv = rgb_matrix_config.hsv; + hsv.v = 0; + for (uint8_t j = start; j < count; j++) { + int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; + int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; + uint8_t dist = sqrt16(dx * dx + dy * dy); + uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed); + hsv = effect_func(hsv, dx, dy, dist, tick); + } + hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h b/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h new file mode 100644 index 0000000000..02351de51e --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h @@ -0,0 +1,17 @@ +#pragma once + +typedef HSV (*sin_cos_i_f)(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time); + +bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 4); + int8_t cos_value = cos8(time) - 128; + int8_t sin_value = sin8(time) - 128; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, cos_value, sin_value, i, time)); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} diff --git a/quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc b/quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc new file mode 100644 index 0000000000..c09022bb0f --- /dev/null +++ b/quantum/rgb_matrix/animations/runners/rgb_matrix_runners.inc @@ -0,0 +1,6 @@ +#include "effect_runner_dx_dy_dist.h" +#include "effect_runner_dx_dy.h" +#include "effect_runner_i.h" +#include "effect_runner_sin_cos_i.h" +#include "effect_runner_reactive.h" +#include "effect_runner_reactive_splash.h" diff --git a/quantum/rgb_matrix/animations/solid_color_anim.h b/quantum/rgb_matrix/animations/solid_color_anim.h new file mode 100644 index 0000000000..79d63cf133 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_color_anim.h @@ -0,0 +1,15 @@ +RGB_MATRIX_EFFECT(SOLID_COLOR) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool SOLID_COLOR(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix/animations/solid_reactive_anim.h b/quantum/rgb_matrix/animations/solid_reactive_anim.h new file mode 100644 index 0000000000..d45bb961bc --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_anim.h @@ -0,0 +1,15 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE +RGB_MATRIX_EFFECT(SOLID_REACTIVE) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV SOLID_REACTIVE_math(HSV hsv, uint16_t offset) { + hsv.h += qsub8(130, offset); + return hsv; +} + +bool SOLID_REACTIVE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_cross.h b/quantum/rgb_matrix/animations/solid_reactive_cross.h new file mode 100644 index 0000000000..f76c68e8c7 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_cross.h @@ -0,0 +1,36 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_CROSS) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV SOLID_REACTIVE_CROSS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick + dist; + dx = dx < 0 ? dx * -1 : dx; + dy = dy < 0 ? dy * -1 : dy; + dx = dx * 16 > 255 ? 255 : dx * 16; + dy = dy * 16 > 255 ? 255 : dy * 16; + effect += dx > dy ? dy : dx; + if (effect > 255) effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + return hsv; +} + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); } +# endif + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_nexus.h b/quantum/rgb_matrix/animations/solid_reactive_nexus.h new file mode 100644 index 0000000000..17f94e3c18 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_nexus.h @@ -0,0 +1,34 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV SOLID_REACTIVE_NEXUS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; + if (dist > 72) effect = 255; + if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + hsv.h = rgb_matrix_config.hsv.h + dy / 4; + return hsv; +} + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); } +# endif + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h new file mode 100644 index 0000000000..12eb248cc0 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h @@ -0,0 +1,15 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv, uint16_t offset) { + hsv.v = scale8(255 - offset, hsv.v); + return hsv; +} + +bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_reactive_wide.h b/quantum/rgb_matrix/animations/solid_reactive_wide.h new file mode 100644 index 0000000000..1cc4dca728 --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_reactive_wide.h @@ -0,0 +1,31 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +RGB_MATRIX_EFFECT(SOLID_REACTIVE_WIDE) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +static HSV SOLID_REACTIVE_WIDE_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick + dist * 5; + if (effect > 255) effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + return hsv; +} + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); } +# endif + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/solid_splash_anim.h b/quantum/rgb_matrix/animations/solid_splash_anim.h new file mode 100644 index 0000000000..99efb4996a --- /dev/null +++ b/quantum/rgb_matrix/animations/solid_splash_anim.h @@ -0,0 +1,31 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) + +# ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH +RGB_MATRIX_EFFECT(SOLID_SPLASH) +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH +RGB_MATRIX_EFFECT(SOLID_MULTISPLASH) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +HSV SOLID_SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + return hsv; +} + +# ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH +bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } +# endif + +# ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH +bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } +# endif + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/splash_anim.h b/quantum/rgb_matrix/animations/splash_anim.h new file mode 100644 index 0000000000..1415bcc0fa --- /dev/null +++ b/quantum/rgb_matrix/animations/splash_anim.h @@ -0,0 +1,32 @@ +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +# if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) + +# ifndef DISABLE_RGB_MATRIX_SPLASH +RGB_MATRIX_EFFECT(SPLASH) +# endif + +# ifndef DISABLE_RGB_MATRIX_MULTISPLASH +RGB_MATRIX_EFFECT(MULTISPLASH) +# endif + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +HSV SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; + hsv.h += effect; + hsv.v = qadd8(hsv.v, 255 - effect); + return hsv; +} + +# ifndef DISABLE_RGB_MATRIX_SPLASH +bool SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math); } +# endif + +# ifndef DISABLE_RGB_MATRIX_MULTISPLASH +bool MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SPLASH_math); } +# endif + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +# endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix/animations/typing_heatmap_anim.h b/quantum/rgb_matrix/animations/typing_heatmap_anim.h new file mode 100644 index 0000000000..e7dda11a2f --- /dev/null +++ b/quantum/rgb_matrix/animations/typing_heatmap_anim.h @@ -0,0 +1,86 @@ +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) +RGB_MATRIX_EFFECT(TYPING_HEATMAP) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +# ifndef RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS +# define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 25 +# endif + +void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { + uint8_t m_row = row - 1; + uint8_t p_row = row + 1; + uint8_t m_col = col - 1; + uint8_t p_col = col + 1; + + if (m_col < col) g_rgb_frame_buffer[row][m_col] = qadd8(g_rgb_frame_buffer[row][m_col], 16); + g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32); + if (p_col < MATRIX_COLS) g_rgb_frame_buffer[row][p_col] = qadd8(g_rgb_frame_buffer[row][p_col], 16); + + if (p_row < MATRIX_ROWS) { + if (m_col < col) g_rgb_frame_buffer[p_row][m_col] = qadd8(g_rgb_frame_buffer[p_row][m_col], 13); + g_rgb_frame_buffer[p_row][col] = qadd8(g_rgb_frame_buffer[p_row][col], 16); + if (p_col < MATRIX_COLS) g_rgb_frame_buffer[p_row][p_col] = qadd8(g_rgb_frame_buffer[p_row][p_col], 13); + } + + if (m_row < row) { + if (m_col < col) g_rgb_frame_buffer[m_row][m_col] = qadd8(g_rgb_frame_buffer[m_row][m_col], 13); + g_rgb_frame_buffer[m_row][col] = qadd8(g_rgb_frame_buffer[m_row][col], 16); + if (p_col < MATRIX_COLS) g_rgb_frame_buffer[m_row][p_col] = qadd8(g_rgb_frame_buffer[m_row][p_col], 13); + } +} + +// A timer to track the last time we decremented all heatmap values. +static uint16_t heatmap_decrease_timer; +// Whether we should decrement the heatmap values during the next update. +static bool decrease_heatmap_values; + +bool TYPING_HEATMAP(effect_params_t* params) { + // Modified version of RGB_MATRIX_USE_LIMITS to work off of matrix row / col size + uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; + uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT; + if (led_max > sizeof(g_rgb_frame_buffer)) led_max = sizeof(g_rgb_frame_buffer); + + if (params->init) { + rgb_matrix_set_color_all(0, 0, 0); + memset(g_rgb_frame_buffer, 0, sizeof g_rgb_frame_buffer); + } + + // The heatmap animation might run in several iterations depending on + // `RGB_MATRIX_LED_PROCESS_LIMIT`, therefore we only want to update the + // timer when the animation starts. + if (params->iter == 0) { + decrease_heatmap_values = timer_elapsed(heatmap_decrease_timer) >= RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS; + + // Restart the timer if we are going to decrease the heatmap this frame. + if (decrease_heatmap_values) { + heatmap_decrease_timer = timer_read(); + } + } + + // Render heatmap & decrease + for (int i = led_min; i < led_max; i++) { + uint8_t row = i % MATRIX_ROWS; + uint8_t col = i / MATRIX_ROWS; + uint8_t val = g_rgb_frame_buffer[row][col]; + + // set the pixel colour + uint8_t led[LED_HITS_TO_REMEMBER]; + uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); + for (uint8_t j = 0; j < led_count; ++j) { + if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags)) continue; + + HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)}; + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b); + } + + if (decrease_heatmap_values) { + g_rgb_frame_buffer[row][col] = qsub8(val, 1); + } + } + + return led_max < sizeof(g_rgb_frame_buffer); +} + +# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c new file mode 100644 index 0000000000..789cd28605 --- /dev/null +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -0,0 +1,640 @@ +/* Copyright 2017 Jason Williams + * Copyright 2017 Jack Humbert + * Copyright 2018 Yiancar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "rgb_matrix.h" +#include "progmem.h" +#include "config.h" +#include "eeprom.h" +#include +#include + +#include + +#ifndef RGB_MATRIX_CENTER +const led_point_t k_rgb_matrix_center = {112, 32}; +#else +const led_point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; +#endif + +// clang-format off +#ifndef RGB_MATRIX_IMMEDIATE_EEPROM +# define rgb_eeconfig_update(v) rgb_update_eeprom |= v +#else +# define rgb_eeconfig_update(v) if (v) eeconfig_update_rgb_matrix() +#endif +// clang-format on + +__attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } + +// Generic effect runners +#include "rgb_matrix_runners.inc" + +// ------------------------------------------ +// -----Begin rgb effect includes macros----- +#define RGB_MATRIX_EFFECT(name) +#define RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +#include "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------- +// ------------------------------------------ + +#if defined(RGB_DISABLE_AFTER_TIMEOUT) && !defined(RGB_DISABLE_TIMEOUT) +# define RGB_DISABLE_TIMEOUT (RGB_DISABLE_AFTER_TIMEOUT * 1200UL) +#endif + +#ifndef RGB_DISABLE_TIMEOUT +# define RGB_DISABLE_TIMEOUT 0 +#endif + +#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX +# undef RGB_MATRIX_MAXIMUM_BRIGHTNESS +# define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX +#endif + +#if !defined(RGB_MATRIX_HUE_STEP) +# define RGB_MATRIX_HUE_STEP 8 +#endif + +#if !defined(RGB_MATRIX_SAT_STEP) +# define RGB_MATRIX_SAT_STEP 16 +#endif + +#if !defined(RGB_MATRIX_VAL_STEP) +# define RGB_MATRIX_VAL_STEP 16 +#endif + +#if !defined(RGB_MATRIX_SPD_STEP) +# define RGB_MATRIX_SPD_STEP 16 +#endif + +#if !defined(RGB_MATRIX_STARTUP_MODE) +# ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +# define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT +# else +// fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace +# define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR +# endif +#endif + +#if !defined(RGB_MATRIX_STARTUP_HUE) +# define RGB_MATRIX_STARTUP_HUE 0 +#endif + +#if !defined(RGB_MATRIX_STARTUP_SAT) +# define RGB_MATRIX_STARTUP_SAT UINT8_MAX +#endif + +#if !defined(RGB_MATRIX_STARTUP_VAL) +# define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS +#endif + +#if !defined(RGB_MATRIX_STARTUP_SPD) +# define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2 +#endif + +// globals +rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr +uint32_t g_rgb_timer; +#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS +uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; +#endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +last_hit_t g_last_hit_tracker; +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED + +// internals +static bool suspend_state = false; +static bool rgb_update_eeprom = false; +static uint8_t rgb_last_enable = UINT8_MAX; +static uint8_t rgb_last_effect = UINT8_MAX; +static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; +static rgb_task_states rgb_task_state = SYNCING; +#if RGB_DISABLE_TIMEOUT > 0 +static uint32_t rgb_anykey_timer; +#endif // RGB_DISABLE_TIMEOUT > 0 + +// double buffers +static uint32_t rgb_timer_buffer; +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +static last_hit_t last_hit_buffer; +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED + +// split rgb matrix +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; +#endif + +void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } + +void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } + +void eeconfig_update_rgb_matrix_default(void) { + dprintf("eeconfig_update_rgb_matrix_default\n"); + rgb_matrix_config.enable = 1; + rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; + rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; + rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; + rgb_matrix_config.flags = LED_FLAG_ALL; + eeconfig_update_rgb_matrix(); +} + +void eeconfig_debug_rgb_matrix(void) { + dprintf("rgb_matrix_config EEPROM\n"); + dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); + dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); + dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); + dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); + dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); + dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); + dprintf("rgb_matrix_config.flags = %d\n", rgb_matrix_config.flags); +} + +__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } + +uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { + uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i); + 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; +} + +void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } + +void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + if (!is_keyboard_left() && index >= k_rgb_matrix_split[0]) + rgb_matrix_driver.set_color(index - k_rgb_matrix_split[0], red, green, blue); + else if (is_keyboard_left() && index < k_rgb_matrix_split[0]) +#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) { +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + for (uint8_t 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 +} + +void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { +#ifndef RGB_MATRIX_SPLIT + if (!is_keyboard_master()) return; +#endif +#if RGB_DISABLE_TIMEOUT > 0 + rgb_anykey_timer = 0; +#endif // RGB_DISABLE_TIMEOUT > 0 + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + uint8_t led[LED_HITS_TO_REMEMBER]; + uint8_t led_count = 0; + +# if defined(RGB_MATRIX_KEYRELEASES) + if (!pressed) +# elif defined(RGB_MATRIX_KEYPRESSES) + if (pressed) +# endif // defined(RGB_MATRIX_KEYRELEASES) + { + led_count = rgb_matrix_map_row_column_to_led(row, col, led); + } + + if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { + memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); + memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); + memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit + memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); + last_hit_buffer.count--; + } + + for (uint8_t i = 0; i < led_count; i++) { + uint8_t index = last_hit_buffer.count; + 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++; + } +#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(row, col); + } +#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) +} + +void rgb_matrix_test(void) { + // Mask out bits 4 and 5 + // Increase the factor to make the test animation slower (and reduce to make it faster) + uint8_t factor = 10; + switch ((g_rgb_timer & (0b11 << factor)) >> factor) { + case 0: { + rgb_matrix_set_color_all(20, 0, 0); + break; + } + case 1: { + rgb_matrix_set_color_all(0, 20, 0); + break; + } + case 2: { + rgb_matrix_set_color_all(0, 0, 20); + break; + } + case 3: { + rgb_matrix_set_color_all(20, 20, 20); + break; + } + } +} + +static bool rgb_matrix_none(effect_params_t *params) { + if (!params->init) { + return false; + } + + rgb_matrix_set_color_all(0, 0, 0); + return false; +} + +static void rgb_task_timers(void) { +#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 + uint32_t deltaTime = sync_timer_elapsed32(rgb_timer_buffer); +#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 + rgb_timer_buffer = sync_timer_read32(); + + // Update double buffer timers +#if RGB_DISABLE_TIMEOUT > 0 + if (rgb_anykey_timer < UINT32_MAX) { + if (UINT32_MAX - deltaTime < rgb_anykey_timer) { + rgb_anykey_timer = UINT32_MAX; + } else { + rgb_anykey_timer += deltaTime; + } + } +#endif // RGB_DISABLE_TIMEOUT > 0 + + // Update double buffer last hit timers +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + uint8_t count = last_hit_buffer.count; + for (uint8_t i = 0; i < count; ++i) { + if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { + last_hit_buffer.count--; + continue; + } + last_hit_buffer.tick[i] += deltaTime; + } +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED +} + +static void rgb_task_sync(void) { + // next task + if (rgb_update_eeprom) eeconfig_update_rgb_matrix(); + rgb_update_eeprom = false; + if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; +} + +static void rgb_task_start(void) { + // reset iter + rgb_effect_params.iter = 0; + + // update double buffers + g_rgb_timer = rgb_timer_buffer; +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + g_last_hit_tracker = last_hit_buffer; +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED + + // next task + rgb_task_state = RENDERING; +} + +static void rgb_task_render(uint8_t effect) { + bool rendering = false; + rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); + if (rgb_effect_params.flags != rgb_matrix_config.flags) { + rgb_effect_params.flags = rgb_matrix_config.flags; + rgb_matrix_set_color_all(0, 0, 0); + } + + // each effect can opt to do calculations + // and/or request PWM buffer updates. + switch (effect) { + case RGB_MATRIX_NONE: + rendering = rgb_matrix_none(&rgb_effect_params); + break; + +// --------------------------------------------- +// -----Begin rgb effect switch case macros----- +#define RGB_MATRIX_EFFECT(name, ...) \ + case RGB_MATRIX_##name: \ + rendering = name(&rgb_effect_params); \ + break; +#include "rgb_matrix_effects.inc" +#undef RGB_MATRIX_EFFECT + +#if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) +# define RGB_MATRIX_EFFECT(name, ...) \ + case RGB_MATRIX_CUSTOM_##name: \ + rendering = name(&rgb_effect_params); \ + break; +# 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 +#endif + // -----End rgb effect switch case macros------- + // --------------------------------------------- + + // Factory default magic value + case UINT8_MAX: { + rgb_matrix_test(); + rgb_task_state = FLUSHING; + } + return; + } + + rgb_effect_params.iter++; + + // next task + if (!rendering) { + rgb_task_state = FLUSHING; + if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) { + // We only need to flush once if we are RGB_MATRIX_NONE + rgb_task_state = SYNCING; + } + } +} + +static void rgb_task_flush(uint8_t effect) { + // update last trackers after the first full render so we can init over several frames + rgb_last_effect = effect; + rgb_last_enable = rgb_matrix_config.enable; + + // update pwm buffers + rgb_matrix_update_pwm_buffers(); + + // next task + rgb_task_state = SYNCING; +} + +void rgb_matrix_task(void) { + rgb_task_timers(); + + // Ideally we would also stop sending zeros to the LED driver PWM buffers + // while suspended and just do a software shutdown. This is a cheap hack for now. + bool suspend_backlight = suspend_state || +#if RGB_DISABLE_TIMEOUT > 0 + (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || +#endif // RGB_DISABLE_TIMEOUT > 0 + false; + + uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; + + switch (rgb_task_state) { + case STARTING: + rgb_task_start(); + break; + case RENDERING: + rgb_task_render(effect); + if (effect) { + rgb_matrix_indicators(); + rgb_matrix_indicators_advanced(&rgb_effect_params); + } + break; + case FLUSHING: + rgb_task_flush(effect); + break; + case SYNCING: + rgb_task_sync(); + break; + } +} + +void rgb_matrix_indicators(void) { + rgb_matrix_indicators_kb(); + rgb_matrix_indicators_user(); +} + +__attribute__((weak)) void rgb_matrix_indicators_kb(void) {} + +__attribute__((weak)) void rgb_matrix_indicators_user(void) {} + +void rgb_matrix_indicators_advanced(effect_params_t *params) { + /* special handling is needed for "params->iter", since it's already been incremented. + * Could move the invocations to rgb_task_render, but then it's missing a few checks + * and not sure which would be better. Otherwise, this should be called from + * rgb_task_render, right before the iter++ line. + */ +#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL + uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); + uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; + if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; +#else + uint8_t min = 0; + uint8_t max = DRIVER_LED_TOTAL; +#endif + rgb_matrix_indicators_advanced_kb(min, max); + rgb_matrix_indicators_advanced_user(min, max); +} + +__attribute__((weak)) void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {} + +__attribute__((weak)) void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {} + +void rgb_matrix_init(void) { + rgb_matrix_driver.init(); + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED + g_last_hit_tracker.count = 0; + for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { + g_last_hit_tracker.tick[i] = UINT16_MAX; + } + + last_hit_buffer.count = 0; + for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { + last_hit_buffer.tick[i] = UINT16_MAX; + } +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED + + if (!eeconfig_is_enabled()) { + dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); + eeconfig_init(); + eeconfig_update_rgb_matrix_default(); + } + + eeconfig_read_rgb_matrix(); + if (!rgb_matrix_config.mode) { + dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); + eeconfig_update_rgb_matrix_default(); + } + eeconfig_debug_rgb_matrix(); // display current eeprom values +} + +void rgb_matrix_set_suspend_state(bool state) { +#ifdef RGB_DISABLE_WHEN_USB_SUSPENDED + if (state) { + rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending + } + suspend_state = state; +#endif +} + +bool rgb_matrix_get_suspend_state(void) { return suspend_state; } + +void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { + rgb_matrix_config.enable ^= 1; + rgb_task_state = STARTING; + rgb_eeconfig_update(write_to_eeprom); + dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); +} +void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } +void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } + +void rgb_matrix_enable(void) { + rgb_matrix_enable_noeeprom(); + rgb_eeconfig_update(true); +} + +void rgb_matrix_enable_noeeprom(void) { + if (!rgb_matrix_config.enable) rgb_task_state = STARTING; + rgb_matrix_config.enable = 1; +} + +void rgb_matrix_disable(void) { + rgb_matrix_disable_noeeprom(); + rgb_eeconfig_update(true); +} + +void rgb_matrix_disable_noeeprom(void) { + if (rgb_matrix_config.enable) rgb_task_state = STARTING; + rgb_matrix_config.enable = 0; +} + +uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } + +void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { + if (!rgb_matrix_config.enable) { + return; + } + if (mode < 1) { + rgb_matrix_config.mode = 1; + } else if (mode >= RGB_MATRIX_EFFECT_MAX) { + rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; + } else { + rgb_matrix_config.mode = mode; + } + rgb_task_state = STARTING; + rgb_eeconfig_update(write_to_eeprom); + dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); +} +void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } +void rgb_matrix_mode(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, true); } + +uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } + +void rgb_matrix_step_helper(bool write_to_eeprom) { + uint8_t mode = rgb_matrix_config.mode + 1; + rgb_matrix_mode_eeprom_helper((mode < RGB_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); +} +void rgb_matrix_step_noeeprom(void) { rgb_matrix_step_helper(false); } +void rgb_matrix_step(void) { rgb_matrix_step_helper(true); } + +void rgb_matrix_step_reverse_helper(bool write_to_eeprom) { + uint8_t mode = rgb_matrix_config.mode - 1; + rgb_matrix_mode_eeprom_helper((mode < 1) ? RGB_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); +} +void rgb_matrix_step_reverse_noeeprom(void) { rgb_matrix_step_reverse_helper(false); } +void rgb_matrix_step_reverse(void) { rgb_matrix_step_reverse_helper(true); } + +void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { + if (!rgb_matrix_config.enable) { + return; + } + rgb_matrix_config.hsv.h = hue; + rgb_matrix_config.hsv.s = sat; + rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; + rgb_eeconfig_update(write_to_eeprom); + dprintf("rgb matrix set hsv [%s]: %u,%u,%u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v); +} +void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } +void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); } + +HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } +uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } +uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } +uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } + +void rgb_matrix_increase_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h + RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } +void rgb_matrix_increase_hue_noeeprom(void) { rgb_matrix_increase_hue_helper(false); } +void rgb_matrix_increase_hue(void) { rgb_matrix_increase_hue_helper(true); } + +void rgb_matrix_decrease_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h - RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } +void rgb_matrix_decrease_hue_noeeprom(void) { rgb_matrix_decrease_hue_helper(false); } +void rgb_matrix_decrease_hue(void) { rgb_matrix_decrease_hue_helper(true); } + +void rgb_matrix_increase_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } +void rgb_matrix_increase_sat_noeeprom(void) { rgb_matrix_increase_sat_helper(false); } +void rgb_matrix_increase_sat(void) { rgb_matrix_increase_sat_helper(true); } + +void rgb_matrix_decrease_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } +void rgb_matrix_decrease_sat_noeeprom(void) { rgb_matrix_decrease_sat_helper(false); } +void rgb_matrix_decrease_sat(void) { rgb_matrix_decrease_sat_helper(true); } + +void rgb_matrix_increase_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } +void rgb_matrix_increase_val_noeeprom(void) { rgb_matrix_increase_val_helper(false); } +void rgb_matrix_increase_val(void) { rgb_matrix_increase_val_helper(true); } + +void rgb_matrix_decrease_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } +void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); } +void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } + +void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { + rgb_matrix_config.speed = speed; + rgb_eeconfig_update(write_to_eeprom); + dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); +} +void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } +void rgb_matrix_set_speed(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, true); } + +uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } + +void rgb_matrix_increase_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } +void rgb_matrix_increase_speed_noeeprom(void) { rgb_matrix_increase_speed_helper(false); } +void rgb_matrix_increase_speed(void) { rgb_matrix_increase_speed_helper(true); } + +void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } +void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } +void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } + +led_flags_t rgb_matrix_get_flags(void) { return rgb_matrix_config.flags; } + +void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; } diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h new file mode 100644 index 0000000000..28f07c84d6 --- /dev/null +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -0,0 +1,228 @@ +/* Copyright 2017 Jason Williams + * Copyright 2017 Jack Humbert + * Copyright 2018 Yiancar + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include "rgb_matrix_types.h" +#include "color.h" +#include "quantum.h" +#include "rgblight_list.h" + +#ifdef IS31FL3731 +# include "is31fl3731.h" +#elif defined(IS31FL3733) +# include "is31fl3733.h" +#elif defined(IS31FL3737) +# include "is31fl3737.h" +#elif defined(IS31FL3741) +# include "is31fl3741.h" +#elif defined(AW20216) +# include "aw20216.h" +#elif defined(WS2812) +# include "ws2812.h" +#endif + +#ifndef RGB_MATRIX_LED_FLUSH_LIMIT +# define RGB_MATRIX_LED_FLUSH_LIMIT 16 +#endif + +#ifndef RGB_MATRIX_LED_PROCESS_LIMIT +# define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 +#endif + +#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL +# define RGB_MATRIX_USE_LIMITS(min, max) \ + uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ + uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ + if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; +#else +# define RGB_MATRIX_USE_LIMITS(min, max) \ + uint8_t min = 0; \ + uint8_t max = DRIVER_LED_TOTAL; +#endif + +#define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \ + if (i >= led_min && i <= led_max) { \ + rgb_matrix_set_color(i, r, g, b); \ + } + +#define RGB_MATRIX_TEST_LED_FLAGS() \ + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue + +enum rgb_matrix_effects { + RGB_MATRIX_NONE = 0, + +// -------------------------------------- +// -----Begin rgb effect enum macros----- +#define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name, +#include "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, +# 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 +#endif + // -------------------------------------- + // -----End rgb effect enum macros------- + + RGB_MATRIX_EFFECT_MAX +}; + +void eeconfig_update_rgb_matrix_default(void); +void eeconfig_update_rgb_matrix(void); + +uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); +uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i); + +void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); + +void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed); + +void rgb_matrix_task(void); + +// This runs after another backlight effect and replaces +// colors already set +void rgb_matrix_indicators(void); +void rgb_matrix_indicators_kb(void); +void rgb_matrix_indicators_user(void); + +void rgb_matrix_indicators_advanced(effect_params_t *params); +void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max); +void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max); + +void rgb_matrix_init(void); + +void rgb_matrix_set_suspend_state(bool state); +bool rgb_matrix_get_suspend_state(void); +void rgb_matrix_toggle(void); +void rgb_matrix_toggle_noeeprom(void); +void rgb_matrix_enable(void); +void rgb_matrix_enable_noeeprom(void); +void rgb_matrix_disable(void); +void rgb_matrix_disable_noeeprom(void); +uint8_t rgb_matrix_is_enabled(void); +void rgb_matrix_mode(uint8_t mode); +void rgb_matrix_mode_noeeprom(uint8_t mode); +uint8_t rgb_matrix_get_mode(void); +void rgb_matrix_step(void); +void rgb_matrix_step_noeeprom(void); +void rgb_matrix_step_reverse(void); +void rgb_matrix_step_reverse_noeeprom(void); +void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val); +void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); +HSV rgb_matrix_get_hsv(void); +uint8_t rgb_matrix_get_hue(void); +uint8_t rgb_matrix_get_sat(void); +uint8_t rgb_matrix_get_val(void); +void rgb_matrix_increase_hue(void); +void rgb_matrix_increase_hue_noeeprom(void); +void rgb_matrix_decrease_hue(void); +void rgb_matrix_decrease_hue_noeeprom(void); +void rgb_matrix_increase_sat(void); +void rgb_matrix_increase_sat_noeeprom(void); +void rgb_matrix_decrease_sat(void); +void rgb_matrix_decrease_sat_noeeprom(void); +void rgb_matrix_increase_val(void); +void rgb_matrix_increase_val_noeeprom(void); +void rgb_matrix_decrease_val(void); +void rgb_matrix_decrease_val_noeeprom(void); +void rgb_matrix_set_speed(uint8_t speed); +void rgb_matrix_set_speed_noeeprom(uint8_t speed); +uint8_t rgb_matrix_get_speed(void); +void rgb_matrix_increase_speed(void); +void rgb_matrix_increase_speed_noeeprom(void); +void rgb_matrix_decrease_speed(void); +void rgb_matrix_decrease_speed_noeeprom(void); +led_flags_t rgb_matrix_get_flags(void); +void rgb_matrix_set_flags(led_flags_t flags); + +#ifndef RGBLIGHT_ENABLE +# define eeconfig_update_rgblight_current eeconfig_update_rgb_matrix +# define rgblight_toggle rgb_matrix_toggle +# define rgblight_toggle_noeeprom rgb_matrix_toggle_noeeprom +# define rgblight_enable rgb_matrix_enable +# define rgblight_enable_noeeprom rgb_matrix_enable_noeeprom +# define rgblight_disable rgb_matrix_disable +# define rgblight_disable_noeeprom rgb_matrix_disable_noeeprom +# define rgblight_is_enabled rgb_matrix_is_enabled +# define rgblight_mode rgb_matrix_mode +# define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom +# define rgblight_get_mode rgb_matrix_get_mode +# define rgblight_get_hue rgb_matrix_get_hue +# define rgblight_get_sat rgb_matrix_get_sat +# define rgblight_get_val rgb_matrix_get_val +# define rgblight_get_hsv rgb_matrix_get_hsv +# define rgblight_step rgb_matrix_step +# define rgblight_step_noeeprom rgb_matrix_step_noeeprom +# define rgblight_step_reverse rgb_matrix_step_reverse +# define rgblight_step_reverse_noeeprom rgb_matrix_step_reverse_noeeprom +# define rgblight_sethsv rgb_matrix_sethsv +# define rgblight_sethsv_noeeprom rgb_matrix_sethsv_noeeprom +# define rgblight_increase_hue rgb_matrix_increase_hue +# define rgblight_increase_hue_noeeprom rgb_matrix_increase_hue_noeeprom +# define rgblight_decrease_hue rgb_matrix_decrease_hue +# define rgblight_decrease_hue_noeeprom rgb_matrix_decrease_hue_noeeprom +# define rgblight_increase_sat rgb_matrix_increase_sat +# define rgblight_increase_sat_noeeprom rgb_matrix_increase_sat_noeeprom +# define rgblight_decrease_sat rgb_matrix_decrease_sat +# define rgblight_decrease_sat_noeeprom rgb_matrix_decrease_sat_noeeprom +# define rgblight_increase_val rgb_matrix_increase_val +# define rgblight_increase_val_noeeprom rgb_matrix_increase_val_noeeprom +# define rgblight_decrease_val rgb_matrix_decrease_val +# define rgblight_decrease_val_noeeprom rgb_matrix_decrease_val_noeeprom +# define rgblight_set_speed rgb_matrix_set_speed +# define rgblight_set_speed_noeeprom rgb_matrix_set_speed_noeeprom +# define rgblight_get_speed rgb_matrix_get_speed +# define rgblight_increase_speed rgb_matrix_increase_speed +# define rgblight_increase_speed_noeeprom rgb_matrix_increase_speed_noeeprom +# define rgblight_decrease_speed rgb_matrix_decrease_speed +# define rgblight_decrease_speed_noeeprom rgb_matrix_decrease_speed_noeeprom +#endif + +typedef struct { + /* Perform any initialisation required for the other driver functions to work. */ + void (*init)(void); + /* Set the colour of a single LED in the buffer. */ + void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b); + /* Set the colour of all LEDS on the keyboard in the buffer. */ + void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b); + /* Flush any buffered changes to the hardware. */ + void (*flush)(void); +} rgb_matrix_driver_t; + +extern const rgb_matrix_driver_t rgb_matrix_driver; + +extern rgb_config_t rgb_matrix_config; + +extern uint32_t g_rgb_timer; +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 g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; +#endif diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c new file mode 100644 index 0000000000..6a11d4791e --- /dev/null +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -0,0 +1,228 @@ +/* Copyright 2018 James Laird-Wah + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "rgb_matrix.h" + +/* Each driver needs to define the struct + * const rgb_matrix_driver_t rgb_matrix_driver; + * All members must be provided. + * Keyboard custom drivers can define this in their own files, it should only + * be here if shared between boards. + */ + +#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) || defined(IS31FL3741) + +# include "i2c_master.h" + +static void init(void) { + i2c_init(); +# ifdef IS31FL3731 + IS31FL3731_init(DRIVER_ADDR_1); +# ifdef DRIVER_ADDR_2 + IS31FL3731_init(DRIVER_ADDR_2); +# endif +# ifdef DRIVER_ADDR_3 + IS31FL3731_init(DRIVER_ADDR_3); +# endif +# ifdef DRIVER_ADDR_4 + IS31FL3731_init(DRIVER_ADDR_4); +# endif +# elif defined(IS31FL3733) +# ifndef DRIVER_SYNC_1 +# define DRIVER_SYNC_1 0 +# endif + IS31FL3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1); +# if defined DRIVER_ADDR_2 && (DRIVER_ADDR_1 != DRIVER_ADDR_2) +# ifndef DRIVER_SYNC_2 +# define DRIVER_SYNC_2 0 +# endif + IS31FL3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2); +# endif +# ifdef DRIVER_ADDR_3 +# ifndef DRIVER_SYNC_3 +# define DRIVER_SYNC_3 0 +# endif + IS31FL3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3); +# endif +# ifdef DRIVER_ADDR_4 +# ifndef DRIVER_SYNC_4 +# define DRIVER_SYNC_4 0 +# endif + IS31FL3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4); +# endif +# elif defined(IS31FL3737) + IS31FL3737_init(DRIVER_ADDR_1); +# else + IS31FL3741_init(DRIVER_ADDR_1); +# endif + for (int index = 0; index < DRIVER_LED_TOTAL; index++) { + bool enabled = true; + // This only caches it for later +# ifdef IS31FL3731 + IS31FL3731_set_led_control_register(index, enabled, enabled, enabled); +# elif defined(IS31FL3733) + IS31FL3733_set_led_control_register(index, enabled, enabled, enabled); +# elif defined(IS31FL3737) + IS31FL3737_set_led_control_register(index, enabled, enabled, enabled); +# else + IS31FL3741_set_led_control_register(index, enabled, enabled, enabled); +# endif + } + // This actually updates the LED drivers +# ifdef IS31FL3731 + IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0); +# ifdef DRIVER_ADDR_2 + IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1); +# endif +# ifdef DRIVER_ADDR_3 + IS31FL3731_update_led_control_registers(DRIVER_ADDR_3, 2); +# endif +# ifdef DRIVER_ADDR_4 + IS31FL3731_update_led_control_registers(DRIVER_ADDR_4, 3); +# endif +# elif defined(IS31FL3733) + IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0); +# ifdef DRIVER_ADDR_2 + IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1); +# endif +# ifdef DRIVER_ADDR_3 + IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2); +# endif +# ifdef DRIVER_ADDR_4 + IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3); +# endif +# elif defined(IS31FL3737) + IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2); +# else + IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0); +# endif +} + +# ifdef IS31FL3731 +static void flush(void) { + IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0); +# ifdef DRIVER_ADDR_2 + IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1); +# endif +# ifdef DRIVER_ADDR_3 + IS31FL3731_update_pwm_buffers(DRIVER_ADDR_3, 2); +# endif +# ifdef DRIVER_ADDR_4 + IS31FL3731_update_pwm_buffers(DRIVER_ADDR_4, 3); +# endif +} + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = IS31FL3731_set_color, + .set_color_all = IS31FL3731_set_color_all, +}; +# elif defined(IS31FL3733) +static void flush(void) { + IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0); +# ifdef DRIVER_ADDR_2 + IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1); +# endif +# ifdef DRIVER_ADDR_3 + IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2); +# endif +# ifdef DRIVER_ADDR_4 + IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3); +# endif +} + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = IS31FL3733_set_color, + .set_color_all = IS31FL3733_set_color_all, +}; +# elif defined(IS31FL3737) +static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); } + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = IS31FL3737_set_color, + .set_color_all = IS31FL3737_set_color_all, +}; +# else +static void flush(void) { IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); } + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = IS31FL3741_set_color, + .set_color_all = IS31FL3741_set_color_all, +}; +# endif + +#elif defined(AW20216) +# include "spi_master.h" +static void init(void) { + spi_init(); + AW20216_init(); +} + +static void flush(void) { AW20216_update_pwm_buffers(); } + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = AW20216_set_color, + .set_color_all = AW20216_set_color_all, +}; + +#elif defined(WS2812) +# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_CUSTOM_DRIVER) +# pragma message "Cannot use RGBLIGHT and RGB Matrix using WS2812 at the same time." +# pragma message "You need to use a custom driver, or re-implement the WS2812 driver to use a different configuration." +# endif + +// LED color buffer +LED_TYPE rgb_matrix_ws2812_array[DRIVER_LED_TOTAL]; + +static void init(void) {} + +static void flush(void) { + // Assumes use of RGB_DI_PIN + ws2812_setleds(rgb_matrix_ws2812_array, DRIVER_LED_TOTAL); +} + +// Set an led in the buffer to a color +static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { + rgb_matrix_ws2812_array[i].r = r; + rgb_matrix_ws2812_array[i].g = g; + rgb_matrix_ws2812_array[i].b = b; +# ifdef RGBW + convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]); +# endif +} + +static void setled_all(uint8_t r, uint8_t g, uint8_t b) { + for (int i = 0; i < sizeof(rgb_matrix_ws2812_array) / sizeof(rgb_matrix_ws2812_array[0]); i++) { + setled(i, r, g, b); + } +} + +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = setled, + .set_color_all = setled_all, +}; +#endif diff --git a/quantum/rgb_matrix/rgb_matrix_types.h b/quantum/rgb_matrix/rgb_matrix_types.h new file mode 100644 index 0000000000..df575d6577 --- /dev/null +++ b/quantum/rgb_matrix/rgb_matrix_types.h @@ -0,0 +1,98 @@ +/* Copyright 2021 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include "color.h" + +#if defined(__GNUC__) +# define PACKED __attribute__((__packed__)) +#else +# define PACKED +#endif + +#if defined(_MSC_VER) +# pragma pack(push, 1) +#endif + +#if defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES) +# define RGB_MATRIX_KEYREACTIVE_ENABLED +#endif + +// Last led hit +#ifndef LED_HITS_TO_REMEMBER +# define LED_HITS_TO_REMEMBER 8 +#endif // LED_HITS_TO_REMEMBER + +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +typedef struct PACKED { + uint8_t count; + uint8_t x[LED_HITS_TO_REMEMBER]; + uint8_t y[LED_HITS_TO_REMEMBER]; + uint8_t index[LED_HITS_TO_REMEMBER]; + uint16_t tick[LED_HITS_TO_REMEMBER]; +} last_hit_t; +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED + +typedef enum rgb_task_states { STARTING, RENDERING, FLUSHING, SYNCING } rgb_task_states; + +typedef uint8_t led_flags_t; + +typedef struct PACKED { + uint8_t iter; + led_flags_t flags; + bool init; +} effect_params_t; + +typedef struct PACKED { + uint8_t x; + uint8_t y; +} led_point_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 +#define LED_FLAG_INDICATOR 0x08 + +#define NO_LED 255 + +typedef struct PACKED { + uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; + led_point_t point[DRIVER_LED_TOTAL]; + uint8_t flags[DRIVER_LED_TOTAL]; +} led_config_t; + +typedef union { + uint32_t raw; + struct PACKED { + uint8_t enable : 2; + uint8_t mode : 6; + HSV hsv; + uint8_t speed; // EECONFIG needs to be increased to support this + led_flags_t flags; + }; +} rgb_config_t; + +#if defined(_MSC_VER) +# pragma pack(pop) +#endif diff --git a/quantum/rgb_matrix_animations/alpha_mods_anim.h b/quantum/rgb_matrix_animations/alpha_mods_anim.h deleted file mode 100644 index 426d88ef35..0000000000 --- a/quantum/rgb_matrix_animations/alpha_mods_anim.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS -RGB_MATRIX_EFFECT(ALPHAS_MODS) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -// alphas = color1, mods = color2 -bool ALPHAS_MODS(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = rgb_matrix_config.hsv; - RGB rgb1 = rgb_matrix_hsv_to_rgb(hsv); - hsv.h += rgb_matrix_config.speed; - RGB rgb2 = rgb_matrix_hsv_to_rgb(hsv); - - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) { - rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b); - } else { - rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b); - } - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS diff --git a/quantum/rgb_matrix_animations/breathing_anim.h b/quantum/rgb_matrix_animations/breathing_anim.h deleted file mode 100644 index 340bd93e5d..0000000000 --- a/quantum/rgb_matrix_animations/breathing_anim.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_BREATHING -RGB_MATRIX_EFFECT(BREATHING) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -bool BREATHING(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = rgb_matrix_config.hsv; - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); - hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_BREATHING diff --git a/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h b/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h deleted file mode 100644 index 3df3cfda7d..0000000000 --- a/quantum/rgb_matrix_animations/colorband_pinwheel_sat_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT -RGB_MATRIX_EFFECT(BAND_PINWHEEL_SAT) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV BAND_PINWHEEL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { - hsv.s = scale8(hsv.s - time - atan2_8(dy, dx) * 3, hsv.s); - return hsv; -} - -bool BAND_PINWHEEL_SAT(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_SAT_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT diff --git a/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h b/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h deleted file mode 100644 index 7d80074fd5..0000000000 --- a/quantum/rgb_matrix_animations/colorband_pinwheel_val_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL -RGB_MATRIX_EFFECT(BAND_PINWHEEL_VAL) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV BAND_PINWHEEL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { - hsv.v = scale8(hsv.v - time - atan2_8(dy, dx) * 3, hsv.v); - return hsv; -} - -bool BAND_PINWHEEL_VAL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_VAL_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL diff --git a/quantum/rgb_matrix_animations/colorband_sat_anim.h b/quantum/rgb_matrix_animations/colorband_sat_anim.h deleted file mode 100644 index 35b830af6b..0000000000 --- a/quantum/rgb_matrix_animations/colorband_sat_anim.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_BAND_SAT -RGB_MATRIX_EFFECT(BAND_SAT) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV BAND_SAT_math(HSV hsv, uint8_t i, uint8_t time) { - int16_t s = hsv.s - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; - hsv.s = scale8(s < 0 ? 0 : s, hsv.s); - return hsv; -} - -bool BAND_SAT(effect_params_t* params) { return effect_runner_i(params, &BAND_SAT_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_BAND_SAT diff --git a/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h b/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h deleted file mode 100644 index 048157aa1b..0000000000 --- a/quantum/rgb_matrix_animations/colorband_spiral_sat_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT -RGB_MATRIX_EFFECT(BAND_SPIRAL_SAT) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV BAND_SPIRAL_SAT_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { - hsv.s = scale8(hsv.s + dist - time - atan2_8(dy, dx), hsv.s); - return hsv; -} - -bool BAND_SPIRAL_SAT(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_SAT_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT diff --git a/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h b/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h deleted file mode 100644 index bff2da1616..0000000000 --- a/quantum/rgb_matrix_animations/colorband_spiral_val_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL -RGB_MATRIX_EFFECT(BAND_SPIRAL_VAL) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV BAND_SPIRAL_VAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { - hsv.v = scale8(hsv.v + dist - time - atan2_8(dy, dx), hsv.v); - return hsv; -} - -bool BAND_SPIRAL_VAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_VAL_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL diff --git a/quantum/rgb_matrix_animations/colorband_val_anim.h b/quantum/rgb_matrix_animations/colorband_val_anim.h deleted file mode 100644 index f1aaf1d067..0000000000 --- a/quantum/rgb_matrix_animations/colorband_val_anim.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_BAND_VAL -RGB_MATRIX_EFFECT(BAND_VAL) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV BAND_VAL_math(HSV hsv, uint8_t i, uint8_t time) { - int16_t v = hsv.v - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; - hsv.v = scale8(v < 0 ? 0 : v, hsv.v); - return hsv; -} - -bool BAND_VAL(effect_params_t* params) { return effect_runner_i(params, &BAND_VAL_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_BAND_VAL diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h deleted file mode 100644 index faf8598a39..0000000000 --- a/quantum/rgb_matrix_animations/cycle_all_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL -RGB_MATRIX_EFFECT(CYCLE_ALL) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV CYCLE_ALL_math(HSV hsv, uint8_t i, uint8_t time) { - hsv.h = time; - return hsv; -} - -bool CYCLE_ALL(effect_params_t* params) { return effect_runner_i(params, &CYCLE_ALL_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_CYCLE_ALL diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h deleted file mode 100644 index cf911eb937..0000000000 --- a/quantum/rgb_matrix_animations/cycle_left_right_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT -RGB_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV CYCLE_LEFT_RIGHT_math(HSV hsv, uint8_t i, uint8_t time) { - hsv.h = g_led_config.point[i].x - time; - return hsv; -} - -bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT diff --git a/quantum/rgb_matrix_animations/cycle_out_in_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_anim.h deleted file mode 100644 index d66acd4b2b..0000000000 --- a/quantum/rgb_matrix_animations/cycle_out_in_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN -RGB_MATRIX_EFFECT(CYCLE_OUT_IN) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV CYCLE_OUT_IN_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { - hsv.h = 3 * dist / 2 + time; - return hsv; -} - -bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN diff --git a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h b/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h deleted file mode 100644 index fe8396140f..0000000000 --- a/quantum/rgb_matrix_animations/cycle_out_in_dual_anim.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL -RGB_MATRIX_EFFECT(CYCLE_OUT_IN_DUAL) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV CYCLE_OUT_IN_DUAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { - dx = (k_rgb_matrix_center.x / 2) - abs8(dx); - uint8_t dist = sqrt16(dx * dx + dy * dy); - hsv.h = 3 * dist + time; - return hsv; -} - -bool CYCLE_OUT_IN_DUAL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_OUT_IN_DUAL_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL diff --git a/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h b/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h deleted file mode 100644 index 7799887099..0000000000 --- a/quantum/rgb_matrix_animations/cycle_pinwheel_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_CYCLE_PINWHEEL -RGB_MATRIX_EFFECT(CYCLE_PINWHEEL) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV CYCLE_PINWHEEL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t time) { - hsv.h = atan2_8(dy, dx) + time; - return hsv; -} - -bool CYCLE_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &CYCLE_PINWHEEL_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_CYCLE_PINWHEEL diff --git a/quantum/rgb_matrix_animations/cycle_spiral_anim.h b/quantum/rgb_matrix_animations/cycle_spiral_anim.h deleted file mode 100644 index 80cfb0dbc7..0000000000 --- a/quantum/rgb_matrix_animations/cycle_spiral_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_CYCLE_SPIRAL -RGB_MATRIX_EFFECT(CYCLE_SPIRAL) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV CYCLE_SPIRAL_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { - hsv.h = dist - time - atan2_8(dy, dx); - return hsv; -} - -bool CYCLE_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_SPIRAL_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_CYCLE_SPIRAL diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h deleted file mode 100644 index 5016f739d6..0000000000 --- a/quantum/rgb_matrix_animations/cycle_up_down_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN -RGB_MATRIX_EFFECT(CYCLE_UP_DOWN) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV CYCLE_UP_DOWN_math(HSV hsv, uint8_t i, uint8_t time) { - hsv.h = g_led_config.point[i].y - time; - return hsv; -} - -bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN diff --git a/quantum/rgb_matrix_animations/digital_rain_anim.h b/quantum/rgb_matrix_animations/digital_rain_anim.h deleted file mode 100644 index 1de45f8e8d..0000000000 --- a/quantum/rgb_matrix_animations/digital_rain_anim.h +++ /dev/null @@ -1,75 +0,0 @@ -#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) -RGB_MATRIX_EFFECT(DIGITAL_RAIN) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -# ifndef RGB_DIGITAL_RAIN_DROPS -// lower the number for denser effect/wider keyboard -# define RGB_DIGITAL_RAIN_DROPS 24 -# endif - -bool DIGITAL_RAIN(effect_params_t* params) { - // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain - const uint8_t drop_ticks = 28; - const uint8_t pure_green_intensity = 0xd0; - const uint8_t max_brightness_boost = 0xc0; - const uint8_t max_intensity = 0xff; - - static uint8_t drop = 0; - - if (params->init) { - rgb_matrix_set_color_all(0, 0, 0); - memset(g_rgb_frame_buffer, 0, sizeof(g_rgb_frame_buffer)); - drop = 0; - } - - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { - // top row, pixels have just fallen and we're - // making a new rain drop in this column - g_rgb_frame_buffer[row][col] = max_intensity; - } else if (g_rgb_frame_buffer[row][col] > 0 && g_rgb_frame_buffer[row][col] < max_intensity) { - // neither fully bright nor dark, decay it - g_rgb_frame_buffer[row][col]--; - } - // set the pixel colour - uint8_t led[LED_HITS_TO_REMEMBER]; - uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); - - // TODO: multiple leds are supported mapped to the same row/column - if (led_count > 0) { - if (g_rgb_frame_buffer[row][col] > pure_green_intensity) { - const uint8_t boost = (uint8_t)((uint16_t)max_brightness_boost * (g_rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity)); - rgb_matrix_set_color(led[0], boost, max_intensity, boost); - } else { - const uint8_t green = (uint8_t)((uint16_t)max_intensity * g_rgb_frame_buffer[row][col] / pure_green_intensity); - rgb_matrix_set_color(led[0], 0, green, 0); - } - } - } - } - - if (++drop > drop_ticks) { - // reset drop timer - drop = 0; - for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - // if ths is on the bottom row and bright allow decay - if (row == MATRIX_ROWS - 1 && g_rgb_frame_buffer[row][col] == max_intensity) { - g_rgb_frame_buffer[row][col]--; - } - // check if the pixel above is bright - if (g_rgb_frame_buffer[row - 1][col] == max_intensity) { - // allow old bright pixel to decay - g_rgb_frame_buffer[row - 1][col]--; - // make this pixel bright - g_rgb_frame_buffer[row][col] = max_intensity; - } - } - } - } - return false; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h deleted file mode 100644 index ce94871681..0000000000 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON -RGB_MATRIX_EFFECT(DUAL_BEACON) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV DUAL_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { - hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * sin) / 128; - return hsv; -} - -bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_DUAL_BEACON diff --git a/quantum/rgb_matrix_animations/gradient_left_right_anim.h b/quantum/rgb_matrix_animations/gradient_left_right_anim.h deleted file mode 100644 index 53dfd04e2c..0000000000 --- a/quantum/rgb_matrix_animations/gradient_left_right_anim.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT -RGB_MATRIX_EFFECT(GRADIENT_LEFT_RIGHT) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -bool GRADIENT_LEFT_RIGHT(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = rgb_matrix_config.hsv; - uint8_t scale = scale8(64, rgb_matrix_config.speed); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - // The x range will be 0..224, map this to 0..7 - // Relies on hue being 8-bit and wrapping - hsv.h = rgb_matrix_config.hsv.h + (scale * g_led_config.point[i].x >> 5); - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT diff --git a/quantum/rgb_matrix_animations/gradient_up_down_anim.h b/quantum/rgb_matrix_animations/gradient_up_down_anim.h deleted file mode 100644 index 7e0d2898cf..0000000000 --- a/quantum/rgb_matrix_animations/gradient_up_down_anim.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN -RGB_MATRIX_EFFECT(GRADIENT_UP_DOWN) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -bool GRADIENT_UP_DOWN(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - HSV hsv = rgb_matrix_config.hsv; - uint8_t scale = scale8(64, rgb_matrix_config.speed); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - // The y range will be 0..64, map this to 0..4 - // Relies on hue being 8-bit and wrapping - hsv.h = rgb_matrix_config.hsv.h + scale * (g_led_config.point[i].y >> 4); - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN diff --git a/quantum/rgb_matrix_animations/hue_breathing_anim.h b/quantum/rgb_matrix_animations/hue_breathing_anim.h deleted file mode 100644 index 54dea958af..0000000000 --- a/quantum/rgb_matrix_animations/hue_breathing_anim.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_HUE_BREATHING -RGB_MATRIX_EFFECT(HUE_BREATHING) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -// Change huedelta to adjust range of hue change. 0-255. -// Hue Breathing - All LED's light up -bool HUE_BREATHING(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - uint8_t huedelta = 12; - HSV hsv = rgb_matrix_config.hsv; - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); - hsv.h = hsv.h + scale8(abs8(sin8(time) - 128) * 2, huedelta); - RGB rgb = hsv_to_rgb(hsv); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_HUE_BREATHING diff --git a/quantum/rgb_matrix_animations/hue_pendulum_anim.h b/quantum/rgb_matrix_animations/hue_pendulum_anim.h deleted file mode 100644 index 2d8d36174f..0000000000 --- a/quantum/rgb_matrix_animations/hue_pendulum_anim.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_HUE_PENDULUM -RGB_MATRIX_EFFECT(HUE_PENDULUM) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -// Change huedelta to adjust range of hue change. 0-255. -// Looks better with a low value and slow speed for subtle change. -// Hue Pendulum - color changes in a wave to the right before reversing direction -static HSV HUE_PENDULUM_math(HSV hsv, uint8_t i, uint8_t time) { - uint8_t huedelta = 12; - hsv.h = hsv.h + scale8(abs8(sin8(time) + (g_led_config.point[i].x) - 128) * 2, huedelta); - return hsv; -} - -bool HUE_PENDULUM(effect_params_t* params) { return effect_runner_i(params, &HUE_PENDULUM_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_HUE_PENDULUM diff --git a/quantum/rgb_matrix_animations/hue_wave_anim.h b/quantum/rgb_matrix_animations/hue_wave_anim.h deleted file mode 100644 index fd9026fc90..0000000000 --- a/quantum/rgb_matrix_animations/hue_wave_anim.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_HUE_WAVE -RGB_MATRIX_EFFECT(HUE_WAVE) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -// Change huedelta to adjust range of hue change. 0-255. -// Looks better with a low value and slow speed for subtle change. -// Hue Wave - color changes in a wave to the right -static HSV HUE_WAVE_math(HSV hsv, uint8_t i, uint8_t time) { - uint8_t huedelta = 24; - hsv.h = hsv.h + scale8(abs8(g_led_config.point[i].x - time), huedelta); - return hsv; -} - -bool HUE_WAVE(effect_params_t* params) { return effect_runner_i(params, &HUE_WAVE_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_HUE_WAVE diff --git a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h deleted file mode 100644 index a17e954b1b..0000000000 --- a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS -RGB_MATRIX_EFFECT(JELLYBEAN_RAINDROPS) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static void jellybean_raindrops_set_color(int i, effect_params_t* params) { - if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; - HSV hsv = {rand() & 0xFF, qadd8(rand() & 0x7F, 0x80), rgb_matrix_config.hsv.v}; - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); -} - -bool JELLYBEAN_RAINDROPS(effect_params_t* params) { - if (!params->init) { - // Change one LED every tick, make sure speed is not 0 - if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { - jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL, params); - } - return false; - } - - RGB_MATRIX_USE_LIMITS(led_min, led_max); - for (int i = led_min; i < led_max; i++) { - jellybean_raindrops_set_color(i, params); - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h deleted file mode 100644 index 977261182f..0000000000 --- a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON -RGB_MATRIX_EFFECT(RAINBOW_BEACON) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV RAINBOW_BEACON_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { - hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 2 * cos + (g_led_config.point[i].x - k_rgb_matrix_center.x) * 2 * sin) / 128; - return hsv; -} - -bool RAINBOW_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_BEACON_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON diff --git a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h deleted file mode 100644 index e51e7b2516..0000000000 --- a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON -RGB_MATRIX_EFFECT(RAINBOW_MOVING_CHEVRON) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV RAINBOW_MOVING_CHEVRON_math(HSV hsv, uint8_t i, uint8_t time) { - hsv.h += abs8(g_led_config.point[i].y - k_rgb_matrix_center.y) + (g_led_config.point[i].x - time); - return hsv; -} - -bool RAINBOW_MOVING_CHEVRON(effect_params_t* params) { return effect_runner_i(params, &RAINBOW_MOVING_CHEVRON_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h deleted file mode 100644 index 1cd4ed2acf..0000000000 --- a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS -RGB_MATRIX_EFFECT(RAINBOW_PINWHEELS) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV RAINBOW_PINWHEELS_math(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { - hsv.h += ((g_led_config.point[i].y - k_rgb_matrix_center.y) * 3 * cos + (56 - abs8(g_led_config.point[i].x - k_rgb_matrix_center.x)) * 3 * sin) / 128; - return hsv; -} - -bool RAINBOW_PINWHEELS(effect_params_t* params) { return effect_runner_sin_cos_i(params, &RAINBOW_PINWHEELS_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS diff --git a/quantum/rgb_matrix_animations/raindrops_anim.h b/quantum/rgb_matrix_animations/raindrops_anim.h deleted file mode 100644 index 38359cdca7..0000000000 --- a/quantum/rgb_matrix_animations/raindrops_anim.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef DISABLE_RGB_MATRIX_RAINDROPS -RGB_MATRIX_EFFECT(RAINDROPS) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static void raindrops_set_color(int i, effect_params_t* params) { - if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; - HSV hsv = {0, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v}; - - // Take the shortest path between hues - int16_t deltaH = ((rgb_matrix_config.hsv.h + 180) % 360 - rgb_matrix_config.hsv.h) / 4; - if (deltaH > 127) { - deltaH -= 256; - } else if (deltaH < -127) { - deltaH += 256; - } - - hsv.h = rgb_matrix_config.hsv.h + (deltaH * (rand() & 0x03)); - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); -} - -bool RAINDROPS(effect_params_t* params) { - if (!params->init) { - // Change one LED every tick, make sure speed is not 0 - if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { - raindrops_set_color(rand() % DRIVER_LED_TOTAL, params); - } - return false; - } - - RGB_MATRIX_USE_LIMITS(led_min, led_max); - for (int i = led_min; i < led_max; i++) { - raindrops_set_color(i, params); - } - return led_max < DRIVER_LED_TOTAL; -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // DISABLE_RGB_MATRIX_RAINDROPS diff --git a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc b/quantum/rgb_matrix_animations/rgb_matrix_effects.inc deleted file mode 100644 index 053d441506..0000000000 --- a/quantum/rgb_matrix_animations/rgb_matrix_effects.inc +++ /dev/null @@ -1,37 +0,0 @@ -// 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/gradient_left_right_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/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" -#include "rgb_matrix_animations/raindrops_anim.h" -#include "rgb_matrix_animations/jellybean_raindrops_anim.h" -#include "rgb_matrix_animations/hue_breathing_anim.h" -#include "rgb_matrix_animations/hue_pendulum_anim.h" -#include "rgb_matrix_animations/hue_wave_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 deleted file mode 100644 index 79d63cf133..0000000000 --- a/quantum/rgb_matrix_animations/solid_color_anim.h +++ /dev/null @@ -1,15 +0,0 @@ -RGB_MATRIX_EFFECT(SOLID_COLOR) -#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -bool SOLID_COLOR(effect_params_t* params) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} - -#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/quantum/rgb_matrix_animations/solid_reactive_anim.h b/quantum/rgb_matrix_animations/solid_reactive_anim.h deleted file mode 100644 index d45bb961bc..0000000000 --- a/quantum/rgb_matrix_animations/solid_reactive_anim.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE -RGB_MATRIX_EFFECT(SOLID_REACTIVE) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV SOLID_REACTIVE_math(HSV hsv, uint16_t offset) { - hsv.h += qsub8(130, offset); - return hsv; -} - -bool SOLID_REACTIVE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_animations/solid_reactive_cross.h b/quantum/rgb_matrix_animations/solid_reactive_cross.h deleted file mode 100644 index f76c68e8c7..0000000000 --- a/quantum/rgb_matrix_animations/solid_reactive_cross.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS -RGB_MATRIX_EFFECT(SOLID_REACTIVE_CROSS) -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS -RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) -# endif - -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV SOLID_REACTIVE_CROSS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick + dist; - dx = dx < 0 ? dx * -1 : dx; - dy = dy < 0 ? dy * -1 : dy; - dx = dx * 16 > 255 ? 255 : dx * 16; - dy = dy * 16 > 255 ? 255 : dy * 16; - effect += dx > dy ? dy : dx; - if (effect > 255) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - return hsv; -} - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS -bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS -bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); } -# endif - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_animations/solid_reactive_nexus.h b/quantum/rgb_matrix_animations/solid_reactive_nexus.h deleted file mode 100644 index 17f94e3c18..0000000000 --- a/quantum/rgb_matrix_animations/solid_reactive_nexus.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS -RGB_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS) -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS -RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS) -# endif - -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV SOLID_REACTIVE_NEXUS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick - dist; - if (effect > 255) effect = 255; - if (dist > 72) effect = 255; - if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - hsv.h = rgb_matrix_config.hsv.h + dy / 4; - return hsv; -} - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS -bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS -bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); } -# endif - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h deleted file mode 100644 index 12eb248cc0..0000000000 --- a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE -RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv, uint16_t offset) { - hsv.v = scale8(255 - offset, hsv.v); - return hsv; -} - -bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_animations/solid_reactive_wide.h b/quantum/rgb_matrix_animations/solid_reactive_wide.h deleted file mode 100644 index 1cc4dca728..0000000000 --- a/quantum/rgb_matrix_animations/solid_reactive_wide.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE -RGB_MATRIX_EFFECT(SOLID_REACTIVE_WIDE) -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE -RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE) -# endif - -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -static HSV SOLID_REACTIVE_WIDE_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick + dist * 5; - if (effect > 255) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - return hsv; -} - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE -bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE -bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); } -# endif - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_animations/solid_splash_anim.h b/quantum/rgb_matrix_animations/solid_splash_anim.h deleted file mode 100644 index 99efb4996a..0000000000 --- a/quantum/rgb_matrix_animations/solid_splash_anim.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) - -# ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH -RGB_MATRIX_EFFECT(SOLID_SPLASH) -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH -RGB_MATRIX_EFFECT(SOLID_MULTISPLASH) -# endif - -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -HSV SOLID_SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick - dist; - if (effect > 255) effect = 255; - hsv.v = qadd8(hsv.v, 255 - effect); - return hsv; -} - -# ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH -bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } -# endif - -# ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH -bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } -# endif - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_animations/splash_anim.h b/quantum/rgb_matrix_animations/splash_anim.h deleted file mode 100644 index 1415bcc0fa..0000000000 --- a/quantum/rgb_matrix_animations/splash_anim.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -# if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) - -# ifndef DISABLE_RGB_MATRIX_SPLASH -RGB_MATRIX_EFFECT(SPLASH) -# endif - -# ifndef DISABLE_RGB_MATRIX_MULTISPLASH -RGB_MATRIX_EFFECT(MULTISPLASH) -# endif - -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -HSV SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { - uint16_t effect = tick - dist; - if (effect > 255) effect = 255; - hsv.h += effect; - hsv.v = qadd8(hsv.v, 255 - effect); - return hsv; -} - -# ifndef DISABLE_RGB_MATRIX_SPLASH -bool SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math); } -# endif - -# ifndef DISABLE_RGB_MATRIX_MULTISPLASH -bool MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SPLASH_math); } -# endif - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -# endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_animations/typing_heatmap_anim.h b/quantum/rgb_matrix_animations/typing_heatmap_anim.h deleted file mode 100644 index e7dda11a2f..0000000000 --- a/quantum/rgb_matrix_animations/typing_heatmap_anim.h +++ /dev/null @@ -1,86 +0,0 @@ -#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) -RGB_MATRIX_EFFECT(TYPING_HEATMAP) -# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS - -# ifndef RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS -# define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 25 -# endif - -void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) { - uint8_t m_row = row - 1; - uint8_t p_row = row + 1; - uint8_t m_col = col - 1; - uint8_t p_col = col + 1; - - if (m_col < col) g_rgb_frame_buffer[row][m_col] = qadd8(g_rgb_frame_buffer[row][m_col], 16); - g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32); - if (p_col < MATRIX_COLS) g_rgb_frame_buffer[row][p_col] = qadd8(g_rgb_frame_buffer[row][p_col], 16); - - if (p_row < MATRIX_ROWS) { - if (m_col < col) g_rgb_frame_buffer[p_row][m_col] = qadd8(g_rgb_frame_buffer[p_row][m_col], 13); - g_rgb_frame_buffer[p_row][col] = qadd8(g_rgb_frame_buffer[p_row][col], 16); - if (p_col < MATRIX_COLS) g_rgb_frame_buffer[p_row][p_col] = qadd8(g_rgb_frame_buffer[p_row][p_col], 13); - } - - if (m_row < row) { - if (m_col < col) g_rgb_frame_buffer[m_row][m_col] = qadd8(g_rgb_frame_buffer[m_row][m_col], 13); - g_rgb_frame_buffer[m_row][col] = qadd8(g_rgb_frame_buffer[m_row][col], 16); - if (p_col < MATRIX_COLS) g_rgb_frame_buffer[m_row][p_col] = qadd8(g_rgb_frame_buffer[m_row][p_col], 13); - } -} - -// A timer to track the last time we decremented all heatmap values. -static uint16_t heatmap_decrease_timer; -// Whether we should decrement the heatmap values during the next update. -static bool decrease_heatmap_values; - -bool TYPING_HEATMAP(effect_params_t* params) { - // Modified version of RGB_MATRIX_USE_LIMITS to work off of matrix row / col size - uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; - uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT; - if (led_max > sizeof(g_rgb_frame_buffer)) led_max = sizeof(g_rgb_frame_buffer); - - if (params->init) { - rgb_matrix_set_color_all(0, 0, 0); - memset(g_rgb_frame_buffer, 0, sizeof g_rgb_frame_buffer); - } - - // The heatmap animation might run in several iterations depending on - // `RGB_MATRIX_LED_PROCESS_LIMIT`, therefore we only want to update the - // timer when the animation starts. - if (params->iter == 0) { - decrease_heatmap_values = timer_elapsed(heatmap_decrease_timer) >= RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS; - - // Restart the timer if we are going to decrease the heatmap this frame. - if (decrease_heatmap_values) { - heatmap_decrease_timer = timer_read(); - } - } - - // Render heatmap & decrease - for (int i = led_min; i < led_max; i++) { - uint8_t row = i % MATRIX_ROWS; - uint8_t col = i / MATRIX_ROWS; - uint8_t val = g_rgb_frame_buffer[row][col]; - - // set the pixel colour - uint8_t led[LED_HITS_TO_REMEMBER]; - uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); - for (uint8_t j = 0; j < led_count; ++j) { - if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags)) continue; - - HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)}; - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b); - } - - if (decrease_heatmap_values) { - g_rgb_frame_buffer[row][col] = qsub8(val, 1); - } - } - - return led_max < sizeof(g_rgb_frame_buffer); -} - -# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS -#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c deleted file mode 100644 index 6a11d4791e..0000000000 --- a/quantum/rgb_matrix_drivers.c +++ /dev/null @@ -1,228 +0,0 @@ -/* Copyright 2018 James Laird-Wah - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "rgb_matrix.h" - -/* Each driver needs to define the struct - * const rgb_matrix_driver_t rgb_matrix_driver; - * All members must be provided. - * Keyboard custom drivers can define this in their own files, it should only - * be here if shared between boards. - */ - -#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) || defined(IS31FL3741) - -# include "i2c_master.h" - -static void init(void) { - i2c_init(); -# ifdef IS31FL3731 - IS31FL3731_init(DRIVER_ADDR_1); -# ifdef DRIVER_ADDR_2 - IS31FL3731_init(DRIVER_ADDR_2); -# endif -# ifdef DRIVER_ADDR_3 - IS31FL3731_init(DRIVER_ADDR_3); -# endif -# ifdef DRIVER_ADDR_4 - IS31FL3731_init(DRIVER_ADDR_4); -# endif -# elif defined(IS31FL3733) -# ifndef DRIVER_SYNC_1 -# define DRIVER_SYNC_1 0 -# endif - IS31FL3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1); -# if defined DRIVER_ADDR_2 && (DRIVER_ADDR_1 != DRIVER_ADDR_2) -# ifndef DRIVER_SYNC_2 -# define DRIVER_SYNC_2 0 -# endif - IS31FL3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2); -# endif -# ifdef DRIVER_ADDR_3 -# ifndef DRIVER_SYNC_3 -# define DRIVER_SYNC_3 0 -# endif - IS31FL3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3); -# endif -# ifdef DRIVER_ADDR_4 -# ifndef DRIVER_SYNC_4 -# define DRIVER_SYNC_4 0 -# endif - IS31FL3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4); -# endif -# elif defined(IS31FL3737) - IS31FL3737_init(DRIVER_ADDR_1); -# else - IS31FL3741_init(DRIVER_ADDR_1); -# endif - for (int index = 0; index < DRIVER_LED_TOTAL; index++) { - bool enabled = true; - // This only caches it for later -# ifdef IS31FL3731 - IS31FL3731_set_led_control_register(index, enabled, enabled, enabled); -# elif defined(IS31FL3733) - IS31FL3733_set_led_control_register(index, enabled, enabled, enabled); -# elif defined(IS31FL3737) - IS31FL3737_set_led_control_register(index, enabled, enabled, enabled); -# else - IS31FL3741_set_led_control_register(index, enabled, enabled, enabled); -# endif - } - // This actually updates the LED drivers -# ifdef IS31FL3731 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0); -# ifdef DRIVER_ADDR_2 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1); -# endif -# ifdef DRIVER_ADDR_3 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_3, 2); -# endif -# ifdef DRIVER_ADDR_4 - IS31FL3731_update_led_control_registers(DRIVER_ADDR_4, 3); -# endif -# elif defined(IS31FL3733) - IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0); -# ifdef DRIVER_ADDR_2 - IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1); -# endif -# ifdef DRIVER_ADDR_3 - IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2); -# endif -# ifdef DRIVER_ADDR_4 - IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3); -# endif -# elif defined(IS31FL3737) - IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2); -# else - IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0); -# endif -} - -# ifdef IS31FL3731 -static void flush(void) { - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0); -# ifdef DRIVER_ADDR_2 - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1); -# endif -# ifdef DRIVER_ADDR_3 - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_3, 2); -# endif -# ifdef DRIVER_ADDR_4 - IS31FL3731_update_pwm_buffers(DRIVER_ADDR_4, 3); -# endif -} - -const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = IS31FL3731_set_color, - .set_color_all = IS31FL3731_set_color_all, -}; -# elif defined(IS31FL3733) -static void flush(void) { - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0); -# ifdef DRIVER_ADDR_2 - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1); -# endif -# ifdef DRIVER_ADDR_3 - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2); -# endif -# ifdef DRIVER_ADDR_4 - IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3); -# endif -} - -const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = IS31FL3733_set_color, - .set_color_all = IS31FL3733_set_color_all, -}; -# elif defined(IS31FL3737) -static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); } - -const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = IS31FL3737_set_color, - .set_color_all = IS31FL3737_set_color_all, -}; -# else -static void flush(void) { IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); } - -const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = IS31FL3741_set_color, - .set_color_all = IS31FL3741_set_color_all, -}; -# endif - -#elif defined(AW20216) -# include "spi_master.h" -static void init(void) { - spi_init(); - AW20216_init(); -} - -static void flush(void) { AW20216_update_pwm_buffers(); } - -const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = AW20216_set_color, - .set_color_all = AW20216_set_color_all, -}; - -#elif defined(WS2812) -# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_CUSTOM_DRIVER) -# pragma message "Cannot use RGBLIGHT and RGB Matrix using WS2812 at the same time." -# pragma message "You need to use a custom driver, or re-implement the WS2812 driver to use a different configuration." -# endif - -// LED color buffer -LED_TYPE rgb_matrix_ws2812_array[DRIVER_LED_TOTAL]; - -static void init(void) {} - -static void flush(void) { - // Assumes use of RGB_DI_PIN - ws2812_setleds(rgb_matrix_ws2812_array, DRIVER_LED_TOTAL); -} - -// Set an led in the buffer to a color -static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { - rgb_matrix_ws2812_array[i].r = r; - rgb_matrix_ws2812_array[i].g = g; - rgb_matrix_ws2812_array[i].b = b; -# ifdef RGBW - convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]); -# endif -} - -static void setled_all(uint8_t r, uint8_t g, uint8_t b) { - for (int i = 0; i < sizeof(rgb_matrix_ws2812_array) / sizeof(rgb_matrix_ws2812_array[0]); i++) { - setled(i, r, g, b); - } -} - -const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = setled, - .set_color_all = setled_all, -}; -#endif diff --git a/quantum/rgb_matrix_runners/effect_runner_dx_dy.h b/quantum/rgb_matrix_runners/effect_runner_dx_dy.h deleted file mode 100644 index 4867609c81..0000000000 --- a/quantum/rgb_matrix_runners/effect_runner_dx_dy.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -typedef HSV (*dx_dy_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t time); - -bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; - int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; - RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, time)); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h b/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h deleted file mode 100644 index 9545b418d9..0000000000 --- a/quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -typedef HSV (*dx_dy_dist_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8_t time); - -bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 2); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; - int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y; - uint8_t dist = sqrt16(dx * dx + dy * dy); - RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, dist, time)); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/rgb_matrix_runners/effect_runner_i.h b/quantum/rgb_matrix_runners/effect_runner_i.h deleted file mode 100644 index 95bfe8b390..0000000000 --- a/quantum/rgb_matrix_runners/effect_runner_i.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -typedef HSV (*i_f)(HSV hsv, uint8_t i, uint8_t time); - -bool effect_runner_i(effect_params_t* params, i_f effect_func) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 4); - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time)); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/rgb_matrix_runners/effect_runner_reactive.h b/quantum/rgb_matrix_runners/effect_runner_reactive.h deleted file mode 100644 index 8485b61f3d..0000000000 --- a/quantum/rgb_matrix_runners/effect_runner_reactive.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED - -typedef HSV (*reactive_f)(HSV hsv, uint16_t offset); - -bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - uint16_t max_tick = 65535 / rgb_matrix_config.speed; - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - uint16_t tick = max_tick; - // Reverse search to find most recent key hit - for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { - if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { - tick = g_last_hit_tracker.tick[j]; - break; - } - } - - uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); - RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset)); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} - -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h b/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h deleted file mode 100644 index 5c69d0fbb9..0000000000 --- a/quantum/rgb_matrix_runners/effect_runner_reactive_splash.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED - -typedef HSV (*reactive_splash_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick); - -bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, reactive_splash_f effect_func) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - uint8_t count = g_last_hit_tracker.count; - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - HSV hsv = rgb_matrix_config.hsv; - hsv.v = 0; - for (uint8_t j = start; j < count; j++) { - int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; - int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; - uint8_t dist = sqrt16(dx * dx + dy * dy); - uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed); - hsv = effect_func(hsv, dx, dy, dist, tick); - } - hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v); - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} - -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h b/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h deleted file mode 100644 index 02351de51e..0000000000 --- a/quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -typedef HSV (*sin_cos_i_f)(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t time); - -bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) { - RGB_MATRIX_USE_LIMITS(led_min, led_max); - - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 4); - int8_t cos_value = cos8(time) - 128; - int8_t sin_value = sin8(time) - 128; - for (uint8_t i = led_min; i < led_max; i++) { - RGB_MATRIX_TEST_LED_FLAGS(); - RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, cos_value, sin_value, i, time)); - rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); - } - return led_max < DRIVER_LED_TOTAL; -} diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h deleted file mode 100644 index df575d6577..0000000000 --- a/quantum/rgb_matrix_types.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright 2021 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include "color.h" - -#if defined(__GNUC__) -# define PACKED __attribute__((__packed__)) -#else -# define PACKED -#endif - -#if defined(_MSC_VER) -# pragma pack(push, 1) -#endif - -#if defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES) -# define RGB_MATRIX_KEYREACTIVE_ENABLED -#endif - -// Last led hit -#ifndef LED_HITS_TO_REMEMBER -# define LED_HITS_TO_REMEMBER 8 -#endif // LED_HITS_TO_REMEMBER - -#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -typedef struct PACKED { - uint8_t count; - uint8_t x[LED_HITS_TO_REMEMBER]; - uint8_t y[LED_HITS_TO_REMEMBER]; - uint8_t index[LED_HITS_TO_REMEMBER]; - uint16_t tick[LED_HITS_TO_REMEMBER]; -} last_hit_t; -#endif // RGB_MATRIX_KEYREACTIVE_ENABLED - -typedef enum rgb_task_states { STARTING, RENDERING, FLUSHING, SYNCING } rgb_task_states; - -typedef uint8_t led_flags_t; - -typedef struct PACKED { - uint8_t iter; - led_flags_t flags; - bool init; -} effect_params_t; - -typedef struct PACKED { - uint8_t x; - uint8_t y; -} led_point_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 -#define LED_FLAG_INDICATOR 0x08 - -#define NO_LED 255 - -typedef struct PACKED { - uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; - led_point_t point[DRIVER_LED_TOTAL]; - uint8_t flags[DRIVER_LED_TOTAL]; -} led_config_t; - -typedef union { - uint32_t raw; - struct PACKED { - uint8_t enable : 2; - uint8_t mode : 6; - HSV hsv; - uint8_t speed; // EECONFIG needs to be increased to support this - led_flags_t flags; - }; -} rgb_config_t; - -#if defined(_MSC_VER) -# pragma pack(pop) -#endif -- cgit v1.2.3