qmk_me

QMK Firmware userspace, keyboards, & keymaps
git clone git://git.pngu.org.org/qmk_me
Log | Files | Refs | Submodules | README | LICENSE

commit a26f51991859e5e43b346ba9b9817cddf0baa592
parent 18f58aa012daf51008c8bcf3f54d135c3a7c06cb
Author: Jack Sangdahl <jack@pngu.org>
Date:   Sun,  7 Dec 2025 09:31:18 +0100

Migrate RGB Matrix fade functionality to module

Diffstat:
Mkeyboards/boardsource/beiwagon/keymaps/jack/keymap.json | 1+
Mkeyboards/splitkb/kyria/keymaps/jack/keymap.json | 1+
Mkeyboards/sweep/keymaps/jack/keymap.json | 1+
Musers/jack/config.h | 3++-
Musers/jack/jack.c | 6------
Musers/jack/jack.h | 6------
Dusers/jack/rgb_matrix.c | 105-------------------------------------------------------------------------------
Musers/jack/rules.mk | 2+-
8 files changed, 6 insertions(+), 119 deletions(-)

diff --git a/keyboards/boardsource/beiwagon/keymaps/jack/keymap.json b/keyboards/boardsource/beiwagon/keymaps/jack/keymap.json @@ -1,5 +1,6 @@ { "modules": [ + "getreuer/lumino", "getreuer/palettefx" ] } diff --git a/keyboards/splitkb/kyria/keymaps/jack/keymap.json b/keyboards/splitkb/kyria/keymaps/jack/keymap.json @@ -1,5 +1,6 @@ { "modules": [ + "getreuer/lumino", "getreuer/palettefx" ] } diff --git a/keyboards/sweep/keymaps/jack/keymap.json b/keyboards/sweep/keymaps/jack/keymap.json @@ -1,5 +1,6 @@ { "modules": [ + "getreuer/lumino", "getreuer/palettefx" ] } diff --git a/users/jack/config.h b/users/jack/config.h @@ -36,7 +36,8 @@ #ifdef RGB_MATRIX_ENABLE #define RGB_MATRIX_SLEEP -#define RGB_MATRIX_FADE_TIMEOUT 180000 +#define LUMINO_LONG_TIMEOUT (1000 * 60) * 3 +#define LUMINO_SOON_TIMEOUT 0 #define RGB_MATRIX_KEYPRESSES #define PALETTEFX_ENABLE_ALL_EFFECTS #define PALETTEFX_ENABLE_ALL_PALETTES diff --git a/users/jack/jack.c b/users/jack/jack.c @@ -4,9 +4,6 @@ __attribute__((weak)) void housekeeping_task_keymap(void) {} void housekeeping_task_user(void) { -#ifdef RGB_MATRIX_ENABLE - housekeeping_task_rgb_matrix(); -#endif #ifdef QUANTUM_PAINTER_ENABLE housekeeping_task_qp(); #endif @@ -20,9 +17,6 @@ void keyboard_post_init_user(void) { rgblight_sethsv_noeeprom(HSV_CYAN); rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); #endif -#ifdef RGB_MATRIX_ENABLE - keyboard_post_init_rgb_matrix(); -#endif #ifdef QUANTUM_PAINTER_ENABLE keyboard_post_init_qp(); #endif diff --git a/users/jack/jack.h b/users/jack/jack.h @@ -31,12 +31,6 @@ enum combos { bool process_record_unicode(uint16_t keycode, keyrecord_t *record); #endif -#ifdef RGB_MATRIX_ENABLE -void housekeeping_task_rgb_matrix(void); -void keyboard_post_init_rgb_matrix(void); -bool process_record_rgb_matrix(uint16_t keycode, keyrecord_t *record); -#endif - #ifdef TAP_DANCE_ENABLE void em_dash_mins(tap_dance_state_t *state, void *user_data); void ply_nxt_prv(tap_dance_state_t *state, void *user_data); diff --git a/users/jack/rgb_matrix.c b/users/jack/rgb_matrix.c @@ -1,105 +0,0 @@ -// Copyright 2025 jack@pngu.org -// SPDX-License-Identifier: GPL-2.0-or-later -#include "jack.h" -#include <lib/lib8tion/lib8tion.h> - -#define FADE_TRANSITION 500 -#define FRAME_PERIOD 16 - -enum { - ANIM_SLEEP, - ANIM_WAKE, - ANIM_TIME_SCALE_Q6 = (255 * 64 + FADE_TRANSITION / 2) / FADE_TRANSITION -}; - -static bool illuminated = false; -static uint8_t anim_start_value = 0; -static uint8_t anim_end_value = 0; -static uint8_t anim_type = ANIM_SLEEP; -static uint8_t awake_value = 0; -static uint16_t anim_update_time = 0; -static uint16_t anim_start_time = 0; -static uint32_t sleep_time = 0; - -static uint8_t read_curr_value(void) { - return rgb_matrix_is_enabled() ? rgb_matrix_get_val() : 0; -} - -static void update_curr_value(uint8_t value) { - if (value > 0 && !rgb_matrix_is_enabled()) - rgb_matrix_enable_noeeprom(); - hsv_t hsv = rgb_matrix_get_hsv(); - hsv.v = value; - rgb_matrix_sethsv_noeeprom(hsv.h, hsv.s, hsv.v); -} - -static void update_sleep_timer(void) { - sleep_time = (timer_read32() + UINT32_C(RGB_MATRIX_FADE_TIMEOUT)) | 1; -} - -static void anim_play(uint8_t type, uint8_t end_value) { - const uint8_t start_value = read_curr_value(); - if (start_value != end_value) { - anim_start_time = timer_read() | 1; - anim_update_time = anim_start_time; - anim_start_value = start_value; - anim_end_value = end_value; - anim_type = type; - illuminated = true; - } -} - -void housekeeping_task_rgb_matrix(void) { - if (!illuminated) - return; - if (anim_start_time) { - const uint16_t curr_time = timer_read(); - if (timer_expired(curr_time, anim_update_time)) { - uint8_t value; - const uint16_t elapsed_time = curr_time - anim_start_time; - const uint8_t t = - elapsed_time <= FADE_TRANSITION - ? (((uint16_t)elapsed_time * ANIM_TIME_SCALE_Q6) >> 6) - : UINT8_MAX; - const uint8_t weight = ease8InOutCubic(t); - if (weight < UINT8_MAX) { - value = lerp8by8(anim_start_value, anim_end_value, weight); - anim_update_time = curr_time + FRAME_PERIOD; - } else { - anim_start_time = 0; - value = anim_end_value; - switch (anim_type) { - case ANIM_SLEEP: - illuminated = false; - break; - case ANIM_WAKE: - update_sleep_timer(); - break; - } - } - update_curr_value(value); - } - } else if (sleep_time && timer_expired32(timer_read32(), sleep_time)) { - awake_value = read_curr_value(); - anim_play(ANIM_SLEEP, 0); - } -} - -void keyboard_post_init_rgb_matrix(void) { - if (rgb_matrix_is_enabled()) { - awake_value = rgb_matrix_get_val(); - update_curr_value(0); - anim_play(ANIM_WAKE, awake_value); - } -} - -bool process_record_rgb_matrix(uint16_t keycode, keyrecord_t *record) { - if (record->event.pressed) - if (awake_value > 0) { - if (!illuminated || (anim_start_time && !anim_end_value)) - anim_play(ANIM_WAKE, awake_value); - else - update_sleep_timer(); - } - return true; -} diff --git a/users/jack/rules.mk b/users/jack/rules.mk @@ -25,7 +25,7 @@ ifeq ($(strip $(OLED_ENABLE)), yes) endif ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) - SRC += $(USER_PATH)/colour.c $(USER_PATH)/rgb_matrix.c + SRC += $(USER_PATH)/colour.c endif ifeq ($(strip $(QUANTUM_PAINTER_ENABLE)), yes)