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.

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