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.

186 lines
5.1 KiB

  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 <stdint.h>
  18. #include <stdbool.h>
  19. #include "quantum.h"
  20. #include "ledmatrix.h"
  21. /* Each driver needs to define a struct:
  22. *
  23. * const led_matrix_driver_t led_matrix_driver;
  24. *
  25. * All members must be provided. Keyboard custom drivers must define this
  26. * in their own files.
  27. */
  28. #if defined(IS31FL3731) || defined(IS31FL3733)
  29. # if defined(IS31FL3731)
  30. # include "is31fl3731-simple.h"
  31. # endif
  32. # include "i2c_master.h"
  33. #endif
  34. #ifdef LED_MATRIX_PINMATRIX_ENABLE
  35. # include "led_matrix_pinmatrix.h"
  36. #endif
  37. #ifdef LED_MATRIX_PINS_ENABLE
  38. # include "led_matrix_pins.h"
  39. #endif
  40. static void init(void) {
  41. #if defined(IS31FL3731) || defined(IS31FL3733)
  42. i2c_init();
  43. # ifdef IS31FL3731
  44. # ifdef LED_DRIVER_ADDR_1
  45. IS31FL3731_init(LED_DRIVER_ADDR_1);
  46. # endif
  47. # ifdef LED_DRIVER_ADDR_2
  48. IS31FL3731_init(LED_DRIVER_ADDR_2);
  49. # endif
  50. # ifdef LED_DRIVER_ADDR_3
  51. IS31FL3731_init(LED_DRIVER_ADDR_3);
  52. # endif
  53. # ifdef LED_DRIVER_ADDR_4
  54. IS31FL3731_init(LED_DRIVER_ADDR_4);
  55. # endif
  56. # else
  57. # ifdef LED_DRIVER_ADDR_1
  58. IS31FL3733_init(LED_DRIVER_ADDR_1, 0);
  59. # endif
  60. # ifdef LED_DRIVER_ADDR_2
  61. IS31FL3733_init(LED_DRIVER_ADDR_2, 0);
  62. # endif
  63. # ifdef LED_DRIVER_ADDR_3
  64. IS31FL3733_init(LED_DRIVER_ADDR_3, 0);
  65. # endif
  66. # ifdef LED_DRIVER_ADDR_4
  67. IS31FL3733_init(LED_DRIVER_ADDR_4, 0);
  68. # endif
  69. # endif
  70. for (int index = 0; index < LED_DRIVER_LED_COUNT; index++) {
  71. # ifdef IS31FL3731
  72. IS31FL3731_set_led_control_register(index, true);
  73. # endif
  74. # ifdef IS31FL3733
  75. IS31FL3733_set_led_control_register(index, true);
  76. # endif
  77. }
  78. // This actually updates the LED drivers
  79. # ifdef IS31FL3731
  80. # ifdef LED_DRIVER_ADDR_1
  81. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
  82. # endif
  83. # ifdef LED_DRIVER_ADDR_2
  84. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
  85. # endif
  86. # ifdef LED_DRIVER_ADDR_3
  87. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
  88. # endif
  89. # ifdef LED_DRIVER_ADDR_4
  90. IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
  91. # endif
  92. # else
  93. # ifdef LED_DRIVER_ADDR_1
  94. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
  95. # endif
  96. # ifdef LED_DRIVER_ADDR_2
  97. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
  98. # endif
  99. # ifdef LED_DRIVER_ADDR_3
  100. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
  101. # endif
  102. # ifdef LED_DRIVER_ADDR_4
  103. IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
  104. # endif
  105. # endif
  106. #endif
  107. #ifdef LED_MATRIX_PINMATRIX_ENABLE
  108. led_matrix_pinmatrix_init_pins();
  109. #endif
  110. #ifdef LED_MATRIX_PINS_ENABLE
  111. led_matrix_pins_init_pins();
  112. #endif
  113. }
  114. static void flush(void) {
  115. #ifdef IS31FL3731
  116. # ifdef LED_DRIVER_ADDR_1
  117. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
  118. # endif
  119. # ifdef LED_DRIVER_ADDR_2
  120. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
  121. # endif
  122. # ifdef LED_DRIVER_ADDR_3
  123. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
  124. # endif
  125. # ifdef LED_DRIVER_ADDR_4
  126. IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
  127. # endif
  128. #endif
  129. #ifdef IS31FL3733
  130. # ifdef LED_DRIVER_ADDR_1
  131. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
  132. # endif
  133. # ifdef LED_DRIVER_ADDR_2
  134. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
  135. # endif
  136. # ifdef LED_DRIVER_ADDR_3
  137. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
  138. # endif
  139. # ifdef LED_DRIVER_ADDR_4
  140. IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
  141. # endif
  142. #endif
  143. #ifdef LED_MATRIX_PINMATRIX_ENABLE
  144. led_matrix_pinmatrix_flush();
  145. #endif
  146. #ifdef LED_MATRIX_PINS_ENABLE
  147. led_matrix_pins_flush();
  148. #endif
  149. }
  150. const led_matrix_driver_t led_matrix_driver = {
  151. .init = init,
  152. .flush = flush,
  153. #ifdef IS31FL3731
  154. .set_value = IS31FL3731_set_value,
  155. .set_value_all = IS31FL3731_set_value_all,
  156. #endif
  157. #ifdef IS31FL3133
  158. .set_value = IS31FL3733_set_value,
  159. .set_value_all = IS31FL3733_set_value_all,
  160. #endif
  161. #ifdef LED_MATRIX_PINMATRIX_ENABLE
  162. .set_value = led_matrix_pinmatrix_set_value,
  163. .set_value_all = led_matrix_pinmatrix_set_value_all,
  164. #endif
  165. #ifdef LED_MATRIX_PINS_ENABLE
  166. .set_value = led_matrix_pins_set_value,
  167. .set_value_all = led_matrix_pins_set_value_all,
  168. #endif
  169. };