Skip to content

Commit

Permalink
LED Matrix: decouple from Backlight (qmk#12054)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored and nhongooi committed Dec 5, 2021
1 parent a5b0d29 commit a9847d5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
5 changes: 2 additions & 3 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ VALID_LED_MATRIX_TYPES := IS31FL3731 custom

ifeq ($(strip $(LED_MATRIX_ENABLE)), yes)
ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),)
$(error LED_MATRIX_DRIVER="$(LED_MATRIX_DRIVER)" is not a valid matrix type)
$(error "$(LED_MATRIX_DRIVER)" is not a valid matrix type)
else
BACKLIGHT_ENABLE = yes
BACKLIGHT_DRIVER = custom
OPT_DEFS += -DLED_MATRIX_ENABLE
SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c
SRC += $(QUANTUM_DIR)/led_matrix.c
SRC += $(QUANTUM_DIR)/led_matrix_drivers.c
endif
Expand Down
8 changes: 1 addition & 7 deletions quantum/led_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ led_eeconfig_t led_matrix_eeconfig;
# define LED_DISABLE_WHEN_USB_SUSPENDED false
#endif

#ifndef EECONFIG_LED_MATRIX
# define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT
#endif

#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255
# define LED_MATRIX_MAXIMUM_BRIGHTNESS 255
#endif
Expand Down Expand Up @@ -135,7 +131,7 @@ void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; }
void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); }

// Uniform brightness
void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_eeconfig.val); }
void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(led_matrix_eeconfig.val); }

void led_matrix_custom(void) {}

Expand Down Expand Up @@ -344,5 +340,3 @@ void led_matrix_set_value(uint8_t val) {
led_matrix_set_value_noeeprom(val);
eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
}

void backlight_set(uint8_t val) { led_matrix_set_value(val); }
4 changes: 0 additions & 4 deletions quantum/led_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

#include "led_matrix_types.h"

#ifndef BACKLIGHT_ENABLE
# error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE
#endif

enum led_matrix_effects {
LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
// All new effects go above this line
Expand Down
29 changes: 27 additions & 2 deletions quantum/process_keycode/process_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,35 @@

#include "process_backlight.h"

#include "backlight.h"
#ifdef LED_MATRIX_ENABLE
# include "led_matrix.h"
#else
# include "backlight.h"
#endif

bool process_backlight(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
#ifdef LED_MATRIX_ENABLE
case BL_ON:
led_matrix_enable();
return false;
case BL_OFF:
led_matrix_disable();
return false;
case BL_DEC:
led_matrix_decrease_val();
return false;
case BL_INC:
led_matrix_increase_val();
return false;
case BL_TOGG:
led_matrix_toggle();
return false;
case BL_STEP:
led_matrix_step();
return false;
#else
case BL_ON:
backlight_level(BACKLIGHT_LEVELS);
return false;
Expand All @@ -39,10 +63,11 @@ bool process_backlight(uint16_t keycode, keyrecord_t *record) {
case BL_STEP:
backlight_step();
return false;
#ifdef BACKLIGHT_BREATHING
# ifdef BACKLIGHT_BREATHING
case BL_BRTG:
backlight_toggle_breathing();
return false;
# endif
#endif
}
}
Expand Down
9 changes: 4 additions & 5 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef AUDIO_ENABLE
process_audio(keycode, record) &&
#endif
#ifdef BACKLIGHT_ENABLE
#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE)
process_backlight(keycode, record) &&
#endif
#ifdef STENO_ENABLE
Expand Down Expand Up @@ -359,15 +359,14 @@ void matrix_init_quantum() {
led_init_ports();
#endif
#ifdef BACKLIGHT_ENABLE
# ifdef LED_MATRIX_ENABLE
led_matrix_init();
# else
backlight_init_ports();
# endif
#endif
#ifdef AUDIO_ENABLE
audio_init();
#endif
#ifdef LED_MATRIX_ENABLE
led_matrix_init();
#endif
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_init();
#endif
Expand Down
12 changes: 6 additions & 6 deletions quantum/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
#include "keymap.h"

#ifdef BACKLIGHT_ENABLE
# ifdef LED_MATRIX_ENABLE
# include "led_matrix.h"
# else
# include "backlight.h"
# endif
# include "backlight.h"
#endif

#ifdef LED_MATRIX_ENABLE
# include "led_matrix.h"
#endif

#if defined(RGBLIGHT_ENABLE)
Expand Down Expand Up @@ -98,7 +98,7 @@ extern layer_state_t layer_state;
# include "process_music.h"
#endif

#ifdef BACKLIGHT_ENABLE
#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE)
# include "process_backlight.h"
#endif

Expand Down
5 changes: 5 additions & 0 deletions tmk_core/common/eeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
#define EECONFIG_VELOCIKEY (uint8_t *)23

#define EECONFIG_HAPTIC (uint32_t *)24

// Mutually exclusive
#define EECONFIG_LED_MATRIX (uint32_t *)28
#define EECONFIG_RGB_MATRIX (uint32_t *)28
// Speed & Flags
#define EECONFIG_LED_MATRIX_EXTENDED (uint16_t *)32
#define EECONFIG_RGB_MATRIX_EXTENDED (uint16_t *)32

// TODO: Combine these into a single word and single block of EEPROM
#define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)34
// Size of EEPROM being used, other code can refer to this for available EEPROM
Expand Down

0 comments on commit a9847d5

Please sign in to comment.