is31fl3736.h 7.8 KB

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