led_matrix.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifndef LED_MATRIX_H
  20. #define LED_MATRIX_H
  21. typedef struct Point {
  22. uint8_t x;
  23. uint8_t y;
  24. } __attribute__((packed)) Point;
  25. typedef struct led_matrix {
  26. union {
  27. uint8_t raw;
  28. struct {
  29. uint8_t row:4; // 16 max
  30. uint8_t col:4; // 16 max
  31. };
  32. } matrix_co;
  33. Point point;
  34. uint8_t modifier:1;
  35. } __attribute__((packed)) led_matrix;
  36. extern const led_matrix g_leds[DRIVER_LED_TOTAL];
  37. typedef struct {
  38. uint8_t index;
  39. uint8_t value;
  40. } led_indicator;
  41. typedef union {
  42. uint32_t raw;
  43. struct {
  44. bool enable :1;
  45. uint8_t mode :6;
  46. uint8_t hue :8; // Unused by led_matrix
  47. uint8_t sat :8; // Unused by led_matrix
  48. uint8_t val :8;
  49. uint8_t speed :8;//EECONFIG needs to be increased to support this
  50. };
  51. } led_config_t;
  52. enum led_matrix_effects {
  53. LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
  54. // All new effects go above this line
  55. LED_MATRIX_EFFECT_MAX
  56. };
  57. void led_matrix_set_index_value(int index, uint8_t value);
  58. void led_matrix_set_index_value_all(uint8_t value);
  59. // This runs after another backlight effect and replaces
  60. // colors already set
  61. void led_matrix_indicators(void);
  62. void led_matrix_indicators_kb(void);
  63. void led_matrix_indicators_user(void);
  64. void led_matrix_init(void);
  65. void led_matrix_setup_drivers(void);
  66. void led_matrix_set_suspend_state(bool state);
  67. void led_matrix_set_indicator_state(uint8_t state);
  68. void led_matrix_task(void);
  69. // This should not be called from an interrupt
  70. // (eg. from a timer interrupt).
  71. // Call this while idle (in between matrix scans).
  72. // If the buffer is dirty, it will update the driver with the buffer.
  73. void led_matrix_update_pwm_buffers(void);
  74. bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
  75. uint32_t led_matrix_get_tick(void);
  76. void led_matrix_toggle(void);
  77. void led_matrix_enable(void);
  78. void led_matrix_enable_noeeprom(void);
  79. void led_matrix_disable(void);
  80. void led_matrix_disable_noeeprom(void);
  81. void led_matrix_step(void);
  82. void led_matrix_step_reverse(void);
  83. void led_matrix_increase_val(void);
  84. void led_matrix_decrease_val(void);
  85. void led_matrix_increase_speed(void);
  86. void led_matrix_decrease_speed(void);
  87. void led_matrix_mode(uint8_t mode, bool eeprom_write);
  88. void led_matrix_mode_noeeprom(uint8_t mode);
  89. uint8_t led_matrix_get_mode(void);
  90. void led_matrix_set_value(uint8_t mode, bool eeprom_write);
  91. #ifndef BACKLIGHT_ENABLE
  92. #define backlight_toggle() backlight_matrix_toggle()
  93. #define backlight_enable() backlight_matrix_enable()
  94. #define backlight_enable_noeeprom() backlight_matrix_enable_noeeprom()
  95. #define backlight_disable() backlight_matrix_disable()
  96. #define backlight_disable_noeeprom() backlight_matrix_disable_noeeprom()
  97. #define backlight_step() backlight_matrix_step()
  98. #define backlight_set_value(val) backlight_matrix_set_value(val)
  99. #define backlight_set_value_noeeprom(val) backlight_matrix_set_value_noeeprom(val)
  100. #define backlight_step_reverse() backlight_matrix_step_reverse()
  101. #define backlight_increase_val() backlight_matrix_increase_val()
  102. #define backlight_decrease_val() backlight_matrix_decrease_val()
  103. #define backlight_increase_speed() backlight_matrix_increase_speed()
  104. #define backlight_decrease_speed() backlight_matrix_decrease_speed()
  105. #define backlight_mode(mode) backlight_matrix_mode(mode)
  106. #define backlight_mode_noeeprom(mode) backlight_matrix_mode_noeeprom(mode)
  107. #define backlight_get_mode() backlight_matrix_get_mode()
  108. #endif
  109. typedef struct {
  110. /* Perform any initialisation required for the other driver functions to work. */
  111. void (*init)(void);
  112. /* Set the brightness of a single LED in the buffer. */
  113. void (*set_value)(int index, uint8_t value);
  114. /* Set the brightness of all LEDS on the keyboard in the buffer. */
  115. void (*set_value_all)(uint8_t value);
  116. /* Flush any buffered changes to the hardware. */
  117. void (*flush)(void);
  118. } led_matrix_driver_t;
  119. extern const led_matrix_driver_t led_matrix_driver;
  120. #endif