summaryrefslogtreecommitdiffstats
path: root/quantum/rgb_matrix/rgb_matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgb_matrix/rgb_matrix.c')
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c102
1 files changed, 52 insertions, 50 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c
index 1ba1686b44..181199f235 100644
--- a/quantum/rgb_matrix/rgb_matrix.c
+++ b/quantum/rgb_matrix/rgb_matrix.c
@@ -56,12 +56,8 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) {
// -----End rgb effect includes macros-------
// ------------------------------------------
-#if defined(RGB_DISABLE_AFTER_TIMEOUT) && !defined(RGB_DISABLE_TIMEOUT)
-# define RGB_DISABLE_TIMEOUT (RGB_DISABLE_AFTER_TIMEOUT * 1200UL)
-#endif
-
-#ifndef RGB_DISABLE_TIMEOUT
-# define RGB_DISABLE_TIMEOUT 0
+#ifndef RGB_MATRIX_TIMEOUT
+# define RGB_MATRIX_TIMEOUT 0
#endif
#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
@@ -85,29 +81,29 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) {
# define RGB_MATRIX_SPD_STEP 16
#endif
-#if !defined(RGB_MATRIX_STARTUP_MODE)
+#if !defined(RGB_MATRIX_DEFAULT_MODE)
# ifdef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
-# define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
+# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
# else
// fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
-# define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR
+# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR
# endif
#endif
-#if !defined(RGB_MATRIX_STARTUP_HUE)
-# define RGB_MATRIX_STARTUP_HUE 0
+#if !defined(RGB_MATRIX_DEFAULT_HUE)
+# define RGB_MATRIX_DEFAULT_HUE 0
#endif
-#if !defined(RGB_MATRIX_STARTUP_SAT)
-# define RGB_MATRIX_STARTUP_SAT UINT8_MAX
+#if !defined(RGB_MATRIX_DEFAULT_SAT)
+# define RGB_MATRIX_DEFAULT_SAT UINT8_MAX
#endif
-#if !defined(RGB_MATRIX_STARTUP_VAL)
-# define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
+#if !defined(RGB_MATRIX_DEFAULT_VAL)
+# define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
#endif
-#if !defined(RGB_MATRIX_STARTUP_SPD)
-# define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2
+#if !defined(RGB_MATRIX_DEFAULT_SPD)
+# define RGB_MATRIX_DEFAULT_SPD UINT8_MAX / 2
#endif
#if defined(RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) && (RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL >= RGB_MATRIX_MAXIMUM_BRIGHTNESS)
@@ -133,10 +129,10 @@ static uint8_t rgb_last_enable = UINT8_MAX;
static uint8_t rgb_last_effect = UINT8_MAX;
static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false};
static rgb_task_states rgb_task_state = SYNCING;
-#if RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
static uint32_t rgb_anykey_timer;
-static uint32_t rgb_disable_timeout = RGB_DISABLE_TIMEOUT;
-#endif // RGB_DISABLE_TIMEOUT > 0
+static uint32_t rgb_matrix_timeout = RGB_MATRIX_TIMEOUT;
+#endif // RGB_MATRIX_TIMEOUT > 0
// double buffers
static uint32_t rgb_timer_buffer;
@@ -160,9 +156,9 @@ void eeconfig_update_rgb_matrix(void) {
void eeconfig_update_rgb_matrix_default(void) {
dprintf("eeconfig_update_rgb_matrix_default\n");
rgb_matrix_config.enable = 1;
- rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE;
- rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL};
- rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD;
+ rgb_matrix_config.mode = RGB_MATRIX_DEFAULT_MODE;
+ rgb_matrix_config.hsv = (HSV){RGB_MATRIX_DEFAULT_HUE, RGB_MATRIX_DEFAULT_SAT, RGB_MATRIX_DEFAULT_VAL};
+ rgb_matrix_config.speed = RGB_MATRIX_DEFAULT_SPD;
rgb_matrix_config.flags = LED_FLAG_ALL;
eeconfig_flush_rgb_matrix(true);
}
@@ -212,7 +208,7 @@ void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++)
+ for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++)
rgb_matrix_set_color(i, red, green, blue);
#else
rgb_matrix_driver.set_color_all(red, green, blue);
@@ -223,9 +219,9 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
#ifndef RGB_MATRIX_SPLIT
if (!is_keyboard_master()) return;
#endif
-#if RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
rgb_anykey_timer = 0;
-#endif // RGB_DISABLE_TIMEOUT > 0
+#endif // RGB_MATRIX_TIMEOUT > 0
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
uint8_t led[LED_HITS_TO_REMEMBER];
@@ -316,17 +312,17 @@ static bool rgb_matrix_none(effect_params_t *params) {
}
static void rgb_task_timers(void) {
-#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0
+#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_MATRIX_TIMEOUT > 0
uint32_t deltaTime = sync_timer_elapsed32(rgb_timer_buffer);
-#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0
+#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_MATRIX_TIMEOUT > 0
rgb_timer_buffer = sync_timer_read32();
// Update double buffer timers
-#if RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
if (rgb_anykey_timer + deltaTime <= UINT32_MAX) {
rgb_anykey_timer += deltaTime;
}
-#endif // RGB_DISABLE_TIMEOUT > 0
+#endif // RGB_MATRIX_TIMEOUT > 0
// Update double buffer last hit timers
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
@@ -431,7 +427,7 @@ static void rgb_task_flush(uint8_t effect) {
rgb_matrix_driver.exit_shutdown();
driver_shutdown = false;
}
-#endif
+#endif
// update pwm buffers
rgb_matrix_update_pwm_buffers();
#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE
@@ -439,7 +435,7 @@ static void rgb_task_flush(uint8_t effect) {
if (effect == RGB_MATRIX_NONE && !driver_shutdown && rgb_matrix_driver_allow_shutdown()) {
rgb_matrix_driver_shutdown();
}
-#endif
+#endif
// next task
rgb_task_state = SYNCING;
@@ -451,9 +447,9 @@ void rgb_matrix_task(void) {
// Ideally we would also stop sending zeros to the LED driver PWM buffers
// while suspended and just do a software shutdown. This is a cheap hack for now.
bool suspend_backlight = suspend_state ||
-#if RGB_DISABLE_TIMEOUT > 0
- (rgb_anykey_timer > rgb_disable_timeout) ||
-#endif // RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
+ (rgb_anykey_timer > rgb_matrix_timeout) ||
+#endif // RGB_MATRIX_TIMEOUT > 0
false;
uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
@@ -480,12 +476,15 @@ void rgb_matrix_task(void) {
void rgb_matrix_indicators(void) {
rgb_matrix_indicators_kb();
- rgb_matrix_indicators_user();
}
-__attribute__((weak)) void rgb_matrix_indicators_kb(void) {}
+__attribute__((weak)) bool rgb_matrix_indicators_kb(void) {
+ return rgb_matrix_indicators_user();
+}
-__attribute__((weak)) void rgb_matrix_indicators_user(void) {}
+__attribute__((weak)) bool rgb_matrix_indicators_user(void) {
+ return true;
+}
void rgb_matrix_indicators_advanced(effect_params_t *params) {
/* special handling is needed for "params->iter", since it's already been incremented.
@@ -493,27 +492,30 @@ void rgb_matrix_indicators_advanced(effect_params_t *params) {
* and not sure which would be better. Otherwise, this should be called from
* rgb_task_render, right before the iter++ line.
*/
-#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
+#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT
uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT;
- if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
+ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT;
#else
uint8_t min = 0;
- uint8_t max = DRIVER_LED_TOTAL;
+ uint8_t max = RGB_MATRIX_LED_COUNT;
#endif
rgb_matrix_indicators_advanced_kb(min, max);
- rgb_matrix_indicators_advanced_user(min, max);
}
-__attribute__((weak)) void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}
+__attribute__((weak)) bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
+ return rgb_matrix_indicators_advanced_user(led_min, led_max);
+}
-__attribute__((weak)) void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}
+__attribute__((weak)) bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
+ return true;
+}
void rgb_matrix_init(void) {
rgb_matrix_driver.init();
#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE
driver_shutdown = false;
-#endif
+#endif
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
g_last_hit_tracker.count = 0;
@@ -811,15 +813,15 @@ void rgb_matrix_set_flags_noeeprom(led_flags_t flags) {
}
-#if RGB_DISABLE_TIMEOUT > 0
-void rgb_matrix_disable_timeout_set(uint32_t timeout) {
- rgb_disable_timeout = timeout;
+#if RGB_MATRIX_TIMEOUT > 0
+void rgb_matrix_disable_timeout_set(uint32_t timeout) {
+ rgb_matrix_timeout = timeout;
}
void rgb_matrix_disable_time_reset(void){ rgb_anykey_timer = 0; }
#endif
#ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE
-void rgb_matrix_driver_shutdown(void) {
+void rgb_matrix_driver_shutdown(void) {
rgb_matrix_driver.shutdown();
driver_shutdown = true;
};
@@ -827,4 +829,4 @@ void rgb_matrix_driver_shutdown(void) {
bool rgb_matrix_is_driver_shutdown(void) { return driver_shutdown; }
__attribute__((weak)) bool rgb_matrix_driver_allow_shutdown(void) { return true; };
-#endif \ No newline at end of file
+#endif