rgb_matrix_drivers.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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)
  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. #else
  32. IS31FL3733_init( DRIVER_ADDR_1 );
  33. #endif
  34. for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) {
  35. bool enabled = true;
  36. // This only caches it for later
  37. #ifdef IS31FL3731
  38. IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
  39. #else
  40. IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
  41. #endif
  42. }
  43. // This actually updates the LED drivers
  44. #ifdef IS31FL3731
  45. IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  46. #else
  47. IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  48. #endif
  49. }
  50. #ifdef IS31FL3731
  51. static void flush( void )
  52. {
  53. IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  54. }
  55. const rgb_matrix_driver_t rgb_matrix_driver = {
  56. .init = init,
  57. .flush = flush,
  58. .set_color = IS31FL3731_set_color,
  59. .set_color_all = IS31FL3731_set_color_all,
  60. };
  61. #else
  62. static void flush( void )
  63. {
  64. IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
  65. }
  66. const rgb_matrix_driver_t rgb_matrix_driver = {
  67. .init = init,
  68. .flush = flush,
  69. .set_color = IS31FL3733_set_color,
  70. .set_color_all = IS31FL3733_set_color_all,
  71. };
  72. #endif
  73. #endif