diff options
| author | Ryan <fauxpark@gmail.com> | 2021-06-22 18:26:23 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-22 18:26:23 +1000 |
| commit | d61e5c0027e289ccf48652afa4c442342e7ccf04 (patch) | |
| tree | e8edc86d191a190691b4722f05e32bdc40affc58 /quantum/led_matrix | |
| parent | c03cb4edd7ff73391a0a64f0c4f5e0755e902908 (diff) | |
| download | qmk_firmware-d61e5c0027e289ccf48652afa4c442342e7ccf04.tar.gz qmk_firmware-d61e5c0027e289ccf48652afa4c442342e7ccf04.zip | |
Move LED/RGB Matrix code into their own directories (#13257)
Diffstat (limited to 'quantum/led_matrix')
29 files changed, 1418 insertions, 0 deletions
diff --git a/quantum/led_matrix/animations/alpha_mods_anim.h b/quantum/led_matrix/animations/alpha_mods_anim.h new file mode 100644 index 000000000..a4638fde6 --- /dev/null +++ b/quantum/led_matrix/animations/alpha_mods_anim.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_ALPHAS_MODS | ||
| 2 | LED_MATRIX_EFFECT(ALPHAS_MODS) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | // alphas = val1, mods = val2 | ||
| 6 | bool ALPHAS_MODS(effect_params_t* params) { | ||
| 7 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 8 | |||
| 9 | uint8_t val1 = led_matrix_eeconfig.val; | ||
| 10 | uint8_t val2 = val1 + led_matrix_eeconfig.speed; | ||
| 11 | |||
| 12 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 13 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 14 | if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) { | ||
| 15 | led_matrix_set_value(i, val2); | ||
| 16 | } else { | ||
| 17 | led_matrix_set_value(i, val1); | ||
| 18 | } | ||
| 19 | } | ||
| 20 | return led_max < DRIVER_LED_TOTAL; | ||
| 21 | } | ||
| 22 | |||
| 23 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 24 | #endif // DISABLE_LED_MATRIX_ALPHAS_MODS | ||
diff --git a/quantum/led_matrix/animations/band_anim.h b/quantum/led_matrix/animations/band_anim.h new file mode 100644 index 000000000..f9cb85dc4 --- /dev/null +++ b/quantum/led_matrix/animations/band_anim.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_BAND | ||
| 2 | LED_MATRIX_EFFECT(BAND) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t BAND_math(uint8_t val, uint8_t i, uint8_t time) { | ||
| 6 | int16_t v = val - abs(scale8(g_led_config.point[i].x, 228) + 28 - time) * 8; | ||
| 7 | return scale8(v < 0 ? 0 : v, val); | ||
| 8 | } | ||
| 9 | |||
| 10 | bool BAND(effect_params_t* params) { return effect_runner_i(params, &BAND_math); } | ||
| 11 | |||
| 12 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 13 | #endif // DISABLE_LED_MATRIX_BAND | ||
diff --git a/quantum/led_matrix/animations/band_pinwheel_anim.h b/quantum/led_matrix/animations/band_pinwheel_anim.h new file mode 100644 index 000000000..d3144bffb --- /dev/null +++ b/quantum/led_matrix/animations/band_pinwheel_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_BAND_PINWHEEL | ||
| 2 | LED_MATRIX_EFFECT(BAND_PINWHEEL) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t BAND_PINWHEEL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t time) { return scale8(val - time - atan2_8(dy, dx) * 3, val); } | ||
| 6 | |||
| 7 | bool BAND_PINWHEEL(effect_params_t* params) { return effect_runner_dx_dy(params, &BAND_PINWHEEL_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_BAND_PINWHEEL | ||
diff --git a/quantum/led_matrix/animations/band_spiral_anim.h b/quantum/led_matrix/animations/band_spiral_anim.h new file mode 100644 index 000000000..defbe6967 --- /dev/null +++ b/quantum/led_matrix/animations/band_spiral_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_BAND_SPIRAL | ||
| 2 | LED_MATRIX_EFFECT(BAND_SPIRAL) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t BAND_SPIRAL_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(val + dist - time - atan2_8(dy, dx), val); } | ||
| 6 | |||
| 7 | bool BAND_SPIRAL(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &BAND_SPIRAL_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_BAND_SPIRAL | ||
diff --git a/quantum/led_matrix/animations/breathing_anim.h b/quantum/led_matrix/animations/breathing_anim.h new file mode 100644 index 000000000..4f49f5069 --- /dev/null +++ b/quantum/led_matrix/animations/breathing_anim.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_BREATHING | ||
| 2 | LED_MATRIX_EFFECT(BREATHING) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | bool BREATHING(effect_params_t* params) { | ||
| 6 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 7 | |||
| 8 | uint8_t val = led_matrix_eeconfig.val; | ||
| 9 | uint16_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 8); | ||
| 10 | val = scale8(abs8(sin8(time) - 128) * 2, val); | ||
| 11 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 12 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 13 | led_matrix_set_value(i, val); | ||
| 14 | } | ||
| 15 | return led_max < DRIVER_LED_TOTAL; | ||
| 16 | } | ||
| 17 | |||
| 18 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 19 | #endif // DISABLE_LED_MATRIX_BREATHING | ||
diff --git a/quantum/led_matrix/animations/cycle_left_right_anim.h b/quantum/led_matrix/animations/cycle_left_right_anim.h new file mode 100644 index 000000000..c426d02fd --- /dev/null +++ b/quantum/led_matrix/animations/cycle_left_right_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT | ||
| 2 | LED_MATRIX_EFFECT(CYCLE_LEFT_RIGHT) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t CYCLE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].x - time, val); } | ||
| 6 | |||
| 7 | bool CYCLE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &CYCLE_LEFT_RIGHT_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_CYCLE_LEFT_RIGHT | ||
diff --git a/quantum/led_matrix/animations/cycle_out_in_anim.h b/quantum/led_matrix/animations/cycle_out_in_anim.h new file mode 100644 index 000000000..55527556f --- /dev/null +++ b/quantum/led_matrix/animations/cycle_out_in_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_CYCLE_OUT_IN | ||
| 2 | LED_MATRIX_EFFECT(CYCLE_OUT_IN) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t CYCLE_OUT_IN_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time) { return scale8(3 * dist / 2 + time, val); } | ||
| 6 | |||
| 7 | bool CYCLE_OUT_IN(effect_params_t* params) { return effect_runner_dx_dy_dist(params, &CYCLE_OUT_IN_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_CYCLE_OUT_IN | ||
diff --git a/quantum/led_matrix/animations/cycle_up_down_anim.h b/quantum/led_matrix/animations/cycle_up_down_anim.h new file mode 100644 index 000000000..d97de0d1e --- /dev/null +++ b/quantum/led_matrix/animations/cycle_up_down_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_CYCLE_UP_DOWN | ||
| 2 | LED_MATRIX_EFFECT(CYCLE_UP_DOWN) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t CYCLE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(g_led_config.point[i].y - time, val); } | ||
| 6 | |||
| 7 | bool CYCLE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &CYCLE_UP_DOWN_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_CYCLE_UP_DOWN | ||
diff --git a/quantum/led_matrix/animations/dual_beacon_anim.h b/quantum/led_matrix/animations/dual_beacon_anim.h new file mode 100644 index 000000000..e1bc5ae46 --- /dev/null +++ b/quantum/led_matrix/animations/dual_beacon_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_DUAL_BEACON | ||
| 2 | LED_MATRIX_EFFECT(DUAL_BEACON) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t DUAL_BEACON_math(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time) { return scale8(((g_led_config.point[i].y - k_led_matrix_center.y) * cos + (g_led_config.point[i].x - k_led_matrix_center.x) * sin) / 128, val); } | ||
| 6 | |||
| 7 | bool DUAL_BEACON(effect_params_t* params) { return effect_runner_sin_cos_i(params, &DUAL_BEACON_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_DUAL_BEACON | ||
diff --git a/quantum/led_matrix/animations/led_matrix_effects.inc b/quantum/led_matrix/animations/led_matrix_effects.inc new file mode 100644 index 000000000..ad1f46b24 --- /dev/null +++ b/quantum/led_matrix/animations/led_matrix_effects.inc | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | // Add your new core led matrix effect here, order determines enum order | ||
| 2 | #include "solid_anim.h" | ||
| 3 | #include "alpha_mods_anim.h" | ||
| 4 | #include "breathing_anim.h" | ||
| 5 | #include "band_anim.h" | ||
| 6 | #include "band_pinwheel_anim.h" | ||
| 7 | #include "band_spiral_anim.h" | ||
| 8 | #include "cycle_left_right_anim.h" | ||
| 9 | #include "cycle_up_down_anim.h" | ||
| 10 | #include "cycle_out_in_anim.h" | ||
| 11 | #include "dual_beacon_anim.h" | ||
| 12 | #include "solid_reactive_simple_anim.h" | ||
| 13 | #include "solid_reactive_wide.h" | ||
| 14 | #include "solid_reactive_cross.h" | ||
| 15 | #include "solid_reactive_nexus.h" | ||
| 16 | #include "solid_splash_anim.h" | ||
| 17 | #include "wave_left_right_anim.h" | ||
| 18 | #include "wave_up_down_anim.h" | ||
diff --git a/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h b/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h new file mode 100644 index 000000000..ef97631b9 --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | typedef uint8_t (*dx_dy_f)(uint8_t val, int16_t dx, int16_t dy, uint8_t time); | ||
| 4 | |||
| 5 | bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) { | ||
| 6 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 7 | |||
| 8 | uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2); | ||
| 9 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 10 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 11 | int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x; | ||
| 12 | int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y; | ||
| 13 | led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, time)); | ||
| 14 | } | ||
| 15 | return led_max < DRIVER_LED_TOTAL; | ||
| 16 | } | ||
diff --git a/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h b/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h new file mode 100644 index 000000000..5ef5938be --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | typedef uint8_t (*dx_dy_dist_f)(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint8_t time); | ||
| 4 | |||
| 5 | bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) { | ||
| 6 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 7 | |||
| 8 | uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 2); | ||
| 9 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 10 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 11 | int16_t dx = g_led_config.point[i].x - k_led_matrix_center.x; | ||
| 12 | int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y; | ||
| 13 | uint8_t dist = sqrt16(dx * dx + dy * dy); | ||
| 14 | led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, dist, time)); | ||
| 15 | } | ||
| 16 | return led_max < DRIVER_LED_TOTAL; | ||
| 17 | } | ||
diff --git a/quantum/led_matrix/animations/runners/effect_runner_i.h b/quantum/led_matrix/animations/runners/effect_runner_i.h new file mode 100644 index 000000000..b3015759b --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_i.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | typedef uint8_t (*i_f)(uint8_t val, uint8_t i, uint8_t time); | ||
| 4 | |||
| 5 | bool effect_runner_i(effect_params_t* params, i_f effect_func) { | ||
| 6 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 7 | |||
| 8 | uint8_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 4); | ||
| 9 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 10 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 11 | led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, i, time)); | ||
| 12 | } | ||
| 13 | return led_max < DRIVER_LED_TOTAL; | ||
| 14 | } | ||
diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive.h b/quantum/led_matrix/animations/runners/effect_runner_reactive.h new file mode 100644 index 000000000..4369ea8c4 --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_reactive.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 4 | |||
| 5 | typedef uint8_t (*reactive_f)(uint8_t val, uint16_t offset); | ||
| 6 | |||
| 7 | bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { | ||
| 8 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 9 | |||
| 10 | uint16_t max_tick = 65535 / led_matrix_eeconfig.speed; | ||
| 11 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 12 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 13 | uint16_t tick = max_tick; | ||
| 14 | // Reverse search to find most recent key hit | ||
| 15 | for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { | ||
| 16 | if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { | ||
| 17 | tick = g_last_hit_tracker.tick[j]; | ||
| 18 | break; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | uint16_t offset = scale16by8(tick, led_matrix_eeconfig.speed); | ||
| 23 | led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, offset)); | ||
| 24 | } | ||
| 25 | return led_max < DRIVER_LED_TOTAL; | ||
| 26 | } | ||
| 27 | |||
| 28 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h new file mode 100644 index 000000000..d6eb9731e --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 4 | |||
| 5 | typedef uint8_t (*reactive_splash_f)(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick); | ||
| 6 | |||
| 7 | bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, reactive_splash_f effect_func) { | ||
| 8 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 9 | |||
| 10 | uint8_t count = g_last_hit_tracker.count; | ||
| 11 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 12 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 13 | uint8_t val = 0; | ||
| 14 | for (uint8_t j = start; j < count; j++) { | ||
| 15 | int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; | ||
| 16 | int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; | ||
| 17 | uint8_t dist = sqrt16(dx * dx + dy * dy); | ||
| 18 | uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], led_matrix_eeconfig.speed); | ||
| 19 | val = effect_func(val, dx, dy, dist, tick); | ||
| 20 | } | ||
| 21 | led_matrix_set_value(i, scale8(val, led_matrix_eeconfig.val)); | ||
| 22 | } | ||
| 23 | return led_max < DRIVER_LED_TOTAL; | ||
| 24 | } | ||
| 25 | |||
| 26 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h b/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h new file mode 100644 index 000000000..4a5219abd --- /dev/null +++ b/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | typedef uint8_t (*sin_cos_i_f)(uint8_t val, int8_t sin, int8_t cos, uint8_t i, uint8_t time); | ||
| 4 | |||
| 5 | bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) { | ||
| 6 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 7 | |||
| 8 | uint16_t time = scale16by8(g_led_timer, led_matrix_eeconfig.speed / 4); | ||
| 9 | int8_t cos_value = cos8(time) - 128; | ||
| 10 | int8_t sin_value = sin8(time) - 128; | ||
| 11 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 12 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 13 | led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, cos_value, sin_value, i, time)); | ||
| 14 | } | ||
| 15 | return led_max < DRIVER_LED_TOTAL; | ||
| 16 | } | ||
diff --git a/quantum/led_matrix/animations/runners/led_matrix_runners.inc b/quantum/led_matrix/animations/runners/led_matrix_runners.inc new file mode 100644 index 000000000..c09022bb0 --- /dev/null +++ b/quantum/led_matrix/animations/runners/led_matrix_runners.inc | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #include "effect_runner_dx_dy_dist.h" | ||
| 2 | #include "effect_runner_dx_dy.h" | ||
| 3 | #include "effect_runner_i.h" | ||
| 4 | #include "effect_runner_sin_cos_i.h" | ||
| 5 | #include "effect_runner_reactive.h" | ||
| 6 | #include "effect_runner_reactive_splash.h" | ||
diff --git a/quantum/led_matrix/animations/solid_anim.h b/quantum/led_matrix/animations/solid_anim.h new file mode 100644 index 000000000..4c9e43c58 --- /dev/null +++ b/quantum/led_matrix/animations/solid_anim.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | LED_MATRIX_EFFECT(SOLID) | ||
| 2 | #ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 3 | |||
| 4 | bool SOLID(effect_params_t* params) { | ||
| 5 | LED_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 6 | |||
| 7 | uint8_t val = led_matrix_eeconfig.val; | ||
| 8 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 9 | LED_MATRIX_TEST_LED_FLAGS(); | ||
| 10 | led_matrix_set_value(i, val); | ||
| 11 | } | ||
| 12 | return led_max < DRIVER_LED_TOTAL; | ||
| 13 | } | ||
| 14 | |||
| 15 | #endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
diff --git a/quantum/led_matrix/animations/solid_reactive_cross.h b/quantum/led_matrix/animations/solid_reactive_cross.h new file mode 100644 index 000000000..94425c959 --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_cross.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 2 | # if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) | ||
| 3 | |||
| 4 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS | ||
| 5 | LED_MATRIX_EFFECT(SOLID_REACTIVE_CROSS) | ||
| 6 | # endif | ||
| 7 | |||
| 8 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS | ||
| 9 | LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTICROSS) | ||
| 10 | # endif | ||
| 11 | |||
| 12 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 13 | |||
| 14 | static uint8_t SOLID_REACTIVE_CROSS_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { | ||
| 15 | uint16_t effect = tick + dist; | ||
| 16 | dx = dx < 0 ? dx * -1 : dx; | ||
| 17 | dy = dy < 0 ? dy * -1 : dy; | ||
| 18 | dx = dx * 16 > 255 ? 255 : dx * 16; | ||
| 19 | dy = dy * 16 > 255 ? 255 : dy * 16; | ||
| 20 | effect += dx > dy ? dy : dx; | ||
| 21 | if (effect > 255) effect = 255; | ||
| 22 | return qadd8(val, 255 - effect); | ||
| 23 | } | ||
| 24 | |||
| 25 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS | ||
| 26 | bool SOLID_REACTIVE_CROSS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_CROSS_math); } | ||
| 27 | # endif | ||
| 28 | |||
| 29 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS | ||
| 30 | bool SOLID_REACTIVE_MULTICROSS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_CROSS_math); } | ||
| 31 | # endif | ||
| 32 | |||
| 33 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 34 | # endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_CROSS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTICROSS) | ||
| 35 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/led_matrix/animations/solid_reactive_nexus.h b/quantum/led_matrix/animations/solid_reactive_nexus.h new file mode 100644 index 000000000..504b1104f --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_nexus.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 2 | # if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) | ||
| 3 | |||
| 4 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS | ||
| 5 | LED_MATRIX_EFFECT(SOLID_REACTIVE_NEXUS) | ||
| 6 | # endif | ||
| 7 | |||
| 8 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS | ||
| 9 | LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTINEXUS) | ||
| 10 | # endif | ||
| 11 | |||
| 12 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 13 | |||
| 14 | static uint8_t SOLID_REACTIVE_NEXUS_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { | ||
| 15 | uint16_t effect = tick - dist; | ||
| 16 | if (effect > 255) effect = 255; | ||
| 17 | if (dist > 72) effect = 255; | ||
| 18 | if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; | ||
| 19 | return qadd8(val, 255 - effect); | ||
| 20 | } | ||
| 21 | |||
| 22 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS | ||
| 23 | bool SOLID_REACTIVE_NEXUS(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_NEXUS_math); } | ||
| 24 | # endif | ||
| 25 | |||
| 26 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS | ||
| 27 | bool SOLID_REACTIVE_MULTINEXUS(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_NEXUS_math); } | ||
| 28 | # endif | ||
| 29 | |||
| 30 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 31 | # endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_NEXUS) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTINEXUS) | ||
| 32 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/led_matrix/animations/solid_reactive_simple_anim.h b/quantum/led_matrix/animations/solid_reactive_simple_anim.h new file mode 100644 index 000000000..4752a8416 --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_simple_anim.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 2 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 3 | LED_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) | ||
| 4 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 5 | |||
| 6 | static uint8_t SOLID_REACTIVE_SIMPLE_math(uint8_t val, uint16_t offset) { return scale8(255 - offset, val); } | ||
| 7 | |||
| 8 | bool SOLID_REACTIVE_SIMPLE(effect_params_t* params) { return effect_runner_reactive(params, &SOLID_REACTIVE_SIMPLE_math); } | ||
| 9 | |||
| 10 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 11 | # endif // DISABLE_LED_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 12 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/led_matrix/animations/solid_reactive_wide.h b/quantum/led_matrix/animations/solid_reactive_wide.h new file mode 100644 index 000000000..922e32fe5 --- /dev/null +++ b/quantum/led_matrix/animations/solid_reactive_wide.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 2 | # if !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) | ||
| 3 | |||
| 4 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE | ||
| 5 | LED_MATRIX_EFFECT(SOLID_REACTIVE_WIDE) | ||
| 6 | # endif | ||
| 7 | |||
| 8 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE | ||
| 9 | LED_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE) | ||
| 10 | # endif | ||
| 11 | |||
| 12 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 13 | |||
| 14 | static uint8_t SOLID_REACTIVE_WIDE_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { | ||
| 15 | uint16_t effect = tick + dist * 5; | ||
| 16 | if (effect > 255) effect = 255; | ||
| 17 | return qadd8(val, 255 - effect); | ||
| 18 | } | ||
| 19 | |||
| 20 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE | ||
| 21 | bool SOLID_REACTIVE_WIDE(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_REACTIVE_WIDE_math); } | ||
| 22 | # endif | ||
| 23 | |||
| 24 | # ifndef DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE | ||
| 25 | bool SOLID_REACTIVE_MULTIWIDE(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_REACTIVE_WIDE_math); } | ||
| 26 | # endif | ||
| 27 | |||
| 28 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 29 | # endif // !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_WIDE) || !defined(DISABLE_LED_MATRIX_SOLID_REACTIVE_MULTIWIDE) | ||
| 30 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/led_matrix/animations/solid_splash_anim.h b/quantum/led_matrix/animations/solid_splash_anim.h new file mode 100644 index 000000000..d95889b81 --- /dev/null +++ b/quantum/led_matrix/animations/solid_splash_anim.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 2 | # if !defined(DISABLE_LED_MATRIX_SOLID_SPLASH) || !defined(DISABLE_LED_MATRIX_SOLID_MULTISPLASH) | ||
| 3 | |||
| 4 | # ifndef DISABLE_LED_MATRIX_SOLID_SPLASH | ||
| 5 | LED_MATRIX_EFFECT(SOLID_SPLASH) | ||
| 6 | # endif | ||
| 7 | |||
| 8 | # ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH | ||
| 9 | LED_MATRIX_EFFECT(SOLID_MULTISPLASH) | ||
| 10 | # endif | ||
| 11 | |||
| 12 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 13 | |||
| 14 | uint8_t SOLID_SPLASH_math(uint8_t val, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { | ||
| 15 | uint16_t effect = tick - dist; | ||
| 16 | if (effect > 255) effect = 255; | ||
| 17 | return qadd8(val, 255 - effect); | ||
| 18 | } | ||
| 19 | |||
| 20 | # ifndef DISABLE_LED_MATRIX_SOLID_SPLASH | ||
| 21 | bool SOLID_SPLASH(effect_params_t* params) { return effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SOLID_SPLASH_math); } | ||
| 22 | # endif | ||
| 23 | |||
| 24 | # ifndef DISABLE_LED_MATRIX_SOLID_MULTISPLASH | ||
| 25 | bool SOLID_MULTISPLASH(effect_params_t* params) { return effect_runner_reactive_splash(0, params, &SOLID_SPLASH_math); } | ||
| 26 | # endif | ||
| 27 | |||
| 28 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 29 | # endif // !defined(DISABLE_LED_MATRIX_SPLASH) && !defined(DISABLE_LED_MATRIX_MULTISPLASH) | ||
| 30 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/led_matrix/animations/wave_left_right_anim.h b/quantum/led_matrix/animations/wave_left_right_anim.h new file mode 100644 index 000000000..8579f1b45 --- /dev/null +++ b/quantum/led_matrix/animations/wave_left_right_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT | ||
| 2 | LED_MATRIX_EFFECT(WAVE_LEFT_RIGHT) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t WAVE_LEFT_RIGHT_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].x - time), val); } | ||
| 6 | |||
| 7 | bool WAVE_LEFT_RIGHT(effect_params_t* params) { return effect_runner_i(params, &WAVE_LEFT_RIGHT_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_WAVE_LEFT_RIGHT | ||
diff --git a/quantum/led_matrix/animations/wave_up_down_anim.h b/quantum/led_matrix/animations/wave_up_down_anim.h new file mode 100644 index 000000000..635c60841 --- /dev/null +++ b/quantum/led_matrix/animations/wave_up_down_anim.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef DISABLE_LED_MATRIX_WAVE_UP_DOWN | ||
| 2 | LED_MATRIX_EFFECT(WAVE_UP_DOWN) | ||
| 3 | # ifdef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 4 | |||
| 5 | static uint8_t WAVE_UP_DOWN_math(uint8_t val, uint8_t i, uint8_t time) { return scale8(sin8(g_led_config.point[i].y - time), val); } | ||
| 6 | |||
| 7 | bool WAVE_UP_DOWN(effect_params_t* params) { return effect_runner_i(params, &WAVE_UP_DOWN_math); } | ||
| 8 | |||
| 9 | # endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 10 | #endif // DISABLE_LED_MATRIX_WAVE_UP_DOWN | ||
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c new file mode 100644 index 000000000..32788866c --- /dev/null +++ b/quantum/led_matrix/led_matrix.c | |||
| @@ -0,0 +1,577 @@ | |||
| 1 | /* Copyright 2017 Jason Williams | ||
| 2 | * Copyright 2017 Jack Humbert | ||
| 3 | * Copyright 2018 Yiancar | ||
| 4 | * Copyright 2019 Clueboard | ||
| 5 | * | ||
| 6 | * This program is free software: you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation, either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include "led_matrix.h" | ||
| 21 | #include "progmem.h" | ||
| 22 | #include "config.h" | ||
| 23 | #include "eeprom.h" | ||
| 24 | #include <string.h> | ||
| 25 | #include <math.h> | ||
| 26 | #include "led_tables.h" | ||
| 27 | |||
| 28 | #include <lib/lib8tion/lib8tion.h> | ||
| 29 | |||
| 30 | #ifndef LED_MATRIX_CENTER | ||
| 31 | const led_point_t k_led_matrix_center = {112, 32}; | ||
| 32 | #else | ||
| 33 | const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; | ||
| 34 | #endif | ||
| 35 | |||
| 36 | // clang-format off | ||
| 37 | #ifndef LED_MATRIX_IMMEDIATE_EEPROM | ||
| 38 | # define led_eeconfig_update(v) led_update_eeprom |= v | ||
| 39 | #else | ||
| 40 | # define led_eeconfig_update(v) if (v) eeconfig_update_led_matrix() | ||
| 41 | #endif | ||
| 42 | // clang-format on | ||
| 43 | |||
| 44 | // Generic effect runners | ||
| 45 | #include "led_matrix_runners.inc" | ||
| 46 | |||
| 47 | // ------------------------------------------ | ||
| 48 | // -----Begin led effect includes macros----- | ||
| 49 | #define LED_MATRIX_EFFECT(name) | ||
| 50 | #define LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 51 | |||
| 52 | #include "led_matrix_effects.inc" | ||
| 53 | #ifdef LED_MATRIX_CUSTOM_KB | ||
| 54 | # include "led_matrix_kb.inc" | ||
| 55 | #endif | ||
| 56 | #ifdef LED_MATRIX_CUSTOM_USER | ||
| 57 | # include "led_matrix_user.inc" | ||
| 58 | #endif | ||
| 59 | |||
| 60 | #undef LED_MATRIX_CUSTOM_EFFECT_IMPLS | ||
| 61 | #undef LED_MATRIX_EFFECT | ||
| 62 | // -----End led effect includes macros------- | ||
| 63 | // ------------------------------------------ | ||
| 64 | |||
| 65 | #if defined(LED_DISABLE_AFTER_TIMEOUT) && !defined(LED_DISABLE_TIMEOUT) | ||
| 66 | # define LED_DISABLE_TIMEOUT (LED_DISABLE_AFTER_TIMEOUT * 1200UL) | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #ifndef LED_DISABLE_TIMEOUT | ||
| 70 | # define LED_DISABLE_TIMEOUT 0 | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX | ||
| 74 | # undef LED_MATRIX_MAXIMUM_BRIGHTNESS | ||
| 75 | # define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #if !defined(LED_MATRIX_VAL_STEP) | ||
| 79 | # define LED_MATRIX_VAL_STEP 8 | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #if !defined(LED_MATRIX_SPD_STEP) | ||
| 83 | # define LED_MATRIX_SPD_STEP 16 | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #if !defined(LED_MATRIX_STARTUP_MODE) | ||
| 87 | # define LED_MATRIX_STARTUP_MODE LED_MATRIX_SOLID | ||
| 88 | #endif | ||
| 89 | |||
| 90 | #if !defined(LED_MATRIX_STARTUP_VAL) | ||
| 91 | # define LED_MATRIX_STARTUP_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS | ||
| 92 | #endif | ||
| 93 | |||
| 94 | #if !defined(LED_MATRIX_STARTUP_SPD) | ||
| 95 | # define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2 | ||
| 96 | #endif | ||
| 97 | |||
| 98 | // globals | ||
| 99 | led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr | ||
| 100 | uint32_t g_led_timer; | ||
| 101 | #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS | ||
| 102 | uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; | ||
| 103 | #endif // LED_MATRIX_FRAMEBUFFER_EFFECTS | ||
| 104 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 105 | last_hit_t g_last_hit_tracker; | ||
| 106 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 107 | |||
| 108 | // internals | ||
| 109 | static bool suspend_state = false; | ||
| 110 | static bool led_update_eeprom = false; | ||
| 111 | static uint8_t led_last_enable = UINT8_MAX; | ||
| 112 | static uint8_t led_last_effect = UINT8_MAX; | ||
| 113 | static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; | ||
| 114 | static led_task_states led_task_state = SYNCING; | ||
| 115 | #if LED_DISABLE_TIMEOUT > 0 | ||
| 116 | static uint32_t led_anykey_timer; | ||
| 117 | #endif // LED_DISABLE_TIMEOUT > 0 | ||
| 118 | |||
| 119 | // double buffers | ||
| 120 | static uint32_t led_timer_buffer; | ||
| 121 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 122 | static last_hit_t last_hit_buffer; | ||
| 123 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 124 | |||
| 125 | // split led matrix | ||
| 126 | #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) | ||
| 127 | const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; | ||
| 128 | #endif | ||
| 129 | |||
| 130 | void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } | ||
| 131 | |||
| 132 | void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } | ||
| 133 | |||
| 134 | void eeconfig_update_led_matrix_default(void) { | ||
| 135 | dprintf("eeconfig_update_led_matrix_default\n"); | ||
| 136 | led_matrix_eeconfig.enable = 1; | ||
| 137 | led_matrix_eeconfig.mode = LED_MATRIX_STARTUP_MODE; | ||
| 138 | led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL; | ||
| 139 | led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD; | ||
| 140 | led_matrix_eeconfig.flags = LED_FLAG_ALL; | ||
| 141 | eeconfig_update_led_matrix(); | ||
| 142 | } | ||
| 143 | |||
| 144 | void eeconfig_debug_led_matrix(void) { | ||
| 145 | dprintf("led_matrix_eeconfig EEPROM\n"); | ||
| 146 | dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable); | ||
| 147 | dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode); | ||
| 148 | dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val); | ||
| 149 | dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed); | ||
| 150 | dprintf("led_matrix_eeconfig.flags = %d\n", led_matrix_eeconfig.flags); | ||
| 151 | } | ||
| 152 | |||
| 153 | __attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } | ||
| 154 | |||
| 155 | uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { | ||
| 156 | uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i); | ||
| 157 | uint8_t led_index = g_led_config.matrix_co[row][column]; | ||
| 158 | if (led_index != NO_LED) { | ||
| 159 | led_i[led_count] = led_index; | ||
| 160 | led_count++; | ||
| 161 | } | ||
| 162 | return led_count; | ||
| 163 | } | ||
| 164 | |||
| 165 | void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } | ||
| 166 | |||
| 167 | void led_matrix_set_value(int index, uint8_t value) { | ||
| 168 | #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) | ||
| 169 | if (!is_keyboard_left() && index >= k_led_matrix_split[0]) | ||
| 170 | # ifdef USE_CIE1931_CURVE | ||
| 171 | led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value])); | ||
| 172 | # else | ||
| 173 | led_matrix_driver.set_value(index - k_led_matrix_split[0], value); | ||
| 174 | # endif | ||
| 175 | else if (is_keyboard_left() && index < k_led_matrix_split[0]) | ||
| 176 | #endif | ||
| 177 | #ifdef USE_CIE1931_CURVE | ||
| 178 | led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value])); | ||
| 179 | #else | ||
| 180 | led_matrix_driver.set_value(index, value); | ||
| 181 | #endif | ||
| 182 | } | ||
| 183 | |||
| 184 | void led_matrix_set_value_all(uint8_t value) { | ||
| 185 | #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) | ||
| 186 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) led_matrix_set_value(i, value); | ||
| 187 | #else | ||
| 188 | # ifdef USE_CIE1931_CURVE | ||
| 189 | led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value])); | ||
| 190 | # else | ||
| 191 | led_matrix_driver.set_value_all(value); | ||
| 192 | # endif | ||
| 193 | #endif | ||
| 194 | } | ||
| 195 | |||
| 196 | void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { | ||
| 197 | #ifndef LED_MATRIX_SPLIT | ||
| 198 | if (!is_keyboard_master()) return; | ||
| 199 | #endif | ||
| 200 | #if LED_DISABLE_TIMEOUT > 0 | ||
| 201 | led_anykey_timer = 0; | ||
| 202 | #endif // LED_DISABLE_TIMEOUT > 0 | ||
| 203 | |||
| 204 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 205 | uint8_t led[LED_HITS_TO_REMEMBER]; | ||
| 206 | uint8_t led_count = 0; | ||
| 207 | |||
| 208 | # if defined(LED_MATRIX_KEYRELEASES) | ||
| 209 | if (!pressed) | ||
| 210 | # elif defined(LED_MATRIX_KEYPRESSES) | ||
| 211 | if (pressed) | ||
| 212 | # endif // defined(LED_MATRIX_KEYRELEASES) | ||
| 213 | { | ||
| 214 | led_count = led_matrix_map_row_column_to_led(row, col, led); | ||
| 215 | } | ||
| 216 | |||
| 217 | if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { | ||
| 218 | memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); | ||
| 219 | memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); | ||
| 220 | memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit | ||
| 221 | memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); | ||
| 222 | last_hit_buffer.count--; | ||
| 223 | } | ||
| 224 | |||
| 225 | for (uint8_t i = 0; i < led_count; i++) { | ||
| 226 | uint8_t index = last_hit_buffer.count; | ||
| 227 | last_hit_buffer.x[index] = g_led_config.point[led[i]].x; | ||
| 228 | last_hit_buffer.y[index] = g_led_config.point[led[i]].y; | ||
| 229 | last_hit_buffer.index[index] = led[i]; | ||
| 230 | last_hit_buffer.tick[index] = 0; | ||
| 231 | last_hit_buffer.count++; | ||
| 232 | } | ||
| 233 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 234 | |||
| 235 | #if defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP) | ||
| 236 | if (led_matrix_eeconfig.mode == LED_MATRIX_TYPING_HEATMAP) { | ||
| 237 | process_led_matrix_typing_heatmap(row, col); | ||
| 238 | } | ||
| 239 | #endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP) | ||
| 240 | } | ||
| 241 | |||
| 242 | static bool led_matrix_none(effect_params_t *params) { | ||
| 243 | if (!params->init) { | ||
| 244 | return false; | ||
| 245 | } | ||
| 246 | |||
| 247 | led_matrix_set_value_all(0); | ||
| 248 | return false; | ||
| 249 | } | ||
| 250 | |||
| 251 | static void led_task_timers(void) { | ||
| 252 | #if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 | ||
| 253 | uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer); | ||
| 254 | #endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0 | ||
| 255 | led_timer_buffer = sync_timer_read32(); | ||
| 256 | |||
| 257 | // Update double buffer timers | ||
| 258 | #if LED_DISABLE_TIMEOUT > 0 | ||
| 259 | if (led_anykey_timer < UINT32_MAX) { | ||
| 260 | if (UINT32_MAX - deltaTime < led_anykey_timer) { | ||
| 261 | led_anykey_timer = UINT32_MAX; | ||
| 262 | } else { | ||
| 263 | led_anykey_timer += deltaTime; | ||
| 264 | } | ||
| 265 | } | ||
| 266 | #endif // LED_DISABLE_TIMEOUT > 0 | ||
| 267 | |||
| 268 | // Update double buffer last hit timers | ||
| 269 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 270 | uint8_t count = last_hit_buffer.count; | ||
| 271 | for (uint8_t i = 0; i < count; ++i) { | ||
| 272 | if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { | ||
| 273 | last_hit_buffer.count--; | ||
| 274 | continue; | ||
| 275 | } | ||
| 276 | last_hit_buffer.tick[i] += deltaTime; | ||
| 277 | } | ||
| 278 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 279 | } | ||
| 280 | |||
| 281 | static void led_task_sync(void) { | ||
| 282 | // next task | ||
| 283 | if (led_update_eeprom) eeconfig_update_led_matrix(); | ||
| 284 | led_update_eeprom = false; | ||
| 285 | if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING; | ||
| 286 | } | ||
| 287 | |||
| 288 | static void led_task_start(void) { | ||
| 289 | // reset iter | ||
| 290 | led_effect_params.iter = 0; | ||
| 291 | |||
| 292 | // update double buffers | ||
| 293 | g_led_timer = led_timer_buffer; | ||
| 294 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 295 | g_last_hit_tracker = last_hit_buffer; | ||
| 296 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 297 | |||
| 298 | // next task | ||
| 299 | led_task_state = RENDERING; | ||
| 300 | } | ||
| 301 | |||
| 302 | static void led_task_render(uint8_t effect) { | ||
| 303 | bool rendering = false; | ||
| 304 | led_effect_params.init = (effect != led_last_effect) || (led_matrix_eeconfig.enable != led_last_enable); | ||
| 305 | if (led_effect_params.flags != led_matrix_eeconfig.flags) { | ||
| 306 | led_effect_params.flags = led_matrix_eeconfig.flags; | ||
| 307 | led_matrix_set_value_all(0); | ||
| 308 | } | ||
| 309 | |||
| 310 | // each effect can opt to do calculations | ||
| 311 | // and/or request PWM buffer updates. | ||
| 312 | switch (effect) { | ||
| 313 | case LED_MATRIX_NONE: | ||
| 314 | rendering = led_matrix_none(&led_effect_params); | ||
| 315 | break; | ||
| 316 | |||
| 317 | // --------------------------------------------- | ||
| 318 | // -----Begin led effect switch case macros----- | ||
| 319 | #define LED_MATRIX_EFFECT(name, ...) \ | ||
| 320 | case LED_MATRIX_##name: \ | ||
| 321 | rendering = name(&led_effect_params); \ | ||
| 322 | break; | ||
| 323 | #include "led_matrix_effects.inc" | ||
| 324 | #undef LED_MATRIX_EFFECT | ||
| 325 | |||
| 326 | #if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER) | ||
| 327 | # define LED_MATRIX_EFFECT(name, ...) \ | ||
| 328 | case LED_MATRIX_CUSTOM_##name: \ | ||
| 329 | rendering = name(&led_effect_params); \ | ||
| 330 | break; | ||
| 331 | # ifdef LED_MATRIX_CUSTOM_KB | ||
| 332 | # include "led_matrix_kb.inc" | ||
| 333 | # endif | ||
| 334 | # ifdef LED_MATRIX_CUSTOM_USER | ||
| 335 | # include "led_matrix_user.inc" | ||
| 336 | # endif | ||
| 337 | # undef LED_MATRIX_EFFECT | ||
| 338 | #endif | ||
| 339 | // -----End led effect switch case macros------- | ||
| 340 | // --------------------------------------------- | ||
| 341 | } | ||
| 342 | |||
| 343 | led_effect_params.iter++; | ||
| 344 | |||
| 345 | // next task | ||
| 346 | if (!rendering) { | ||
| 347 | led_task_state = FLUSHING; | ||
| 348 | if (!led_effect_params.init && effect == LED_MATRIX_NONE) { | ||
| 349 | // We only need to flush once if we are LED_MATRIX_NONE | ||
| 350 | led_task_state = SYNCING; | ||
| 351 | } | ||
| 352 | } | ||
| 353 | } | ||
| 354 | |||
| 355 | static void led_task_flush(uint8_t effect) { | ||
| 356 | // update last trackers after the first full render so we can init over several frames | ||
| 357 | led_last_effect = effect; | ||
| 358 | led_last_enable = led_matrix_eeconfig.enable; | ||
| 359 | |||
| 360 | // update pwm buffers | ||
| 361 | led_matrix_update_pwm_buffers(); | ||
| 362 | |||
| 363 | // next task | ||
| 364 | led_task_state = SYNCING; | ||
| 365 | } | ||
| 366 | |||
| 367 | void led_matrix_task(void) { | ||
| 368 | led_task_timers(); | ||
| 369 | |||
| 370 | // Ideally we would also stop sending zeros to the LED driver PWM buffers | ||
| 371 | // while suspended and just do a software shutdown. This is a cheap hack for now. | ||
| 372 | bool suspend_backlight = suspend_state || | ||
| 373 | #if LED_DISABLE_TIMEOUT > 0 | ||
| 374 | (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || | ||
| 375 | #endif // LED_DISABLE_TIMEOUT > 0 | ||
| 376 | false; | ||
| 377 | |||
| 378 | uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode; | ||
| 379 | |||
| 380 | switch (led_task_state) { | ||
| 381 | case STARTING: | ||
| 382 | led_task_start(); | ||
| 383 | break; | ||
| 384 | case RENDERING: | ||
| 385 | led_task_render(effect); | ||
| 386 | if (effect) { | ||
| 387 | led_matrix_indicators(); | ||
| 388 | led_matrix_indicators_advanced(&led_effect_params); | ||
| 389 | } | ||
| 390 | break; | ||
| 391 | case FLUSHING: | ||
| 392 | led_task_flush(effect); | ||
| 393 | break; | ||
| 394 | case SYNCING: | ||
| 395 | led_task_sync(); | ||
| 396 | break; | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 | void led_matrix_indicators(void) { | ||
| 401 | led_matrix_indicators_kb(); | ||
| 402 | led_matrix_indicators_user(); | ||
| 403 | } | ||
| 404 | |||
| 405 | __attribute__((weak)) void led_matrix_indicators_kb(void) {} | ||
| 406 | |||
| 407 | __attribute__((weak)) void led_matrix_indicators_user(void) {} | ||
| 408 | |||
| 409 | void led_matrix_indicators_advanced(effect_params_t *params) { | ||
| 410 | /* special handling is needed for "params->iter", since it's already been incremented. | ||
| 411 | * Could move the invocations to led_task_render, but then it's missing a few checks | ||
| 412 | * and not sure which would be better. Otherwise, this should be called from | ||
| 413 | * led_task_render, right before the iter++ line. | ||
| 414 | */ | ||
| 415 | #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL | ||
| 416 | uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); | ||
| 417 | uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; | ||
| 418 | if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; | ||
| 419 | #else | ||
| 420 | uint8_t min = 0; | ||
| 421 | uint8_t max = DRIVER_LED_TOTAL; | ||
| 422 | #endif | ||
| 423 | led_matrix_indicators_advanced_kb(min, max); | ||
| 424 | led_matrix_indicators_advanced_user(min, max); | ||
| 425 | } | ||
| 426 | |||
| 427 | __attribute__((weak)) void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {} | ||
| 428 | |||
| 429 | __attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {} | ||
| 430 | |||
| 431 | void led_matrix_init(void) { | ||
| 432 | led_matrix_driver.init(); | ||
| 433 | |||
| 434 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 435 | g_last_hit_tracker.count = 0; | ||
| 436 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { | ||
| 437 | g_last_hit_tracker.tick[i] = UINT16_MAX; | ||
| 438 | } | ||
| 439 | |||
| 440 | last_hit_buffer.count = 0; | ||
| 441 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { | ||
| 442 | last_hit_buffer.tick[i] = UINT16_MAX; | ||
| 443 | } | ||
| 444 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 445 | |||
| 446 | if (!eeconfig_is_enabled()) { | ||
| 447 | dprintf("led_matrix_init_drivers eeconfig is not enabled.\n"); | ||
| 448 | eeconfig_init(); | ||
| 449 | eeconfig_update_led_matrix_default(); | ||
| 450 | } | ||
| 451 | |||
| 452 | eeconfig_read_led_matrix(); | ||
| 453 | if (!led_matrix_eeconfig.mode) { | ||
| 454 | dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); | ||
| 455 | eeconfig_update_led_matrix_default(); | ||
| 456 | } | ||
| 457 | eeconfig_debug_led_matrix(); // display current eeprom values | ||
| 458 | } | ||
| 459 | |||
| 460 | void led_matrix_set_suspend_state(bool state) { | ||
| 461 | #ifdef LED_DISABLE_WHEN_USB_SUSPENDED | ||
| 462 | if (state) { | ||
| 463 | led_matrix_set_value_all(0); // turn off all LEDs when suspending | ||
| 464 | } | ||
| 465 | suspend_state = state; | ||
| 466 | #endif | ||
| 467 | } | ||
| 468 | |||
| 469 | bool led_matrix_get_suspend_state(void) { return suspend_state; } | ||
| 470 | |||
| 471 | void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { | ||
| 472 | led_matrix_eeconfig.enable ^= 1; | ||
| 473 | led_task_state = STARTING; | ||
| 474 | led_eeconfig_update(write_to_eeprom); | ||
| 475 | dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); | ||
| 476 | } | ||
| 477 | void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } | ||
| 478 | void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); } | ||
| 479 | |||
| 480 | void led_matrix_enable(void) { | ||
| 481 | led_matrix_enable_noeeprom(); | ||
| 482 | led_eeconfig_update(true); | ||
| 483 | } | ||
| 484 | |||
| 485 | void led_matrix_enable_noeeprom(void) { | ||
| 486 | if (!led_matrix_eeconfig.enable) led_task_state = STARTING; | ||
| 487 | led_matrix_eeconfig.enable = 1; | ||
| 488 | } | ||
| 489 | |||
| 490 | void led_matrix_disable(void) { | ||
| 491 | led_matrix_disable_noeeprom(); | ||
| 492 | led_eeconfig_update(true); | ||
| 493 | } | ||
| 494 | |||
| 495 | void led_matrix_disable_noeeprom(void) { | ||
| 496 | if (led_matrix_eeconfig.enable) led_task_state = STARTING; | ||
| 497 | led_matrix_eeconfig.enable = 0; | ||
| 498 | } | ||
| 499 | |||
| 500 | uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; } | ||
| 501 | |||
| 502 | void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | ||
| 503 | if (!led_matrix_eeconfig.enable) { | ||
| 504 | return; | ||
| 505 | } | ||
| 506 | if (mode < 1) { | ||
| 507 | led_matrix_eeconfig.mode = 1; | ||
| 508 | } else if (mode >= LED_MATRIX_EFFECT_MAX) { | ||
| 509 | led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1; | ||
| 510 | } else { | ||
| 511 | led_matrix_eeconfig.mode = mode; | ||
| 512 | } | ||
| 513 | led_task_state = STARTING; | ||
| 514 | led_eeconfig_update(write_to_eeprom); | ||
| 515 | dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); | ||
| 516 | } | ||
| 517 | void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } | ||
| 518 | void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); } | ||
| 519 | |||
| 520 | uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } | ||
| 521 | |||
| 522 | void led_matrix_step_helper(bool write_to_eeprom) { | ||
| 523 | uint8_t mode = led_matrix_eeconfig.mode + 1; | ||
| 524 | led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); | ||
| 525 | } | ||
| 526 | void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); } | ||
| 527 | void led_matrix_step(void) { led_matrix_step_helper(true); } | ||
| 528 | |||
| 529 | void led_matrix_step_reverse_helper(bool write_to_eeprom) { | ||
| 530 | uint8_t mode = led_matrix_eeconfig.mode - 1; | ||
| 531 | led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); | ||
| 532 | } | ||
| 533 | void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); } | ||
| 534 | void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); } | ||
| 535 | |||
| 536 | void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) { | ||
| 537 | if (!led_matrix_eeconfig.enable) { | ||
| 538 | return; | ||
| 539 | } | ||
| 540 | led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; | ||
| 541 | led_eeconfig_update(write_to_eeprom); | ||
| 542 | dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); | ||
| 543 | } | ||
| 544 | void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } | ||
| 545 | void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); } | ||
| 546 | |||
| 547 | uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; } | ||
| 548 | |||
| 549 | void led_matrix_increase_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } | ||
| 550 | void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); } | ||
| 551 | void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); } | ||
| 552 | |||
| 553 | void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); } | ||
| 554 | void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); } | ||
| 555 | void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); } | ||
| 556 | |||
| 557 | void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { | ||
| 558 | led_matrix_eeconfig.speed = speed; | ||
| 559 | led_eeconfig_update(write_to_eeprom); | ||
| 560 | dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); | ||
| 561 | } | ||
| 562 | void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } | ||
| 563 | void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); } | ||
| 564 | |||
| 565 | uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; } | ||
| 566 | |||
| 567 | void led_matrix_increase_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } | ||
| 568 | void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); } | ||
| 569 | void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); } | ||
| 570 | |||
| 571 | void led_matrix_decrease_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); } | ||
| 572 | void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); } | ||
| 573 | void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); } | ||
| 574 | |||
| 575 | led_flags_t led_matrix_get_flags(void) { return led_matrix_eeconfig.flags; } | ||
| 576 | |||
| 577 | void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; } | ||
diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h new file mode 100644 index 000000000..6f85854fb --- /dev/null +++ b/quantum/led_matrix/led_matrix.h | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | /* Copyright 2017 Jason Williams | ||
| 2 | * Copyright 2017 Jack Humbert | ||
| 3 | * Copyright 2018 Yiancar | ||
| 4 | * Copyright 2019 Clueboard | ||
| 5 | * | ||
| 6 | * This program is free software: you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation, either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #pragma once | ||
| 21 | |||
| 22 | #include <stdint.h> | ||
| 23 | #include <stdbool.h> | ||
| 24 | #include "led_matrix_types.h" | ||
| 25 | #include "quantum.h" | ||
| 26 | |||
| 27 | #ifdef IS31FL3731 | ||
| 28 | # include "is31fl3731-simple.h" | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifndef LED_MATRIX_LED_FLUSH_LIMIT | ||
| 32 | # define LED_MATRIX_LED_FLUSH_LIMIT 16 | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #ifndef LED_MATRIX_LED_PROCESS_LIMIT | ||
| 36 | # define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL | ||
| 40 | # define LED_MATRIX_USE_LIMITS(min, max) \ | ||
| 41 | uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \ | ||
| 42 | uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \ | ||
| 43 | if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; | ||
| 44 | #else | ||
| 45 | # define LED_MATRIX_USE_LIMITS(min, max) \ | ||
| 46 | uint8_t min = 0; \ | ||
| 47 | uint8_t max = DRIVER_LED_TOTAL; | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #define LED_MATRIX_TEST_LED_FLAGS() \ | ||
| 51 | if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue | ||
| 52 | |||
| 53 | enum led_matrix_effects { | ||
| 54 | LED_MATRIX_NONE = 0, | ||
| 55 | |||
| 56 | // -------------------------------------- | ||
| 57 | // -----Begin led effect enum macros----- | ||
| 58 | #define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name, | ||
| 59 | #include "led_matrix_effects.inc" | ||
| 60 | #undef LED_MATRIX_EFFECT | ||
| 61 | |||
| 62 | #if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER) | ||
| 63 | # define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name, | ||
| 64 | # ifdef LED_MATRIX_CUSTOM_KB | ||
| 65 | # include "led_matrix_kb.inc" | ||
| 66 | # endif | ||
| 67 | # ifdef LED_MATRIX_CUSTOM_USER | ||
| 68 | # include "led_matrix_user.inc" | ||
| 69 | # endif | ||
| 70 | # undef LED_MATRIX_EFFECT | ||
| 71 | #endif | ||
| 72 | // -------------------------------------- | ||
| 73 | // -----End led effect enum macros------- | ||
| 74 | |||
| 75 | LED_MATRIX_EFFECT_MAX | ||
| 76 | }; | ||
| 77 | |||
| 78 | void eeconfig_update_led_matrix_default(void); | ||
| 79 | void eeconfig_update_led_matrix(void); | ||
| 80 | void eeconfig_debug_led_matrix(void); | ||
| 81 | |||
| 82 | uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); | ||
| 83 | uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i); | ||
| 84 | |||
| 85 | void led_matrix_set_value(int index, uint8_t value); | ||
| 86 | void led_matrix_set_value_all(uint8_t value); | ||
| 87 | |||
| 88 | void process_led_matrix(uint8_t row, uint8_t col, bool pressed); | ||
| 89 | |||
| 90 | void led_matrix_task(void); | ||
| 91 | |||
| 92 | // This runs after another backlight effect and replaces | ||
| 93 | // values already set | ||
| 94 | void led_matrix_indicators(void); | ||
| 95 | void led_matrix_indicators_kb(void); | ||
| 96 | void led_matrix_indicators_user(void); | ||
| 97 | |||
| 98 | void led_matrix_indicators_advanced(effect_params_t *params); | ||
| 99 | void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max); | ||
| 100 | void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max); | ||
| 101 | |||
| 102 | void led_matrix_init(void); | ||
| 103 | |||
| 104 | void led_matrix_set_suspend_state(bool state); | ||
| 105 | bool led_matrix_get_suspend_state(void); | ||
| 106 | void led_matrix_toggle(void); | ||
| 107 | void led_matrix_toggle_noeeprom(void); | ||
| 108 | void led_matrix_enable(void); | ||
| 109 | void led_matrix_enable_noeeprom(void); | ||
| 110 | void led_matrix_disable(void); | ||
| 111 | void led_matrix_disable_noeeprom(void); | ||
| 112 | uint8_t led_matrix_is_enabled(void); | ||
| 113 | void led_matrix_mode(uint8_t mode); | ||
| 114 | void led_matrix_mode_noeeprom(uint8_t mode); | ||
| 115 | uint8_t led_matrix_get_mode(void); | ||
| 116 | void led_matrix_step(void); | ||
| 117 | void led_matrix_step_noeeprom(void); | ||
| 118 | void led_matrix_step_reverse(void); | ||
| 119 | void led_matrix_step_reverse_noeeprom(void); | ||
| 120 | void led_matrix_set_val(uint8_t val); | ||
| 121 | void led_matrix_set_val_noeeprom(uint8_t val); | ||
| 122 | uint8_t led_matrix_get_val(void); | ||
| 123 | void led_matrix_increase_val(void); | ||
| 124 | void led_matrix_increase_val_noeeprom(void); | ||
| 125 | void led_matrix_decrease_val(void); | ||
| 126 | void led_matrix_decrease_val_noeeprom(void); | ||
| 127 | void led_matrix_set_speed(uint8_t speed); | ||
| 128 | void led_matrix_set_speed_noeeprom(uint8_t speed); | ||
| 129 | uint8_t led_matrix_get_speed(void); | ||
| 130 | void led_matrix_increase_speed(void); | ||
| 131 | void led_matrix_increase_speed_noeeprom(void); | ||
| 132 | void led_matrix_decrease_speed(void); | ||
| 133 | void led_matrix_decrease_speed_noeeprom(void); | ||
| 134 | led_flags_t led_matrix_get_flags(void); | ||
| 135 | void led_matrix_set_flags(led_flags_t flags); | ||
| 136 | |||
| 137 | typedef struct { | ||
| 138 | /* Perform any initialisation required for the other driver functions to work. */ | ||
| 139 | void (*init)(void); | ||
| 140 | |||
| 141 | /* Set the brightness of a single LED in the buffer. */ | ||
| 142 | void (*set_value)(int index, uint8_t value); | ||
| 143 | /* Set the brightness of all LEDS on the keyboard in the buffer. */ | ||
| 144 | void (*set_value_all)(uint8_t value); | ||
| 145 | /* Flush any buffered changes to the hardware. */ | ||
| 146 | void (*flush)(void); | ||
| 147 | } led_matrix_driver_t; | ||
| 148 | |||
| 149 | extern const led_matrix_driver_t led_matrix_driver; | ||
| 150 | |||
| 151 | extern led_eeconfig_t led_matrix_eeconfig; | ||
| 152 | |||
| 153 | extern uint32_t g_led_timer; | ||
| 154 | extern led_config_t g_led_config; | ||
| 155 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 156 | extern last_hit_t g_last_hit_tracker; | ||
| 157 | #endif | ||
| 158 | #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS | ||
| 159 | extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; | ||
| 160 | #endif | ||
diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c new file mode 100644 index 000000000..1d46b2c50 --- /dev/null +++ b/quantum/led_matrix/led_matrix_drivers.c | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | /* Copyright 2018 James Laird-Wah | ||
| 2 | * Copyright 2019 Clueboard | ||
| 3 | * | ||
| 4 | * This program is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "led_matrix.h" | ||
| 19 | |||
| 20 | /* Each driver needs to define a struct: | ||
| 21 | * | ||
| 22 | * const led_matrix_driver_t led_matrix_driver; | ||
| 23 | * | ||
| 24 | * All members must be provided. Keyboard custom drivers must define this | ||
| 25 | * in their own files. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #if defined(IS31FL3731) || defined(IS31FL3733) | ||
| 29 | |||
| 30 | # include "i2c_master.h" | ||
| 31 | |||
| 32 | static void init(void) { | ||
| 33 | i2c_init(); | ||
| 34 | # ifdef IS31FL3731 | ||
| 35 | # ifdef LED_DRIVER_ADDR_1 | ||
| 36 | IS31FL3731_init(LED_DRIVER_ADDR_1); | ||
| 37 | # endif | ||
| 38 | # ifdef LED_DRIVER_ADDR_2 | ||
| 39 | IS31FL3731_init(LED_DRIVER_ADDR_2); | ||
| 40 | # endif | ||
| 41 | # ifdef LED_DRIVER_ADDR_3 | ||
| 42 | IS31FL3731_init(LED_DRIVER_ADDR_3); | ||
| 43 | # endif | ||
| 44 | # ifdef LED_DRIVER_ADDR_4 | ||
| 45 | IS31FL3731_init(LED_DRIVER_ADDR_4); | ||
| 46 | # endif | ||
| 47 | # else | ||
| 48 | # ifdef LED_DRIVER_ADDR_1 | ||
| 49 | # ifndef LED_DRIVER_SYNC_1 | ||
| 50 | # define LED_DRIVER_SYNC_1 0 | ||
| 51 | # endif | ||
| 52 | IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1); | ||
| 53 | # endif | ||
| 54 | # ifdef LED_DRIVER_ADDR_2 | ||
| 55 | # ifndef LED_DRIVER_SYNC_2 | ||
| 56 | # define LED_DRIVER_SYNC_2 0 | ||
| 57 | # endif | ||
| 58 | IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2); | ||
| 59 | # endif | ||
| 60 | # ifdef LED_DRIVER_ADDR_3 | ||
| 61 | # ifndef LED_DRIVER_SYNC_3 | ||
| 62 | # define LED_DRIVER_SYNC_3 0 | ||
| 63 | # endif | ||
| 64 | IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3); | ||
| 65 | # endif | ||
| 66 | # ifdef LED_DRIVER_ADDR_4 | ||
| 67 | # ifndef LED_DRIVER_SYNC_4 | ||
| 68 | # define LED_DRIVER_SYNC_4 0 | ||
| 69 | # endif | ||
| 70 | IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4); | ||
| 71 | # endif | ||
| 72 | # endif | ||
| 73 | |||
| 74 | for (int index = 0; index < DRIVER_LED_TOTAL; index++) { | ||
| 75 | # ifdef IS31FL3731 | ||
| 76 | IS31FL3731_set_led_control_register(index, true); | ||
| 77 | # else | ||
| 78 | IS31FL3733_set_led_control_register(index, true); | ||
| 79 | # endif | ||
| 80 | } | ||
| 81 | // This actually updates the LED drivers | ||
| 82 | # ifdef IS31FL3731 | ||
| 83 | # ifdef LED_DRIVER_ADDR_1 | ||
| 84 | IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0); | ||
| 85 | # endif | ||
| 86 | # ifdef LED_DRIVER_ADDR_2 | ||
| 87 | IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1); | ||
| 88 | # endif | ||
| 89 | # ifdef LED_DRIVER_ADDR_3 | ||
| 90 | IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2); | ||
| 91 | # endif | ||
| 92 | # ifdef LED_DRIVER_ADDR_4 | ||
| 93 | IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3); | ||
| 94 | # endif | ||
| 95 | # else | ||
| 96 | # ifdef LED_DRIVER_ADDR_1 | ||
| 97 | IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0); | ||
| 98 | # endif | ||
| 99 | # ifdef LED_DRIVER_ADDR_2 | ||
| 100 | IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1); | ||
| 101 | # endif | ||
| 102 | # ifdef LED_DRIVER_ADDR_3 | ||
| 103 | IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2); | ||
| 104 | # endif | ||
| 105 | # ifdef LED_DRIVER_ADDR_4 | ||
| 106 | IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3); | ||
| 107 | # endif | ||
| 108 | # endif | ||
| 109 | } | ||
| 110 | |||
| 111 | static void flush(void) { | ||
| 112 | # ifdef IS31FL3731 | ||
| 113 | # ifdef LED_DRIVER_ADDR_1 | ||
| 114 | IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); | ||
| 115 | # endif | ||
| 116 | # ifdef LED_DRIVER_ADDR_2 | ||
| 117 | IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); | ||
| 118 | # endif | ||
| 119 | # ifdef LED_DRIVER_ADDR_3 | ||
| 120 | IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); | ||
| 121 | # endif | ||
| 122 | # ifdef LED_DRIVER_ADDR_4 | ||
| 123 | IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); | ||
| 124 | # endif | ||
| 125 | # else | ||
| 126 | # ifdef LED_DRIVER_ADDR_1 | ||
| 127 | IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); | ||
| 128 | # endif | ||
| 129 | # ifdef LED_DRIVER_ADDR_2 | ||
| 130 | IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); | ||
| 131 | # endif | ||
| 132 | # ifdef LED_DRIVER_ADDR_3 | ||
| 133 | IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); | ||
| 134 | # endif | ||
| 135 | # ifdef LED_DRIVER_ADDR_4 | ||
| 136 | IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); | ||
| 137 | # endif | ||
| 138 | # endif | ||
| 139 | } | ||
| 140 | |||
| 141 | const led_matrix_driver_t led_matrix_driver = { | ||
| 142 | .init = init, | ||
| 143 | .flush = flush, | ||
| 144 | # ifdef IS31FL3731 | ||
| 145 | .set_value = IS31FL3731_set_value, | ||
| 146 | .set_value_all = IS31FL3731_set_value_all, | ||
| 147 | # else | ||
| 148 | .set_value = IS31FL3733_set_value, | ||
| 149 | .set_value_all = IS31FL3733_set_value_all, | ||
| 150 | # endif | ||
| 151 | }; | ||
| 152 | |||
| 153 | #endif | ||
diff --git a/quantum/led_matrix/led_matrix_types.h b/quantum/led_matrix/led_matrix_types.h new file mode 100644 index 000000000..61cdbd9b8 --- /dev/null +++ b/quantum/led_matrix/led_matrix_types.h | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* Copyright 2021 | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #pragma once | ||
| 18 | |||
| 19 | #include <stdint.h> | ||
| 20 | #include <stdbool.h> | ||
| 21 | |||
| 22 | #if defined(__GNUC__) | ||
| 23 | # define PACKED __attribute__((__packed__)) | ||
| 24 | #else | ||
| 25 | # define PACKED | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #if defined(_MSC_VER) | ||
| 29 | # pragma pack(push, 1) | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #if defined(LED_MATRIX_KEYPRESSES) || defined(LED_MATRIX_KEYRELEASES) | ||
| 33 | # define LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 34 | #endif | ||
| 35 | |||
| 36 | // Last led hit | ||
| 37 | #ifndef LED_HITS_TO_REMEMBER | ||
| 38 | # define LED_HITS_TO_REMEMBER 8 | ||
| 39 | #endif // LED_HITS_TO_REMEMBER | ||
| 40 | |||
| 41 | #ifdef LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 42 | typedef struct PACKED { | ||
| 43 | uint8_t count; | ||
| 44 | uint8_t x[LED_HITS_TO_REMEMBER]; | ||
| 45 | uint8_t y[LED_HITS_TO_REMEMBER]; | ||
| 46 | uint8_t index[LED_HITS_TO_REMEMBER]; | ||
| 47 | uint16_t tick[LED_HITS_TO_REMEMBER]; | ||
| 48 | } last_hit_t; | ||
| 49 | #endif // LED_MATRIX_KEYREACTIVE_ENABLED | ||
| 50 | |||
| 51 | typedef enum led_task_states { STARTING, RENDERING, FLUSHING, SYNCING } led_task_states; | ||
| 52 | |||
| 53 | typedef uint8_t led_flags_t; | ||
| 54 | |||
| 55 | typedef struct PACKED { | ||
| 56 | uint8_t iter; | ||
| 57 | led_flags_t flags; | ||
| 58 | bool init; | ||
| 59 | } effect_params_t; | ||
| 60 | |||
| 61 | typedef struct PACKED { | ||
| 62 | uint8_t x; | ||
| 63 | uint8_t y; | ||
| 64 | } led_point_t; | ||
| 65 | |||
| 66 | #define HAS_FLAGS(bits, flags) ((bits & flags) == flags) | ||
| 67 | #define HAS_ANY_FLAGS(bits, flags) ((bits & flags) != 0x00) | ||
| 68 | |||
| 69 | #define LED_FLAG_ALL 0xFF | ||
| 70 | #define LED_FLAG_NONE 0x00 | ||
| 71 | #define LED_FLAG_MODIFIER 0x01 | ||
| 72 | #define LED_FLAG_KEYLIGHT 0x04 | ||
| 73 | #define LED_FLAG_INDICATOR 0x08 | ||
| 74 | |||
| 75 | #define NO_LED 255 | ||
| 76 | |||
| 77 | typedef struct PACKED { | ||
| 78 | uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; | ||
| 79 | led_point_t point[DRIVER_LED_TOTAL]; | ||
| 80 | uint8_t flags[DRIVER_LED_TOTAL]; | ||
| 81 | } led_config_t; | ||
| 82 | |||
| 83 | typedef union { | ||
| 84 | uint32_t raw; | ||
| 85 | struct PACKED { | ||
| 86 | uint8_t enable : 2; | ||
| 87 | uint8_t mode : 6; | ||
| 88 | uint16_t reserved; | ||
| 89 | uint8_t val; | ||
| 90 | uint8_t speed; // EECONFIG needs to be increased to support this | ||
| 91 | led_flags_t flags; | ||
| 92 | }; | ||
| 93 | } led_eeconfig_t; | ||
| 94 | |||
| 95 | #if defined(_MSC_VER) | ||
| 96 | # pragma pack(pop) | ||
| 97 | #endif | ||
