summaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgb_matrix')
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c32
-rw-r--r--quantum/rgb_matrix/rgb_matrix_drivers.c127
2 files changed, 85 insertions, 74 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c
index 8f00b40877..c260b6e1e8 100644
--- a/quantum/rgb_matrix/rgb_matrix.c
+++ b/quantum/rgb_matrix/rgb_matrix.c
@@ -31,14 +31,6 @@ const led_point_t k_rgb_matrix_center = {112, 32};
const led_point_t k_rgb_matrix_center = RGB_MATRIX_CENTER;
#endif
-// clang-format off
-#ifndef RGB_MATRIX_IMMEDIATE_EEPROM
-# define rgb_eeconfig_update(v) rgb_update_eeprom |= v
-#else
-# define rgb_eeconfig_update(v) if (v) eeconfig_update_rgb_matrix()
-#endif
-// clang-format on
-
__attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); }
// Generic effect runners
@@ -128,7 +120,6 @@ last_hit_t g_last_hit_tracker;
// internals
static bool suspend_state = false;
-static bool rgb_update_eeprom = false;
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};
@@ -148,9 +139,9 @@ static last_hit_t last_hit_buffer;
const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
#endif
-void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
+EECONFIG_DEBOUNCE_HELPER(rgb_matrix, EECONFIG_RGB_MATRIX, rgb_matrix_config);
-void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
+void eeconfig_update_rgb_matrix(void) { eeconfig_flush_rgb_matrix(true); }
void eeconfig_update_rgb_matrix_default(void) {
dprintf("eeconfig_update_rgb_matrix_default\n");
@@ -159,7 +150,7 @@ void eeconfig_update_rgb_matrix_default(void) {
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.flags = LED_FLAG_ALL;
- eeconfig_update_rgb_matrix();
+ eeconfig_flush_rgb_matrix(true);
}
void eeconfig_debug_rgb_matrix(void) {
@@ -314,9 +305,8 @@ static void rgb_task_timers(void) {
}
static void rgb_task_sync(void) {
+ eeconfig_flush_rgb_matrix(false);
// next task
- if (rgb_update_eeprom) eeconfig_update_rgb_matrix();
- rgb_update_eeprom = false;
if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING;
}
@@ -491,7 +481,7 @@ void rgb_matrix_init(void) {
eeconfig_update_rgb_matrix_default();
}
- eeconfig_read_rgb_matrix();
+ eeconfig_init_rgb_matrix();
if (!rgb_matrix_config.mode) {
dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
eeconfig_update_rgb_matrix_default();
@@ -514,7 +504,7 @@ bool rgb_matrix_get_suspend_state(void) { return suspend_state; }
void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
rgb_matrix_config.enable ^= 1;
rgb_task_state = STARTING;
- rgb_eeconfig_update(write_to_eeprom);
+ eeconfig_flag_rgb_matrix(write_to_eeprom);
dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable);
}
void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); }
@@ -522,7 +512,7 @@ void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); }
void rgb_matrix_enable(void) {
rgb_matrix_enable_noeeprom();
- rgb_eeconfig_update(true);
+ eeconfig_flag_rgb_matrix(true);
}
void rgb_matrix_enable_noeeprom(void) {
@@ -532,7 +522,7 @@ void rgb_matrix_enable_noeeprom(void) {
void rgb_matrix_disable(void) {
rgb_matrix_disable_noeeprom();
- rgb_eeconfig_update(true);
+ eeconfig_flag_rgb_matrix(true);
}
void rgb_matrix_disable_noeeprom(void) {
@@ -554,7 +544,7 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
rgb_matrix_config.mode = mode;
}
rgb_task_state = STARTING;
- rgb_eeconfig_update(write_to_eeprom);
+ eeconfig_flag_rgb_matrix(write_to_eeprom);
dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode);
}
void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); }
@@ -583,7 +573,7 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo
rgb_matrix_config.hsv.h = hue;
rgb_matrix_config.hsv.s = sat;
rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val;
- rgb_eeconfig_update(write_to_eeprom);
+ eeconfig_flag_rgb_matrix(write_to_eeprom);
dprintf("rgb matrix set hsv [%s]: %u,%u,%u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v);
}
void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); }
@@ -620,7 +610,7 @@ void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); }
void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
rgb_matrix_config.speed = speed;
- rgb_eeconfig_update(write_to_eeprom);
+ eeconfig_flag_rgb_matrix(write_to_eeprom);
dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed);
}
void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); }
diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c
index 2cec162e22..4335088eb8 100644
--- a/quantum/rgb_matrix/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix/rgb_matrix_drivers.c
@@ -24,110 +24,126 @@
*/
#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) || defined(IS31FL3741)
-
# include "i2c_master.h"
+// TODO: Remove this at some later date
+# if defined(DRIVER_ADDR_1) && defined(DRIVER_ADDR_2)
+# if DRIVER_ADDR_1 == DRIVER_ADDR_2
+# error "Setting DRIVER_ADDR_2 == DRIVER_ADDR_1 is obsolete. If you are only using one ISSI driver, set DRIVER_COUNT to 1 and remove DRIVER_ADDR_2"
+# endif
+# endif
+
static void init(void) {
i2c_init();
-# ifdef IS31FL3731
+
+# if defined(IS31FL3731)
IS31FL3731_init(DRIVER_ADDR_1);
-# ifdef DRIVER_ADDR_2
+# if defined(DRIVER_ADDR_2)
IS31FL3731_init(DRIVER_ADDR_2);
-# endif
-# ifdef DRIVER_ADDR_3
+# if defined(DRIVER_ADDR_3)
IS31FL3731_init(DRIVER_ADDR_3);
-# endif
-# ifdef DRIVER_ADDR_4
+# if defined(DRIVER_ADDR_4)
IS31FL3731_init(DRIVER_ADDR_4);
+# endif
+# endif
# endif
+
# elif defined(IS31FL3733)
-# ifndef DRIVER_SYNC_1
+# if !defined(DRIVER_SYNC_1)
# define DRIVER_SYNC_1 0
# endif
IS31FL3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1);
-# if defined DRIVER_ADDR_2 && (DRIVER_ADDR_1 != DRIVER_ADDR_2)
-# ifndef DRIVER_SYNC_2
+# if defined(DRIVER_ADDR_2)
+# if !defined(DRIVER_SYNC_2)
# define DRIVER_SYNC_2 0
# endif
IS31FL3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2);
-# endif
-# ifdef DRIVER_ADDR_3
-# ifndef DRIVER_SYNC_3
-# define DRIVER_SYNC_3 0
-# endif
+# if defined(DRIVER_ADDR_3)
+# if !defined(DRIVER_SYNC_3)
+# define DRIVER_SYNC_3 0
+# endif
IS31FL3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3);
-# endif
-# ifdef DRIVER_ADDR_4
-# ifndef DRIVER_SYNC_4
-# define DRIVER_SYNC_4 0
-# endif
+# if defined(DRIVER_ADDR_4)
+# if !defined(DRIVER_SYNC_4)
+# define DRIVER_SYNC_4 0
+# endif
IS31FL3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4);
+# endif
+# endif
# endif
+
# elif defined(IS31FL3737)
IS31FL3737_init(DRIVER_ADDR_1);
-# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
+# if defined(DRIVER_ADDR_2)
IS31FL3737_init(DRIVER_ADDR_2);
# endif
-# else
+
+# elif defined(IS31FL3741)
IS31FL3741_init(DRIVER_ADDR_1);
# endif
+
for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
bool enabled = true;
+
// This only caches it for later
-# ifdef IS31FL3731
+# if defined(IS31FL3731)
IS31FL3731_set_led_control_register(index, enabled, enabled, enabled);
# elif defined(IS31FL3733)
IS31FL3733_set_led_control_register(index, enabled, enabled, enabled);
# elif defined(IS31FL3737)
IS31FL3737_set_led_control_register(index, enabled, enabled, enabled);
-# else
+# elif defined(IS31FL3741)
IS31FL3741_set_led_control_register(index, enabled, enabled, enabled);
# endif
}
+
// This actually updates the LED drivers
-# ifdef IS31FL3731
+# if defined(IS31FL3731)
IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0);
-# ifdef DRIVER_ADDR_2
+# if defined(DRIVER_ADDR_2)
IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1);
-# endif
-# ifdef DRIVER_ADDR_3
+# if defined(DRIVER_ADDR_3)
IS31FL3731_update_led_control_registers(DRIVER_ADDR_3, 2);
-# endif
-# ifdef DRIVER_ADDR_4
+# if defined(DRIVER_ADDR_4)
IS31FL3731_update_led_control_registers(DRIVER_ADDR_4, 3);
+# endif
+# endif
# endif
+
# elif defined(IS31FL3733)
IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
-# ifdef DRIVER_ADDR_2
+# if defined(DRIVER_ADDR_2)
IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
-# endif
-# ifdef DRIVER_ADDR_3
+# if defined(DRIVER_ADDR_3)
IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2);
-# endif
-# ifdef DRIVER_ADDR_4
+# if defined(DRIVER_ADDR_4)
IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3);
+# endif
+# endif
# endif
+
# elif defined(IS31FL3737)
IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, 0);
-# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
+# if defined(DRIVER_ADDR_2)
IS31FL3737_update_led_control_registers(DRIVER_ADDR_2, 1);
# endif
-# else
+
+# elif defined(IS31FL3741)
IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0);
# endif
}
-# ifdef IS31FL3731
+# if defined(IS31FL3731)
static void flush(void) {
IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0);
-# ifdef DRIVER_ADDR_2
+# if defined(DRIVER_ADDR_2)
IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1);
-# endif
-# ifdef DRIVER_ADDR_3
+# if defined(DRIVER_ADDR_3)
IS31FL3731_update_pwm_buffers(DRIVER_ADDR_3, 2);
-# endif
-# ifdef DRIVER_ADDR_4
+# if defined(DRIVER_ADDR_4)
IS31FL3731_update_pwm_buffers(DRIVER_ADDR_4, 3);
+# endif
+# endif
# endif
}
@@ -137,17 +153,18 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
.set_color = IS31FL3731_set_color,
.set_color_all = IS31FL3731_set_color_all,
};
+
# elif defined(IS31FL3733)
static void flush(void) {
IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
-# ifdef DRIVER_ADDR_2
+# if defined(DRIVER_ADDR_2)
IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
-# endif
-# ifdef DRIVER_ADDR_3
+# if defined(DRIVER_ADDR_3)
IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2);
-# endif
-# ifdef DRIVER_ADDR_4
+# if defined(DRIVER_ADDR_4)
IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3);
+# endif
+# endif
# endif
}
@@ -157,10 +174,11 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
.set_color = IS31FL3733_set_color,
.set_color_all = IS31FL3733_set_color_all,
};
+
# elif defined(IS31FL3737)
static void flush(void) {
IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, 0);
-# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
+# if defined(DRIVER_ADDR_2)
IS31FL3737_update_pwm_buffers(DRIVER_ADDR_2, 1);
# endif
}
@@ -171,10 +189,11 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
.set_color = IS31FL3737_set_color,
.set_color_all = IS31FL3737_set_color_all,
};
-# else
+
+# elif defined(IS31FL3741)
static void flush(void) {
IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, 0);
-# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
+# if defined(DRIVER_ADDR_2)
IS31FL3741_update_pwm_buffers(DRIVER_ADDR_2, 1);
# endif
}
@@ -189,17 +208,19 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
#elif defined(AW20216)
# include "spi_master.h"
+
static void init(void) {
spi_init();
+
AW20216_init(DRIVER_1_CS, DRIVER_1_EN);
-# ifdef DRIVER_2_CS
+# if defined(DRIVER_2_CS)
AW20216_init(DRIVER_2_CS, DRIVER_2_EN);
# endif
}
static void flush(void) {
AW20216_update_pwm_buffers(DRIVER_1_CS, 0);
-# ifdef DRIVER_2_CS
+# if defined(DRIVER_2_CS)
AW20216_update_pwm_buffers(DRIVER_2_CS, 1);
# endif
}