rgb_matrix_drivers.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.h"
  17. /* Each driver needs to define the struct
  18. * const rgb_matrix_driver_t rgb_matrix_driver;
  19. * All members must be provided.
  20. * Keyboard custom drivers can define this in their own files, it should only
  21. * be here if shared between boards.
  22. */
  23. #if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737)
  24. # include "i2c_master.h"
  25. static void init(void) {
  26. i2c_init();
  27. # ifdef IS31FL3731
  28. IS31FL3731_init(DRIVER_ADDR_1);
  29. IS31FL3731_init(DRIVER_ADDR_2);
  30. # elif defined(IS31FL3733)
  31. IS31FL3733_init(DRIVER_ADDR_1, 0);
  32. # else
  33. IS31FL3737_init(DRIVER_ADDR_1);
  34. # endif
  35. for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
  36. bool enabled = true;
  37. // This only caches it for later
  38. # ifdef IS31FL3731
  39. IS31FL3731_set_led_control_register(index, enabled, enabled, enabled);
  40. # elif defined(IS31FL3733)
  41. IS31FL3733_set_led_control_register(index, enabled, enabled, enabled);
  42. # else
  43. IS31FL3737_set_led_control_register(index, enabled, enabled, enabled);
  44. # endif
  45. }
  46. // This actually updates the LED drivers
  47. # ifdef IS31FL3731
  48. IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
  49. # elif defined(IS31FL3733)
  50. IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
  51. IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
  52. # else
  53. IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
  54. # endif
  55. }
  56. # ifdef IS31FL3731
  57. static void flush(void) { IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
  58. const rgb_matrix_driver_t rgb_matrix_driver = {
  59. .init = init,
  60. .flush = flush,
  61. .set_color = IS31FL3731_set_color,
  62. .set_color_all = IS31FL3731_set_color_all,
  63. };
  64. # elif defined(IS31FL3733)
  65. static void flush(void) {
  66. IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
  67. IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
  68. }
  69. const rgb_matrix_driver_t rgb_matrix_driver = {
  70. .init = init,
  71. .flush = flush,
  72. .set_color = IS31FL3733_set_color,
  73. .set_color_all = IS31FL3733_set_color_all,
  74. };
  75. # else
  76. static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
  77. const rgb_matrix_driver_t rgb_matrix_driver = {
  78. .init = init,
  79. .flush = flush,
  80. .set_color = IS31FL3737_set_color,
  81. .set_color_all = IS31FL3737_set_color_all,
  82. };
  83. # endif
  84. #elif defined(WS2812)
  85. extern LED_TYPE led[DRIVER_LED_TOTAL];
  86. static void flush(void) {
  87. // Assumes use of RGB_DI_PIN
  88. ws2812_setleds(led, DRIVER_LED_TOTAL);
  89. }
  90. static void init(void) {}
  91. const rgb_matrix_driver_t rgb_matrix_driver = {
  92. .init = init,
  93. .flush = flush,
  94. .set_color = ws2812_setled,
  95. .set_color_all = ws2812_setled_all,
  96. };
  97. #endif