From 671259680d350c007bc80104a342f11faacc931e Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Wed, 4 Dec 2024 18:45:26 -0800 Subject: [PATCH] Add multithreadedness for lighting options --- builddefs/common_features.mk | 4 ++ quantum/keyboard.c | 75 +++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index 0629522daf89..25dec96358a0 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -952,6 +952,10 @@ ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes) endif endif +ifeq ($(strip $(MULTITHREADED_LIGHTING_ENABLE)), yes) + OPT_DEFS += -DMULTITHREADED_LIGHTING_ENABLE +endif + VALID_WS2812_DRIVER_TYPES := bitbang custom i2c pwm spi vendor WS2812_DRIVER ?= bitbang diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 45409319123a..c6ff97f99cc2 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -403,6 +403,45 @@ void quantum_init(void) { layer_state_set_kb((layer_state_t)layer_state); } +#ifdef MULTITHREADED_LIGHTING_ENABLE +static THD_WORKING_AREA(waLightingThread, 1024); +static THD_FUNCTION(LightingThread, arg) { + (void)arg; + chRegSetThreadName("lighting"); +# ifdef LED_MATRIX_ENABLE + led_matrix_init(); +# endif +# ifdef RGB_MATRIX_ENABLE + rgb_matrix_init(); +# endif +# ifdef RGBLIGHT_ENABLE + rgblight_init(); +# endif +# ifdef BACKLIGHT_ENABLE + backlight_init(); +# endif + + while (true) { +# if defined(RGBLIGHT_ENABLE) + rgblight_task(); +# endif + +# ifdef LED_MATRIX_ENABLE + led_matrix_task(); +# endif +# ifdef RGB_MATRIX_ENABLE + rgb_matrix_task(); +# endif +# if defined(BACKLIGHT_ENABLE) +# if defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS) + backlight_task(); +# endif +# endif + chThdSleepMicroseconds(500); + } +} +#endif // MULTITHREADED_EFFECTS_ENABLE + /** \brief keyboard_init * * FIXME: needs doc @@ -428,11 +467,15 @@ void keyboard_init(void) { #ifdef AUDIO_ENABLE audio_init(); #endif -#ifdef LED_MATRIX_ENABLE +#ifdef MULTITHREADED_LIGHTING_ENABLE + chThdCreateStatic(waLightingThread, sizeof(waLightingThread), HIGHPRIO, LightingThread, NULL); +#else +# ifdef LED_MATRIX_ENABLE led_matrix_init(); -#endif -#ifdef RGB_MATRIX_ENABLE +# endif +# ifdef RGB_MATRIX_ENABLE rgb_matrix_init(); +# endif #endif #if defined(UNICODE_COMMON_ENABLE) unicode_input_mode_init(); @@ -449,11 +492,13 @@ void keyboard_init(void) { #ifdef PS2_MOUSE_ENABLE ps2_mouse_init(); #endif -#ifdef BACKLIGHT_ENABLE +#ifndef MULTITHREADED_LIGHTING_ENABLE +# ifdef BACKLIGHT_ENABLE backlight_init(); -#endif -#ifdef RGBLIGHT_ENABLE +# endif +# ifdef RGBLIGHT_ENABLE rgblight_init(); +# endif #endif #ifdef STENO_ENABLE_ALL steno_init(); @@ -682,20 +727,22 @@ void keyboard_task(void) { split_watchdog_task(); #endif -#if defined(RGBLIGHT_ENABLE) +#ifndef MULTITHREADED_LIGHTING_ENABLE +# if defined(RGBLIGHT_ENABLE) rgblight_task(); -#endif +# endif -#ifdef LED_MATRIX_ENABLE +# ifdef LED_MATRIX_ENABLE led_matrix_task(); -#endif -#ifdef RGB_MATRIX_ENABLE +# endif +# ifdef RGB_MATRIX_ENABLE rgb_matrix_task(); -#endif +# endif -#if defined(BACKLIGHT_ENABLE) -# if defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS) +# if defined(BACKLIGHT_ENABLE) +# if defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS) backlight_task(); +# endif # endif #endif