led_matrix_drivers.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Copyright 2018 James Laird-Wah
  2. * Copyright 2019 Clueboard
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "led_matrix.h"
  18. /* Each driver needs to define a struct:
  19. *
  20. * const led_matrix_driver_t led_matrix_driver;
  21. *
  22. * All members must be provided. Keyboard custom drivers must define this
  23. * in their own files.
  24. */
  25. #if defined(IS31FL3731) || defined(IS31FL3733)
  26. # include "i2c_master.h"
  27. static void init(void) {
  28. i2c_init();
  29. # ifdef IS31FL3731
  30. # ifdef LED_DRIVER_ADDR_1
  31. IS31FL3731_init(LED_DRIVER_ADDR_1);
  32. # endif
  33. # ifdef LED_DRIVER_ADDR_2
  34. IS31FL3731_init(LED_DRIVER_ADDR_2);
  35. # endif
  36. # ifdef LED_DRIVER_ADDR_3
  37. IS31FL3731_init(LED_DRIVER_ADDR_3);
  38. # endif
  39. # ifdef LED_DRIVER_ADDR_4
  40. IS31FL3731_init(LED_DRIVER_ADDR_4);
  41. # endif
  42. # else
  43. # ifdef LED_DRIVER_ADDR_1
  44. IS31FL3733_init(LED_DRIVER_ADDR_1, 0);
  45. # endif
  46. # ifdef LED_DRIVER_ADDR_2
  47. IS31FL3733_init(LED_DRIVER_ADDR_2, 0);
  48. # endif
  49. # ifdef LED_DRIVER_ADDR_3
  50. IS31FL3733_init(LED_DRIVER_ADDR_3, 0);
  51. # endif
  52. # ifdef LED_DRIVER_ADDR_4
  53. IS31FL3733_init(LED_DRIVER_ADDR_4, 0);
  54. # endif
  55. # endif
  56. for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
  57. # ifdef IS31FL3731
  58. IS31FL3731_set_led_control_register(index, true);
  59. # else
  60. IS31FL3733_set_led_control_register(index, true);
  61. # endif
  62. }
  63. // This actually updates the LED drivers
  64. # ifdef IS31FL3731
  65. # ifdef LED_DRIVER_ADDR_1
  66. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
  67. # endif
  68. # ifdef LED_DRIVER_ADDR_2
  69. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
  70. # endif
  71. # ifdef LED_DRIVER_ADDR_3
  72. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
  73. # endif
  74. # ifdef LED_DRIVER_ADDR_4
  75. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
  76. # endif
  77. # else
  78. # ifdef LED_DRIVER_ADDR_1
  79. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
  80. # endif
  81. # ifdef LED_DRIVER_ADDR_2
  82. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
  83. # endif
  84. # ifdef LED_DRIVER_ADDR_3
  85. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
  86. # endif
  87. # ifdef LED_DRIVER_ADDR_4
  88. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
  89. # endif
  90. # endif
  91. }
  92. static void flush(void) {
  93. # ifdef IS31FL3731
  94. # ifdef LED_DRIVER_ADDR_1
  95. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
  96. # endif
  97. # ifdef LED_DRIVER_ADDR_2
  98. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
  99. # endif
  100. # ifdef LED_DRIVER_ADDR_3
  101. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
  102. # endif
  103. # ifdef LED_DRIVER_ADDR_4
  104. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
  105. # endif
  106. # else
  107. # ifdef LED_DRIVER_ADDR_1
  108. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
  109. # endif
  110. # ifdef LED_DRIVER_ADDR_2
  111. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
  112. # endif
  113. # ifdef LED_DRIVER_ADDR_3
  114. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
  115. # endif
  116. # ifdef LED_DRIVER_ADDR_4
  117. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
  118. # endif
  119. # endif
  120. }
  121. const led_matrix_driver_t led_matrix_driver = {
  122. .init = init,
  123. .flush = flush,
  124. # ifdef IS31FL3731
  125. .set_value = IS31FL3731_set_value,
  126. .set_value_all = IS31FL3731_set_value_all,
  127. # else
  128. .set_value = IS31FL3733_set_value,
  129. .set_value_all = IS31FL3733_set_value_all,
  130. # endif
  131. };
  132. #endif