diff options
author | lokher <lokher@gmail.com> | 2022-08-03 16:53:42 +0800 |
---|---|---|
committer | lokher <lokher@gmail.com> | 2022-08-05 14:45:45 +0800 |
commit | 968655c74cc13a1a63320ef795fe436449708429 (patch) | |
tree | b37716e10d16dcf760ba608dc66051cdb47eb31b /quantum | |
parent | 068bfc49de127c1f1305ee7680f51425ca9cd1f1 (diff) |
Add K8 pro
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/keyboard.c | 5 | ||||
-rw-r--r-- | quantum/led_matrix/led_matrix.c | 86 | ||||
-rw-r--r-- | quantum/led_matrix/led_matrix.h | 28 | ||||
-rw-r--r-- | quantum/led_matrix/led_matrix_drivers.c | 94 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix.c | 80 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix.h | 23 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix_drivers.c | 45 | ||||
-rw-r--r-- | quantum/via.c | 6 |
8 files changed, 359 insertions, 8 deletions
diff --git a/quantum/keyboard.c b/quantum/keyboard.c index a65f9d6d18..1a89e70e34 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -257,7 +257,10 @@ __attribute__((weak)) void keyboard_post_init_kb(void) { void keyboard_setup(void) { print_set_sendchar(sendchar); #ifdef EEPROM_DRIVER - eeprom_driver_init(); + if (!eeprom_driver_init()) { + eeconfig_init(); + eeprom_driver_init(); + } #endif matrix_setup(); keyboard_pre_init_kb(); diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 38ed79bed0..07b3bbca30 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -98,6 +98,10 @@ last_hit_t g_last_hit_tracker; #endif // LED_MATRIX_KEYREACTIVE_ENABLED // internals +#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; @@ -105,7 +109,8 @@ static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; static led_task_states led_task_state = SYNCING; #if LED_DISABLE_TIMEOUT > 0 static uint32_t led_anykey_timer; -#endif // LED_DISABLE_TIMEOUT > 0 +static uint32_t led_disable_timeout = LED_DISABLE_TIMEOUT; +#endif // LED_DISABLE_TIMEOUT > 0 // double buffers static uint32_t led_timer_buffer; @@ -227,12 +232,22 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { #endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_LED_MATRIX_TYPING_HEATMAP) } +void led_matrix_none_indicators(void) { + led_matrix_none_indicators_kb(); + led_matrix_none_indicators_user(); +} + +__attribute__((weak)) void led_matrix_none_indicators_kb(void) {} + +__attribute__((weak)) void led_matrix_none_indicators_user(void) {} + static bool led_matrix_none(effect_params_t *params) { if (!params->init) { return false; } led_matrix_set_value_all(0); + led_matrix_none_indicators(); return false; } @@ -343,10 +358,24 @@ static void led_task_flush(uint8_t effect) { // update last trackers after the first full render so we can init over several frames led_last_effect = effect; led_last_enable = led_matrix_eeconfig.enable; +#ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE + // exit from shutdown to if neccesary + if (driver_shutdown) { + led_matrix_driver.exit_shutdown(); + driver_shutdown = false; + } +#endif // update pwm buffers led_matrix_update_pwm_buffers(); +#ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE + // shutdown if neccesary + if (effect == LED_MATRIX_NONE && !driver_shutdown && led_matrix_driver_allow_shutdown()) { + led_matrix_driver_shutdown(); + } +#endif + // next task led_task_state = SYNCING; } @@ -358,8 +387,8 @@ void led_matrix_task(void) { // while suspended and just do a software shutdown. This is a cheap hack for now. bool suspend_backlight = suspend_state || #if LED_DISABLE_TIMEOUT > 0 - (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || -#endif // LED_DISABLE_TIMEOUT > 0 + (led_anykey_timer > led_disable_timeout) || +#endif // LED_DISABLE_TIMEOUT > 0 false; uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode; @@ -384,6 +413,11 @@ 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(); @@ -417,6 +451,9 @@ __attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, void led_matrix_init(void) { led_matrix_driver.init(); +#ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE + driver_shutdown = false; +#endif #ifdef LED_MATRIX_KEYREACTIVE_ENABLED g_last_hit_tracker.count = 0; @@ -441,6 +478,7 @@ 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 } @@ -462,6 +500,7 @@ 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); } void led_matrix_toggle_noeeprom(void) { @@ -474,6 +513,7 @@ void led_matrix_toggle(void) { void led_matrix_enable(void) { led_matrix_enable_noeeprom(); eeconfig_flag_led_matrix(true); + led_enable_state_backup(); } void led_matrix_enable_noeeprom(void) { @@ -484,6 +524,7 @@ void led_matrix_enable_noeeprom(void) { void led_matrix_disable(void) { led_matrix_disable_noeeprom(); eeconfig_flag_led_matrix(true); + led_enable_state_backup(); } void led_matrix_disable_noeeprom(void) { @@ -495,6 +536,11 @@ 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; @@ -563,6 +609,12 @@ 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); + } +#endif led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } void led_matrix_increase_val_noeeprom(void) { @@ -580,6 +632,12 @@ void led_matrix_decrease_val_noeeprom(void) { } void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); +#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(true); + } +#endif } void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { @@ -625,3 +683,25 @@ led_flags_t led_matrix_get_flags(void) { void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; } + +#if LED_DISABLE_TIMEOUT > 0 +void led_matrix_disable_timeout_set(uint32_t timeout) { + led_disable_timeout = timeout; +} +void led_matrix_disable_time_reset(void){ + led_anykey_timer = 0; +} +#endif + +#ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE +void led_matrix_driver_shutdown(void) { + led_matrix_driver.shutdown(); + driver_shutdown = true; +}; + +bool led_matrix_is_driver_shutdown(void) { + return driver_shutdown; +} + +__attribute__((weak)) bool led_matrix_driver_allow_shutdown(void) { return true; }; +#endif
\ No newline at end of file diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index d21f36e295..963992fb55 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -33,6 +33,9 @@ #ifdef IS31FL3733 # include "is31fl3733-simple.h" #endif +#ifdef CKLED2001 +# include "ckled2001-simple.h" +#endif #ifndef LED_MATRIX_LED_FLUSH_LIMIT # define LED_MATRIX_LED_FLUSH_LIMIT 16 @@ -75,6 +78,8 @@ #define LED_MATRIX_TEST_LED_FLAGS() \ if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue +#define LED_DISABLE_TIME_INFINITE (UINT32_MAX) + enum led_matrix_effects { LED_MATRIX_NONE = 0, @@ -114,6 +119,9 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed); void led_matrix_task(void); +void led_matrix_none_indicators_kb(void); +void led_matrix_none_indicators_user(void); + // This runs after another backlight effect and replaces // values already set void led_matrix_indicators(void); @@ -135,6 +143,7 @@ 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); @@ -158,6 +167,19 @@ void led_matrix_decrease_speed(void); void led_matrix_decrease_speed_noeeprom(void); led_flags_t led_matrix_get_flags(void); void led_matrix_set_flags(led_flags_t flags); +#ifdef LED_DISABLE_TIMEOUT +# if LED_DISABLE_TIMEOUT > 0 +void led_matrix_disable_timeout_set(uint32_t timeout); +void led_matrix_disable_time_reset(void); +# endif +#endif + +#ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE +void led_matrix_driver_shutdown(void); +bool led_matrix_is_driver_shutdown(void); +bool led_matrix_driver_allow_shutdown(void); +#endif + typedef struct { /* Perform any initialisation required for the other driver functions to work. */ @@ -169,6 +191,12 @@ typedef struct { void (*set_value_all)(uint8_t value); /* Flush any buffered changes to the hardware. */ void (*flush)(void); +#ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE + /* Shutdown the driver. */ + void (*shutdown)(void); + /* Exit from shutdown state. */ + void (*exit_shutdown)(void); +#endif } led_matrix_driver_t; static inline bool led_matrix_check_finished_leds(uint8_t led_idx) { diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c index 847ca1c310..7a6f3c5767 100644 --- a/quantum/led_matrix/led_matrix_drivers.c +++ b/quantum/led_matrix/led_matrix_drivers.c @@ -25,7 +25,7 @@ * in their own files. */ -#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FLCOMMON) +#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FLCOMMON) || defined(CKLED2001) # include "i2c_master.h" static void init(void) { @@ -78,6 +78,23 @@ static void init(void) { # endif # endif # endif + +# elif defined(CKLED2001) +# if defined(LED_DRIVER_SHUTDOWN_PIN) + setPinOutput(LED_DRIVER_SHUTDOWN_PIN); + writePinHigh(LED_DRIVER_SHUTDOWN_PIN); +# endif + + CKLED2001_init(DRIVER_ADDR_1); +# if defined(DRIVER_ADDR_2) + CKLED2001_init(DRIVER_ADDR_2); +# if defined(DRIVER_ADDR_3) + CKLED2001_init(DRIVER_ADDR_3); +# if defined(DRIVER_ADDR_4) + CKLED2001_init(DRIVER_ADDR_4); +# endif +# endif +# endif # endif for (int index = 0; index < DRIVER_LED_TOTAL; index++) { @@ -87,6 +104,8 @@ static void init(void) { IS31FL3733_set_led_control_register(index, true); # elif defined(IS31FLCOMMON) IS31FL_simple_set_scaling_buffer(index, true); +# elif defined(CKLED2001) + CKLED2001_set_led_control_register(index, true); # endif } @@ -129,6 +148,18 @@ static void init(void) { # endif # endif # endif + +# elif defined(CKLED2001) + CKLED2001_update_led_control_registers(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) + CKLED2001_update_led_control_registers(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + CKLED2001_update_led_control_registers(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + CKLED2001_update_led_control_registers(DRIVER_ADDR_4, 3); +# endif +# endif +# endif # endif } @@ -194,5 +225,66 @@ const led_matrix_driver_t led_matrix_driver = { .set_value = IS31FL_simple_set_brightness, .set_value_all = IS31FL_simple_set_brigntness_all, }; + +# elif defined(CKLED2001) +static void flush(void) { + CKLED2001_update_pwm_buffers(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) + CKLED2001_update_pwm_buffers(DRIVER_ADDR_2, 1); +# if defined(DRIVER_ADDR_3) + CKLED2001_update_pwm_buffers(DRIVER_ADDR_3, 2); +# if defined(DRIVER_ADDR_4) + CKLED2001_update_pwm_buffers(DRIVER_ADDR_4, 3); +# endif +# endif +# endif +} + +# if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) +static void shutdown(void) { +# if defined(LED_DRIVER_SHUTDOWN_PIN) + writePinLow(LED_DRIVER_SHUTDOWN_PIN); +# else + CKLED2001_sw_shutdown(DRIVER_ADDR_1); +# if defined(DRIVER_ADDR_2) + CKLED2001_sw_shutdown(DRIVER_ADDR_2); +# if defined(DRIVER_ADDR_3) + CKLED2001_sw_shutdown(DRIVER_ADDR_3); +# if defined(DRIVER_ADDR_4) + CKLED2001_sw_shutdown(DRIVER_ADDR_4); +# endif +# endif +# endif +# endif +} + +static void exit_shutdown(void) { +# if defined(LED_DRIVER_SHUTDOWN_PIN) + writePinHigh(LED_DRIVER_SHUTDOWN_PIN); +# else + CKLED2001_sw_return_normal(DRIVER_ADDR_1); +# if defined(DRIVER_ADDR_2) + CKLED2001_sw_return_normal(DRIVER_ADDR_2); +# if defined(DRIVER_ADDR_3) + CKLED2001_sw_return_normal(DRIVER_ADDR_3); +# if defined(DRIVER_ADDR_4) + CKLED2001_sw_return_normal(DRIVER_ADDR_4); +# endif +# endif +# endif +# endif +} +# endif + +const led_matrix_driver_t led_matrix_driver = { + .init = init, + .flush = flush, + .set_value = CKLED2001_set_value, + .set_value_all = CKLED2001_set_value_all, +# if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) + .shutdown = shutdown, + .exit_shutdown = exit_shutdown +# endif +}; # endif #endif diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index f721dfc7f2..1f9ad47c81 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -121,6 +121,10 @@ last_hit_t g_last_hit_tracker; #endif // RGB_MATRIX_KEYREACTIVE_ENABLED // internals +#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; @@ -128,7 +132,8 @@ static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; static rgb_task_states rgb_task_state = SYNCING; #if RGB_DISABLE_TIMEOUT > 0 static uint32_t rgb_anykey_timer; -#endif // RGB_DISABLE_TIMEOUT > 0 +static uint32_t rgb_disable_timeout = RGB_DISABLE_TIMEOUT; +#endif // RGB_DISABLE_TIMEOUT > 0 // double buffers static uint32_t rgb_timer_buffer; @@ -279,12 +284,22 @@ void rgb_matrix_test(void) { } } +void rgb_matrix_none_indicators(void) { + rgb_matrix_none_indicators_kb(); + rgb_matrix_none_indicators_user(); +} + +__attribute__((weak)) void rgb_matrix_none_indicators_kb(void) {} + +__attribute__((weak)) void rgb_matrix_none_indicators_user(void) {} + static bool rgb_matrix_none(effect_params_t *params) { if (!params->init) { return false; } rgb_matrix_set_color_all(0, 0, 0); + rgb_matrix_none_indicators(); return false; } @@ -398,9 +413,21 @@ static void rgb_task_flush(uint8_t effect) { // update last trackers after the first full render so we can init over several frames rgb_last_effect = effect; rgb_last_enable = rgb_matrix_config.enable; - +#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE + // exit from shutdown to if neccesary + if (driver_shutdown) { + rgb_matrix_driver.exit_shutdown(); + driver_shutdown = false; + } +#endif // update pwm buffers rgb_matrix_update_pwm_buffers(); +#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE + // shutdown to if neccesary + if (effect == RGB_MATRIX_NONE && !driver_shutdown && rgb_matrix_driver_allow_shutdown()) { + rgb_matrix_driver_shutdown(); + } +#endif // next task rgb_task_state = SYNCING; @@ -413,7 +440,7 @@ void rgb_matrix_task(void) { // while suspended and just do a software shutdown. This is a cheap hack for now. bool suspend_backlight = suspend_state || #if RGB_DISABLE_TIMEOUT > 0 - (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || + (rgb_anykey_timer > rgb_disable_timeout) || #endif // RGB_DISABLE_TIMEOUT > 0 false; @@ -439,6 +466,11 @@ 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(); @@ -472,6 +504,9 @@ __attribute__((weak)) void rgb_matrix_indicators_advanced_user(uint8_t led_min, void rgb_matrix_init(void) { rgb_matrix_driver.init(); +#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE + driver_shutdown = false; +#endif #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED g_last_hit_tracker.count = 0; @@ -496,6 +531,7 @@ 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 } @@ -517,6 +553,7 @@ 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); } void rgb_matrix_toggle_noeeprom(void) { @@ -529,6 +566,7 @@ void rgb_matrix_toggle(void) { void rgb_matrix_enable(void) { rgb_matrix_enable_noeeprom(); eeconfig_flag_rgb_matrix(true); + rgb_enable_state_backup(); } void rgb_matrix_enable_noeeprom(void) { @@ -539,6 +577,7 @@ void rgb_matrix_enable_noeeprom(void) { void rgb_matrix_disable(void) { rgb_matrix_disable_noeeprom(); eeconfig_flag_rgb_matrix(true); + rgb_enable_state_backup(); } void rgb_matrix_disable_noeeprom(void) { @@ -550,6 +589,10 @@ 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; @@ -669,6 +712,12 @@ 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); + } +#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); } void rgb_matrix_increase_val_noeeprom(void) { @@ -680,6 +729,12 @@ void rgb_matrix_increase_val(void) { 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 } void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); @@ -731,3 +786,22 @@ led_flags_t rgb_matrix_get_flags(void) { void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; } + + +#if RGB_DISABLE_TIMEOUT > 0 +void rgb_matrix_disable_timeout_set(uint32_t timeout) { + rgb_disable_timeout = timeout; +} +void rgb_matrix_disable_time_reset(void){ rgb_anykey_timer = 0; } +#endif + +#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE +void rgb_matrix_driver_shutdown(void) { + rgb_matrix_driver.shutdown(); + driver_shutdown = true; +}; + +bool rgb_matrix_is_driver_shutdown(void) { return driver_shutdown; } + +__attribute__((weak)) bool rgb_matrix_driver_allow_shutdown(void) { return true; }; +#endif
\ No newline at end of file diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 359d507a4d..dc3bda53a4 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -88,6 +88,8 @@ #define RGB_MATRIX_TEST_LED_FLAGS() \ if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue +#define RGB_DISABLE_TIME_INFINITE (UINT32_MAX) + enum rgb_matrix_effects { RGB_MATRIX_NONE = 0, @@ -126,6 +128,9 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed); void rgb_matrix_task(void); +void rgb_matrix_none_indicators_kb(void); +void rgb_matrix_none_indicators_user(void); + // This runs after another backlight effect and replaces // colors already set void rgb_matrix_indicators(void); @@ -149,6 +154,7 @@ 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); @@ -183,6 +189,17 @@ void rgb_matrix_decrease_speed(void); void rgb_matrix_decrease_speed_noeeprom(void); led_flags_t rgb_matrix_get_flags(void); void rgb_matrix_set_flags(led_flags_t flags); +#ifdef RGB_DISABLE_TIMEOUT +# if RGB_DISABLE_TIMEOUT > 0 +void rgb_matrix_disable_timeout_set(uint32_t timeout); +void rgb_matrix_disable_time_reset(void); +# endif +#endif +#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE +void rgb_matrix_driver_shutdown(void); +bool rgb_matrix_is_driver_shutdown(void); +bool rgb_matrix_driver_allow_shutdown(void); +#endif #ifndef RGBLIGHT_ENABLE # define eeconfig_update_rgblight_current eeconfig_update_rgb_matrix @@ -237,6 +254,12 @@ typedef struct { void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b); /* Flush any buffered changes to the hardware. */ void (*flush)(void); +#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE + /* Shutdown the driver. */ + void (*shutdown)(void); + /* Exit from shutdown state. */ + void (*exit_shutdown)(void); +#endif } rgb_matrix_driver_t; static inline bool rgb_matrix_check_finished_leds(uint8_t led_idx) { diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index 27fa7369bf..4b02be98d2 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -94,6 +94,11 @@ static void init(void) { # endif # elif defined(CKLED2001) +# if defined(LED_DRIVER_SHUTDOWN_PIN) + setPinOutput(LED_DRIVER_SHUTDOWN_PIN); + writePinHigh(LED_DRIVER_SHUTDOWN_PIN); +# endif + CKLED2001_init(DRIVER_ADDR_1); # if defined(DRIVER_ADDR_2) CKLED2001_init(DRIVER_ADDR_2); @@ -295,11 +300,51 @@ static void flush(void) { # endif } +# if defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) +static void shutdown(void) { +# if defined(LED_DRIVER_SHUTDOWN_PIN) + writePinLow(LED_DRIVER_SHUTDOWN_PIN); +# else + CKLED2001_sw_shutdown(DRIVER_ADDR_1); +# if defined(DRIVER_ADDR_2) + CKLED2001_sw_shutdown(DRIVER_ADDR_2); +# if defined(DRIVER_ADDR_3) + CKLED2001_sw_shutdown(DRIVER_ADDR_3); +# if defined(DRIVER_ADDR_4) + CKLED2001_sw_shutdown(DRIVER_ADDR_4); +# endif +# endif +# endif +# endif +} + +static void exit_shutdown(void) { +# if defined(LED_DRIVER_SHUTDOWN_PIN) + writePinHigh(LED_DRIVER_SHUTDOWN_PIN); +# else + CKLED2001_sw_return_normal(DRIVER_ADDR_1); +# if defined(DRIVER_ADDR_2) + CKLED2001_sw_return_normal(DRIVER_ADDR_2); +# if defined(DRIVER_ADDR_3) + CKLED2001_sw_return_normal(DRIVER_ADDR_3); +# if defined(DRIVER_ADDR_4) + CKLED2001_sw_return_normal(DRIVER_ADDR_4); +# endif +# endif +# endif +# endif +} +# endif + const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, .set_color = CKLED2001_set_color, .set_color_all = CKLED2001_set_color_all, +# if defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) + .shutdown = shutdown, + .exit_shutdown = exit_shutdown +# endif }; # endif diff --git a/quantum/via.c b/quantum/via.c index 320bd5546d..55c4cb66cd 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -396,6 +396,12 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { dynamic_keymap_set_buffer(offset, size, &command_data[3]); break; } +#ifdef RAW_HID_CMD + case RAW_HID_CMD: { + raw_hid_receive_kb(data, length); + return; + } +#endif default: { // The command ID is not known // Return the unhandled state |