led_matrix.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #pragma once
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include "led_matrix_types.h"
  23. #include "quantum.h"
  24. #include "led_matrix_legacy_enables.h"
  25. #ifdef IS31FL3731
  26. # include "is31fl3731-simple.h"
  27. #endif
  28. #ifndef LED_MATRIX_LED_FLUSH_LIMIT
  29. # define LED_MATRIX_LED_FLUSH_LIMIT 16
  30. #endif
  31. #ifndef LED_MATRIX_LED_PROCESS_LIMIT
  32. # define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
  33. #endif
  34. #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
  35. # if defined(LED_MATRIX_SPLIT)
  36. # define LED_MATRIX_USE_LIMITS(min, max) \
  37. uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
  38. uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
  39. if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; \
  40. uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
  41. if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
  42. if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
  43. # else
  44. # define LED_MATRIX_USE_LIMITS(min, max) \
  45. uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
  46. uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
  47. if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
  48. # endif
  49. #else
  50. # if defined(LED_MATRIX_SPLIT)
  51. # define LED_MATRIX_USE_LIMITS(min, max) \
  52. uint8_t min = 0; \
  53. uint8_t max = DRIVER_LED_TOTAL; \
  54. const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
  55. if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
  56. if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
  57. # else
  58. # define LED_MATRIX_USE_LIMITS(min, max) \
  59. uint8_t min = 0; \
  60. uint8_t max = DRIVER_LED_TOTAL;
  61. # endif
  62. #endif
  63. #define LED_MATRIX_TEST_LED_FLAGS() \
  64. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
  65. enum led_matrix_effects {
  66. LED_MATRIX_NONE = 0,
  67. // --------------------------------------
  68. // -----Begin led effect enum macros-----
  69. #define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name,
  70. #include "led_matrix_effects.inc"
  71. #undef LED_MATRIX_EFFECT
  72. #if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER)
  73. # define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name,
  74. # ifdef LED_MATRIX_CUSTOM_KB
  75. # include "led_matrix_kb.inc"
  76. # endif
  77. # ifdef LED_MATRIX_CUSTOM_USER
  78. # include "led_matrix_user.inc"
  79. # endif
  80. # undef LED_MATRIX_EFFECT
  81. #endif
  82. // --------------------------------------
  83. // -----End led effect enum macros-------
  84. LED_MATRIX_EFFECT_MAX
  85. };
  86. void eeconfig_update_led_matrix_default(void);
  87. void eeconfig_update_led_matrix(void);
  88. void eeconfig_debug_led_matrix(void);
  89. uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
  90. uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
  91. void led_matrix_set_value(int index, uint8_t value);
  92. void led_matrix_set_value_all(uint8_t value);
  93. void process_led_matrix(uint8_t row, uint8_t col, bool pressed);
  94. void led_matrix_task(void);
  95. // This runs after another backlight effect and replaces
  96. // values already set
  97. void led_matrix_indicators(void);
  98. void led_matrix_indicators_kb(void);
  99. void led_matrix_indicators_user(void);
  100. void led_matrix_indicators_advanced(effect_params_t *params);
  101. void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
  102. void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
  103. void led_matrix_init(void);
  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. typedef struct {
  137. /* Perform any initialisation required for the other driver functions to work. */
  138. void (*init)(void);
  139. /* Set the brightness of a single LED in the buffer. */
  140. void (*set_value)(int index, uint8_t value);
  141. /* Set the brightness of all LEDS on the keyboard in the buffer. */
  142. void (*set_value_all)(uint8_t value);
  143. /* Flush any buffered changes to the hardware. */
  144. void (*flush)(void);
  145. } led_matrix_driver_t;
  146. static inline bool led_matrix_check_finished_leds(uint8_t led_idx) {
  147. #if defined(LED_MATRIX_SPLIT)
  148. if (is_keyboard_left()) {
  149. uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
  150. return led_idx < k_led_matrix_split[0];
  151. } else
  152. return led_idx < DRIVER_LED_TOTAL;
  153. #else
  154. return led_idx < DRIVER_LED_TOTAL;
  155. #endif
  156. }
  157. extern const led_matrix_driver_t led_matrix_driver;
  158. extern led_eeconfig_t led_matrix_eeconfig;
  159. extern uint32_t g_led_timer;
  160. extern led_config_t g_led_config;
  161. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  162. extern last_hit_t g_last_hit_tracker;
  163. #endif
  164. #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
  165. extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
  166. #endif