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.

197 lines
6.1 KiB

  1. /* Copyright 2018 James Laird-Wah
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "rgb_matrix_drivers.h"
  17. #include <stdbool.h>
  18. #include "keyboard.h"
  19. #include "color.h"
  20. #include "util.h"
  21. /* Each driver needs to define the struct
  22. * const rgb_matrix_driver_t rgb_matrix_driver;
  23. * All members must be provided.
  24. * Keyboard custom drivers can define this in their own files, it should only
  25. * be here if shared between boards.
  26. */
  27. #if defined(RGB_MATRIX_IS31FL3218)
  28. const rgb_matrix_driver_t rgb_matrix_driver = {
  29. .init = is31fl3218_init,
  30. .flush = is31fl3218_update_pwm_buffers,
  31. .set_color = is31fl3218_set_color,
  32. .set_color_all = is31fl3218_set_color_all,
  33. };
  34. #elif defined(RGB_MATRIX_IS31FL3729)
  35. const rgb_matrix_driver_t rgb_matrix_driver = {
  36. .init = is31fl3729_init_drivers,
  37. .flush = is31fl3729_flush,
  38. .set_color = is31fl3729_set_color,
  39. .set_color_all = is31fl3729_set_color_all,
  40. };
  41. #elif defined(RGB_MATRIX_IS31FL3731)
  42. const rgb_matrix_driver_t rgb_matrix_driver = {
  43. .init = is31fl3731_init_drivers,
  44. .flush = is31fl3731_flush,
  45. .set_color = is31fl3731_set_color,
  46. .set_color_all = is31fl3731_set_color_all,
  47. };
  48. #elif defined(RGB_MATRIX_IS31FL3733)
  49. const rgb_matrix_driver_t rgb_matrix_driver = {
  50. .init = is31fl3733_init_drivers,
  51. .flush = is31fl3733_flush,
  52. .set_color = is31fl3733_set_color,
  53. .set_color_all = is31fl3733_set_color_all,
  54. };
  55. #elif defined(RGB_MATRIX_IS31FL3736)
  56. const rgb_matrix_driver_t rgb_matrix_driver = {
  57. .init = is31fl3736_init_drivers,
  58. .flush = is31fl3736_flush,
  59. .set_color = is31fl3736_set_color,
  60. .set_color_all = is31fl3736_set_color_all,
  61. };
  62. #elif defined(RGB_MATRIX_IS31FL3737)
  63. const rgb_matrix_driver_t rgb_matrix_driver = {
  64. .init = is31fl3737_init_drivers,
  65. .flush = is31fl3737_flush,
  66. .set_color = is31fl3737_set_color,
  67. .set_color_all = is31fl3737_set_color_all,
  68. };
  69. #elif defined(RGB_MATRIX_IS31FL3741)
  70. const rgb_matrix_driver_t rgb_matrix_driver = {
  71. .init = is31fl3741_init_drivers,
  72. .flush = is31fl3741_flush,
  73. .set_color = is31fl3741_set_color,
  74. .set_color_all = is31fl3741_set_color_all,
  75. };
  76. #elif defined(RGB_MATRIX_IS31FL3742A)
  77. const rgb_matrix_driver_t rgb_matrix_driver = {
  78. .init = is31fl3742a_init_drivers,
  79. .flush = is31fl3742a_flush,
  80. .set_color = is31fl3742a_set_color,
  81. .set_color_all = is31fl3742a_set_color_all,
  82. };
  83. #elif defined(RGB_MATRIX_IS31FL3743A)
  84. const rgb_matrix_driver_t rgb_matrix_driver = {
  85. .init = is31fl3743a_init_drivers,
  86. .flush = is31fl3743a_flush,
  87. .set_color = is31fl3743a_set_color,
  88. .set_color_all = is31fl3743a_set_color_all,
  89. };
  90. #elif defined(RGB_MATRIX_IS31FL3745)
  91. const rgb_matrix_driver_t rgb_matrix_driver = {
  92. .init = is31fl3745_init_drivers,
  93. .flush = is31fl3745_flush,
  94. .set_color = is31fl3745_set_color,
  95. .set_color_all = is31fl3745_set_color_all,
  96. };
  97. #elif defined(RGB_MATRIX_IS31FL3746A)
  98. const rgb_matrix_driver_t rgb_matrix_driver = {
  99. .init = is31fl3746a_init_drivers,
  100. .flush = is31fl3746a_flush,
  101. .set_color = is31fl3746a_set_color,
  102. .set_color_all = is31fl3746a_set_color_all,
  103. };
  104. #elif defined(RGB_MATRIX_SNLED27351)
  105. const rgb_matrix_driver_t rgb_matrix_driver = {
  106. .init = snled27351_init_drivers,
  107. .flush = snled27351_flush,
  108. .set_color = snled27351_set_color,
  109. .set_color_all = snled27351_set_color_all,
  110. };
  111. #elif defined(RGB_MATRIX_AW20216S)
  112. const rgb_matrix_driver_t rgb_matrix_driver = {
  113. .init = aw20216s_init_drivers,
  114. .flush = aw20216s_flush,
  115. .set_color = aw20216s_set_color,
  116. .set_color_all = aw20216s_set_color_all,
  117. };
  118. #elif defined(RGB_MATRIX_WS2812)
  119. # if defined(RGBLIGHT_WS2812)
  120. # pragma message "Cannot use RGBLIGHT and RGB Matrix using WS2812 at the same time."
  121. # pragma message "You need to use a custom driver, or re-implement the WS2812 driver to use a different configuration."
  122. # endif
  123. // LED color buffer
  124. rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_COUNT];
  125. bool ws2812_dirty = false;
  126. static void init(void) {
  127. ws2812_dirty = false;
  128. }
  129. static void flush(void) {
  130. if (ws2812_dirty) {
  131. ws2812_setleds(rgb_matrix_ws2812_array, WS2812_LED_COUNT);
  132. ws2812_dirty = false;
  133. }
  134. }
  135. // Set an led in the buffer to a color
  136. static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
  137. # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
  138. const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
  139. if (!is_keyboard_left()) {
  140. if (i >= k_rgb_matrix_split[0]) {
  141. i -= k_rgb_matrix_split[0];
  142. } else {
  143. return;
  144. }
  145. } else if (i >= k_rgb_matrix_split[0]) {
  146. return;
  147. }
  148. # endif
  149. if (rgb_matrix_ws2812_array[i].r == r && rgb_matrix_ws2812_array[i].g == g && rgb_matrix_ws2812_array[i].b == b) {
  150. return;
  151. }
  152. ws2812_dirty = true;
  153. rgb_matrix_ws2812_array[i].r = r;
  154. rgb_matrix_ws2812_array[i].g = g;
  155. rgb_matrix_ws2812_array[i].b = b;
  156. # ifdef RGBW
  157. convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]);
  158. # endif
  159. }
  160. static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
  161. for (int i = 0; i < ARRAY_SIZE(rgb_matrix_ws2812_array); i++) {
  162. setled(i, r, g, b);
  163. }
  164. }
  165. const rgb_matrix_driver_t rgb_matrix_driver = {
  166. .init = init,
  167. .flush = flush,
  168. .set_color = setled,
  169. .set_color_all = setled_all,
  170. };
  171. #endif