diff options
author | Dasky <32983009+daskygit@users.noreply.github.com> | 2023-10-25 22:06:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-25 22:06:51 +0100 |
commit | f2936581473a86c3b72bd744808d57c50ee9bb32 (patch) | |
tree | b6bdc01672f1e75c3efe6ccde5f8638b13b27ed4 /quantum/rgb_matrix | |
parent | 896d3dc497a89f3a5fb7765e735d1f335b86898f (diff) |
RGB/LED matrix use limits size optimisation (#22325)
Diffstat (limited to 'quantum/rgb_matrix')
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix.c | 30 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix.h | 42 |
2 files changed, 43 insertions, 29 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index e56802f164..d93d189827 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -410,6 +410,36 @@ __attribute__((weak)) bool rgb_matrix_indicators_user(void) { return true; } +struct rgb_matrix_limits_t rgb_matrix_get_limits(uint8_t iter) { + struct rgb_matrix_limits_t limits = {0}; +#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT +# if defined(RGB_MATRIX_SPLIT) + limits.led_min_index = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); + limits.led_max_index = limits.led_min_index + RGB_MATRIX_LED_PROCESS_LIMIT; + if (limits.led_max_index > RGB_MATRIX_LED_COUNT) limits.led_max_index = RGB_MATRIX_LED_COUNT; + uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; + if (is_keyboard_left() && (limits.led_max_index > k_rgb_matrix_split[0])) limits.led_max_index = k_rgb_matrix_split[0]; + if (!(is_keyboard_left()) && (limits.led_min_index < k_rgb_matrix_split[0])) limits.led_min_index = k_rgb_matrix_split[0]; +# else + limits.led_min_index = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); + limits.led_max_index = limits.led_min_index + RGB_MATRIX_LED_PROCESS_LIMIT; + if (limits.led_max_index > RGB_MATRIX_LED_COUNT) limits.led_max_index = RGB_MATRIX_LED_COUNT; +# endif +#else +# if defined(RGB_MATRIX_SPLIT) + limits.led_min_index = 0; + limits.led_max_index = RGB_MATRIX_LED_COUNT; + const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; + if (is_keyboard_left() && (limits.led_max_index > k_rgb_matrix_split[0])) limits.led_max_index = k_rgb_matrix_split[0]; + if (!(is_keyboard_left()) && (limits.led_min_index < k_rgb_matrix_split[0])) limits.led_min_index = k_rgb_matrix_split[0]; +# else + limits.led_min_index = 0; + limits.led_max_index = RGB_MATRIX_LED_COUNT; +# endif +#endif + return limits; +} + void rgb_matrix_indicators_advanced(effect_params_t *params) { /* special handling is needed for "params->iter", since it's already been incremented. * Could move the invocations to rgb_task_render, but then it's missing a few checks diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index bba07af79d..9a3ffb8ea3 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -107,35 +107,19 @@ # define RGB_MATRIX_LED_PROCESS_LIMIT ((RGB_MATRIX_LED_COUNT + 4) / 5) #endif -#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT -# if defined(RGB_MATRIX_SPLIT) -# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ - if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; \ - uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ - if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ - if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; -# else -# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ - if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; -# endif -#else -# if defined(RGB_MATRIX_SPLIT) -# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ - uint8_t min = 0; \ - uint8_t max = RGB_MATRIX_LED_COUNT; \ - const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ - if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ - if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; -# else -# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ - uint8_t min = 0; \ - uint8_t max = RGB_MATRIX_LED_COUNT; -# endif -#endif +struct rgb_matrix_limits_t { + uint8_t led_min_index; + uint8_t led_max_index; +}; + +struct rgb_matrix_limits_t rgb_matrix_get_limits(uint8_t iter); + +#define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + struct rgb_matrix_limits_t limits = rgb_matrix_get_limits(iter); \ + uint8_t min = limits.led_min_index; \ + uint8_t max = limits.led_max_index; \ + (void)min; \ + (void)max; #define RGB_MATRIX_USE_LIMITS(min, max) RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter) |