summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--keyboards/keychron/bluetooth/bat_level_animation.c12
-rw-r--r--keyboards/keychron/bluetooth/bluetooth.c4
-rw-r--r--keyboards/keychron/bluetooth/bluetooth.h3
-rw-r--r--keyboards/keychron/bluetooth/indicator.c268
-rw-r--r--keyboards/keychron/bluetooth/indicator.h2
-rw-r--r--keyboards/keychron/bluetooth/lpm.c4
-rw-r--r--keyboards/keychron/bluetooth/lpm_stm32l432.c20
-rw-r--r--keyboards/keychron/k8_pro/k8_pro.c13
-rw-r--r--quantum/led_matrix/led_matrix.c38
-rw-r--r--quantum/led_matrix/led_matrix.h1
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c38
-rw-r--r--quantum/rgb_matrix/rgb_matrix.h1
-rw-r--r--quantum/via.c10
13 files changed, 252 insertions, 162 deletions
diff --git a/keyboards/keychron/bluetooth/bat_level_animation.c b/keyboards/keychron/bluetooth/bat_level_animation.c
index 83a4f91cae..2e726e17b8 100644
--- a/keyboards/keychron/bluetooth/bat_level_animation.c
+++ b/keyboards/keychron/bluetooth/bat_level_animation.c
@@ -8,6 +8,7 @@
#elif if defined(PROTOCOL_LUFA)
# include "lufa.h"
#endif
+#include "eeprom.h"
#ifndef BAT_LEVEL_GROWING_INTERVAL
# define BAT_LEVEL_GROWING_INTERVAL 150
@@ -17,6 +18,14 @@
# define BAT_LEVEL_ON_INTERVAL 3000
#endif
+#ifdef LED_MATRIX_ENABLE
+# define LED_DRIVER_IS_ENABLED led_matrix_is_enabled
+#endif
+
+#ifdef RGB_MATRIX_ENABLE
+# define LED_DRIVER_IS_ENABLED rgb_matrix_is_enabled
+#endif
+
enum {
BAT_LVL_ANI_NONE,
BAT_LVL_ANI_GROWING,
@@ -113,7 +122,8 @@ void bat_level_animiation_update(void) {
case BAT_LVL_ANI_BLINK_ON:
animation_state = BAT_LVL_ANI_NONE;
- if (indicator_config.value == 0 && !indicator_is_backlit_enabled_eeprom()) {
+ indicator_eeconfig_reload();
+ if (indicator_config.value == 0 && !LED_DRIVER_IS_ENABLED()) {
indicator_disable();
}
break;
diff --git a/keyboards/keychron/bluetooth/bluetooth.c b/keyboards/keychron/bluetooth/bluetooth.c
index 10c79257a9..e93fd8d4ac 100644
--- a/keyboards/keychron/bluetooth/bluetooth.c
+++ b/keyboards/keychron/bluetooth/bluetooth.c
@@ -432,10 +432,12 @@ bluetooth_state_t bluetooth_get_state(void) {
return bt_state;
};
+__attribute__((weak)) bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record) { return true;};
+
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (get_transport() == TRANSPORT_BLUETOOTH) {
lpm_timer_reset();
}
-
+ process_record_kb_bt(keycode, record);
return process_record_user(keycode, record);
}
diff --git a/keyboards/keychron/bluetooth/bluetooth.h b/keyboards/keychron/bluetooth/bluetooth.h
index b24df48845..bfbc838000 100644
--- a/keyboards/keychron/bluetooth/bluetooth.h
+++ b/keyboards/keychron/bluetooth/bluetooth.h
@@ -83,3 +83,6 @@ bluetooth_state_t bluetooth_get_state(void);
void bluetooth_low_battery_shutdown(void);
+bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record);
+
+
diff --git a/keyboards/keychron/bluetooth/indicator.c b/keyboards/keychron/bluetooth/indicator.c
index fa9c9fc6e4..de7023e2fb 100644
--- a/keyboards/keychron/bluetooth/indicator.c
+++ b/keyboards/keychron/bluetooth/indicator.c
@@ -30,6 +30,7 @@
# endif
# include "i2c_master.h"
# include "bat_level_animation.h"
+# include "eeprom.h"
#endif
#ifdef LED_MATRIX_ENABLE
@@ -40,19 +41,7 @@
#endif
#define LED_ON 0x80
-
-#define INDICATOR_SET(s) \
- indicator_config.type = s##_config.type; \
- indicator_config.on_time = s##_config.on_time; \
- indicator_config.off_time = s##_config.off_time; \
- indicator_config.duration = s##_config.duration; \
- indicator_config.highlight = s##_config.highlight; \
- indicator_config.elapsed = 0;
-
-indicator_config_t pairing_config = INDICATOR_CONFIG_PARING;
-indicator_config_t connected_config = INDICATOR_CONFIG_CONNECTD;
-indicator_config_t reconnecting_config = INDICATOR_CONFIG_RECONNECTING;
-indicator_config_t disconnected_config = INDICATOR_CONFIG_DISCONNECTED;
+#define INDICATOR_SET(s) memcpy(&indicator_config, &s##_config, sizeof(indicator_config_t));
enum {
BACKLIGHT_OFF = 0x00,
@@ -60,8 +49,11 @@ enum {
BACKLIGHT_ON_UNCONNECTED = 0x02,
};
+static indicator_config_t pairing_config = INDICATOR_CONFIG_PARING;
+static indicator_config_t connected_config = INDICATOR_CONFIG_CONNECTD;
+static indicator_config_t reconnecting_config = INDICATOR_CONFIG_RECONNECTING;
+static indicator_config_t disconnected_config = INDICATOR_CONFIG_DISCONNECTED;
indicator_config_t indicator_config;
-
static bluetooth_state_t indicator_state;
static uint16_t next_period;
static indicator_type_t type;
@@ -78,6 +70,51 @@ static uint8_t host_led_matrix_list[HOST_DEVICES_COUNT] = HOST_LED_MATRIX_LIST;
static pin_t host_led_pin_list[HOST_DEVICES_COUNT] = HOST_LED_PIN_LIST;
#endif
+#ifndef BACKLIGHT_TURN_OFF_VALUE
+# define BACKLIGHT_TURN_OFF_VALUE 32
+#endif
+
+#ifdef LED_MATRIX_ENABLE
+# define LED_DRIVER led_matrix_driver
+# define LED_INDICATORS_KB led_matrix_indicators_kb
+# define LED_NONE_INDICATORS_KB led_matrix_none_indicators_kb
+# define SET_ALL_LED_OFF() led_matrix_set_value_all(0)
+# define SET_LED_OFF(idx) led_matrix_set_value(idx, 0)
+# define SET_LED_ON(idx) led_matrix_set_value(idx, 255)
+# define SET_LED_BT(idx) led_matrix_set_value(idx, 255)
+# define LED_DRIVER_IS_ENABLED led_matrix_is_enabled
+# define LED_DRIVER_EECONFIG_RELOAD() \
+ eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); \
+ if (!led_matrix_eeconfig.mode) { \
+ eeconfig_update_led_matrix_default(); \
+ }
+# define LED_DRIVER_ALLOW_SHUTDOWN led_matrix_driver_allow_shutdown
+# define LED_DRIVER_ENABLE_NOEEPROM led_matrix_enable_noeeprom
+# define LED_DRIVER_DISABLE_NOEEPROM led_matrix_disable_noeeprom
+# define LED_DRIVER_DISABLE_TIMEOUT_SET led_matrix_disable_timeout_set
+# define LED_DRIVER_DISABLE_TIME_RESET led_matrix_disable_time_reset
+#endif
+
+#ifdef RGB_MATRIX_ENABLE
+# define LED_DRIVER rgb_matrix_driver
+# define LED_INDICATORS_KB rgb_matrix_indicators_kb
+# define LED_NONE_INDICATORS_KB rgb_matrix_none_indicators_kb
+# define SET_ALL_LED_OFF() rgb_matrix_set_color_all(0, 0, 0)
+# define SET_LED_OFF(idx) rgb_matrix_set_color(idx, 0, 0, 0)
+# define SET_LED_ON(idx) rgb_matrix_set_color(idx, 255, 255, 255)
+# define SET_LED_BT(idx) rgb_matrix_set_color(idx, 0, 0, 255)
+# define LED_DRIVER_IS_ENABLED rgb_matrix_is_enabled
+# define LED_DRIVER_EECONFIG_RELOAD() \
+ eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); \
+ if (!rgb_matrix_config.mode) { \
+ eeconfig_update_rgb_matrix_default(); \
+ }
+# define LED_DRIVER_ALLOW_SHUTDOWN rgb_matrix_driver_allow_shutdown
+# define LED_DRIVER_ENABLE_NOEEPROM rgb_matrix_enable_noeeprom
+# define LED_DRIVER_DISABLE_NOEEPROM rgb_matrix_disable_noeeprom
+# define LED_DRIVER_DISABLE_TIMEOUT_SET rgb_matrix_disable_timeout_set
+# define LED_DRIVER_DISABLE_TIME_RESET rgb_matrix_disable_time_reset
+#endif
void indicator_init(void) {
memset(&indicator_config, 0, sizeof(indicator_config));
@@ -96,69 +133,39 @@ void indicator_init(void) {
#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
void indicator_enable(void) {
-# ifdef LED_MATRIX_ENABLE
- if (!led_matrix_is_enabled()) {
- led_matrix_enable_noeeprom();
- }
-# endif
-# ifdef RGB_MATRIX_ENABLE
- if (!rgb_matrix_is_enabled()) {
- rgb_matrix_enable_noeeprom();
+ if (!LED_DRIVER_IS_ENABLED()) {
+ LED_DRIVER_ENABLE_NOEEPROM();
}
-# endif
}
-void indicator_disable(void) {
-# ifdef LED_MATRIX_ENABLE
- led_matrix_disable_noeeprom();
-# endif
-# ifdef RGB_MATRIX_ENABLE
- rgb_matrix_disable_noeeprom();
-# endif
+inline void indicator_disable(void) {
+ LED_DRIVER_DISABLE_NOEEPROM();
}
void indicator_set_backlit_timeout(uint32_t time) {
-# ifdef LED_MATRIX_ENABLE
- led_matrix_disable_timeout_set(time);
-# endif
-# ifdef RGB_MATRIX_ENABLE
- rgb_matrix_disable_timeout_set(time);
-# endif
+ LED_DRIVER_DISABLE_TIMEOUT_SET(time);
}
static inline void indicator_reset_backlit_time(void) {
-# ifdef LED_MATRIX_ENABLE
- led_matrix_disable_time_reset();
-# endif
-# ifdef RGB_MATRIX_ENABLE
- rgb_matrix_disable_time_reset();
-# endif
+ LED_DRIVER_DISABLE_TIME_RESET();
}
bool indicator_is_enabled(void) {
-# ifdef LED_MATRIX_ENABLE
- return led_matrix_is_enabled();
-# endif
-# ifdef RGB_MATRIX_ENABLE
- return rgb_matrix_is_enabled();
-# endif
+ return LED_DRIVER_IS_ENABLED();
}
-bool indicator_is_backlit_enabled_eeprom(void) {
-# ifdef LED_MATRIX_ENABLE
- return led_matrix_is_enabled_eeprom();
-# endif
-# ifdef RGB_MATRIX_ENABLE
- return rgb_matrix_is_enabled_eeprom();
-# endif
- return false;
+void indicator_eeconfig_reload(void) {
+ LED_DRIVER_EECONFIG_RELOAD();
}
#endif
-bool indicator_is_running(void) { return !!indicator_config.value; }
+bool indicator_is_running(void) {
+ return !!indicator_config.value;
+}
static void indicator_timer_cb(void *arg) {
+uprintf("indicator_timer_cb: %02x\n", (uint8_t)(*(indicator_type_t *)arg));
if (*(indicator_type_t *)arg != INDICATOR_LAST) type = *(indicator_type_t *)arg;
bool time_up = false;
@@ -226,8 +233,7 @@ static void indicator_timer_cb(void *arg) {
}
#ifdef HOST_LED_PIN_LIST
- if (indicator_config.value)
- {
+ if (indicator_config.value) {
uint8_t idx = (indicator_config.value & 0x0F) - 1;
if (idx < HOST_DEVICES_COUNT) {
@@ -243,17 +249,15 @@ static void indicator_timer_cb(void *arg) {
if (time_up) {
/* Set indicator to off on timeup, avoid keeping light up until next update in raindrop effect */
indicator_config.value = indicator_config.value & 0x0F;
-#ifdef LED_MATRIX_ENABLE
- led_matrix_indicators_kb();
-#endif
-#ifdef RGB_MATRIX_ENABLE
- rgb_matrix_indicators_kb();
+#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
+ LED_INDICATORS_KB();
#endif
indicator_config.value = 0;
}
- if (indicator_config.value == 0 && !indicator_is_backlit_enabled_eeprom()) {
- indicator_disable();
+ if (indicator_config.value == 0) {
+ indicator_eeconfig_reload();
+ if (!LED_DRIVER_IS_ENABLED()) indicator_disable();
}
}
@@ -335,8 +339,9 @@ void indicator_set(bluetooth_state_t state, uint8_t host_index) {
void indicator_stop(void) {
indicator_config.value = 0;
+ indicator_eeconfig_reload();
- if (indicator_is_backlit_enabled_eeprom()) {
+ if (indicator_is_enabled()) {
indicator_enable();
} else {
indicator_disable();
@@ -366,50 +371,44 @@ void indicator_task(void) {
}
}
-#ifdef LED_MATRIX_ENABLE
-void led_matrix_indicators_kb(void) {
- if (get_transport() == TRANSPORT_BLUETOOTH) {
- if (battery_is_critical_low()) {
- /* Prevent backlight flash caused by key activities */
- led_matrix_set_value_all(0);
- return;
- }
-
- if (bat_level_animiation_actived()) {
- bat_level_animiation_indicate();
- }
-
- static uint8_t last_host_index = 0xFF;
- if (indicator_config.value) {
- uint8_t host_index = indicator_config.value & 0x0F;
-
- if (indicator_config.highlight) {
- led_matrix_set_value_all(0);
- } else if (last_host_index != host_index) {
- led_matrix_set_value(host_led_matrix_list[last_host_index - 1], 0);
- last_host_index = host_index;
- }
-
- if (indicator_config.value & 0x80)
- led_matrix_set_value(host_led_matrix_list[host_index - 1], 255);
- else
- led_matrix_set_value(host_led_matrix_list[host_index - 1], 0);
- }
-# if defined(DIM_CAPS_LOCK) && defined(CAPS_LOCK_INDEX)
- else if (host_keyboard_led_state().caps_lock) {
- led_matrix_set_value(CAPS_LOCK_INDEX, 0);
- }
+#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)
+static void os_state_indicate(void) {
+# if defined(NUM_LOCK_INDEX)
+ if (host_keyboard_led_state().num_lock) {
+ SET_LED_ON(NUM_LOCK_INDEX);
+ }
# endif
+# if defined(CAPS_LOCK_INDEX)
+ if (host_keyboard_led_state().caps_lock) {
+# if defined(DIM_CAPS_LOCK)
+ SET_LED_OFF(CAPS_LOCK_INDEX);
+# else
+ SET_LED_ON(CAPS_LOCK_INDEX);
+# endif
}
+# endif
+# if defined(SCROLL_LOCK_INDEX)
+ if (host_keyboard_led_state().scroll_lock) {
+ SET_LED_ON(SCROLL_LOCK_INDEX);
+ }
+# endif
+# if defined(COMPOSE_LOCK_INDEX)
+ if (host_keyboard_led_state().compose) {
+ SET_LED_ON(COMPOSE_LOCK_INDEX);
+ }
+# endif
+# if defined(KANA_LOCK_INDEX)
+ if (host_keyboard_led_state().kana) {
+ SET_LED_ON(KANA_LOCK_INDEX);
+ }
+# endif
}
-#endif
-#ifdef RGB_MATRIX_ENABLE
-void rgb_matrix_indicators_kb(void) {
- {
+void LED_INDICATORS_KB(void) {
+ if (get_transport() == TRANSPORT_BLUETOOTH) {
+ /* Prevent backlight flash caused by key activities */
if (battery_is_critical_low()) {
- /* Prevent backlight flash caused by key activities */
- rgb_matrix_set_color_all(0, 0, 0);
+ SET_ALL_LED_OFF();
return;
}
@@ -422,23 +421,62 @@ void rgb_matrix_indicators_kb(void) {
uint8_t host_index = indicator_config.value & 0x0F;
if (indicator_config.highlight) {
- rgb_matrix_set_color_all(0, 0, 0);
+ SET_ALL_LED_OFF();
} else if (last_host_index != host_index) {
- rgb_matrix_set_color(host_led_matrix_list[last_host_index - 1], 0, 0, 0);
+ SET_LED_OFF(host_led_matrix_list[last_host_index - 1]);
last_host_index = host_index;
}
if (indicator_config.value & 0x80) {
- rgb_matrix_set_color(host_led_matrix_list[host_index - 1], 0, 0, 255);
+ SET_LED_BT(host_led_matrix_list[host_index - 1]);
} else {
- rgb_matrix_set_color(host_led_matrix_list[host_index - 1], 0, 0, 0);
+ SET_LED_OFF(host_led_matrix_list[host_index - 1]);
}
- }
-# if defined(DIM_CAPS_LOCK) && defined(CAPS_LOCK_INDEX)
- else if (host_keyboard_led_state().caps_lock) {
- rgb_matrix_set_color(CAPS_LOCK_INDEX, 0, 0, 0);
- }
+ } else
+ os_state_indicate();
+
+ } else
+ os_state_indicate();
+}
+
+bool led_update_user(led_t led_state) {
+ if (!LED_DRIVER_IS_ENABLED()) {
+# ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE
+ LED_DRIVER.exit_shutdown();
+# endif
+ SET_ALL_LED_OFF();
+ os_state_indicate();
+ LED_DRIVER.flush();
+# ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE
+ if (LED_DRIVER_ALLOW_SHUTDOWN()) LED_DRIVER.shutdown();
# endif
}
+ return true;
}
+
+void LED_NONE_INDICATORS_KB(void) {
+ os_state_indicate();
+}
+
+# ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE
+bool LED_DRIVER_ALLOW_SHUTDOWN(void) {
+# if defined(NUM_LOCK_INDEX)
+ if (host_keyboard_led_state().num_lock) return false;
+# endif
+# if defined(CAPS_LOCK_INDEX) && !defined(DIM_CAPS_LOCK)
+ if (host_keyboard_led_state().caps_lock) return false;
+# endif
+# if defined(SCROLL_LOCK_INDEX)
+ if (host_keyboard_led_state().scroll_lock) return false;
+# endif
+# if defined(COMPOSE_LOCK_INDEX)
+ if (host_keyboard_led_state().compose) return false;
+# endif
+# if defined(KANA_LOCK_INDEX)
+ if (host_keyboard_led_state().kana) return false;
+# endif
+ return true;
+}
+# endif
+
#endif
diff --git a/keyboards/keychron/bluetooth/indicator.h b/keyboards/keychron/bluetooth/indicator.h
index d09cf3c7cf..17bda1e65a 100644
--- a/keyboards/keychron/bluetooth/indicator.h
+++ b/keyboards/keychron/bluetooth/indicator.h
@@ -81,7 +81,7 @@ bool indicator_hook_key(uint16_t keycode);
void indicator_enable(void);
void indicator_disable(void);
void indicator_stop(void);
-bool indicator_is_backlit_enabled_eeprom(void);
+void indicator_eeconfig_reload(void);
bool indicator_is_running(void);
void indicator_battery_low_enable(bool enable);
diff --git a/keyboards/keychron/bluetooth/lpm.c b/keyboards/keychron/bluetooth/lpm.c
index 84f629a672..62e78d03b1 100644
--- a/keyboards/keychron/bluetooth/lpm.c
+++ b/keyboards/keychron/bluetooth/lpm.c
@@ -41,7 +41,11 @@ static matrix_row_t empty_matrix[MATRIX_ROWS] = {0};
void lpm_init(void) {
#ifdef USB_POWER_SENSE_PIN
+# if (USB_POWER_CONNECTED_LEVEL == 0)
setPinInputHigh(USB_POWER_SENSE_PIN);
+# else
+ setPinInputLow(USB_POWER_SENSE_PIN);
+# endif
#endif
lpm_timer_reset();
}
diff --git a/keyboards/keychron/bluetooth/lpm_stm32l432.c b/keyboards/keychron/bluetooth/lpm_stm32l432.c
index a871a1b53c..10fe9f5ceb 100644
--- a/keyboards/keychron/bluetooth/lpm_stm32l432.c
+++ b/keyboards/keychron/bluetooth/lpm_stm32l432.c
@@ -192,12 +192,6 @@ static inline void lpm_wakeup(void) {
PWR->SCR |= PWR_SCR_CWUF;
PWR->SCR |= PWR_SCR_CSBF;
-#if defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE)
- /* Remove USB isolation.*/
- PWR->CR2 |= PWR_CR2_USV; /* PWR_CR2_USV is available on STM32L4x2xx and STM32L4x3xx devices only. */
- usb_start(&USBD1);
-#endif
-
/* TIMx is disable during stop/standby/sleep mode, init after wakeup */
stInit();
timer_init();
@@ -211,8 +205,21 @@ static inline void lpm_wakeup(void) {
}
}
palDisableLineEvent(BLUETOOTH_INT_INPUT_PIN);
+
+#ifdef USB_POWER_SENSE_PIN
palDisableLineEvent(USB_POWER_SENSE_PIN);
+#if defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE)
+ if (usb_power_connected()) {
+ /* Remove USB isolation.*/
+ //PWR->CR2 |= PWR_CR2_USV; /* PWR_CR2_USV is available on STM32L4x2xx and STM32L4x3xx devices only. */
+ usb_power_connect();
+ usb_start(&USBD1);
+ }
+#endif
+
+#endif
+
#if defined(DIP_SWITCH_PINS)
dip_switch_init();
dip_switch_read(true);
@@ -222,6 +229,7 @@ static inline void lpm_wakeup(void) {
rtcSTM32SetPeriodicWakeup(&RTCD1, NULL);
nvicDisableVector(STM32_EXTI20_NUMBER);
#endif
+
}
/*
diff --git a/keyboards/keychron/k8_pro/k8_pro.c b/keyboards/keychron/k8_pro/k8_pro.c
index 58b1e70779..19852b0c06 100644
--- a/keyboards/keychron/k8_pro/k8_pro.c
+++ b/keyboards/keychron/k8_pro/k8_pro.c
@@ -67,7 +67,11 @@ bool dip_switch_update_kb(uint8_t index, bool active) {
return true;
}
-bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+#ifdef BLUETOOTH_ENABLE
+bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record) {
+#else
+bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
+#endif
static uint8_t host_idx = 0;
switch (keycode) {
@@ -136,7 +140,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
-void keyboard_post_init_user(void) {
+void keyboard_post_init_kb(void) {
dip_switch_read(true);
#ifdef BLUETOOTH_ENABLE
@@ -158,9 +162,11 @@ void keyboard_post_init_user(void) {
#ifdef BLUETOOTH_ENABLE
writePin(H3, HOST_LED_PIN_ON_STATE);
# endif
+
+ keyboard_post_init_user();
}
-void matrix_scan_user(void) {
+void matrix_scan_kb(void) {
if (power_on_indicator_timer_buffer) {
if (sync_timer_elapsed32(power_on_indicator_timer_buffer) > POWER_ON_LED_DURATION) {
power_on_indicator_timer_buffer = 0;
@@ -184,6 +190,7 @@ void matrix_scan_user(void) {
#ifdef FACTORY_RESET_TASK
FACTORY_RESET_TASK();
# endif
+ matrix_scan_user();
}
#ifdef BLUETOOTH_ENABLE
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index 67898d5f18..b421480d41 100644
--- a/quantum/led_matrix/led_matrix.c
+++ b/quantum/led_matrix/led_matrix.c
@@ -87,6 +87,9 @@ const led_point_t k_led_matrix_center = LED_MATRIX_CENTER;
# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2
#endif
+#if defined(LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) && (LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL >= LED_MATRIX_MAXIMUM_BRIGHTNESS)
+# pragma error("LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL must be less than LED_MATRIX_MAXIMUM_BRIGHTNESS")
+#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;
@@ -101,7 +104,6 @@ last_hit_t g_last_hit_tracker;
#ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE
static bool driver_shutdown = false;
#endif
-static uint8_t led_enable_eeprom = false;
static bool suspend_state = false;
static uint8_t led_last_enable = UINT8_MAX;
static uint8_t led_last_effect = UINT8_MAX;
@@ -125,6 +127,8 @@ const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
EECONFIG_DEBOUNCE_HELPER(led_matrix, EECONFIG_LED_MATRIX, led_matrix_eeconfig);
+void led_matrix_increase_val_helper(bool write_to_eeprom);
+
void eeconfig_update_led_matrix(void) {
eeconfig_flush_led_matrix(true);
}
@@ -413,11 +417,6 @@ void led_matrix_task(void) {
}
}
-static inline void led_enable_state_backup(void) {
- dprintf("led_enable_state_backup\n");
- led_enable_eeprom = led_matrix_eeconfig.enable;
-}
-
void led_matrix_indicators(void) {
led_matrix_indicators_kb();
led_matrix_indicators_user();
@@ -478,7 +477,6 @@ void led_matrix_init(void) {
dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
eeconfig_update_led_matrix_default();
}
- led_enable_state_backup();
eeconfig_debug_led_matrix(); // display current eeprom values
}
@@ -500,8 +498,12 @@ void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
led_matrix_eeconfig.enable ^= 1;
led_task_state = STARTING;
eeconfig_flag_led_matrix(write_to_eeprom);
- if (write_to_eeprom) led_enable_state_backup();
dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable);
+#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL
+ while (led_matrix_eeconfig.enable && led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
+ led_matrix_increase_val_helper(write_to_eeprom);
+ }
+#endif
}
void led_matrix_toggle_noeeprom(void) {
led_matrix_toggle_eeprom_helper(false);
@@ -513,18 +515,26 @@ void led_matrix_toggle(void) {
void led_matrix_enable(void) {
led_matrix_enable_noeeprom();
eeconfig_flag_led_matrix(true);
- led_enable_state_backup();
+#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL
+ while (led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
+ led_matrix_increase_val_helper(true);
+ }
+#endif
}
void led_matrix_enable_noeeprom(void) {
if (!led_matrix_eeconfig.enable) led_task_state = STARTING;
led_matrix_eeconfig.enable = 1;
+#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL
+ while (led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
+ led_matrix_increase_val_helper(false);
+ }
+#endif
}
void led_matrix_disable(void) {
led_matrix_disable_noeeprom();
eeconfig_flag_led_matrix(true);
- led_enable_state_backup();
}
void led_matrix_disable_noeeprom(void) {
@@ -536,11 +546,6 @@ uint8_t led_matrix_is_enabled(void) {
return led_matrix_eeconfig.enable;
}
-
-uint8_t led_matrix_is_enabled_eeprom(void) {
- return led_enable_eeprom;
-}
-
void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
if (!led_matrix_eeconfig.enable) {
return;
@@ -611,8 +616,8 @@ uint8_t led_matrix_get_val(void) {
void led_matrix_increase_val_helper(bool write_to_eeprom) {
#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL
if (!led_matrix_eeconfig.enable) {
- dprintf("increase_val to enable");
led_matrix_toggle_eeprom_helper(write_to_eeprom);
+ return;
}
#endif
led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom);
@@ -628,7 +633,6 @@ void led_matrix_decrease_val_helper(bool write_to_eeprom) {
led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom);
#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL
if (led_matrix_eeconfig.enable && led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
- dprintf("decrease_val to disable\n");
led_matrix_toggle_eeprom_helper(write_to_eeprom);
}
#endif
diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h
index 936083c259..d5da114c92 100644
--- a/quantum/led_matrix/led_matrix.h
+++ b/quantum/led_matrix/led_matrix.h
@@ -143,7 +143,6 @@ void led_matrix_enable_noeeprom(void);
void led_matrix_disable(void);
void led_matrix_disable_noeeprom(void);
uint8_t led_matrix_is_enabled(void);
-uint8_t led_matrix_is_enabled_eeprom(void);
void led_matrix_mode(uint8_t mode);
void led_matrix_mode_noeeprom(uint8_t mode);
uint8_t led_matrix_get_mode(void);
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c
index 92da08b31c..1ba1686b44 100644
--- a/quantum/rgb_matrix/rgb_matrix.c
+++ b/quantum/rgb_matrix/rgb_matrix.c
@@ -110,6 +110,10 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) {
# define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2
#endif
+#if defined(RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) && (RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL >= RGB_MATRIX_MAXIMUM_BRIGHTNESS)
+# pragma error("RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL must be less than RGB_MATRIX_MAXIMUM_BRIGHTNESS")
+#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;
@@ -124,7 +128,6 @@ last_hit_t g_last_hit_tracker;
#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE
static bool driver_shutdown = false;
#endif
-static uint8_t rgb_enable_eeprom = false;
static bool suspend_state = false;
static uint8_t rgb_last_enable = UINT8_MAX;
static uint8_t rgb_last_effect = UINT8_MAX;
@@ -148,6 +151,8 @@ const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
EECONFIG_DEBOUNCE_HELPER(rgb_matrix, EECONFIG_RGB_MATRIX, rgb_matrix_config);
+void rgb_matrix_increase_val_helper(bool write_to_eeprom);
+
void eeconfig_update_rgb_matrix(void) {
eeconfig_flush_rgb_matrix(true);
}
@@ -473,11 +478,6 @@ void rgb_matrix_task(void) {
}
}
-static inline void rgb_enable_state_backup(void) {
- dprintf("rgb_enable_state_backup\n");
- rgb_enable_eeprom = rgb_matrix_config.enable;
-}
-
void rgb_matrix_indicators(void) {
rgb_matrix_indicators_kb();
rgb_matrix_indicators_user();
@@ -538,7 +538,6 @@ void rgb_matrix_init(void) {
dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
eeconfig_update_rgb_matrix_default();
}
- rgb_enable_state_backup();
eeconfig_debug_rgb_matrix(); // display current eeprom values
}
@@ -560,8 +559,12 @@ void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
rgb_matrix_config.enable ^= 1;
rgb_task_state = STARTING;
eeconfig_flag_rgb_matrix(write_to_eeprom);
- if (write_to_eeprom) rgb_enable_state_backup();
dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable);
+#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL
+ while (rgb_matrix_config.enable && rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
+ rgb_matrix_increase_val_helper(write_to_eeprom);
+ }
+#endif
}
void rgb_matrix_toggle_noeeprom(void) {
rgb_matrix_toggle_eeprom_helper(false);
@@ -573,18 +576,26 @@ void rgb_matrix_toggle(void) {
void rgb_matrix_enable(void) {
rgb_matrix_enable_noeeprom();
eeconfig_flag_rgb_matrix(true);
- rgb_enable_state_backup();
+#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL
+ while (rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
+ rgb_matrix_increase_val_helper(true);
+ }
+#endif
}
void rgb_matrix_enable_noeeprom(void) {
if (!rgb_matrix_config.enable) rgb_task_state = STARTING;
rgb_matrix_config.enable = 1;
+#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL
+ while (rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
+ rgb_matrix_increase_val_helper(false);
+ }
+#endif
}
void rgb_matrix_disable(void) {
rgb_matrix_disable_noeeprom();
eeconfig_flag_rgb_matrix(true);
- rgb_enable_state_backup();
}
void rgb_matrix_disable_noeeprom(void) {
@@ -596,10 +607,6 @@ uint8_t rgb_matrix_is_enabled(void) {
return rgb_matrix_config.enable;
}
-uint8_t rgb_matrix_is_enabled_eeprom(void) {
- return rgb_enable_eeprom;
-}
-
void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
if (!rgb_matrix_config.enable) {
return;
@@ -721,8 +728,8 @@ void rgb_matrix_decrease_sat(void) {
void rgb_matrix_increase_val_helper(bool write_to_eeprom) {
#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL
if (!rgb_matrix_config.enable) {
- dprintf("increase_val to enable");
rgb_matrix_toggle_eeprom_helper(write_to_eeprom);
+ return;
}
#endif
rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom);
@@ -738,7 +745,6 @@ void rgb_matrix_decrease_val_helper(bool write_to_eeprom) {
rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom);
#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL
if (rgb_matrix_config.enable && rgb_matrix_config.hsv.v <= RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
- dprintf("decrease_val to disable\n");
rgb_matrix_toggle_eeprom_helper(write_to_eeprom);
}
#endif
diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h
index 3b11cf7781..dca07cf367 100644
--- a/quantum/rgb_matrix/rgb_matrix.h
+++ b/quantum/rgb_matrix/rgb_matrix.h
@@ -154,7 +154,6 @@ void rgb_matrix_enable_noeeprom(void);
void rgb_matrix_disable(void);
void rgb_matrix_disable_noeeprom(void);
uint8_t rgb_matrix_is_enabled(void);
-uint8_t rgb_matrix_is_enabled_eeprom(void);
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/via.c b/quantum/via.c
index f70cf26347..83239ae773 100644
--- a/quantum/via.c
+++ b/quantum/via.c
@@ -604,7 +604,17 @@ void via_qmk_rgb_matrix_set_value(uint8_t *data) {
uint8_t *value_data = &(data[1]);
switch (*value_id) {
case id_qmk_rgblight_brightness:
+#ifdef RGB_MATRIX_TURN_OFF_VAL
+ if (!rgb_matrix_is_enabled() && value_data[0] >= RGB_MATRIX_TURN_OFF_VAL) {
+ rgb_matrix_toggle_noeeprom();
+ }
+#endif
rgb_matrix_sethsv_noeeprom(rgb_matrix_get_hue(), rgb_matrix_get_sat(), scale8(value_data[0], RGB_MATRIX_MAXIMUM_BRIGHTNESS));
+#ifdef RGB_MATRIX_TURN_OFF_VAL
+ if (rgb_matrix_is_enabled() && value_data[0] < RGB_MATRIX_TURN_OFF_VAL) {
+ rgb_matrix_toggle_noeeprom();
+ }
+#endif
break;
case id_qmk_rgblight_effect:
rgb_matrix_mode_noeeprom(value_data[0]);