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.

115 lines
3.5 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.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, 0);
  49. IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1);
  50. # elif defined(IS31FL3733)
  51. IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
  52. IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
  53. # else
  54. IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
  55. # endif
  56. }
  57. # ifdef IS31FL3731
  58. static void flush(void) {
  59. IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0);
  60. IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1);
  61. }
  62. const rgb_matrix_driver_t rgb_matrix_driver = {
  63. .init = init,
  64. .flush = flush,
  65. .set_color = IS31FL3731_set_color,
  66. .set_color_all = IS31FL3731_set_color_all,
  67. };
  68. # elif defined(IS31FL3733)
  69. static void flush(void) {
  70. IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
  71. IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
  72. }
  73. const rgb_matrix_driver_t rgb_matrix_driver = {
  74. .init = init,
  75. .flush = flush,
  76. .set_color = IS31FL3733_set_color,
  77. .set_color_all = IS31FL3733_set_color_all,
  78. };
  79. # else
  80. static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
  81. const rgb_matrix_driver_t rgb_matrix_driver = {
  82. .init = init,
  83. .flush = flush,
  84. .set_color = IS31FL3737_set_color,
  85. .set_color_all = IS31FL3737_set_color_all,
  86. };
  87. # endif
  88. #elif defined(WS2812)
  89. extern LED_TYPE led[DRIVER_LED_TOTAL];
  90. static void flush(void) {
  91. // Assumes use of RGB_DI_PIN
  92. ws2812_setleds(led, DRIVER_LED_TOTAL);
  93. }
  94. static void init(void) {}
  95. const rgb_matrix_driver_t rgb_matrix_driver = {
  96. .init = init,
  97. .flush = flush,
  98. .set_color = ws2812_setled,
  99. .set_color_all = ws2812_setled_all,
  100. };
  101. #endif