logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

is31fl3736.h (6778B)


  1. /* Copyright 2018 Jason Williams (Wilba)
  2. * Copyright 2021 Doni Crosby
  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. #pragma once
  18. #include <stdint.h>
  19. #include <stdbool.h>
  20. #include "progmem.h"
  21. #include "util.h"
  22. #define IS31FL3736_REG_INTERRUPT_MASK 0xF0
  23. #define IS31FL3736_REG_INTERRUPT_STATUS 0xF1
  24. #define IS31FL3736_REG_COMMAND 0xFD
  25. #define IS31FL3736_COMMAND_LED_CONTROL 0x00
  26. #define IS31FL3736_COMMAND_PWM 0x01
  27. #define IS31FL3736_COMMAND_AUTO_BREATH 0x02
  28. #define IS31FL3736_COMMAND_FUNCTION 0x03
  29. #define IS31FL3736_FUNCTION_REG_CONFIGURATION 0x00
  30. #define IS31FL3736_FUNCTION_REG_GLOBAL_CURRENT 0x01
  31. #define IS31FL3736_FUNCTION_REG_SW_PULLUP 0x0F
  32. #define IS31FL3736_FUNCTION_REG_CS_PULLDOWN 0x10
  33. #define IS31FL3736_FUNCTION_REG_RESET 0x11
  34. #define IS31FL3736_REG_COMMAND_WRITE_LOCK 0xFE
  35. #define IS31FL3736_COMMAND_WRITE_LOCK_MAGIC 0xC5
  36. #define IS31FL3736_I2C_ADDRESS_GND_GND 0x50
  37. #define IS31FL3736_I2C_ADDRESS_GND_SCL 0x51
  38. #define IS31FL3736_I2C_ADDRESS_GND_SDA 0x52
  39. #define IS31FL3736_I2C_ADDRESS_GND_VCC 0x53
  40. #define IS31FL3736_I2C_ADDRESS_SCL_GND 0x54
  41. #define IS31FL3736_I2C_ADDRESS_SCL_SCL 0x55
  42. #define IS31FL3736_I2C_ADDRESS_SCL_SDA 0x56
  43. #define IS31FL3736_I2C_ADDRESS_SCL_VCC 0x57
  44. #define IS31FL3736_I2C_ADDRESS_SDA_GND 0x58
  45. #define IS31FL3736_I2C_ADDRESS_SDA_SCL 0x59
  46. #define IS31FL3736_I2C_ADDRESS_SDA_SDA 0x5A
  47. #define IS31FL3736_I2C_ADDRESS_SDA_VCC 0x5B
  48. #define IS31FL3736_I2C_ADDRESS_VCC_GND 0x5C
  49. #define IS31FL3736_I2C_ADDRESS_VCC_SCL 0x5D
  50. #define IS31FL3736_I2C_ADDRESS_VCC_SDA 0x5E
  51. #define IS31FL3736_I2C_ADDRESS_VCC_VCC 0x5F
  52. #if defined(RGB_MATRIX_IS31FL3736)
  53. # define IS31FL3736_LED_COUNT RGB_MATRIX_LED_COUNT
  54. #endif
  55. #if defined(IS31FL3736_I2C_ADDRESS_4)
  56. # define IS31FL3736_DRIVER_COUNT 4
  57. #elif defined(IS31FL3736_I2C_ADDRESS_3)
  58. # define IS31FL3736_DRIVER_COUNT 3
  59. #elif defined(IS31FL3736_I2C_ADDRESS_2)
  60. # define IS31FL3736_DRIVER_COUNT 2
  61. #elif defined(IS31FL3736_I2C_ADDRESS_1)
  62. # define IS31FL3736_DRIVER_COUNT 1
  63. #endif
  64. typedef struct is31fl3736_led_t {
  65. uint8_t driver : 2;
  66. uint8_t r;
  67. uint8_t g;
  68. uint8_t b;
  69. } PACKED is31fl3736_led_t;
  70. extern const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT];
  71. void is31fl3736_init_drivers(void);
  72. void is31fl3736_init(uint8_t index);
  73. void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data);
  74. void is31fl3736_select_page(uint8_t index, uint8_t page);
  75. void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
  76. void is31fl3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
  77. void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
  78. // This should not be called from an interrupt
  79. // (eg. from a timer interrupt).
  80. // Call this while idle (in between matrix scans).
  81. // If the buffer is dirty, it will update the driver with the buffer.
  82. void is31fl3736_update_pwm_buffers(uint8_t index);
  83. void is31fl3736_update_led_control_registers(uint8_t index);
  84. void is31fl3736_flush(void);
  85. #define IS31FL3736_PDR_0_OHM 0b000 // No pull-down resistor
  86. #define IS31FL3736_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor
  87. #define IS31FL3736_PDR_1K_OHM 0b010 // 1 kOhm resistor
  88. #define IS31FL3736_PDR_2K_OHM 0b011 // 2 kOhm resistor
  89. #define IS31FL3736_PDR_4K_OHM 0b100 // 4 kOhm resistor
  90. #define IS31FL3736_PDR_8K_OHM 0b101 // 8 kOhm resistor
  91. #define IS31FL3736_PDR_16K_OHM 0b110 // 16 kOhm resistor
  92. #define IS31FL3736_PDR_32K_OHM 0b111 // 32 kOhm resistor
  93. #define IS31FL3736_PUR_0_OHM 0b000 // No pull-up resistor
  94. #define IS31FL3736_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor
  95. #define IS31FL3736_PUR_1K_OHM 0b010 // 1 kOhm resistor
  96. #define IS31FL3736_PUR_2K_OHM 0b011 // 2 kOhm resistor
  97. #define IS31FL3736_PUR_4K_OHM 0b100 // 4 kOhm resistor
  98. #define IS31FL3736_PUR_8K_OHM 0b101 // 8 kOhm resistor
  99. #define IS31FL3736_PUR_16K_OHM 0b110 // 16 kOhm resistor
  100. #define IS31FL3736_PUR_32K_OHM 0b111 // 32 kOhm resistor
  101. #define IS31FL3736_PWM_FREQUENCY_8K4_HZ 0b000
  102. #define IS31FL3736_PWM_FREQUENCY_4K2_HZ 0b001
  103. #define IS31FL3736_PWM_FREQUENCY_26K7_HZ 0b010
  104. #define IS31FL3736_PWM_FREQUENCY_2K1_HZ 0b011
  105. #define IS31FL3736_PWM_FREQUENCY_1K05_HZ 0b100
  106. #define SW1_CS1 0x00
  107. #define SW1_CS2 0x02
  108. #define SW1_CS3 0x04
  109. #define SW1_CS4 0x06
  110. #define SW1_CS5 0x08
  111. #define SW1_CS6 0x0A
  112. #define SW1_CS7 0x0C
  113. #define SW1_CS8 0x0E
  114. #define SW2_CS1 0x10
  115. #define SW2_CS2 0x12
  116. #define SW2_CS3 0x14
  117. #define SW2_CS4 0x16
  118. #define SW2_CS5 0x18
  119. #define SW2_CS6 0x1A
  120. #define SW2_CS7 0x1C
  121. #define SW2_CS8 0x1E
  122. #define SW3_CS1 0x20
  123. #define SW3_CS2 0x22
  124. #define SW3_CS3 0x24
  125. #define SW3_CS4 0x26
  126. #define SW3_CS5 0x28
  127. #define SW3_CS6 0x2A
  128. #define SW3_CS7 0x2C
  129. #define SW3_CS8 0x2E
  130. #define SW4_CS1 0x30
  131. #define SW4_CS2 0x32
  132. #define SW4_CS3 0x34
  133. #define SW4_CS4 0x36
  134. #define SW4_CS5 0x38
  135. #define SW4_CS6 0x3A
  136. #define SW4_CS7 0x3C
  137. #define SW4_CS8 0x3E
  138. #define SW5_CS1 0x40
  139. #define SW5_CS2 0x42
  140. #define SW5_CS3 0x44
  141. #define SW5_CS4 0x46
  142. #define SW5_CS5 0x48
  143. #define SW5_CS6 0x4A
  144. #define SW5_CS7 0x4C
  145. #define SW5_CS8 0x4E
  146. #define SW6_CS1 0x50
  147. #define SW6_CS2 0x52
  148. #define SW6_CS3 0x54
  149. #define SW6_CS4 0x56
  150. #define SW6_CS5 0x58
  151. #define SW6_CS6 0x5A
  152. #define SW6_CS7 0x5C
  153. #define SW6_CS8 0x5E
  154. #define SW7_CS1 0x60
  155. #define SW7_CS2 0x62
  156. #define SW7_CS3 0x64
  157. #define SW7_CS4 0x66
  158. #define SW7_CS5 0x68
  159. #define SW7_CS6 0x6A
  160. #define SW7_CS7 0x6C
  161. #define SW7_CS8 0x6E
  162. #define SW8_CS1 0x70
  163. #define SW8_CS2 0x72
  164. #define SW8_CS3 0x74
  165. #define SW8_CS4 0x76
  166. #define SW8_CS5 0x78
  167. #define SW8_CS6 0x7A
  168. #define SW8_CS7 0x7C
  169. #define SW8_CS8 0x7E
  170. #define SW9_CS1 0x80
  171. #define SW9_CS2 0x82
  172. #define SW9_CS3 0x84
  173. #define SW9_CS4 0x86
  174. #define SW9_CS5 0x88
  175. #define SW9_CS6 0x8A
  176. #define SW9_CS7 0x8C
  177. #define SW9_CS8 0x8E
  178. #define SW10_CS1 0x90
  179. #define SW10_CS2 0x92
  180. #define SW10_CS3 0x94
  181. #define SW10_CS4 0x96
  182. #define SW10_CS5 0x98
  183. #define SW10_CS6 0x9A
  184. #define SW10_CS7 0x9C
  185. #define SW10_CS8 0x9E
  186. #define SW11_CS1 0xA0
  187. #define SW11_CS2 0xA2
  188. #define SW11_CS3 0xA4
  189. #define SW11_CS4 0xA6
  190. #define SW11_CS5 0xA8
  191. #define SW11_CS6 0xAA
  192. #define SW11_CS7 0xAC
  193. #define SW11_CS8 0xAE
  194. #define SW12_CS1 0xB0
  195. #define SW12_CS2 0xB2
  196. #define SW12_CS3 0xB4
  197. #define SW12_CS4 0xB6
  198. #define SW12_CS5 0xB8
  199. #define SW12_CS6 0xBA
  200. #define SW12_CS7 0xBC
  201. #define SW12_CS8 0xBE