Skip to content

Commit

Permalink
Add multithreadedness for lighting options
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Dec 18, 2024
1 parent 5bc8cbb commit 88fcdd9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
4 changes: 4 additions & 0 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 61 additions & 14 deletions quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 88fcdd9

Please sign in to comment.