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.

129 lines
3.7 KiB

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