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.

275 lines
7.4 KiB

  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 A_1 0x00
  146. #define A_2 0x02
  147. #define A_3 0x04
  148. #define A_4 0x06
  149. #define A_5 0x08
  150. #define A_6 0x0A
  151. #define A_7 0x0C
  152. #define A_8 0x0E
  153. #define B_1 0x10
  154. #define B_2 0x12
  155. #define B_3 0x14
  156. #define B_4 0x16
  157. #define B_5 0x18
  158. #define B_6 0x1A
  159. #define B_7 0x1C
  160. #define B_8 0x1E
  161. #define C_1 0x20
  162. #define C_2 0x22
  163. #define C_3 0x24
  164. #define C_4 0x26
  165. #define C_5 0x28
  166. #define C_6 0x2A
  167. #define C_7 0x2C
  168. #define C_8 0x2E
  169. #define D_1 0x30
  170. #define D_2 0x32
  171. #define D_3 0x34
  172. #define D_4 0x36
  173. #define D_5 0x38
  174. #define D_6 0x3A
  175. #define D_7 0x3C
  176. #define D_8 0x3E
  177. #define E_1 0x40
  178. #define E_2 0x42
  179. #define E_3 0x44
  180. #define E_4 0x46
  181. #define E_5 0x48
  182. #define E_6 0x4A
  183. #define E_7 0x4C
  184. #define E_8 0x4E
  185. #define F_1 0x50
  186. #define F_2 0x52
  187. #define F_3 0x54
  188. #define F_4 0x56
  189. #define F_5 0x58
  190. #define F_6 0x5A
  191. #define F_7 0x5C
  192. #define F_8 0x5E
  193. #define G_1 0x60
  194. #define G_2 0x62
  195. #define G_3 0x64
  196. #define G_4 0x66
  197. #define G_5 0x68
  198. #define G_6 0x6A
  199. #define G_7 0x6C
  200. #define G_8 0x6E
  201. #define H_1 0x70
  202. #define H_2 0x72
  203. #define H_3 0x74
  204. #define H_4 0x76
  205. #define H_5 0x78
  206. #define H_6 0x7A
  207. #define H_7 0x7C
  208. #define H_8 0x7E
  209. #define I_1 0x80
  210. #define I_2 0x82
  211. #define I_3 0x84
  212. #define I_4 0x86
  213. #define I_5 0x88
  214. #define I_6 0x8A
  215. #define I_7 0x8C
  216. #define I_8 0x8E
  217. #define J_1 0x90
  218. #define J_2 0x92
  219. #define J_3 0x94
  220. #define J_4 0x96
  221. #define J_5 0x98
  222. #define J_6 0x9A
  223. #define J_7 0x9C
  224. #define J_8 0x9E
  225. #define K_1 0xA0
  226. #define K_2 0xA2
  227. #define K_3 0xA4
  228. #define K_4 0xA6
  229. #define K_5 0xA8
  230. #define K_6 0xAA
  231. #define K_7 0xAC
  232. #define K_8 0xAE
  233. #define L_1 0xB0
  234. #define L_2 0xB2
  235. #define L_3 0xB4
  236. #define L_4 0xB6
  237. #define L_5 0xB8
  238. #define L_6 0xBA
  239. #define L_7 0xBC
  240. #define L_8 0xBE