led_matrix_drivers.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. # if defined(IS31FL3731)
  30. IS31FL3731_init(LED_DRIVER_ADDR_1);
  31. # if defined(LED_DRIVER_ADDR_2)
  32. IS31FL3731_init(LED_DRIVER_ADDR_2);
  33. # if defined(LED_DRIVER_ADDR_3)
  34. IS31FL3731_init(LED_DRIVER_ADDR_3);
  35. # if defined(LED_DRIVER_ADDR_4)
  36. IS31FL3731_init(LED_DRIVER_ADDR_4);
  37. # endif
  38. # endif
  39. # endif
  40. # elif defined(IS31FL3733)
  41. # if !defined(LED_DRIVER_SYNC_1)
  42. # define LED_DRIVER_SYNC_1 0
  43. # endif
  44. IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1);
  45. # if defined(LED_DRIVER_ADDR_2)
  46. # if !defined(LED_DRIVER_SYNC_2)
  47. # define LED_DRIVER_SYNC_2 0
  48. # endif
  49. IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2);
  50. # if defined(LED_DRIVER_ADDR_3)
  51. # if !defined(LED_DRIVER_SYNC_3)
  52. # define LED_DRIVER_SYNC_3 0
  53. # endif
  54. IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3);
  55. # if defined(LED_DRIVER_ADDR_4)
  56. # if !defined(LED_DRIVER_SYNC_4)
  57. # define LED_DRIVER_SYNC_4 0
  58. # endif
  59. IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4);
  60. # endif
  61. # endif
  62. # endif
  63. # endif
  64. for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
  65. # if defined(IS31FL3731)
  66. IS31FL3731_set_led_control_register(index, true);
  67. # elif defined(IS31FL3733)
  68. IS31FL3733_set_led_control_register(index, true);
  69. # endif
  70. }
  71. // This actually updates the LED drivers
  72. # if defined(IS31FL3731)
  73. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
  74. # if defined(LED_DRIVER_ADDR_2)
  75. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
  76. # if defined(LED_DRIVER_ADDR_3)
  77. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
  78. # if defined(LED_DRIVER_ADDR_4)
  79. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
  80. # endif
  81. # endif
  82. # endif
  83. # elif defined(IS31FL3733)
  84. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
  85. # if defined(LED_DRIVER_ADDR_2)
  86. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
  87. # if defined(LED_DRIVER_ADDR_3)
  88. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
  89. # if defined(LED_DRIVER_ADDR_4)
  90. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
  91. # endif
  92. # endif
  93. # endif
  94. # endif
  95. }
  96. # if defined(IS31FL3731)
  97. static void flush(void) {
  98. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
  99. # if defined(LED_DRIVER_ADDR_2)
  100. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
  101. # if defined(LED_DRIVER_ADDR_3)
  102. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
  103. # if defined(LED_DRIVER_ADDR_4)
  104. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
  105. # endif
  106. # endif
  107. # endif
  108. }
  109. const led_matrix_driver_t led_matrix_driver = {
  110. .init = init,
  111. .flush = flush,
  112. .set_value = IS31FL3731_set_value,
  113. .set_value_all = IS31FL3731_set_value_all,
  114. };
  115. # elif defined(IS31FL3733)
  116. static void flush(void) {
  117. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
  118. # if defined(LED_DRIVER_ADDR_2)
  119. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
  120. # if defined(LED_DRIVER_ADDR_3)
  121. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
  122. # if defined(LED_DRIVER_ADDR_4)
  123. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
  124. # endif
  125. # endif
  126. # endif
  127. }
  128. const led_matrix_driver_t led_matrix_driver = {
  129. .init = init,
  130. .flush = flush,
  131. .set_value = IS31FL3733_set_value,
  132. .set_value_all = IS31FL3733_set_value_all,
  133. };
  134. # endif
  135. #endif