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.

121 lines
3.3 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. {
  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 );
  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, DRIVER_ADDR_2 );
  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 )
  58. {
  59. IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  60. }
  61. const rgb_matrix_driver_t rgb_matrix_driver = {
  62. .init = init,
  63. .flush = flush,
  64. .set_color = IS31FL3731_set_color,
  65. .set_color_all = IS31FL3731_set_color_all,
  66. };
  67. #elif defined(IS31FL3733)
  68. static void flush( void )
  69. {
  70. IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  71. }
  72. const rgb_matrix_driver_t rgb_matrix_driver = {
  73. .init = init,
  74. .flush = flush,
  75. .set_color = IS31FL3733_set_color,
  76. .set_color_all = IS31FL3733_set_color_all,
  77. };
  78. #else
  79. static void flush( void )
  80. {
  81. IS31FL3737_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  82. }
  83. const rgb_matrix_driver_t rgb_matrix_driver = {
  84. .init = init,
  85. .flush = flush,
  86. .set_color = IS31FL3737_set_color,
  87. .set_color_all = IS31FL3737_set_color_all,
  88. };
  89. #endif
  90. #elif defined(WS2812)
  91. extern LED_TYPE led[RGBLED_NUM];
  92. static void flush( void )
  93. {
  94. // Assumes use of RGB_DI_PIN
  95. ws2812_setleds(led, RGBLED_NUM);
  96. }
  97. static void init( void )
  98. {
  99. }
  100. const rgb_matrix_driver_t rgb_matrix_driver = {
  101. .init = init,
  102. .flush = flush,
  103. .set_color = ws2812_setled,
  104. .set_color_all = ws2812_setled_all,
  105. };
  106. #endif