rgb_matrix_drivers.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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, DRIVER_ADDR_2 );
  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. {
  60. IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  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. {
  71. IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, 0);
  72. IS31FL3733_update_pwm_buffers( DRIVER_ADDR_2, 1);
  73. }
  74. const rgb_matrix_driver_t rgb_matrix_driver = {
  75. .init = init,
  76. .flush = flush,
  77. .set_color = IS31FL3733_set_color,
  78. .set_color_all = IS31FL3733_set_color_all,
  79. };
  80. #else
  81. static void flush( void )
  82. {
  83. IS31FL3737_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  84. }
  85. const rgb_matrix_driver_t rgb_matrix_driver = {
  86. .init = init,
  87. .flush = flush,
  88. .set_color = IS31FL3737_set_color,
  89. .set_color_all = IS31FL3737_set_color_all,
  90. };
  91. #endif
  92. #elif defined(WS2812)
  93. extern LED_TYPE led[DRIVER_LED_TOTAL];
  94. static void flush( void )
  95. {
  96. // Assumes use of RGB_DI_PIN
  97. ws2812_setleds(led, DRIVER_LED_TOTAL);
  98. }
  99. static void init( void )
  100. {
  101. }
  102. const rgb_matrix_driver_t rgb_matrix_driver = {
  103. .init = init,
  104. .flush = flush,
  105. .set_color = ws2812_setled,
  106. .set_color_all = ws2812_setled_all,
  107. };
  108. #endif