From 066818f5f9cbee4ade1ea94ee167ee2df7d9e559 Mon Sep 17 00:00:00 2001 From: Erovia Date: Mon, 22 Apr 2019 17:26:41 +0200 Subject: Define RGB colors (#5300) * Define RGB colors Define RGB colors and pass them to the rgblight functions, instead of defining multiple macros. * Add new color definitions support for RGB Matrix * Add/clarify info about new color definitions in Docs * Add deprecation warning banner to rgblight_list.h --- quantum/rgb_matrix.h | 1 + quantum/rgblight_list.h | 240 +++++++++++++++++++++++++++++------------------- 2 files changed, 147 insertions(+), 94 deletions(-) (limited to 'quantum') diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 0a11f26920..f5be494354 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -24,6 +24,7 @@ #include "rgb_matrix_types.h" #include "color.h" #include "quantum.h" +#include "rgblight_list.h" #ifdef IS31FL3731 #include "is31fl3731.h" diff --git a/quantum/rgblight_list.h b/quantum/rgblight_list.h index 407fd8e9d3..7b83133808 100644 --- a/quantum/rgblight_list.h +++ b/quantum/rgblight_list.h @@ -13,111 +13,163 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef RGBLIGHT_LIST_H -#define RGBLIGHT_LIST_H +#pragma once + +/* RGB COLORS */ +#define RGB_WHITE 0xFF, 0xFF, 0xFF +#define RGB_RED 0xFF, 0x00, 0x00 +#define RGB_CORAL 0xFF, 0x7C, 0x4D +#define RGB_ORANGE 0xFF, 0x80, 0x00 +#define RGB_GOLDENROD 0xD9, 0xA5, 0x21 +#define RGB_GOLD 0xFF, 0xD9, 0x00 +#define RGB_YELLOW 0xFF, 0xFF, 0x00 +#define RGB_CHARTREUSE 0x80, 0xFF, 0x00 +#define RGB_GREEN 0x00, 0xFF, 0x00 +#define RGB_SPRINGGREEN 0x00, 0xFF, 0x80 +#define RGB_TURQUOISE 0x47, 0x6E, 0x6A +#define RGB_TEAL 0x00, 0x80, 0x80 +#define RGB_CYAN 0x00, 0xFF, 0xFF +#define RGB_AZURE 0x99, 0xf5, 0xFF +#define RGB_BLUE 0x00, 0x00, 0xFF +#define RGB_PURPLE 0x7A, 0x00, 0xFF +#define RGB_MAGENTA 0xFF, 0x00, 0xFF +#define RGB_PINK 0xFF, 0x80, 0xBF + +/* HSV COLORS */ +#define HSV_WHITE 0, 0, 255 +#define HSV_RED 0, 255, 255 +#define HSV_CORAL 16, 176, 255 +#define HSV_ORANGE 39, 255, 255 +#define HSV_GOLDENROD 43, 218, 218 +#define HSV_GOLD 51, 255, 255 +#define HSV_YELLOW 60, 255, 255 +#define HSV_CHARTREUSE 90, 255, 255 +#define HSV_GREEN 120, 255, 255 +#define HSV_SPRINGGREEN 150, 255, 255 +#define HSV_TURQUOISE 174, 90, 112 +#define HSV_TEAL 180, 255, 128 +#define HSV_CYAN 180, 255, 255 +#define HSV_AZURE 186, 102, 255 +#define HSV_BLUE 240, 255, 255 +#define HSV_PURPLE 270, 255, 255 +#define HSV_MAGENTA 300, 255, 255 +#define HSV_PINK 330, 128, 255 + + +/* +######################################################################################## +## ## +## ## +## ## +## The functions below have been deprecated and may be removed in a future release. ## +## ## +## Please use the values above with the RGB functions. ## +## ## +## ## +## ## +######################################################################################## +*/ /* SET RGB List */ -#define rgblight_setrgb_white() rgblight_setrgb (0xFF, 0xFF, 0xFF) -#define rgblight_setrgb_red() rgblight_setrgb (0xFF, 0x00, 0x00) -#define rgblight_setrgb_coral() rgblight_setrgb (0xFF, 0x7C, 0x4D) -#define rgblight_setrgb_orange() rgblight_setrgb (0xFF, 0x80, 0x00) -#define rgblight_setrgb_goldenrod() rgblight_setrgb (0xD9, 0xA5, 0x21) -#define rgblight_setrgb_gold() rgblight_setrgb (0xFF, 0xD9, 0x00) -#define rgblight_setrgb_yellow() rgblight_setrgb (0xFF, 0xFF, 0x00) -#define rgblight_setrgb_chartreuse() rgblight_setrgb (0x80, 0xFF, 0x00) -#define rgblight_setrgb_green() rgblight_setrgb (0x00, 0xFF, 0x00) -#define rgblight_setrgb_springgreen() rgblight_setrgb (0x00, 0xFF, 0x80) -#define rgblight_setrgb_turquoise() rgblight_setrgb (0x47, 0x6E, 0x6A) -#define rgblight_setrgb_teal() rgblight_setrgb (0x00, 0x80, 0x80) -#define rgblight_setrgb_cyan() rgblight_setrgb (0x00, 0xFF, 0xFF) -#define rgblight_setrgb_azure() rgblight_setrgb (0x99, 0xf5, 0xFF) -#define rgblight_setrgb_blue() rgblight_setrgb (0x00, 0x00, 0xFF) -#define rgblight_setrgb_purple() rgblight_setrgb (0x7A, 0x00, 0xFF) -#define rgblight_setrgb_magenta() rgblight_setrgb (0xFF, 0x00, 0xFF) -#define rgblight_setrgb_pink() rgblight_setrgb (0xFF, 0x80, 0xBF) +#define rgblight_setrgb_white() rgblight_setrgb (RGB_WHITE) +#define rgblight_setrgb_red() rgblight_setrgb (RGB_RED) +#define rgblight_setrgb_coral() rgblight_setrgb (RGB_CORAL) +#define rgblight_setrgb_orange() rgblight_setrgb (RGB_ORANGE) +#define rgblight_setrgb_goldenrod() rgblight_setrgb (RGB_GOLDENROD) +#define rgblight_setrgb_gold() rgblight_setrgb (RGB_GOLD) +#define rgblight_setrgb_yellow() rgblight_setrgb (RGB_YEllOW) +#define rgblight_setrgb_chartreuse() rgblight_setrgb (RGB_CHARTREUSE) +#define rgblight_setrgb_green() rgblight_setrgb (RGB_GREEN) +#define rgblight_setrgb_springgreen() rgblight_setrgb (RGB_SPRINGGREEN) +#define rgblight_setrgb_turquoise() rgblight_setrgb (RGB_TURQUOISE) +#define rgblight_setrgb_teal() rgblight_setrgb (RGB_TEAL) +#define rgblight_setrgb_cyan() rgblight_setrgb (RGB_CYAN) +#define rgblight_setrgb_azure() rgblight_setrgb (RGB_AZURE) +#define rgblight_setrgb_blue() rgblight_setrgb (RGB_BLUE) +#define rgblight_setrgb_purple() rgblight_setrgb (RGB_PURPLE) +#define rgblight_setrgb_magenta() rgblight_setrgb (RGB_MAGENTA) +#define rgblight_setrgb_pink() rgblight_setrgb (RGB_PINK) /* SET RGB List */ -#define rgblight_setrgb_white_at(at) rgblight_setrgb_at (0xFF, 0xFF, 0xFF, at) -#define rgblight_setrgb_red_at(at) rgblight_setrgb_at (0xFF, 0x00, 0x00, at) -#define rgblight_setrgb_coral_at(at) rgblight_setrgb_at (0xFF, 0x7C, 0x4D, at) -#define rgblight_setrgb_orange_at(at) rgblight_setrgb_at (0xFF, 0x80, 0x00, at) -#define rgblight_setrgb_goldenrod_at(at) rgblight_setrgb_at (0xD9, 0xA5, 0x21, at) -#define rgblight_setrgb_gold_at(at) rgblight_setrgb_at (0xFF, 0xD9, 0x00, at) -#define rgblight_setrgb_yellow_at(at) rgblight_setrgb_at (0xFF, 0xFF, 0x00, at) -#define rgblight_setrgb_chartreuse_at(at) rgblight_setrgb_at (0x80, 0xFF, 0x00, at) -#define rgblight_setrgb_green_at(at) rgblight_setrgb_at (0x00, 0xFF, 0x00, at) -#define rgblight_setrgb_springgreen_at(at) rgblight_setrgb_at (0x00, 0xFF, 0x80, at) -#define rgblight_setrgb_turquoise_at(at) rgblight_setrgb_at (0x47, 0x6E, 0x6A, at) -#define rgblight_setrgb_teal_at(at) rgblight_setrgb_at (0x00, 0x80, 0x80, at) -#define rgblight_setrgb_cyan_at(at) rgblight_setrgb_at (0x00, 0xFF, 0xFF, at) -#define rgblight_setrgb_azure_at(at) rgblight_setrgb_at (0x99, 0xf5, 0xFF, at) -#define rgblight_setrgb_blue_at(at) rgblight_setrgb_at (0x00, 0x00, 0xFF, at) -#define rgblight_setrgb_purple_at(at) rgblight_setrgb_at (0x7A, 0x00, 0xFF, at) -#define rgblight_setrgb_magenta_at(at) rgblight_setrgb_at (0xFF, 0x00, 0xFF, at) -#define rgblight_setrgb_pink_at(at) rgblight_setrgb_at (0xFF, 0x80, 0xBF, at) +#define rgblight_setrgb_white_at(at) rgblight_setrgb_at (RGB_WHITE, at) +#define rgblight_setrgb_red_at(at) rgblight_setrgb_at (RGB_RED, at) +#define rgblight_setrgb_coral_at(at) rgblight_setrgb_at (RGB_CORAL, at) +#define rgblight_setrgb_orange_at(at) rgblight_setrgb_at (RGB_ORANGE at) +#define rgblight_setrgb_goldenrod_at(at) rgblight_setrgb_at (RGB_GOLDENROD, at) +#define rgblight_setrgb_gold_at(at) rgblight_setrgb_at (RGB_GOLD, at) +#define rgblight_setrgb_yellow_at(at) rgblight_setrgb_at (RGB_YELLOW, at) +#define rgblight_setrgb_chartreuse_at(at) rgblight_setrgb_at (RGB_CHARTREUSE, at) +#define rgblight_setrgb_green_at(at) rgblight_setrgb_at (RGB_GREEN, at) +#define rgblight_setrgb_springgreen_at(at) rgblight_setrgb_at (RGB_SPRINGGREEN, at) +#define rgblight_setrgb_turquoise_at(at) rgblight_setrgb_at (RGB_TURQUOISE, at) +#define rgblight_setrgb_teal_at(at) rgblight_setrgb_at (RGB_TEAL, at) +#define rgblight_setrgb_cyan_at(at) rgblight_setrgb_at (RGB_CYAN, at) +#define rgblight_setrgb_azure_at(at) rgblight_setrgb_at (RGB_AZURE, at) +#define rgblight_setrgb_blue_at(at) rgblight_setrgb_at (RGB_BLUE, at) +#define rgblight_setrgb_purple_at(at) rgblight_setrgb_at (RGB_PURPLE, at) +#define rgblight_setrgb_magenta_at(at) rgblight_setrgb_at (RGB_MAGENTA, at) +#define rgblight_setrgb_pink_at(at) rgblight_setrgb_at (RGB_PINK, at) /* SET HSV List */ -#define rgblight_sethsv_white() rgblight_sethsv ( 0, 0, 255) -#define rgblight_sethsv_red() rgblight_sethsv ( 0, 255, 255) -#define rgblight_sethsv_coral() rgblight_sethsv ( 16, 176, 255) -#define rgblight_sethsv_orange() rgblight_sethsv ( 39, 255, 255) -#define rgblight_sethsv_goldenrod() rgblight_sethsv ( 43, 218, 218) -#define rgblight_sethsv_gold() rgblight_sethsv ( 51, 255, 255) -#define rgblight_sethsv_yellow() rgblight_sethsv ( 60, 255, 255) -#define rgblight_sethsv_chartreuse() rgblight_sethsv ( 90, 255, 255) -#define rgblight_sethsv_green() rgblight_sethsv (120, 255, 255) -#define rgblight_sethsv_springgreen() rgblight_sethsv (150, 255, 255) -#define rgblight_sethsv_turquoise() rgblight_sethsv (174, 90, 112) -#define rgblight_sethsv_teal() rgblight_sethsv (180, 255, 128) -#define rgblight_sethsv_cyan() rgblight_sethsv (180, 255, 255) -#define rgblight_sethsv_azure() rgblight_sethsv (186, 102, 255) -#define rgblight_sethsv_blue() rgblight_sethsv (240, 255, 255) -#define rgblight_sethsv_purple() rgblight_sethsv (270, 255, 255) -#define rgblight_sethsv_magenta() rgblight_sethsv (300, 255, 255) -#define rgblight_sethsv_pink() rgblight_sethsv (330, 128, 255) +#define rgblight_sethsv_white() rgblight_sethsv (HSV_WHITE) +#define rgblight_sethsv_red() rgblight_sethsv (HSV_RED) +#define rgblight_sethsv_coral() rgblight_sethsv (HSV_CORAL) +#define rgblight_sethsv_orange() rgblight_sethsv (HSV_ORANGE) +#define rgblight_sethsv_goldenrod() rgblight_sethsv (HSV_GOLDENROD) +#define rgblight_sethsv_gold() rgblight_sethsv (HSV_GOLD) +#define rgblight_sethsv_yellow() rgblight_sethsv (HSV_YELLOW) +#define rgblight_sethsv_chartreuse() rgblight_sethsv (HSV_CHARTREUSE) +#define rgblight_sethsv_green() rgblight_sethsv (HSV_GREEN) +#define rgblight_sethsv_springgreen() rgblight_sethsv (HSV_SPRINGGREEN) +#define rgblight_sethsv_turquoise() rgblight_sethsv (HSV_TURQUOISE) +#define rgblight_sethsv_teal() rgblight_sethsv (HSV_TEAL) +#define rgblight_sethsv_cyan() rgblight_sethsv (HSV_CYAN) +#define rgblight_sethsv_azure() rgblight_sethsv (HSV_AZURE) +#define rgblight_sethsv_blue() rgblight_sethsv (HSV_BLUE) +#define rgblight_sethsv_purple() rgblight_sethsv (HSV_PURPLE) +#define rgblight_sethsv_magenta() rgblight_sethsv (HSV_MAGENTA) +#define rgblight_sethsv_pink() rgblight_sethsv (HSV_PINK) /* SET HSV List */ /* If you're doing layer indication, this is best, as it won't */ /* write to the eeprom, since it's limited (very high value). */ /* If you want to use modes with this (since you can), then you */ /* want to use rgblight_mode_noeeprom(x) instead. */ -#define rgblight_sethsv_noeeprom_white() rgblight_sethsv_noeeprom ( 0, 0, 255) -#define rgblight_sethsv_noeeprom_red() rgblight_sethsv_noeeprom ( 0, 255, 255) -#define rgblight_sethsv_noeeprom_coral() rgblight_sethsv_noeeprom ( 16, 176, 255) -#define rgblight_sethsv_noeeprom_orange() rgblight_sethsv_noeeprom ( 39, 255, 255) -#define rgblight_sethsv_noeeprom_goldenrod() rgblight_sethsv_noeeprom ( 43, 218, 218) -#define rgblight_sethsv_noeeprom_gold() rgblight_sethsv_noeeprom ( 51, 255, 255) -#define rgblight_sethsv_noeeprom_yellow() rgblight_sethsv_noeeprom ( 60, 255, 255) -#define rgblight_sethsv_noeeprom_chartreuse() rgblight_sethsv_noeeprom ( 90, 255, 255) -#define rgblight_sethsv_noeeprom_green() rgblight_sethsv_noeeprom (120, 255, 255) -#define rgblight_sethsv_noeeprom_springgreen() rgblight_sethsv_noeeprom (150, 255, 255) -#define rgblight_sethsv_noeeprom_turquoise() rgblight_sethsv_noeeprom (174, 90, 112) -#define rgblight_sethsv_noeeprom_teal() rgblight_sethsv_noeeprom (180, 255, 128) -#define rgblight_sethsv_noeeprom_cyan() rgblight_sethsv_noeeprom (180, 255, 255) -#define rgblight_sethsv_noeeprom_azure() rgblight_sethsv_noeeprom (186, 102, 255) -#define rgblight_sethsv_noeeprom_blue() rgblight_sethsv_noeeprom (240, 255, 255) -#define rgblight_sethsv_noeeprom_purple() rgblight_sethsv_noeeprom (270, 255, 255) -#define rgblight_sethsv_noeeprom_magenta() rgblight_sethsv_noeeprom (300, 255, 255) -#define rgblight_sethsv_noeeprom_pink() rgblight_sethsv_noeeprom (330, 128, 255) +#define rgblight_sethsv_noeeprom_white() rgblight_sethsv_noeeprom (HSV_WHITE) +#define rgblight_sethsv_noeeprom_red() rgblight_sethsv_noeeprom (HSV_RED) +#define rgblight_sethsv_noeeprom_coral() rgblight_sethsv_noeeprom (HSV_CORAL) +#define rgblight_sethsv_noeeprom_orange() rgblight_sethsv_noeeprom (HSV_ORANGE) +#define rgblight_sethsv_noeeprom_goldenrod() rgblight_sethsv_noeeprom (HSV_GOLDENROD) +#define rgblight_sethsv_noeeprom_gold() rgblight_sethsv_noeeprom (HSV_GOLD) +#define rgblight_sethsv_noeeprom_yellow() rgblight_sethsv_noeeprom (HSV_YELLOW) +#define rgblight_sethsv_noeeprom_chartreuse() rgblight_sethsv_noeeprom (HSV_CHARTREUSE) +#define rgblight_sethsv_noeeprom_green() rgblight_sethsv_noeeprom (HSV_GREEN) +#define rgblight_sethsv_noeeprom_springgreen() rgblight_sethsv_noeeprom (HSV_SPRINGGREEN) +#define rgblight_sethsv_noeeprom_turquoise() rgblight_sethsv_noeeprom (HSV_TURQUOISE) +#define rgblight_sethsv_noeeprom_teal() rgblight_sethsv_noeeprom (HSV_TEAL) +#define rgblight_sethsv_noeeprom_cyan() rgblight_sethsv_noeeprom (HSV_CYAN) +#define rgblight_sethsv_noeeprom_azure() rgblight_sethsv_noeeprom (HSV_AZURE) +#define rgblight_sethsv_noeeprom_blue() rgblight_sethsv_noeeprom (HSV_BLUE) +#define rgblight_sethsv_noeeprom_purple() rgblight_sethsv_noeeprom (HSV_PURPLE) +#define rgblight_sethsv_noeeprom_magenta() rgblight_sethsv_noeeprom (HSV_MAGENTA) +#define rgblight_sethsv_noeeprom_pink() rgblight_sethsv_noeeprom (HSV_PINK) /* SET HSV List */ -#define rgblight_sethsv_white_at(at) rgblight_sethsv_at ( 0, 0, 255, at) -#define rgblight_sethsv_red_at(at) rgblight_sethsv_at ( 0, 255, 255, at) -#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at ( 16, 176, 255, at) -#define rgblight_sethsv_orange_at(at) rgblight_sethsv_at ( 39, 255, 255, at) -#define rgblight_sethsv_goldenrod_at(at) rgblight_sethsv_at ( 43, 218, 218, at) -#define rgblight_sethsv_gold_at(at) rgblight_sethsv_at ( 51, 255, 255, at) -#define rgblight_sethsv_yellow_at(at) rgblight_sethsv_at ( 60, 255, 255, at) -#define rgblight_sethsv_chartreuse_at(at) rgblight_sethsv_at ( 90, 255, 255, at) -#define rgblight_sethsv_green_at(at) rgblight_sethsv_at (120, 255, 255, at) -#define rgblight_sethsv_springgreen_at(at) rgblight_sethsv_at (150, 255, 255, at) -#define rgblight_sethsv_turquoise_at(at) rgblight_sethsv_at (174, 90, 112, at) -#define rgblight_sethsv_teal_at(at) rgblight_sethsv_at (180, 255, 128, at) -#define rgblight_sethsv_cyan_at(at) rgblight_sethsv_at (180, 255, 255, at) -#define rgblight_sethsv_azure_at(at) rgblight_sethsv_at (186, 102, 255, at) -#define rgblight_sethsv_blue_at(at) rgblight_sethsv_at (240, 255, 255, at) -#define rgblight_sethsv_purple_at(at) rgblight_sethsv_at (270, 255, 255, at) -#define rgblight_sethsv_magenta_at(at) rgblight_sethsv_at (300, 255, 255, at) -#define rgblight_sethsv_pink_at(at) rgblight_sethsv_at (330, 128, 255, at) - -#endif +#define rgblight_sethsv_white_at(at) rgblight_sethsv_at (HSV_WHITE, at) +#define rgblight_sethsv_red_at(at) rgblight_sethsv_at (HSV_RED, at) +#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at (HSV_CORAL, at) +#define rgblight_sethsv_orange_at(at) rgblight_sethsv_at (HSV_ORANGE, at) +#define rgblight_sethsv_goldenrod_at(at) rgblight_sethsv_at (HSV_GOLDENROD, at) +#define rgblight_sethsv_gold_at(at) rgblight_sethsv_at (HSV_GOLD, at) +#define rgblight_sethsv_yellow_at(at) rgblight_sethsv_at (HSV_YELLOW, at) +#define rgblight_sethsv_chartreuse_at(at) rgblight_sethsv_at (HSV_CHARTREUSE, at) +#define rgblight_sethsv_green_at(at) rgblight_sethsv_at (HSV_GREEN, at) +#define rgblight_sethsv_springgreen_at(at) rgblight_sethsv_at (HSV_SPRINGGREEN, at) +#define rgblight_sethsv_turquoise_at(at) rgblight_sethsv_at (HSV_TURQUOISE, at) +#define rgblight_sethsv_teal_at(at) rgblight_sethsv_at (HSV_TEAL, at) +#define rgblight_sethsv_cyan_at(at) rgblight_sethsv_at (HSV_CYAN, at) +#define rgblight_sethsv_azure_at(at) rgblight_sethsv_at (HSV_AZURE, at) +#define rgblight_sethsv_blue_at(at) rgblight_sethsv_at (HSV_BLUE, at) +#define rgblight_sethsv_purple_at(at) rgblight_sethsv_at (HSV_PURPLE, at) +#define rgblight_sethsv_magenta_at(at) rgblight_sethsv_at (HSV_MAGENTA, at) +#define rgblight_sethsv_pink_at(at) rgblight_sethsv_at (HSV_PINK, at) -- cgit v1.2.3 From b61baf4281bde34bfe28aaa1109bd5d5c6471116 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Mon, 22 Apr 2019 11:34:13 -0400 Subject: Fix #3566 use an hardware timer for software PWM stability (#3615) With my XD60, I noticed that when typing the backlight was flickering. The XD60 doesn't have the backlight wired to a hardware PWM pin. I assumed it was a timing issue in the matrix scan that made the PWM lit the LED a bit too longer. I verified it because the more keys that were pressed, the more lighting I observed. This patch makes the software PWM be called during CPU interruptions. It works almost like the hardware PWM, except instead of using the CPU waveform generation, the CPU will fire interruption when the LEDs need be turned on or off. Using the same timer system as for hardware PWM, when the counter will reach OCRxx (the current backlight level), an Output Compare match interrupt will be fired and we'll turn the LEDs off. When the counter reaches its maximum value, an overflow interrupt will be triggered in which we turn the LEDs on. This way we replicate the hardware backlight PWM duty cycle. This gives a better time stability of the PWM computation than pure software PWM, leading to a flicker free backlight. Since this is reusing the hardware PWM code, software PWM also supports backlight breathing. Note that if timer1 is used for audio, backlight will use timer3, and if timer3 is used for audio backlight will use timer1. If both timers are used for audio, then this feature is disabled and we revert to the matrix scan based PWM computation. Signed-off-by: Brice Figureau --- quantum/quantum.c | 256 +++++++++++++++++++++++++++++++++++++++++++++--------- quantum/quantum.h | 4 + 2 files changed, 217 insertions(+), 43 deletions(-) (limited to 'quantum') diff --git a/quantum/quantum.c b/quantum/quantum.c index 9aa498dadb..0fb798a748 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -1138,30 +1138,38 @@ void matrix_scan_quantum() { matrix_scan_kb(); } -#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN) +#if defined(BACKLIGHT_ENABLE) && (defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)) -static const uint8_t backlight_pin = BACKLIGHT_PIN; +// The logic is a bit complex, we support 3 setups: +// 1. hardware PWM when backlight is wired to a PWM pin +// depending on this pin, we use a different output compare unit +// 2. software PWM with hardware timers, but the used timer depends +// on the audio setup (audio wins other backlight) +// 3. full software PWM -// depending on the pin, we use a different output compare unit #if BACKLIGHT_PIN == B7 +# define HARDWARE_PWM # define TCCRxA TCCR1A # define TCCRxB TCCR1B # define COMxx1 COM1C1 # define OCRxx OCR1C # define ICRx ICR1 #elif BACKLIGHT_PIN == B6 +# define HARDWARE_PWM # define TCCRxA TCCR1A # define TCCRxB TCCR1B # define COMxx1 COM1B1 # define OCRxx OCR1B # define ICRx ICR1 #elif BACKLIGHT_PIN == B5 +# define HARDWARE_PWM # define TCCRxA TCCR1A # define TCCRxB TCCR1B # define COMxx1 COM1A1 # define OCRxx OCR1A # define ICRx ICR1 #elif BACKLIGHT_PIN == C6 +# define HARDWARE_PWM # define TCCRxA TCCR3A # define TCCRxB TCCR3B # define COMxx1 COM1A1 @@ -1175,28 +1183,115 @@ static const uint8_t backlight_pin = BACKLIGHT_PIN; # define ICRx ICR1 # define TIMSK1 TIMSK #else -# define NO_HARDWARE_PWM +# if !defined(BACKLIGHT_CUSTOM_DRIVER) +# if !defined(B5_AUDIO) && !defined(B6_AUDIO) && !defined(B7_AUDIO) + // timer 1 is not used by audio , backlight can use it +#pragma message "Using hardware timer 1 with software PWM" +# define HARDWARE_PWM +# define BACKLIGHT_PWM_TIMER +# define TCCRxA TCCR1A +# define TCCRxB TCCR1B +# define OCRxx OCR1A +# define OCRxAH OCR1AH +# define OCRxAL OCR1AL +# define TIMERx_COMPA_vect TIMER1_COMPA_vect +# define TIMERx_OVF_vect TIMER1_OVF_vect +# define OCIExA OCIE1A +# define TOIEx TOIE1 +# define ICRx ICR1 +# ifndef TIMSK +# define TIMSK TIMSK1 +# endif +# elif !defined(C6_AUDIO) && !defined(C5_AUDIO) && !defined(C4_AUDIO) +#pragma message "Using hardware timer 3 with software PWM" +// timer 3 is not used by audio, backlight can use it +# define HARDWARE_PWM +# define BACKLIGHT_PWM_TIMER +# define TCCRxA TCCR3A +# define TCCRxB TCCR3B +# define OCRxx OCR3A +# define OCRxAH OCR3AH +# define OCRxAL OCR3AL +# define TIMERx_COMPA_vect TIMER3_COMPA_vect +# define TIMERx_OVF_vect TIMER3_OVF_vect +# define OCIExA OCIE3A +# define TOIEx TOIE3 +# define ICRx ICR1 +# ifndef TIMSK +# define TIMSK TIMSK3 +# endif +# else +#pragma message "Audio in use - using pure software PWM" +#define NO_HARDWARE_PWM +# endif +# else +#pragma message "Custom driver defined - using pure software PWM" +#define NO_HARDWARE_PWM +# endif #endif #ifndef BACKLIGHT_ON_STATE #define BACKLIGHT_ON_STATE 0 #endif -#ifdef NO_HARDWARE_PWM // pwm through software +void backlight_on(uint8_t backlight_pin) { +#if BACKLIGHT_ON_STATE == 0 + writePinLow(backlight_pin); +#else + writePinHigh(backlight_pin); +#endif +} -__attribute__ ((weak)) +void backlight_off(uint8_t backlight_pin) { +#if BACKLIGHT_ON_STATE == 0 + writePinHigh(backlight_pin); +#else + writePinLow(backlight_pin); +#endif +} + + +#if defined(NO_HARDWARE_PWM) || defined(BACKLIGHT_PWM_TIMER) // pwm through software + +// we support multiple backlight pins +#ifndef BACKLIGHT_LED_COUNT +#define BACKLIGHT_LED_COUNT 1 +#endif + +#if BACKLIGHT_LED_COUNT == 1 +#define BACKLIGHT_PIN_INIT { BACKLIGHT_PIN } +#else +#define BACKLIGHT_PIN_INIT BACKLIGHT_PINS +#endif + +#define FOR_EACH_LED(x) \ + for (uint8_t i = 0; i < BACKLIGHT_LED_COUNT; i++) \ + { \ + uint8_t backlight_pin = backlight_pins[i]; \ + { \ + x \ + } \ + } + +static const uint8_t backlight_pins[BACKLIGHT_LED_COUNT] = BACKLIGHT_PIN_INIT; + +#else // full hardware PWM + +// we support only one backlight pin +static const uint8_t backlight_pin = BACKLIGHT_PIN; +#define FOR_EACH_LED(x) x + +#endif + +#ifdef NO_HARDWARE_PWM +__attribute__((weak)) void backlight_init_ports(void) { // Setup backlight pin as output and output to on state. - // DDRx |= n - _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF); - #if BACKLIGHT_ON_STATE == 0 - // PORTx &= ~n - _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); - #else - // PORTx |= n - _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); - #endif + FOR_EACH_LED( + setPinOutput(backlight_pin); + backlight_on(backlight_pin); + ) } __attribute__ ((weak)) @@ -1207,21 +1302,14 @@ uint8_t backlight_tick = 0; #ifndef BACKLIGHT_CUSTOM_DRIVER void backlight_task(void) { if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) { - #if BACKLIGHT_ON_STATE == 0 - // PORTx &= ~n - _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); - #else - // PORTx |= n - _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); - #endif - } else { - #if BACKLIGHT_ON_STATE == 0 - // PORTx |= n - _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); - #else - // PORTx &= ~n - _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); - #endif + FOR_EACH_LED( + backlight_on(backlight_pin); + ) + } + else { + FOR_EACH_LED( + backlight_off(backlight_pin); + ) } backlight_tick = (backlight_tick + 1) % 16; } @@ -1233,7 +1321,52 @@ void backlight_task(void) { #endif #endif -#else // pwm through timer +#else // hardware pwm through timer + +#ifdef BACKLIGHT_PWM_TIMER + +// The idea of software PWM assisted by hardware timers is the following +// we use the hardware timer in fast PWM mode like for hardware PWM, but +// instead of letting the Output Match Comparator control the led pin +// (which is not possible since the backlight is not wired to PWM pins on the +// CPU), we do the LED on/off by oursleves. +// The timer is setup to count up to 0xFFFF, and we set the Output Compare +// register to the current 16bits backlight level (after CIE correction). +// This means the CPU will trigger a compare match interrupt when the counter +// reaches the backlight level, where we turn off the LEDs, +// but also an overflow interrupt when the counter rolls back to 0, +// in which we're going to turn on the LEDs. +// The LED will then be on for OCRxx/0xFFFF time, adjusted every 244Hz. + +// Triggered when the counter reaches the OCRx value +ISR(TIMERx_COMPA_vect) { + FOR_EACH_LED( + backlight_off(backlight_pin); + ) +} + +// Triggered when the counter reaches the TOP value +// this one triggers at F_CPU/65536 =~ 244 Hz +ISR(TIMERx_OVF_vect) { +#ifdef BACKLIGHT_BREATHING + breathing_task(); +#endif + // for very small values of OCRxx (or backlight level) + // we can't guarantee this whole code won't execute + // at the same time as the compare match interrupt + // which means that we might turn on the leds while + // trying to turn them off, leading to flickering + // artifacts (especially while breathing, because breathing_task + // takes many computation cycles). + // so better not turn them on while the counter TOP is very low. + if (OCRxx > 256) { + FOR_EACH_LED( + backlight_on(backlight_pin); + ) + } +} + +#endif #define TIMER_TOP 0xFFFFU @@ -1265,11 +1398,28 @@ void backlight_set(uint8_t level) { level = BACKLIGHT_LEVELS; if (level == 0) { + #ifdef BACKLIGHT_PWM_TIMER + if (OCRxx) { + TIMSK &= ~(_BV(OCIExA)); + TIMSK &= ~(_BV(TOIEx)); + FOR_EACH_LED( + backlight_off(backlight_pin); + ) + } + #else // Turn off PWM control on backlight pin TCCRxA &= ~(_BV(COMxx1)); + #endif } else { + #ifdef BACKLIGHT_PWM_TIMER + if (!OCRxx) { + TIMSK |= _BV(OCIExA); + TIMSK |= _BV(TOIEx); + } + #else // Turn on PWM control of backlight pin TCCRxA |= _BV(COMxx1); + #endif } // Set the brightness set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS)); @@ -1289,12 +1439,25 @@ static uint8_t breathing_period = BREATHING_PERIOD; static uint8_t breathing_halt = BREATHING_NO_HALT; static uint16_t breathing_counter = 0; +#ifdef BACKLIGHT_PWM_TIMER +static bool breathing = false; + +bool is_breathing(void) { + return breathing; +} + +#define breathing_interrupt_enable() do { breathing = true; } while (0) +#define breathing_interrupt_disable() do { breathing = false; } while (0) +#else + bool is_breathing(void) { return !!(TIMSK1 & _BV(TOIE1)); } #define breathing_interrupt_enable() do {TIMSK1 |= _BV(TOIE1);} while (0) #define breathing_interrupt_disable() do {TIMSK1 &= ~_BV(TOIE1);} while (0) +#endif + #define breathing_min() do {breathing_counter = 0;} while (0) #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0) @@ -1368,10 +1531,14 @@ static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS * get_backlight_level(); } +#ifdef BACKLIGHT_PWM_TIMER +void breathing_task(void) +#else /* Assuming a 16MHz CPU clock and a timer that resets at 64k (ICR1), the following interrupt handler will run * about 244 times per second. */ ISR(TIMER1_OVF_vect) +#endif { uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; // resetting after one period to prevent ugly reset at overflow. @@ -1393,19 +1560,21 @@ __attribute__ ((weak)) void backlight_init_ports(void) { // Setup backlight pin as output and output to on state. - // DDRx |= n - _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF); - #if BACKLIGHT_ON_STATE == 0 - // PORTx &= ~n - _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); - #else - // PORTx |= n - _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); - #endif + FOR_EACH_LED( + setPinOutput(backlight_pin); + backlight_on(backlight_pin); + ) + // I could write a wall of text here to explain... but TL;DW // Go read the ATmega32u4 datasheet. // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on +#ifdef BACKLIGHT_PWM_TIMER + // TimerX setup, Fast PWM mode count to TOP set in ICRx + TCCRxA = _BV(WGM11); // = 0b00000010; + // clock select clk/1 + TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; +#else // hardware PWM // Pin PB7 = OCR1C (Timer 1, Channel C) // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 // (i.e. start high, go low when counter matches.) @@ -1417,8 +1586,9 @@ void backlight_init_ports(void) "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]." "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)." */ - TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; + TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; +#endif // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0. ICRx = TIMER_TOP; @@ -1428,9 +1598,9 @@ void backlight_init_ports(void) #endif } -#endif // NO_HARDWARE_PWM +#endif // hardware backlight -#else // backlight +#else // no backlight __attribute__ ((weak)) void backlight_init_ports(void) {} diff --git a/quantum/quantum.h b/quantum/quantum.h index 987516dedb..17cb902740 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -260,8 +260,12 @@ void tap_code16(uint16_t code); #ifdef BACKLIGHT_ENABLE void backlight_init_ports(void); void backlight_task(void); +void backlight_task_internal(void); +void backlight_on(uint8_t backlight_pin); +void backlight_off(uint8_t backlight_pin); #ifdef BACKLIGHT_BREATHING +void breathing_task(void); void breathing_enable(void); void breathing_pulse(void); void breathing_disable(void); -- cgit v1.2.3 From bb52119a6dfe9c6f0314d1bcd948efda59626a70 Mon Sep 17 00:00:00 2001 From: M-AS Date: Mon, 22 Apr 2019 11:37:40 -0400 Subject: RGB Matrix Animations: Three/six new reactive effects (wide, cross, nexus) (#5602) * added 3 new RGB_Matrix effects * made cross effect behavior smoother * removed dead code * added effect descriptions --- quantum/rgb_matrix.c | 33 ++++++++++++++ quantum/rgb_matrix.h | 18 ++++++++ .../rgb_matrix_animations/solid_reactive_cross.h | 50 ++++++++++++++++++++++ .../rgb_matrix_animations/solid_reactive_nexus.h | 48 +++++++++++++++++++++ .../rgb_matrix_animations/solid_reactive_wide.h | 42 ++++++++++++++++++ 5 files changed, 191 insertions(+) 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_wide.h (limited to 'quantum') diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index a1193d4c07..41ed8983ef 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -41,6 +41,9 @@ #include "rgb_matrix_animations/digital_rain_anim.h" #include "rgb_matrix_animations/solid_reactive_simple_anim.h" #include "rgb_matrix_animations/solid_reactive_anim.h" +#include "rgb_matrix_animations/solid_reactive_wide.h" +#include "rgb_matrix_animations/solid_reactive_cross.h" +#include "rgb_matrix_animations/solid_reactive_nexus.h" #include "rgb_matrix_animations/splash_anim.h" #include "rgb_matrix_animations/solid_splash_anim.h" #include "rgb_matrix_animations/breathing_anim.h" @@ -380,6 +383,36 @@ static void rgb_task_render(uint8_t effect) { rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms break; #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE + case RGB_MATRIX_SOLID_REACTIVE_WIDE: + rendering = rgb_matrix_solid_reactive_wide(&rgb_effect_params); // Max ?? ms Avg ?? ms + break; +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE + case RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE: + rendering = rgb_matrix_solid_reactive_multiwide(&rgb_effect_params); // Max ?? ms Avg ?? ms + break; +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS + case RGB_MATRIX_SOLID_REACTIVE_CROSS: + rendering = rgb_matrix_solid_reactive_cross(&rgb_effect_params); // Max ?? ms Avg ?? ms + break; +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS + case RGB_MATRIX_SOLID_REACTIVE_MULTICROSS: + rendering = rgb_matrix_solid_reactive_multicross(&rgb_effect_params); // Max ?? ms Avg ?? ms + break; +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS + case RGB_MATRIX_SOLID_REACTIVE_NEXUS: + rendering = rgb_matrix_solid_reactive_nexus(&rgb_effect_params); // Max ?? ms Avg ?? ms + break; +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS + case RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS: + rendering = rgb_matrix_solid_reactive_multinexus(&rgb_effect_params); // Max ?? ms Avg ?? ms + break; +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS #ifndef DISABLE_RGB_MATRIX_SPLASH case RGB_MATRIX_SPLASH: rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index f5be494354..5fdc854f08 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -111,6 +111,24 @@ enum rgb_matrix_effects { #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE RGB_MATRIX_SOLID_REACTIVE, #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE + RGB_MATRIX_SOLID_REACTIVE_WIDE, +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE + RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE, +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS + RGB_MATRIX_SOLID_REACTIVE_CROSS, +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS + RGB_MATRIX_SOLID_REACTIVE_MULTICROSS, +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS + RGB_MATRIX_SOLID_REACTIVE_NEXUS, +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS + RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS, +#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS #ifndef DISABLE_RGB_MATRIX_SPLASH RGB_MATRIX_SPLASH, #endif // DISABLE_RGB_MATRIX_SPLASH 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..af602cba15 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_cross.h @@ -0,0 +1,50 @@ +#pragma once +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS) + +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; +extern last_hit_t g_last_hit_tracker; + +static bool rgb_matrix_solid_reactive_multicross_range(uint8_t start, effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + hsv.v = 0; + point_t point = g_rgb_leds[i].point; + for (uint8_t j = start; j < count; j++) { + int16_t dx = point.x - g_last_hit_tracker.x[j]; + int16_t dy = point.y - g_last_hit_tracker.y[j]; + uint8_t dist = sqrt16(dx * dx + dy * dy); + int16_t dist2 = 16; + uint8_t dist3; + uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist; + dx = dx < 0 ? dx * -1 : dx; + dy = dy < 0 ? dy * -1 : dy; + dx = dx * dist2 > 255 ? 255 : dx * dist2; + dy = dy * dist2 > 255 ? 255 : dy * dist2; + dist3 = dx > dy ? dy : dx; + effect += dist3; + if (effect > 255) + effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + } + hsv.v = scale8(hsv.v, rgb_matrix_config.val); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +bool rgb_matrix_solid_reactive_multicross(effect_params_t* params) { + return rgb_matrix_solid_reactive_multicross_range(0, params); +} + +bool rgb_matrix_solid_reactive_cross(effect_params_t* params) { + return rgb_matrix_solid_reactive_multicross_range(qsub8(g_last_hit_tracker.count, 1), params); +} + +#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..8b4a139dc9 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_nexus.h @@ -0,0 +1,48 @@ +#pragma once +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS) + +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; +extern last_hit_t g_last_hit_tracker; + +static bool rgb_matrix_solid_reactive_multinexus_range(uint8_t start, effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + hsv.v = 0; + point_t point = g_rgb_leds[i].point; + for (uint8_t j = start; j < count; j++) { + int16_t dx = point.x - g_last_hit_tracker.x[j]; + int16_t dy = point.y - g_last_hit_tracker.y[j]; + uint8_t dist = sqrt16(dx * dx + dy * dy); + int16_t dist2 = 8; + uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; + if (effect > 255) + effect = 255; + if (dist > 72) + effect = 255; + if ((dx > dist2 || dx < -dist2) && (dy > dist2 || dy < -dist2)) + effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + hsv.h = rgb_matrix_config.hue + dy / 4; + } + hsv.v = scale8(hsv.v, rgb_matrix_config.val); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +bool rgb_matrix_solid_reactive_multinexus(effect_params_t* params) { + return rgb_matrix_solid_reactive_multinexus_range(0, params); +} + +bool rgb_matrix_solid_reactive_nexus(effect_params_t* params) { + return rgb_matrix_solid_reactive_multinexus_range(qsub8(g_last_hit_tracker.count, 1), params); +} + +#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_wide.h b/quantum/rgb_matrix_animations/solid_reactive_wide.h new file mode 100644 index 0000000000..abb01892ed --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_wide.h @@ -0,0 +1,42 @@ +#pragma once +#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED +#if !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) + +extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_config_t rgb_matrix_config; +extern last_hit_t g_last_hit_tracker; + +static bool rgb_matrix_solid_reactive_multiwide_range(uint8_t start, effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + hsv.v = 0; + point_t point = g_rgb_leds[i].point; + for (uint8_t j = start; j < count; j++) { + int16_t dx = point.x - g_last_hit_tracker.x[j]; + int16_t dy = point.y - g_last_hit_tracker.y[j]; + uint8_t dist = sqrt16(dx * dx + dy * dy); + uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) + dist * 5; + if (effect > 255) + effect = 255; + hsv.v = qadd8(hsv.v, 255 - effect); + } + hsv.v = scale8(hsv.v, rgb_matrix_config.val); + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < DRIVER_LED_TOTAL; +} + +bool rgb_matrix_solid_reactive_multiwide(effect_params_t* params) { + return rgb_matrix_solid_reactive_multiwide_range(0, params); +} + +bool rgb_matrix_solid_reactive_wide(effect_params_t* params) { + return rgb_matrix_solid_reactive_multiwide_range(qsub8(g_last_hit_tracker.count, 1), params); +} + +#endif // !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE) +#endif // RGB_MATRIX_KEYREACTIVE_ENABLED -- cgit v1.2.3 From 479baf98e093b83339c9c1a628d9d25d3d0ab034 Mon Sep 17 00:00:00 2001 From: Rockman18 Date: Wed, 24 Apr 2019 04:27:29 +0200 Subject: [FIX] Misspelled RGB_YELLOW (#5692) --- quantum/rgblight_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum') diff --git a/quantum/rgblight_list.h b/quantum/rgblight_list.h index 7b83133808..e024364f05 100644 --- a/quantum/rgblight_list.h +++ b/quantum/rgblight_list.h @@ -77,7 +77,7 @@ #define rgblight_setrgb_orange() rgblight_setrgb (RGB_ORANGE) #define rgblight_setrgb_goldenrod() rgblight_setrgb (RGB_GOLDENROD) #define rgblight_setrgb_gold() rgblight_setrgb (RGB_GOLD) -#define rgblight_setrgb_yellow() rgblight_setrgb (RGB_YEllOW) +#define rgblight_setrgb_yellow() rgblight_setrgb (RGB_YELLOW) #define rgblight_setrgb_chartreuse() rgblight_setrgb (RGB_CHARTREUSE) #define rgblight_setrgb_green() rgblight_setrgb (RGB_GREEN) #define rgblight_setrgb_springgreen() rgblight_setrgb (RGB_SPRINGGREEN) -- cgit v1.2.3 From 5312131d35ee389231bfc596625ac5915264cc16 Mon Sep 17 00:00:00 2001 From: mtei <2170248+mtei@users.noreply.github.com> Date: Wed, 24 Apr 2019 02:38:54 +0900 Subject: add RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; to eeconfig_update_rgblight_default() --- quantum/rgblight.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'quantum') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 5ec11bc077..0b90b79eaf 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -38,11 +38,13 @@ /* for split keyboard */ #define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS + #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE|RGBLIGHT_STATUS_CHANGE_HSVS) #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER #define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK #else #define RGBLIGHT_SPLIT_SET_CHANGE_MODE #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS + #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE #define RGBLIGHT_SPLIT_ANIMATION_TICK #endif @@ -221,6 +223,7 @@ void eeconfig_update_rgblight_default(void) { rgblight_config.sat = 255; rgblight_config.val = RGBLIGHT_LIMIT_VAL; rgblight_config.speed = 0; + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; eeconfig_update_rgblight(rgblight_config.raw); } @@ -249,7 +252,7 @@ void rgblight_init(void) { eeconfig_update_rgblight_default(); } rgblight_config.raw = eeconfig_read_rgblight(); - RGBLIGHT_SPLIT_SET_CHANGE_HSVS; + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; if (!rgblight_config.mode) { dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_rgblight_default(); -- cgit v1.2.3 From 9f8c8c53a51ec6bb8acd55683b1d024558b071ab Mon Sep 17 00:00:00 2001 From: mtei <2170248+mtei@users.noreply.github.com> Date: Wed, 24 Apr 2019 02:43:44 +0900 Subject: add RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; to rgblight_update_dword() --- quantum/rgblight.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 0b90b79eaf..2f23768ed7 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -279,6 +279,7 @@ uint32_t rgblight_read_dword(void) { } void rgblight_update_dword(uint32_t dword) { + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; rgblight_config.raw = dword; if (rgblight_config.enable) rgblight_mode_noeeprom(rgblight_config.mode); -- cgit v1.2.3 From c3be0520c4c6d4799670ab3639a3de561b4c6c1d Mon Sep 17 00:00:00 2001 From: fauxpark Date: Sun, 28 Apr 2019 04:04:28 +1000 Subject: =?UTF-8?q?Fix=20sendstring=20"#"=20producing=20"=C2=A3"=20instead?= =?UTF-8?q?=20(#5724)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quantum/keymap_extras/sendstring_uk.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum') diff --git a/quantum/keymap_extras/sendstring_uk.h b/quantum/keymap_extras/sendstring_uk.h index 3c71f97640..2824e5d444 100644 --- a/quantum/keymap_extras/sendstring_uk.h +++ b/quantum/keymap_extras/sendstring_uk.h @@ -25,7 +25,7 @@ const bool ascii_to_shift_lut[0x80] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 1, 1, 1, 0, + 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, @@ -45,7 +45,7 @@ const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KC_ESC, 0, 0, 0, 0, - KC_SPC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_7, KC_QUOT, + KC_SPC, KC_1, KC_2, KC_NUHS, KC_4, KC_5, KC_7, KC_QUOT, KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, -- cgit v1.2.3 From 1d784f0f9575b70e35c9c8338b0ff80dc7316d7e Mon Sep 17 00:00:00 2001 From: Daniel Prilik Date: Mon, 29 Apr 2019 17:48:41 -0400 Subject: RGB Matrix: Custom effects on a kb/user level (#5338) * Revamped custom effects approach See docs for example usage * push-up RGB Matrix default mode Override default effect using RGB_MATRIX_STARTUP_MODE. Useful on boards without EEPROM support (*cough* Massdrop ALT/CTRL *cough*) * update docs --- quantum/rgb_matrix.c | 43 +++++++++++++++++++++++++++++++++++++------ quantum/rgb_matrix.h | 12 ++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) (limited to 'quantum') diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 41ed8983ef..5ca9b87a63 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -48,6 +48,19 @@ #include "rgb_matrix_animations/solid_splash_anim.h" #include "rgb_matrix_animations/breathing_anim.h" +#if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) + #define RGB_MATRIX_CUSTOM_EFFECT_IMPLS + #define RGB_MATRIX_EFFECT(name, ...) + #ifdef RGB_MATRIX_CUSTOM_KB + #include "rgb_matrix_kb.inc" + #endif + #ifdef RGB_MATRIX_CUSTOM_USER + #include "rgb_matrix_user.inc" + #endif + #undef RGB_MATRIX_EFFECT + #undef RGB_MATRIX_CUSTOM_EFFECT_IMPLS +#endif + #ifndef RGB_DISABLE_AFTER_TIMEOUT #define RGB_DISABLE_AFTER_TIMEOUT 0 #endif @@ -81,6 +94,15 @@ #define RGB_MATRIX_SPD_STEP 16 #endif +#if !defined(RGB_MATRIX_STARTUP_MODE) + #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL + #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 + bool g_suspend_state = false; rgb_config_t rgb_matrix_config; @@ -104,12 +126,7 @@ void eeconfig_update_rgb_matrix(uint32_t val) { void eeconfig_update_rgb_matrix_default(void) { dprintf("eeconfig_update_rgb_matrix_default\n"); rgb_matrix_config.enable = 1; -#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT - rgb_matrix_config.mode = RGB_MATRIX_CYCLE_LEFT_RIGHT; -#else - // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace - rgb_matrix_config.mode = RGB_MATRIX_SOLID_COLOR; -#endif + rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; rgb_matrix_config.hue = 0; rgb_matrix_config.sat = UINT8_MAX; rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; @@ -435,6 +452,20 @@ static void rgb_task_render(uint8_t effect) { #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH #endif // RGB_MATRIX_KEYREACTIVE_ENABLED +#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 + // Factory default magic value case UINT8_MAX: { rgb_matrix_test(); diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 5fdc854f08..775cbeac03 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -142,6 +142,18 @@ enum rgb_matrix_effects { RGB_MATRIX_SOLID_MULTISPLASH, #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH #endif // RGB_MATRIX_KEYREACTIVE_ENABLED + +#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 + RGB_MATRIX_EFFECT_MAX }; -- cgit v1.2.3 From a7113c8ed090d0ac647f30ee9b8ef41252e568ed Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Tue, 30 Apr 2019 00:18:50 +0200 Subject: Updated rgb_led struct field modifier to flags (#5619) Updated effects to test led flags Updated massdrop to use new flags field for led toggle --- quantum/rgb_matrix.c | 45 +++++++++------------- quantum/rgb_matrix.h | 6 ++- quantum/rgb_matrix_animations/alpha_mods_anim.h | 5 ++- quantum/rgb_matrix_animations/breathing_anim.h | 1 + quantum/rgb_matrix_animations/cycle_all_anim.h | 6 +-- .../rgb_matrix_animations/cycle_left_right_anim.h | 3 +- quantum/rgb_matrix_animations/cycle_up_down_anim.h | 3 +- quantum/rgb_matrix_animations/dual_beacon_anim.h | 3 +- .../rgb_matrix_animations/gradient_up_down_anim.h | 3 +- .../jellybean_raindrops_anim.h | 9 +++-- .../rgb_matrix_animations/rainbow_beacon_anim.h | 3 +- .../rainbow_moving_chevron_anim.h | 3 +- .../rgb_matrix_animations/rainbow_pinwheels_anim.h | 3 +- quantum/rgb_matrix_animations/raindrops_anim.h | 7 ++-- quantum/rgb_matrix_animations/solid_color_anim.h | 1 + .../rgb_matrix_animations/solid_reactive_anim.h | 1 + .../rgb_matrix_animations/solid_reactive_cross.h | 3 +- .../rgb_matrix_animations/solid_reactive_nexus.h | 3 +- .../solid_reactive_simple_anim.h | 1 + .../rgb_matrix_animations/solid_reactive_wide.h | 3 +- quantum/rgb_matrix_animations/solid_splash_anim.h | 3 +- quantum/rgb_matrix_animations/splash_anim.h | 3 +- quantum/rgb_matrix_types.h | 22 ++++++----- 23 files changed, 79 insertions(+), 61 deletions(-) (limited to 'quantum') diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 5ca9b87a63..8c16c7790e 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -162,28 +162,11 @@ void rgb_matrix_update_pwm_buffers(void) { } void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { -#ifdef RGB_MATRIX_EXTRA_TOG - const bool is_key = g_rgb_leds[index].matrix_co.raw != 0xff; - if ( - (rgb_matrix_config.enable == RGB_ZONE_KEYS && !is_key) || - (rgb_matrix_config.enable == RGB_ZONE_UNDER && is_key) - ) { - rgb_matrix_driver.set_color(index, 0, 0, 0); - return; - } -#endif - rgb_matrix_driver.set_color(index, red, green, blue); } void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { -#ifdef RGB_MATRIX_EXTRA_TOG - for (int i = 0; i < DRIVER_LED_TOTAL; i++) { - rgb_matrix_set_color(i, red, green, blue); - } -#else rgb_matrix_driver.set_color_all(red, green, blue); -#endif } bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { @@ -262,7 +245,7 @@ static bool rgb_matrix_none(effect_params_t* params) { static uint8_t rgb_last_enable = UINT8_MAX; static uint8_t rgb_last_effect = UINT8_MAX; -static effect_params_t rgb_effect_params = { 0, 0 }; +static effect_params_t rgb_effect_params = { 0, 0xFF }; static rgb_task_states rgb_task_state = SYNCING; static void rgb_task_timers(void) { @@ -575,29 +558,31 @@ void rgb_matrix_set_suspend_state(bool state) { } void rgb_matrix_toggle(void) { - rgb_matrix_config.enable++; - if (!rgb_matrix_config.enable) { - rgb_task_state = STARTING; - } + rgb_matrix_config.enable ^= 1; + rgb_task_state = STARTING; eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgb_matrix_enable(void) { - rgb_matrix_config.enable = 1; + rgb_matrix_enable_noeeprom(); eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgb_matrix_enable_noeeprom(void) { - rgb_matrix_config.enable = 1; + if (!rgb_matrix_config.enable) + rgb_task_state = STARTING; + rgb_matrix_config.enable = 1; } void rgb_matrix_disable(void) { - rgb_matrix_config.enable = 0; + rgb_matrix_disable_noeeprom(); eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } void rgb_matrix_disable_noeeprom(void) { - rgb_matrix_config.enable = 0; + if (rgb_matrix_config.enable) + rgb_task_state = STARTING; + rgb_matrix_config.enable = 0; } void rgb_matrix_step(void) { @@ -658,6 +643,14 @@ void rgb_matrix_decrease_speed(void) { eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this } +led_flags_t rgb_matrix_get_flags(void) { + return rgb_effect_params.flags; +} + +void rgb_matrix_set_flags(led_flags_t flags) { + rgb_effect_params.flags = flags; +} + void rgb_matrix_mode(uint8_t mode) { rgb_matrix_config.mode = mode; rgb_task_state = STARTING; diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 775cbeac03..33665ffff2 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -54,7 +54,9 @@ uint8_t max = DRIVER_LED_TOTAL; #endif -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +#define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) continue + +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; typedef struct { @@ -209,6 +211,8 @@ void rgb_matrix_increase_val(void); void rgb_matrix_decrease_val(void); void rgb_matrix_increase_speed(void); void rgb_matrix_decrease_speed(void); +led_flags_t rgb_matrix_get_flags(void); +void rgb_matrix_set_flags(led_flags_t flags); void rgb_matrix_mode(uint8_t mode); void rgb_matrix_mode_noeeprom(uint8_t mode); uint8_t rgb_matrix_get_mode(void); diff --git a/quantum/rgb_matrix_animations/alpha_mods_anim.h b/quantum/rgb_matrix_animations/alpha_mods_anim.h index cc1914d7f4..4bd01c4fc8 100644 --- a/quantum/rgb_matrix_animations/alpha_mods_anim.h +++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h @@ -1,7 +1,7 @@ #pragma once #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; // alphas = color1, mods = color2 @@ -14,7 +14,8 @@ bool rgb_matrix_alphas_mods(effect_params_t* params) { RGB rgb2 = hsv_to_rgb(hsv); for (uint8_t i = led_min; i < led_max; i++) { - if (g_rgb_leds[i].modifier) { + RGB_MATRIX_TEST_LED_FLAGS(); + if (HAS_FLAGS(g_rgb_leds[i].flags, LED_FLAG_MODIFIER)) { rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b); } else { rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b); diff --git a/quantum/rgb_matrix_animations/breathing_anim.h b/quantum/rgb_matrix_animations/breathing_anim.h index 4a9a1dcdb2..54d60f927d 100644 --- a/quantum/rgb_matrix_animations/breathing_anim.h +++ b/quantum/rgb_matrix_animations/breathing_anim.h @@ -12,6 +12,7 @@ bool rgb_matrix_breathing(effect_params_t* params) { HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, val }; RGB rgb = hsv_to_rgb(hsv); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } return led_max < DRIVER_LED_TOTAL; diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h index 5c18cfa0c9..513dff1281 100644 --- a/quantum/rgb_matrix_animations/cycle_all_anim.h +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h @@ -2,16 +2,16 @@ #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL extern rgb_counters_t g_rgb_counters; -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_all(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; - uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); + hsv.h = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { - hsv.h = time; + RGB_MATRIX_TEST_LED_FLAGS(); RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); } diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h index f519aeb476..428adea223 100644 --- a/quantum/rgb_matrix_animations/cycle_left_right_anim.h +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT extern rgb_counters_t g_rgb_counters; -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_left_right(effect_params_t* params) { @@ -11,6 +11,7 @@ bool rgb_matrix_cycle_left_right(effect_params_t* params) { HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); point_t point = g_rgb_leds[i].point; hsv.h = point.x - time; RGB rgb = hsv_to_rgb(hsv); diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h index 8b91d890de..ea63095d2e 100644 --- a/quantum/rgb_matrix_animations/cycle_up_down_anim.h +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN extern rgb_counters_t g_rgb_counters; -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_cycle_up_down(effect_params_t* params) { @@ -11,6 +11,7 @@ bool rgb_matrix_cycle_up_down(effect_params_t* params) { HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); point_t point = g_rgb_leds[i].point; hsv.h = point.y - time; RGB rgb = hsv_to_rgb(hsv); diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h index dda3157809..00f6e50880 100644 --- a/quantum/rgb_matrix_animations/dual_beacon_anim.h +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h @@ -2,7 +2,7 @@ #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON extern rgb_counters_t g_rgb_counters; -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_config; bool rgb_matrix_dual_beacon(effect_params_t* params) { @@ -13,6 +13,7 @@ bool rgb_matrix_dual_beacon(effect_params_t* params) { int8_t cos_value = cos8(time) - 128; int8_t sin_value = sin8(time) - 128; for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); point_t point = g_rgb_leds[i].point; hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * sin_value) / 128 + rgb_matrix_config.hue; RGB rgb = hsv_to_rgb(hsv); diff --git a/quantum/rgb_matrix_animations/gradient_up_down_anim.h b/quantum/rgb_matrix_animations/gradient_up_down_anim.h index 11498e22f5..05117540ae 100644 --- a/quantum/rgb_matrix_animations/gradient_up_down_anim.h +++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h @@ -1,7 +1,7 @@ #pragma once #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN -extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; +extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; extern rgb_config_t rgb_matrix_conf