logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

led_matrix.h (6740B)


  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 "led_matrix_drivers.h"
  25. #include "keyboard.h"
  26. #ifndef LED_MATRIX_TIMEOUT
  27. # define LED_MATRIX_TIMEOUT 0
  28. #endif
  29. #ifndef LED_MATRIX_MAXIMUM_BRIGHTNESS
  30. # define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
  31. #endif
  32. #ifndef LED_MATRIX_VAL_STEP
  33. # define LED_MATRIX_VAL_STEP 8
  34. #endif
  35. #ifndef LED_MATRIX_SPD_STEP
  36. # define LED_MATRIX_SPD_STEP 16
  37. #endif
  38. #ifndef LED_MATRIX_DEFAULT_ON
  39. # define LED_MATRIX_DEFAULT_ON true
  40. #endif
  41. #ifndef LED_MATRIX_DEFAULT_MODE
  42. # define LED_MATRIX_DEFAULT_MODE LED_MATRIX_SOLID
  43. #endif
  44. #ifndef LED_MATRIX_DEFAULT_VAL
  45. # define LED_MATRIX_DEFAULT_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS
  46. #endif
  47. #ifndef LED_MATRIX_DEFAULT_SPD
  48. # define LED_MATRIX_DEFAULT_SPD UINT8_MAX / 2
  49. #endif
  50. #ifndef LED_MATRIX_DEFAULT_FLAGS
  51. # define LED_MATRIX_DEFAULT_FLAGS LED_FLAG_ALL
  52. #endif
  53. #ifndef LED_MATRIX_LED_FLUSH_LIMIT
  54. # define LED_MATRIX_LED_FLUSH_LIMIT 16
  55. #endif
  56. #ifndef LED_MATRIX_LED_PROCESS_LIMIT
  57. # define LED_MATRIX_LED_PROCESS_LIMIT ((LED_MATRIX_LED_COUNT + 4) / 5)
  58. #endif
  59. struct led_matrix_limits_t {
  60. uint8_t led_min_index;
  61. uint8_t led_max_index;
  62. };
  63. struct led_matrix_limits_t led_matrix_get_limits(uint8_t iter);
  64. #define LED_MATRIX_USE_LIMITS_ITER(min, max, iter) \
  65. struct led_matrix_limits_t limits = led_matrix_get_limits(iter); \
  66. uint8_t min = limits.led_min_index; \
  67. uint8_t max = limits.led_max_index; \
  68. (void)min; \
  69. (void)max;
  70. #define LED_MATRIX_USE_LIMITS(min, max) LED_MATRIX_USE_LIMITS_ITER(min, max, params->iter)
  71. #define LED_MATRIX_TEST_LED_FLAGS() \
  72. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
  73. enum led_matrix_effects {
  74. LED_MATRIX_NONE = 0,
  75. // --------------------------------------
  76. // -----Begin led effect enum macros-----
  77. #define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name,
  78. #include "led_matrix_effects.inc"
  79. #undef LED_MATRIX_EFFECT
  80. #ifdef COMMUNITY_MODULES_ENABLE
  81. # define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_COMMUNITY_MODULE_##name,
  82. # include "led_matrix_community_modules.inc"
  83. # undef LED_MATRIX_EFFECT
  84. #endif
  85. #if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER)
  86. # define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name,
  87. # ifdef LED_MATRIX_CUSTOM_KB
  88. # include "led_matrix_kb.inc"
  89. # endif
  90. # ifdef LED_MATRIX_CUSTOM_USER
  91. # include "led_matrix_user.inc"
  92. # endif
  93. # undef LED_MATRIX_EFFECT
  94. #endif
  95. // --------------------------------------
  96. // -----End led effect enum macros-------
  97. LED_MATRIX_EFFECT_MAX
  98. };
  99. void eeconfig_update_led_matrix_default(void);
  100. void eeconfig_force_flush_led_matrix(void);
  101. void eeconfig_debug_led_matrix(void);
  102. uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
  103. uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
  104. int led_matrix_led_index(int index);
  105. void led_matrix_set_value(int index, uint8_t value);
  106. void led_matrix_set_value_all(uint8_t value);
  107. void led_matrix_handle_key_event(uint8_t row, uint8_t col, bool pressed);
  108. void led_matrix_task(void);
  109. // This runs after another backlight effect and replaces
  110. // values already set
  111. void led_matrix_indicators(void);
  112. bool led_matrix_indicators_kb(void);
  113. bool led_matrix_indicators_user(void);
  114. void led_matrix_indicators_advanced(effect_params_t *params);
  115. bool led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
  116. bool led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
  117. void led_matrix_init(void);
  118. void led_matrix_reload_from_eeprom(void);
  119. void led_matrix_set_suspend_state(bool state);
  120. bool led_matrix_get_suspend_state(void);
  121. void led_matrix_toggle(void);
  122. void led_matrix_toggle_noeeprom(void);
  123. void led_matrix_enable(void);
  124. void led_matrix_enable_noeeprom(void);
  125. void led_matrix_disable(void);
  126. void led_matrix_disable_noeeprom(void);
  127. uint8_t led_matrix_is_enabled(void);
  128. void led_matrix_mode(uint8_t mode);
  129. void led_matrix_mode_noeeprom(uint8_t mode);
  130. uint8_t led_matrix_get_mode(void);
  131. void led_matrix_step(void);
  132. void led_matrix_step_noeeprom(void);
  133. void led_matrix_step_reverse(void);
  134. void led_matrix_step_reverse_noeeprom(void);
  135. void led_matrix_set_val(uint8_t val);
  136. void led_matrix_set_val_noeeprom(uint8_t val);
  137. uint8_t led_matrix_get_val(void);
  138. void led_matrix_increase_val(void);
  139. void led_matrix_increase_val_noeeprom(void);
  140. void led_matrix_decrease_val(void);
  141. void led_matrix_decrease_val_noeeprom(void);
  142. void led_matrix_set_speed(uint8_t speed);
  143. void led_matrix_set_speed_noeeprom(uint8_t speed);
  144. uint8_t led_matrix_get_speed(void);
  145. void led_matrix_increase_speed(void);
  146. void led_matrix_increase_speed_noeeprom(void);
  147. void led_matrix_decrease_speed(void);
  148. void led_matrix_decrease_speed_noeeprom(void);
  149. led_flags_t led_matrix_get_flags(void);
  150. void led_matrix_set_flags(led_flags_t flags);
  151. void led_matrix_set_flags_noeeprom(led_flags_t flags);
  152. static inline bool led_matrix_check_finished_leds(uint8_t led_idx) {
  153. #if defined(LED_MATRIX_SPLIT)
  154. if (is_keyboard_left()) {
  155. uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
  156. return led_idx < k_led_matrix_split[0];
  157. } else
  158. return led_idx < LED_MATRIX_LED_COUNT;
  159. #else
  160. return led_idx < LED_MATRIX_LED_COUNT;
  161. #endif
  162. }
  163. extern led_eeconfig_t led_matrix_eeconfig;
  164. extern uint32_t g_led_timer;
  165. extern led_config_t g_led_config;
  166. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  167. extern last_hit_t g_last_hit_tracker;
  168. #endif
  169. #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
  170. extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
  171. #endif