]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - quantum/rgb_matrix.c
Implement kb function for rgb matrix to led lookup (#5738)
[qmk_firmware.git] / quantum / rgb_matrix.c
index 5ca9b87a6370adafdd5d1a6d75fc762a558c42d3..5528a08347302d249239d901991ab4d8c7f5ad09 100644 (file)
@@ -144,9 +144,14 @@ void eeconfig_debug_rgb_matrix(void) {
   dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
 }
 
+__attribute__ ((weak))
+uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) {
+  return 0;
+}
+
 uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
   // TODO: This is kinda expensive, fix this soonish
-  uint8_t led_count = 0;
+  uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i);
   for (uint8_t i = 0; i < DRIVER_LED_TOTAL && led_count < LED_HITS_TO_REMEMBER; i++) {
     matrix_co_t matrix_co = g_rgb_leds[i].matrix_co;
     if (row == matrix_co.row && column == matrix_co.col) {
@@ -162,28 +167,11 @@ void rgb_matrix_update_pwm_buffers(void) {
 }
 
 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
-#ifdef RGB_MATRIX_EXTRA_TOG
-  const bool is_key = g_rgb_leds[index].matrix_co.raw != 0xff;
-  if (
-    (rgb_matrix_config.enable == RGB_ZONE_KEYS && !is_key) ||
-    (rgb_matrix_config.enable == RGB_ZONE_UNDER && is_key)
-  ) {
-    rgb_matrix_driver.set_color(index, 0, 0, 0);
-    return;
-  }
-#endif
-
   rgb_matrix_driver.set_color(index, red, green, blue);
 }
 
 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
-#ifdef RGB_MATRIX_EXTRA_TOG
-  for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
-      rgb_matrix_set_color(i, red, green, blue);
-  }
-#else
   rgb_matrix_driver.set_color_all(red, green, blue);
-#endif
 }
 
 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
@@ -262,7 +250,7 @@ static bool rgb_matrix_none(effect_params_t* params) {
 
 static uint8_t rgb_last_enable = UINT8_MAX;
 static uint8_t rgb_last_effect = UINT8_MAX;
-static effect_params_t rgb_effect_params = { 0, 0 };
+static effect_params_t rgb_effect_params = { 0, 0xFF };
 static rgb_task_states rgb_task_state = SYNCING;
 
 static void rgb_task_timers(void) {
@@ -575,29 +563,31 @@ void rgb_matrix_set_suspend_state(bool state) {
 }
 
 void rgb_matrix_toggle(void) {
-  rgb_matrix_config.enable++;
-  if (!rgb_matrix_config.enable) {
-    rgb_task_state = STARTING;
-  }
+  rgb_matrix_config.enable ^= 1;
+  rgb_task_state = STARTING;
   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
 }
 
 void rgb_matrix_enable(void) {
-       rgb_matrix_config.enable = 1;
+  rgb_matrix_enable_noeeprom();
   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
 }
 
 void rgb_matrix_enable_noeeprom(void) {
-       rgb_matrix_config.enable = 1;
+  if (!rgb_matrix_config.enable)
+    rgb_task_state = STARTING;
+  rgb_matrix_config.enable = 1;
 }
 
 void rgb_matrix_disable(void) {
-       rgb_matrix_config.enable = 0;
+  rgb_matrix_disable_noeeprom();
   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
 }
 
 void rgb_matrix_disable_noeeprom(void) {
-       rgb_matrix_config.enable = 0;
+  if (rgb_matrix_config.enable)
+    rgb_task_state = STARTING;
+  rgb_matrix_config.enable = 0;
 }
 
 void rgb_matrix_step(void) {
@@ -658,6 +648,14 @@ void rgb_matrix_decrease_speed(void) {
   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
 }
 
+led_flags_t rgb_matrix_get_flags(void) {
+  return rgb_effect_params.flags;
+}
+
+void rgb_matrix_set_flags(led_flags_t flags) {
+  rgb_effect_params.flags = flags;
+}
+
 void rgb_matrix_mode(uint8_t mode) {
   rgb_matrix_config.mode = mode;
   rgb_task_state = STARTING;