led_matrix.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. # define LED_MATRIX_USE_LIMITS(min, max) \
  36. uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
  37. uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
  38. if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
  39. #else
  40. # define LED_MATRIX_USE_LIMITS(min, max) \
  41. uint8_t min = 0; \
  42. uint8_t max = DRIVER_LED_TOTAL;
  43. #endif
  44. #define LED_MATRIX_TEST_LED_FLAGS() \
  45. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
  46. enum led_matrix_effects {
  47. LED_MATRIX_NONE = 0,
  48. // --------------------------------------
  49. // -----Begin led effect enum macros-----
  50. #define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_##name,
  51. #include "led_matrix_effects.inc"
  52. #undef LED_MATRIX_EFFECT
  53. #if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER)
  54. # define LED_MATRIX_EFFECT(name, ...) LED_MATRIX_CUSTOM_##name,
  55. # ifdef LED_MATRIX_CUSTOM_KB
  56. # include "led_matrix_kb.inc"
  57. # endif
  58. # ifdef LED_MATRIX_CUSTOM_USER
  59. # include "led_matrix_user.inc"
  60. # endif
  61. # undef LED_MATRIX_EFFECT
  62. #endif
  63. // --------------------------------------
  64. // -----End led effect enum macros-------
  65. LED_MATRIX_EFFECT_MAX
  66. };
  67. void eeconfig_update_led_matrix_default(void);
  68. void eeconfig_update_led_matrix(void);
  69. void eeconfig_debug_led_matrix(void);
  70. uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
  71. uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
  72. void led_matrix_set_value(int index, uint8_t value);
  73. void led_matrix_set_value_all(uint8_t value);
  74. void process_led_matrix(uint8_t row, uint8_t col, bool pressed);
  75. void led_matrix_task(void);
  76. // This runs after another backlight effect and replaces
  77. // values already set
  78. void led_matrix_indicators(void);
  79. void led_matrix_indicators_kb(void);
  80. void led_matrix_indicators_user(void);
  81. void led_matrix_indicators_advanced(effect_params_t *params);
  82. void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
  83. void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
  84. void led_matrix_init(void);
  85. void led_matrix_set_suspend_state(bool state);
  86. bool led_matrix_get_suspend_state(void);
  87. void led_matrix_toggle(void);
  88. void led_matrix_toggle_noeeprom(void);
  89. void led_matrix_enable(void);
  90. void led_matrix_enable_noeeprom(void);
  91. void led_matrix_disable(void);
  92. void led_matrix_disable_noeeprom(void);
  93. uint8_t led_matrix_is_enabled(void);
  94. void led_matrix_mode(uint8_t mode);
  95. void led_matrix_mode_noeeprom(uint8_t mode);
  96. uint8_t led_matrix_get_mode(void);
  97. void led_matrix_step(void);
  98. void led_matrix_step_noeeprom(void);
  99. void led_matrix_step_reverse(void);
  100. void led_matrix_step_reverse_noeeprom(void);
  101. void led_matrix_set_val(uint8_t val);
  102. void led_matrix_set_val_noeeprom(uint8_t val);
  103. uint8_t led_matrix_get_val(void);
  104. void led_matrix_increase_val(void);
  105. void led_matrix_increase_val_noeeprom(void);
  106. void led_matrix_decrease_val(void);
  107. void led_matrix_decrease_val_noeeprom(void);
  108. void led_matrix_set_speed(uint8_t speed);
  109. void led_matrix_set_speed_noeeprom(uint8_t speed);
  110. uint8_t led_matrix_get_speed(void);
  111. void led_matrix_increase_speed(void);
  112. void led_matrix_increase_speed_noeeprom(void);
  113. void led_matrix_decrease_speed(void);
  114. void led_matrix_decrease_speed_noeeprom(void);
  115. led_flags_t led_matrix_get_flags(void);
  116. void led_matrix_set_flags(led_flags_t flags);
  117. typedef struct {
  118. /* Perform any initialisation required for the other driver functions to work. */
  119. void (*init)(void);
  120. /* Set the brightness of a single LED in the buffer. */
  121. void (*set_value)(int index, uint8_t value);
  122. /* Set the brightness of all LEDS on the keyboard in the buffer. */
  123. void (*set_value_all)(uint8_t value);
  124. /* Flush any buffered changes to the hardware. */
  125. void (*flush)(void);
  126. } led_matrix_driver_t;
  127. extern const led_matrix_driver_t led_matrix_driver;
  128. extern led_eeconfig_t led_matrix_eeconfig;
  129. extern uint32_t g_led_timer;
  130. extern led_config_t g_led_config;
  131. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  132. extern last_hit_t g_last_hit_tracker;
  133. #endif
  134. #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
  135. extern uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
  136. #endif