From 6ead9bc147bdcf5b3bd8e73d6d39654f7149eb93 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Fri, 25 Aug 2023 00:45:44 -0400 Subject: [PATCH 1/3] refactor: move default RGB/LED matrix #defines Moving the fallback definitions of macros like LED_MATRIX_VAL_STEP and RGB_MATRIX_MAXIMUM_BRIGHTNESS to header files allows keyboards to leverage these defaults without requiring #ifdef guards (and often repeating said fallback definitions). --- .../ergodox_infinity/ergodox_infinity.c | 3 -- keyboards/input_club/k_type/k_type.c | 3 -- keyboards/input_club/whitefox/whitefox.c | 3 -- keyboards/kbdfans/kbd67/mkiirgb/v3/info.json | 3 +- keyboards/kbdfans/kbd67/mkiirgb/v3/v3.c | 8 +-- .../native/ansi/keymaps/default/keymap.c | 2 +- .../native/ansi/keymaps/perfmode/keymap.c | 2 +- .../teleport/native/ansi/keymaps/via/keymap.c | 2 +- keyboards/teleport/native/config.h | 7 +-- .../native/iso/keymaps/default/keymap.c | 2 +- .../native/iso/keymaps/perfmode/keymap.c | 2 +- .../teleport/native/iso/keymaps/via/keymap.c | 2 +- keyboards/zykrah/fuyu/keymaps/via/keymap.c | 8 +-- quantum/led_matrix/led_matrix.c | 31 +---------- quantum/led_matrix/led_matrix.h | 29 +++++++++++ quantum/rgb_matrix/rgb_matrix.c | 52 +------------------ quantum/rgb_matrix/rgb_matrix.h | 50 ++++++++++++++++++ quantum/via.c | 10 ---- 18 files changed, 94 insertions(+), 125 deletions(-) diff --git a/keyboards/input_club/ergodox_infinity/ergodox_infinity.c b/keyboards/input_club/ergodox_infinity/ergodox_infinity.c index b8f0d4ae13fc..70cd26a3f37d 100644 --- a/keyboards/input_club/ergodox_infinity/ergodox_infinity.c +++ b/keyboards/input_club/ergodox_infinity/ergodox_infinity.c @@ -117,9 +117,6 @@ void matrix_init_kb(void) { * Since K20x is stuck with a 32 byte EEPROM (see tmk_core/common/chibios/eeprom_teensy.c), * and neither led_matrix_eeconfig.speed or .flags fit in this boundary, just force their values to default on boot. */ -# if !defined(LED_MATRIX_DEFAULT_SPD) -# define LED_MATRIX_DEFAULT_SPD UINT8_MAX / 2 -# endif led_matrix_set_speed(LED_MATRIX_DEFAULT_SPD); led_matrix_set_flags(LED_FLAG_ALL); #endif diff --git a/keyboards/input_club/k_type/k_type.c b/keyboards/input_club/k_type/k_type.c index 23a389540861..f690e0a5ce61 100644 --- a/keyboards/input_club/k_type/k_type.c +++ b/keyboards/input_club/k_type/k_type.c @@ -223,9 +223,6 @@ void matrix_init_kb(void) { * Since K20x is stuck with a 32 byte EEPROM (see tmk_core/common/chibios/eeprom_teensy.c), * and neither led_matrix_eeconfig.speed or .flags fit in this boundary, just force their values to default on boot. */ -# if !defined(RGB_MATRIX_DEFAULT_SPD) -# define RGB_MATRIX_DEFAULT_SPD UINT8_MAX / 2 -# endif rgb_matrix_set_speed(RGB_MATRIX_DEFAULT_SPD), rgb_matrix_set_flags(LED_FLAG_ALL); #endif diff --git a/keyboards/input_club/whitefox/whitefox.c b/keyboards/input_club/whitefox/whitefox.c index 4aa12586f3fb..b0f0f0377665 100644 --- a/keyboards/input_club/whitefox/whitefox.c +++ b/keyboards/input_club/whitefox/whitefox.c @@ -83,9 +83,6 @@ void matrix_init_kb(void) { * Since K20x is stuck with a 32 byte EEPROM (see tmk_core/common/chibios/eeprom_teensy.c), * and neither led_matrix_eeconfig.speed or .flags fit in this boundary, just force their values to default on boot. */ -# if !defined(LED_MATRIX_DEFAULT_SPD) -# define LED_MATRIX_DEFAULT_SPD UINT8_MAX / 2 -# endif led_matrix_set_speed(LED_MATRIX_DEFAULT_SPD), led_matrix_set_flags(LED_FLAG_ALL); #endif diff --git a/keyboards/kbdfans/kbd67/mkiirgb/v3/info.json b/keyboards/kbdfans/kbd67/mkiirgb/v3/info.json index 165db9629369..284461c2a752 100644 --- a/keyboards/kbdfans/kbd67/mkiirgb/v3/info.json +++ b/keyboards/kbdfans/kbd67/mkiirgb/v3/info.json @@ -5,7 +5,8 @@ "device_version": "0.0.3" }, "rgb_matrix": { - "driver": "is31fl3741" + "driver": "is31fl3741", + "val_steps": 8 }, "matrix_pins": { "cols": ["F7", "F6", "F5", "C7", "B0", "B1", "B2", "B3", "B4", "D7", "D6", "D4", "D5", "D3", "D2"], diff --git a/keyboards/kbdfans/kbd67/mkiirgb/v3/v3.c b/keyboards/kbdfans/kbd67/mkiirgb/v3/v3.c index 4329893ac12a..c0f892980e58 100755 --- a/keyboards/kbdfans/kbd67/mkiirgb/v3/v3.c +++ b/keyboards/kbdfans/kbd67/mkiirgb/v3/v3.c @@ -125,16 +125,12 @@ led_config_t g_led_config = { { #if defined(RGB_MATRIX_ENABLE) && defined(CAPS_LOCK_LED_INDEX) -#ifdef RGB_MATRIX_MAXIMUM_BRIGHTNESS +#if !defined(CAPS_LOCK_MAX_BRIGHTNESS) #define CAPS_LOCK_MAX_BRIGHTNESS RGB_MATRIX_MAXIMUM_BRIGHTNESS -#else - #define CAPS_LOCK_MAX_BRIGHTNESS 0xFF #endif -#ifdef RGB_MATRIX_VAL_STEP +#if !defined(CAPS_LOCK_VAL_STEP) #define CAPS_LOCK_VAL_STEP RGB_MATRIX_VAL_STEP -#else - #define CAPS_LOCK_VAL_STEP 8 #endif bool rgb_matrix_indicators_kb(void) { diff --git a/keyboards/teleport/native/ansi/keymaps/default/keymap.c b/keyboards/teleport/native/ansi/keymaps/default/keymap.c index fcea5c41f3ae..f45971f7b2fb 100644 --- a/keyboards/teleport/native/ansi/keymaps/default/keymap.c +++ b/keyboards/teleport/native/ansi/keymaps/default/keymap.c @@ -53,7 +53,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* RGB matrix indicator code It reads the current matrix color, offsets the hue by 30, -and sets val to either 255 or, if defined, RGB_MATRIX_MAXIMUM_BRIGHTNESS +and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { diff --git a/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c b/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c index 1a7852a062e7..3eabb90017d8 100644 --- a/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c +++ b/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c @@ -144,7 +144,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* RGB matrix indicator code It reads the current matrix color, offsets the hue by 30, -and sets val to either 255 or, if defined, RGB_MATRIX_MAXIMUM_BRIGHTNESS +and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { diff --git a/keyboards/teleport/native/ansi/keymaps/via/keymap.c b/keyboards/teleport/native/ansi/keymaps/via/keymap.c index e1fbd285ec35..7b49d600ec90 100644 --- a/keyboards/teleport/native/ansi/keymaps/via/keymap.c +++ b/keyboards/teleport/native/ansi/keymaps/via/keymap.c @@ -53,7 +53,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* RGB matrix indicator code It reads the current matrix color, offsets the hue by 30, -and sets val to either 255 or, if defined, RGB_MATRIX_MAXIMUM_BRIGHTNESS +and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { diff --git a/keyboards/teleport/native/config.h b/keyboards/teleport/native/config.h index 1453bfdc9444..f3f4a3532242 100644 --- a/keyboards/teleport/native/config.h +++ b/keyboards/teleport/native/config.h @@ -61,12 +61,7 @@ along with this program. If not, see . #define ENABLE_RGB_MATRIX_CUSTOM_SINGLE_COLOR_RAINDROPS // 0 Single color raindrops, random keys lighting up at randomized intensity #define ENABLE_RGB_MATRIX_CUSTOM_STATIC_GAME_MODE // - Game mode sets the entire matrix (static) once, then stops LED refreshes -#define INDICATOR_MAX_BRIGHTNESS 255 -#ifdef RGB_MATRIX_MAXIMUM_BRIGHTNESS - #undef INDICATOR_MAX_BRIGHTNESS - #define INDICATOR_MAX_BRIGHTNESS RGB_MATRIX_MAXIMUM_BRIGHTNESS -#endif - +#define INDICATOR_MAX_BRIGHTNESS RGB_MATRIX_MAXIMUM_BRIGHTNESS /* Define indicator LED indices, used for lighting effects */ #define W_LED_INDEX 33 diff --git a/keyboards/teleport/native/iso/keymaps/default/keymap.c b/keyboards/teleport/native/iso/keymaps/default/keymap.c index c1ed3cd4f41a..dce865e239c3 100644 --- a/keyboards/teleport/native/iso/keymaps/default/keymap.c +++ b/keyboards/teleport/native/iso/keymaps/default/keymap.c @@ -53,7 +53,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* RGB matrix indicator code It reads the current matrix color, offsets the hue by 30, -and sets val to either 255 or, if defined, RGB_MATRIX_MAXIMUM_BRIGHTNESS +and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { diff --git a/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c b/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c index 3be8eec3ddf9..f0f4e7dfa05e 100644 --- a/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c +++ b/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c @@ -144,7 +144,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* RGB matrix indicator code It reads the current matrix color, offsets the hue by 30, -and sets val to either 255 or, if defined, RGB_MATRIX_MAXIMUM_BRIGHTNESS +and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { diff --git a/keyboards/teleport/native/iso/keymaps/via/keymap.c b/keyboards/teleport/native/iso/keymaps/via/keymap.c index c1ed3cd4f41a..dce865e239c3 100644 --- a/keyboards/teleport/native/iso/keymaps/via/keymap.c +++ b/keyboards/teleport/native/iso/keymaps/via/keymap.c @@ -53,7 +53,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* RGB matrix indicator code It reads the current matrix color, offsets the hue by 30, -and sets val to either 255 or, if defined, RGB_MATRIX_MAXIMUM_BRIGHTNESS +and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { diff --git a/keyboards/zykrah/fuyu/keymaps/via/keymap.c b/keyboards/zykrah/fuyu/keymaps/via/keymap.c index 11f33854cefe..8162fa484636 100644 --- a/keyboards/zykrah/fuyu/keymaps/via/keymap.c +++ b/keyboards/zykrah/fuyu/keymaps/via/keymap.c @@ -73,15 +73,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // Code for Caps Locks indicator #if defined(RGB_MATRIX_ENABLE) && defined(CAPS_LOCK_LED_INDEX) -#define CAPS_LOCK_MAX_BRIGHTNESS 0xFF -#ifdef RGB_MATRIX_MAXIMUM_BRIGHTNESS - #undef CAPS_LOCK_MAX_BRIGHTNESS +#if !defined(CAPS_LOCK_MAX_BRIGHTNESS) #define CAPS_LOCK_MAX_BRIGHTNESS RGB_MATRIX_MAXIMUM_BRIGHTNESS #endif -#define CAPS_LOCK_VAL_STEP 8 -#ifdef RGB_MATRIX_VAL_STEP - #undef CAPS_LOCK_VAL_STEP +#if !defined(CAPS_LOCK_VAL_STEP) #define CAPS_LOCK_VAL_STEP RGB_MATRIX_VAL_STEP #endif diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 1676a60aa35d..a59d475521ef 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -58,35 +58,6 @@ const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; // -----End led effect includes macros------- // ------------------------------------------ -#ifndef LED_MATRIX_TIMEOUT -# define LED_MATRIX_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_DEFAULT_MODE) -# define LED_MATRIX_DEFAULT_MODE LED_MATRIX_SOLID -#endif - -#if !defined(LED_MATRIX_DEFAULT_VAL) -# define LED_MATRIX_DEFAULT_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS -#endif - -#if !defined(LED_MATRIX_DEFAULT_SPD) -# define LED_MATRIX_DEFAULT_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; @@ -632,7 +603,7 @@ void led_matrix_decrease_speed(void) { void led_matrix_set_flags_eeprom_helper(led_flags_t flags, bool write_to_eeprom) { led_matrix_eeconfig.flags = flags; eeconfig_flag_led_matrix(write_to_eeprom); - dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.flags); + dprintf("led matrix set flags [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.flags); } led_flags_t led_matrix_get_flags(void) { diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index c2533ca49cbc..bd61e8650ae8 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -37,6 +37,35 @@ # include "ckled2001-simple.h" #endif +#ifndef LED_MATRIX_TIMEOUT +# define LED_MATRIX_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_DEFAULT_MODE) +# define LED_MATRIX_DEFAULT_MODE LED_MATRIX_SOLID +#endif + +#if !defined(LED_MATRIX_DEFAULT_VAL) +# define LED_MATRIX_DEFAULT_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS +#endif + +#if !defined(LED_MATRIX_DEFAULT_SPD) +# define LED_MATRIX_DEFAULT_SPD UINT8_MAX / 2 +#endif + #ifndef LED_MATRIX_LED_FLUSH_LIMIT # define LED_MATRIX_LED_FLUSH_LIMIT 16 #endif diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 96be6151628f..ff3e5b2b355e 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -60,56 +60,6 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { // -----End rgb effect includes macros------- // ------------------------------------------ -#ifndef RGB_MATRIX_TIMEOUT -# define RGB_MATRIX_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_DEFAULT_MODE) -# ifdef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT -# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT -# else -// fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace -# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR -# endif -#endif - -#if !defined(RGB_MATRIX_DEFAULT_HUE) -# define RGB_MATRIX_DEFAULT_HUE 0 -#endif - -#if !defined(RGB_MATRIX_DEFAULT_SAT) -# define RGB_MATRIX_DEFAULT_SAT UINT8_MAX -#endif - -#if !defined(RGB_MATRIX_DEFAULT_VAL) -# define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS -#endif - -#if !defined(RGB_MATRIX_DEFAULT_SPD) -# define RGB_MATRIX_DEFAULT_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; @@ -736,7 +686,7 @@ void rgb_matrix_decrease_speed(void) { void rgb_matrix_set_flags_eeprom_helper(led_flags_t flags, bool write_to_eeprom) { rgb_matrix_config.flags = flags; eeconfig_flag_rgb_matrix(write_to_eeprom); - dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.flags); + dprintf("rgb matrix set flags [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.flags); } led_flags_t rgb_matrix_get_flags(void) { diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 38040fb0ccc4..f4f52428599d 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -44,6 +44,56 @@ # include "ws2812.h" #endif +#ifndef RGB_MATRIX_TIMEOUT +# define RGB_MATRIX_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_DEFAULT_MODE) +# ifdef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT +# else +// fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace +# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR +# endif +#endif + +#if !defined(RGB_MATRIX_DEFAULT_HUE) +# define RGB_MATRIX_DEFAULT_HUE 0 +#endif + +#if !defined(RGB_MATRIX_DEFAULT_SAT) +# define RGB_MATRIX_DEFAULT_SAT UINT8_MAX +#endif + +#if !defined(RGB_MATRIX_DEFAULT_VAL) +# define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS +#endif + +#if !defined(RGB_MATRIX_DEFAULT_SPD) +# define RGB_MATRIX_DEFAULT_SPD UINT8_MAX / 2 +#endif + #ifndef RGB_MATRIX_LED_FLUSH_LIMIT # define RGB_MATRIX_LED_FLUSH_LIMIT 16 #endif diff --git a/quantum/via.c b/quantum/via.c index 2acd7aa90c31..643d7aa3c39f 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -634,11 +634,6 @@ void via_qmk_rgblight_save(void) { #if defined(RGB_MATRIX_ENABLE) -# 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 - void via_qmk_rgb_matrix_command(uint8_t *data, uint8_t length) { // data = [ command_id, channel_id, value_id, value_data ] uint8_t *command_id = &(data[0]); @@ -727,11 +722,6 @@ void via_qmk_rgb_matrix_save(void) { #if defined(LED_MATRIX_ENABLE) -# 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 - void via_qmk_led_matrix_command(uint8_t *data, uint8_t length) { // data = [ command_id, channel_id, value_id, value_data ] uint8_t *command_id = &(data[0]); From 5d609e3c5db94a232ee6110a0ab3614099252caa Mon Sep 17 00:00:00 2001 From: Less/Rikki <86894501+lesshonor@users.noreply.github.com> Date: Thu, 7 Sep 2023 00:01:28 -0400 Subject: [PATCH 2/3] style: use if(n)def for consistency and remove redundant UINT8_MAX checks on maximum brightness Co-authored-by: Joel Challis --- quantum/led_matrix/led_matrix.h | 13 ++++++------- quantum/rgb_matrix/rgb_matrix.h | 21 ++++++++++----------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index bd61e8650ae8..d70cc7e32417 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -41,28 +41,27 @@ # define LED_MATRIX_TIMEOUT 0 #endif -#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX -# undef LED_MATRIX_MAXIMUM_BRIGHTNESS +#ifndef LED_MATRIX_MAXIMUM_BRIGHTNESS # define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX #endif -#if !defined(LED_MATRIX_VAL_STEP) +#ifndef LED_MATRIX_VAL_STEP # define LED_MATRIX_VAL_STEP 8 #endif -#if !defined(LED_MATRIX_SPD_STEP) +#ifndef LED_MATRIX_SPD_STEP # define LED_MATRIX_SPD_STEP 16 #endif -#if !defined(LED_MATRIX_DEFAULT_MODE) +#ifndef LED_MATRIX_DEFAULT_MODE # define LED_MATRIX_DEFAULT_MODE LED_MATRIX_SOLID #endif -#if !defined(LED_MATRIX_DEFAULT_VAL) +#ifndef LED_MATRIX_DEFAULT_VAL # define LED_MATRIX_DEFAULT_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS #endif -#if !defined(LED_MATRIX_DEFAULT_SPD) +#ifndef LED_MATRIX_DEFAULT_SPD # define LED_MATRIX_DEFAULT_SPD UINT8_MAX / 2 #endif diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index f4f52428599d..f3141bb45e0c 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -48,28 +48,27 @@ # define RGB_MATRIX_TIMEOUT 0 #endif -#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX -# undef RGB_MATRIX_MAXIMUM_BRIGHTNESS +#ifndef RGB_MATRIX_MAXIMUM_BRIGHTNESS # define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX #endif -#if !defined(RGB_MATRIX_HUE_STEP) +#ifndef RGB_MATRIX_HUE_STEP # define RGB_MATRIX_HUE_STEP 8 #endif -#if !defined(RGB_MATRIX_SAT_STEP) +#ifndef RGB_MATRIX_SAT_STEP # define RGB_MATRIX_SAT_STEP 16 #endif -#if !defined(RGB_MATRIX_VAL_STEP) +#ifndef RGB_MATRIX_VAL_STEP # define RGB_MATRIX_VAL_STEP 16 #endif -#if !defined(RGB_MATRIX_SPD_STEP) +#ifndef RGB_MATRIX_SPD_STEP # define RGB_MATRIX_SPD_STEP 16 #endif -#if !defined(RGB_MATRIX_DEFAULT_MODE) +#ifndef RGB_MATRIX_DEFAULT_MODE # ifdef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT # define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT # else @@ -78,19 +77,19 @@ # endif #endif -#if !defined(RGB_MATRIX_DEFAULT_HUE) +#ifndef RGB_MATRIX_DEFAULT_HUE # define RGB_MATRIX_DEFAULT_HUE 0 #endif -#if !defined(RGB_MATRIX_DEFAULT_SAT) +#ifndef RGB_MATRIX_DEFAULT_SAT # define RGB_MATRIX_DEFAULT_SAT UINT8_MAX #endif -#if !defined(RGB_MATRIX_DEFAULT_VAL) +#ifndef RGB_MATRIX_DEFAULT_VAL # define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS #endif -#if !defined(RGB_MATRIX_DEFAULT_SPD) +#ifndef RGB_MATRIX_DEFAULT_SPD # define RGB_MATRIX_DEFAULT_SPD UINT8_MAX / 2 #endif From 1a1d74b8d666e7acf6f1c78e27ad3d51df4a18a3 Mon Sep 17 00:00:00 2001 From: honorless <86894501+lesshonor@users.noreply.github.com> Date: Thu, 7 Sep 2023 07:26:33 -0400 Subject: [PATCH 3/3] refactor: remove INDICATOR_MAX_BRIGHTNESS macro Co-authored-by: Joel Challis --- keyboards/teleport/native/ansi/keymaps/default/keymap.c | 4 ++-- keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c | 4 ++-- keyboards/teleport/native/ansi/keymaps/via/keymap.c | 4 ++-- keyboards/teleport/native/config.h | 2 -- keyboards/teleport/native/iso/keymaps/default/keymap.c | 4 ++-- keyboards/teleport/native/iso/keymaps/perfmode/keymap.c | 4 ++-- keyboards/teleport/native/iso/keymaps/via/keymap.c | 4 ++-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/keyboards/teleport/native/ansi/keymaps/default/keymap.c b/keyboards/teleport/native/ansi/keymaps/default/keymap.c index f45971f7b2fb..2780fdda7dd8 100644 --- a/keyboards/teleport/native/ansi/keymaps/default/keymap.c +++ b/keyboards/teleport/native/ansi/keymaps/default/keymap.c @@ -57,7 +57,7 @@ and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); /* Sets Caps to different color as indicator. If RGB mode is rain, and caps indicator is off, the LED will always be off. @@ -70,7 +70,7 @@ bool rgb_matrix_indicators_user(void) { /* Sets W, A, S, D, LGUI to a different color as layer indicator */ if(IS_LAYER_ON(1)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); rgb_matrix_set_color(W_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b); diff --git a/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c b/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c index 3eabb90017d8..ab598dd5e6d8 100644 --- a/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c +++ b/keyboards/teleport/native/ansi/keymaps/perfmode/keymap.c @@ -150,7 +150,7 @@ This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { /* Layer 2 (perf mode on this keymap) is not supposed to have LED refreshes, hence excluded */ if (!IS_LAYER_ON(2)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); /* Sets Caps to different color as indicator. If RGB mode is rain, and caps indicator is off, the LED will always be off. @@ -163,7 +163,7 @@ bool rgb_matrix_indicators_user(void) { /* Sets W, A, S, D, LGUI to a different color as layer indicator */ if(IS_LAYER_ON(1)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); rgb_matrix_set_color(W_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b); diff --git a/keyboards/teleport/native/ansi/keymaps/via/keymap.c b/keyboards/teleport/native/ansi/keymaps/via/keymap.c index 7b49d600ec90..95a5bc58b130 100644 --- a/keyboards/teleport/native/ansi/keymaps/via/keymap.c +++ b/keyboards/teleport/native/ansi/keymaps/via/keymap.c @@ -57,7 +57,7 @@ and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); /* Sets Caps to different color as indicator. If RGB mode is rain, and caps indicator is off, the LED will always be off. @@ -70,7 +70,7 @@ bool rgb_matrix_indicators_user(void) { /* Sets W, A, S, D, LGUI to a different color as layer indicator */ if(IS_LAYER_ON(1)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); rgb_matrix_set_color(W_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b); diff --git a/keyboards/teleport/native/config.h b/keyboards/teleport/native/config.h index f3f4a3532242..b315ea64a533 100644 --- a/keyboards/teleport/native/config.h +++ b/keyboards/teleport/native/config.h @@ -61,8 +61,6 @@ along with this program. If not, see . #define ENABLE_RGB_MATRIX_CUSTOM_SINGLE_COLOR_RAINDROPS // 0 Single color raindrops, random keys lighting up at randomized intensity #define ENABLE_RGB_MATRIX_CUSTOM_STATIC_GAME_MODE // - Game mode sets the entire matrix (static) once, then stops LED refreshes -#define INDICATOR_MAX_BRIGHTNESS RGB_MATRIX_MAXIMUM_BRIGHTNESS - /* Define indicator LED indices, used for lighting effects */ #define W_LED_INDEX 33 #define A_LED_INDEX 47 diff --git a/keyboards/teleport/native/iso/keymaps/default/keymap.c b/keyboards/teleport/native/iso/keymaps/default/keymap.c index dce865e239c3..b6f2e7ab82f7 100644 --- a/keyboards/teleport/native/iso/keymaps/default/keymap.c +++ b/keyboards/teleport/native/iso/keymaps/default/keymap.c @@ -57,7 +57,7 @@ and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); /* Sets Caps to different color as indicator. If RGB mode is rain, and caps indicator is off, the LED will always be off. @@ -70,7 +70,7 @@ bool rgb_matrix_indicators_user(void) { /* Sets W, A, S, D, LGUI to a different color as layer indicator */ if(IS_LAYER_ON(1)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); rgb_matrix_set_color(W_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b); diff --git a/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c b/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c index f0f4e7dfa05e..f95391358a32 100644 --- a/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c +++ b/keyboards/teleport/native/iso/keymaps/perfmode/keymap.c @@ -150,7 +150,7 @@ This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { /* Layer 2 (perf mode on this keymap) is not supposed to have LED refreshes, hence excluded */ if (!IS_LAYER_ON(2)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); /* Sets Caps to different color as indicator. If RGB mode is rain, and caps indicator is off, the LED will always be off. @@ -163,7 +163,7 @@ bool rgb_matrix_indicators_user(void) { /* Sets W, A, S, D, LGUI to a different color as layer indicator */ if(IS_LAYER_ON(1)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); rgb_matrix_set_color(W_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b); diff --git a/keyboards/teleport/native/iso/keymaps/via/keymap.c b/keyboards/teleport/native/iso/keymaps/via/keymap.c index dce865e239c3..b6f2e7ab82f7 100644 --- a/keyboards/teleport/native/iso/keymaps/via/keymap.c +++ b/keyboards/teleport/native/iso/keymaps/via/keymap.c @@ -57,7 +57,7 @@ and sets val to RGB_MATRIX_MAXIMUM_BRIGHTNESS (by default, 255) This is applied to both caps lock, and other indicator keys for layer 1 */ bool rgb_matrix_indicators_user(void) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); /* Sets Caps to different color as indicator. If RGB mode is rain, and caps indicator is off, the LED will always be off. @@ -70,7 +70,7 @@ bool rgb_matrix_indicators_user(void) { /* Sets W, A, S, D, LGUI to a different color as layer indicator */ if(IS_LAYER_ON(1)) { - HSV hsv_ind = {rgb_matrix_get_hue()+30,255,INDICATOR_MAX_BRIGHTNESS}; + HSV hsv_ind = {rgb_matrix_get_hue()+30,255,RGB_MATRIX_MAXIMUM_BRIGHTNESS}; RGB rgb_ind = hsv_to_rgb(hsv_ind); rgb_matrix_set_color(W_LED_INDEX, rgb_ind.r, rgb_ind.g, rgb_ind.b);