led_matrix.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifdef IS31FL3731
  25. # include "is31fl3731-simple.h"
  26. #endif
  27. #ifndef LED_MATRIX_LED_FLUSH_LIMIT
  28. # define LED_MATRIX_LED_FLUSH_LIMIT 16
  29. #endif
  30. #ifndef LED_MATRIX_LED_PROCESS_LIMIT
  31. # define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
  32. #endif
  33. enum led_matrix_effects {
  34. LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
  35. // All new effects go above this line
  36. LED_MATRIX_EFFECT_MAX
  37. };
  38. void led_matrix_set_index_value(int index, uint8_t value);
  39. void led_matrix_set_index_value_all(uint8_t value);
  40. // This runs after another backlight effect and replaces
  41. // values already set
  42. void led_matrix_indicators(void);
  43. void led_matrix_indicators_kb(void);
  44. void led_matrix_indicators_user(void);
  45. void led_matrix_init(void);
  46. void led_matrix_setup_drivers(void);
  47. void led_matrix_set_suspend_state(bool state);
  48. void led_matrix_set_indicator_state(uint8_t state);
  49. void led_matrix_task(void);
  50. // This should not be called from an interrupt
  51. // (eg. from a timer interrupt).
  52. // Call this while idle (in between matrix scans).
  53. // If the buffer is dirty, it will update the driver with the buffer.
  54. void led_matrix_update_pwm_buffers(void);
  55. bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
  56. uint32_t led_matrix_get_tick(void);
  57. void led_matrix_toggle(void);
  58. void led_matrix_toggle_noeeprom(void);
  59. void led_matrix_enable(void);
  60. void led_matrix_enable_noeeprom(void);
  61. void led_matrix_disable(void);
  62. void led_matrix_disable_noeeprom(void);
  63. uint8_t led_matrix_is_enabled(void);
  64. void led_matrix_mode(uint8_t mode);
  65. void led_matrix_mode_noeeprom(uint8_t mode);
  66. uint8_t led_matrix_get_mode(void);
  67. void led_matrix_step(void);
  68. void led_matrix_step_noeeprom(void);
  69. void led_matrix_step_reverse(void);
  70. void led_matrix_step_reverse_noeeprom(void);
  71. void led_matrix_set_val(uint8_t val);
  72. void led_matrix_set_val_noeeprom(uint8_t val);
  73. uint8_t led_matrix_get_val(void);
  74. void led_matrix_increase_val(void);
  75. void led_matrix_increase_val_noeeprom(void);
  76. void led_matrix_decrease_val(void);
  77. void led_matrix_decrease_val_noeeprom(void);
  78. void led_matrix_set_speed(uint8_t speed);
  79. void led_matrix_set_speed_noeeprom(uint8_t speed);
  80. uint8_t led_matrix_get_speed(void);
  81. void led_matrix_increase_speed(void);
  82. void led_matrix_increase_speed_noeeprom(void);
  83. void led_matrix_decrease_speed(void);
  84. void led_matrix_decrease_speed_noeeprom(void);
  85. typedef struct {
  86. /* Perform any initialisation required for the other driver functions to work. */
  87. void (*init)(void);
  88. /* Set the brightness of a single LED in the buffer. */
  89. void (*set_value)(int index, uint8_t value);
  90. /* Set the brightness of all LEDS on the keyboard in the buffer. */
  91. void (*set_value_all)(uint8_t value);
  92. /* Flush any buffered changes to the hardware. */
  93. void (*flush)(void);
  94. } led_matrix_driver_t;
  95. extern const led_matrix_driver_t led_matrix_driver;
  96. extern led_eeconfig_t led_matrix_eeconfig;
  97. extern led_config_t g_led_config;