You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
7.7 KiB

  1. /* Copyright 2017 Jason Williams
  2. * Copyright 2017 Jack Humbert
  3. * Copyright 2018 Yiancar
  4. * Copyright 2019 Clueboard
  5. * Copyright 2021 Leo Deng
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #pragma once
  21. #include <stdint.h>
  22. #include <stdbool.h>
  23. #include "led_matrix_types.h"
  24. #include "keyboard.h"
  25. #ifdef IS31FL3731
  26. # include "is31fl3731-simple.h"
  27. #elif defined(IS31FLCOMMON)
  28. # include "is31flcommon.h"
  29. #endif
  30. #ifdef IS31FL3733
  31. # include "is31fl3733-simple.h"
  32. #endif
  33. #ifdef CKLED2001
  34. # include "ckled2001-simple.h"
  35. #endif
  36. #ifndef LED_MATRIX_LED_FLUSH_LIMIT
  37. # define LED_MATRIX_LED_FLUSH_LIMIT 16
  38. #endif
  39. #ifndef LED_MATRIX_LED_PROCESS_LIMIT
  40. # define LED_MATRIX_LED_PROCESS_LIMIT ((LED_MATRIX_LED_COUNT + 4) / 5)
  41. #endif
  42. #define LED_MATRIX_LED_PROCESS_MAX_ITERATIONS ((LED_MATRIX_LED_COUNT + LED_MATRIX_LED_PROCESS_LIMIT - 1) / LED_MATRIX_LED_PROCESS_LIMIT)
  43. #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT
  44. # if defined(LED_MATRIX_SPLIT)
  45. # define LED_MATRIX_USE_LIMITS(min, max) \
  46. uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
  47. uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
  48. if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT; \
  49. uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
  50. if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
  51. if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
  52. # else
  53. # define LED_MATRIX_USE_LIMITS(min, max) \
  54. uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
  55. uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
  56. if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT;
  57. # endif
  58. #else
  59. # if defined(LED_MATRIX_SPLIT)
  60. # define LED_MATRIX_USE_LIMITS(min, max) \
  61. uint8_t min = 0; \
  62. uint8_t max = LED_MATRIX_LED_COUNT; \
  63. const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
  64. if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
  65. if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
  66. # else
  67. # define LED_MATRIX_USE_LIMITS(min, max) \
  68. uint8_t min = 0; \
  69. uint8_t max = LED_MATRIX_LED_COUNT;
  70. # endif
  71. #endif
  72. #define LED_MATRIX_TEST_LED_FLAGS() \
  73. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
  74. enum led_matrix_effects {
  75. LED_MATRIX_NONE = 0,
  76. // --------------------------------------
  77. // -----Begin led effect enum macros-----
  78. #define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name,
  79. #include "led_matrix_effects.inc"
  80. #undef LED_MATRIX_EFFECT
  81. #if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER)
  82. # define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name,
  83. # ifdef LED_MATRIX_CUSTOM_KB
  84. # include "led_matrix_kb.inc"
  85. # endif
  86. # ifdef LED_MATRIX_CUSTOM_USER
  87. # include "led_matrix_user.inc"
  88. # endif
  89. # undef LED_MATRIX_EFFECT
  90. #endif
  91. // --------------------------------------
  92. // -----End led effect enum macros-------
  93. LED_MATRIX_EFFECT_MAX
  94. };
  95. void eeconfig_update_led_matrix_default(void);
  96. void eeconfig_update_led_matrix(void);
  97. void eeconfig_debug_led_matrix(void);
  98. uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
  99. uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
  100. void led_matrix_set_value(int index, uint8_t value);
  101. void led_matrix_set_value_all(uint8_t value);
  102. void process_led_matrix(uint8_t row, uint8_t col, bool pressed);
  103. void led_matrix_task(void);
  104. // This runs after another backlight effect and replaces
  105. // values already set
  106. void led_matrix_indicators(void);
  107. bool led_matrix_indicators_kb(void);
  108. bool led_matrix_indicators_user(void);
  109. void led_matrix_indicators_advanced(effect_params_t *params);
  110. bool led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
  111. bool led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
  112. void led_matrix_init(void);
  113. void led_matrix_set_suspend_state(bool state);
  114. bool led_matrix_get_suspend_state(void);
  115. void led_matrix_toggle(void);
  116. void led_matrix_toggle_noeeprom(void);
  117. void led_matrix_enable(void);
  118. void led_matrix_enable_noeeprom(void);
  119. void led_matrix_disable(void);
  120. void led_matrix_disable_noeeprom(void);
  121. uint8_t led_matrix_is_enabled(void);
  122. void led_matrix_mode(uint8_t mode);
  123. void led_matrix_mode_noeeprom(uint8_t mode);
  124. uint8_t led_matrix_get_mode(void);
  125. void led_matrix_step(void);
  126. void led_matrix_step_noeeprom(void);
  127. void led_matrix_step_reverse(void);
  128. void led_matrix_step_reverse_noeeprom(void);
  129. void led_matrix_set_val(uint8_t val);
  130. void led_matrix_set_val_noeeprom(uint8_t val);
  131. uint8_t led_matrix_get_val(void);
  132. void led_matrix_increase_val(void);
  133. void led_matrix_increase_val_noeeprom(void);
  134. void led_matrix_decrease_val(void);
  135. void led_matrix_decrease_val_noeeprom(void);
  136. void led_matrix_set_speed(uint8_t speed);
  137. void led_matrix_set_speed_noeeprom(uint8_t speed);
  138. uint8_t led_matrix_get_speed(void);
  139. void led_matrix_increase_speed(void);
  140. void led_matrix_increase_speed_noeeprom(void);
  141. void led_matrix_decrease_speed(void);
  142. void led_matrix_decrease_speed_noeeprom(void);
  143. led_flags_t led_matrix_get_flags(void);
  144. void led_matrix_set_flags(led_flags_t flags);
  145. void led_matrix_set_flags_noeeprom(led_flags_t flags);
  146. typedef struct {
  147. /* Perform any initialisation required for the other driver functions to work. */
  148. void (*init)(void);
  149. /* Set the brightness of a single LED in the buffer. */
  150. void (*set_value)(int index, uint8_t value);
  151. /* Set the brightness of all LEDS on the keyboard in the buffer. */
  152. void (*set_value_all)(uint8_t value);
  153. /* Flush any buffered changes to the hardware. */
  154. void (*flush)(void);
  155. } led_matrix_driver_t;
  156. static inline bool led_matrix_check_finished_leds(uint8_t led_idx) {
  157. #if defined(LED_MATRIX_SPLIT)
  158. if (is_keyboard_left()) {
  159. uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
  160. return led_idx < k_led_matrix_split[0];
  161. } else
  162. return led_idx < LED_MATRIX_LED_COUNT;
  163. #else
  164. return led_idx < LED_MATRIX_LED_COUNT;
  165. #endif
  166. }
  167. extern const led_matrix_driver_t led_matrix_driver;
  168. extern led_eeconfig_t led_matrix_eeconfig;
  169. extern uint32_t g_led_timer;
  170. extern led_config_t g_led_config;
  171. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  172. extern last_hit_t g_last_hit_tracker;
  173. #endif
  174. #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
  175. extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
  176. #endif