rgb_matrix_drivers.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. {
  27. i2c_init();
  28. #ifdef IS31FL3731
  29. IS31FL3731_init( DRIVER_ADDR_1 );
  30. IS31FL3731_init( DRIVER_ADDR_2 );
  31. #elif defined(IS31FL3733)
  32. IS31FL3733_init( DRIVER_ADDR_1, 0 );
  33. #else
  34. IS31FL3737_init( DRIVER_ADDR_1 );
  35. #endif
  36. for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) {
  37. bool enabled = true;
  38. // This only caches it for later
  39. #ifdef IS31FL3731
  40. IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
  41. #elif defined(IS31FL3733)
  42. IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
  43. #else
  44. IS31FL3737_set_led_control_register( index, enabled, enabled, enabled );
  45. #endif
  46. }
  47. // This actually updates the LED drivers
  48. #ifdef IS31FL3731
  49. IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, 0 );
  50. IS31FL3731_update_led_control_registers( DRIVER_ADDR_2, 1 );
  51. #elif defined(IS31FL3733)
  52. IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, 0 );
  53. IS31FL3733_update_led_control_registers( DRIVER_ADDR_2, 1 );
  54. #else
  55. IS31FL3737_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  56. #endif
  57. }
  58. #ifdef IS31FL3731
  59. static void flush( void )
  60. {
  61. IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, 0 );
  62. IS31FL3731_update_pwm_buffers( DRIVER_ADDR_2, 1 );
  63. }
  64. const rgb_matrix_driver_t rgb_matrix_driver = {
  65. .init = init,
  66. .flush = flush,
  67. .set_color = IS31FL3731_set_color,
  68. .set_color_all = IS31FL3731_set_color_all,
  69. };
  70. #elif defined(IS31FL3733)
  71. static void flush( void )
  72. {
  73. IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, 0);
  74. IS31FL3733_update_pwm_buffers( DRIVER_ADDR_2, 1);
  75. }
  76. const rgb_matrix_driver_t rgb_matrix_driver = {
  77. .init = init,
  78. .flush = flush,
  79. .set_color = IS31FL3733_set_color,
  80. .set_color_all = IS31FL3733_set_color_all,
  81. };
  82. #else
  83. static void flush( void )
  84. {
  85. IS31FL3737_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  86. }
  87. const rgb_matrix_driver_t rgb_matrix_driver = {
  88. .init = init,
  89. .flush = flush,
  90. .set_color = IS31FL3737_set_color,
  91. .set_color_all = IS31FL3737_set_color_all,
  92. };
  93. #endif
  94. #elif defined(WS2812)
  95. extern LED_TYPE led[DRIVER_LED_TOTAL];
  96. static void flush( void )
  97. {
  98. // Assumes use of RGB_DI_PIN
  99. ws2812_setleds(led, DRIVER_LED_TOTAL);
  100. }
  101. static void init( void )
  102. {
  103. }
  104. const rgb_matrix_driver_t rgb_matrix_driver = {
  105. .init = init,
  106. .flush = flush,
  107. .set_color = ws2812_setled,
  108. .set_color_all = ws2812_setled_all,
  109. };
  110. #endif