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.

316 lines
7.8 KiB

  1. /* Copyright 2017 Jason Williams
  2. * Copyright 2018 Jack Humbert
  3. * Copyright 2018 Yiancar
  4. * Copyright 2021 Doni Crosby
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #pragma once
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include "progmem.h"
  23. #include "util.h"
  24. // ======== DEPRECATED DEFINES - DO NOT USE ========
  25. #ifdef DRIVER_ADDR_1
  26. # define IS31FL3737_I2C_ADDRESS_1 DRIVER_ADDR_1
  27. #endif
  28. #ifdef DRIVER_ADDR_2
  29. # define IS31FL3737_I2C_ADDRESS_2 DRIVER_ADDR_2
  30. #endif
  31. #ifdef DRIVER_ADDR_3
  32. # define IS31FL3737_I2C_ADDRESS_3 DRIVER_ADDR_3
  33. #endif
  34. #ifdef DRIVER_ADDR_4
  35. # define IS31FL3737_I2C_ADDRESS_4 DRIVER_ADDR_4
  36. #endif
  37. #ifdef ISSI_TIMEOUT
  38. # define IS31FL3737_I2C_TIMEOUT ISSI_TIMEOUT
  39. #endif
  40. #ifdef ISSI_PERSISTENCE
  41. # define IS31FL3737_I2C_PERSISTENCE ISSI_PERSISTENCE
  42. #endif
  43. #ifdef ISSI_PWM_FREQUENCY
  44. # define IS31FL3737_PWM_FREQUENCY ISSI_PWM_FREQUENCY
  45. #endif
  46. #ifdef ISSI_SWPULLUP
  47. # define IS31FL3737_SW_PULLUP ISSI_SWPULLUP
  48. #endif
  49. #ifdef ISSI_CSPULLUP
  50. # define IS31FL3737_CS_PULLDOWN ISSI_CSPULLUP
  51. #endif
  52. #ifdef ISSI_GLOBALCURRENT
  53. # define IS31FL3737_GLOBAL_CURRENT ISSI_GLOBALCURRENT
  54. #endif
  55. #define is31_led is31fl3737_led_t
  56. #define g_is31_leds g_is31fl3737_leds
  57. #define PUR_0R IS31FL3737_PUR_0_OHM
  58. #define PUR_05KR IS31FL3737_PUR_0K5_OHM
  59. #define PUR_1KR IS31FL3737_PUR_1K_OHM
  60. #define PUR_2KR IS31FL3737_PUR_2K_OHM
  61. #define PUR_4KR IS31FL3737_PUR_4K_OHM
  62. #define PUR_8KR IS31FL3737_PUR_8K_OHM
  63. #define PUR_16KR IS31FL3737_PUR_16K_OHM
  64. #define PUR_32KR IS31FL3737_PUR_32K_OHM
  65. // ========
  66. #define IS31FL3737_REG_INTERRUPT_MASK 0xF0
  67. #define IS31FL3737_REG_INTERRUPT_STATUS 0xF1
  68. #define IS31FL3737_REG_COMMAND 0xFD
  69. #define IS31FL3737_COMMAND_LED_CONTROL 0x00
  70. #define IS31FL3737_COMMAND_PWM 0x01
  71. #define IS31FL3737_COMMAND_AUTO_BREATH 0x02
  72. #define IS31FL3737_COMMAND_FUNCTION 0x03
  73. #define IS31FL3737_FUNCTION_REG_CONFIGURATION 0x00
  74. #define IS31FL3737_FUNCTION_REG_GLOBAL_CURRENT 0x01
  75. #define IS31FL3737_FUNCTION_REG_SW_PULLUP 0x0F
  76. #define IS31FL3737_FUNCTION_REG_CS_PULLDOWN 0x10
  77. #define IS31FL3737_FUNCTION_REG_RESET 0x11
  78. #define IS31FL3737_REG_COMMAND_WRITE_LOCK 0xFE
  79. #define IS31FL3737_COMMAND_WRITE_LOCK_MAGIC 0xC5
  80. #define IS31FL3737_I2C_ADDRESS_GND 0x50
  81. #define IS31FL3737_I2C_ADDRESS_SCL 0x55
  82. #define IS31FL3737_I2C_ADDRESS_SDA 0x5A
  83. #define IS31FL3737_I2C_ADDRESS_VCC 0x5F
  84. #if defined(RGB_MATRIX_IS31FL3737)
  85. # define IS31FL3737_LED_COUNT RGB_MATRIX_LED_COUNT
  86. #endif
  87. #if defined(IS31FL3737_I2C_ADDRESS_4)
  88. # define IS31FL3737_DRIVER_COUNT 4
  89. #elif defined(IS31FL3737_I2C_ADDRESS_3)
  90. # define IS31FL3737_DRIVER_COUNT 3
  91. #elif defined(IS31FL3737_I2C_ADDRESS_2)
  92. # define IS31FL3737_DRIVER_COUNT 2
  93. #elif defined(IS31FL3737_I2C_ADDRESS_1)
  94. # define IS31FL3737_DRIVER_COUNT 1
  95. #endif
  96. typedef struct is31fl3737_led_t {
  97. uint8_t driver : 2;
  98. uint8_t r;
  99. uint8_t g;
  100. uint8_t b;
  101. } PACKED is31fl3737_led_t;
  102. extern const is31fl3737_led_t PROGMEM g_is31fl3737_leds[IS31FL3737_LED_COUNT];
  103. void is31fl3737_init_drivers(void);
  104. void is31fl3737_init(uint8_t index);
  105. void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data);
  106. void is31fl3737_select_page(uint8_t index, uint8_t page);
  107. void is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
  108. void is31fl3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
  109. void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
  110. // This should not be called from an interrupt
  111. // (eg. from a timer interrupt).
  112. // Call this while idle (in between matrix scans).
  113. // If the buffer is dirty, it will update the driver with the buffer.
  114. void is31fl3737_update_pwm_buffers(uint8_t index);
  115. void is31fl3737_update_led_control_registers(uint8_t index);
  116. void is31fl3737_flush(void);
  117. #define IS31FL3737_PDR_0_OHM 0b000 // No pull-down resistor
  118. #define IS31FL3737_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor
  119. #define IS31FL3737_PDR_1K_OHM 0b010 // 1 kOhm resistor
  120. #define IS31FL3737_PDR_2K_OHM 0b011 // 2 kOhm resistor
  121. #define IS31FL3737_PDR_4K_OHM 0b100 // 4 kOhm resistor
  122. #define IS31FL3737_PDR_8K_OHM 0b101 // 8 kOhm resistor
  123. #define IS31FL3737_PDR_16K_OHM 0b110 // 16 kOhm resistor
  124. #define IS31FL3737_PDR_32K_OHM 0b111 // 32 kOhm resistor
  125. #define IS31FL3737_PUR_0_OHM 0b000 // No pull-up resistor
  126. #define IS31FL3737_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor
  127. #define IS31FL3737_PUR_1K_OHM 0b010 // 1 kOhm resistor
  128. #define IS31FL3737_PUR_2K_OHM 0b011 // 2 kOhm resistor
  129. #define IS31FL3737_PUR_4K_OHM 0b100 // 4 kOhm resistor
  130. #define IS31FL3737_PUR_8K_OHM 0b101 // 8 kOhm resistor
  131. #define IS31FL3737_PUR_16K_OHM 0b110 // 16 kOhm resistor
  132. #define IS31FL3737_PUR_32K_OHM 0b111 // 32 kOhm resistor
  133. #define IS31FL3737_PWM_FREQUENCY_8K4_HZ 0b000
  134. #define IS31FL3737_PWM_FREQUENCY_4K2_HZ 0b001
  135. #define IS31FL3737_PWM_FREQUENCY_26K7_HZ 0b010
  136. #define IS31FL3737_PWM_FREQUENCY_2K1_HZ 0b011
  137. #define IS31FL3737_PWM_FREQUENCY_1K05_HZ 0b100
  138. #define A_1 0x00
  139. #define A_2 0x01
  140. #define A_3 0x02
  141. #define A_4 0x03
  142. #define A_5 0x04
  143. #define A_6 0x05
  144. #define A_7 0x08
  145. #define A_8 0x09
  146. #define A_9 0x0A
  147. #define A_10 0x0B
  148. #define A_11 0x0C
  149. #define A_12 0x0D
  150. #define B_1 0x10
  151. #define B_2 0x11
  152. #define B_3 0x12
  153. #define B_4 0x13
  154. #define B_5 0x14
  155. #define B_6 0x15
  156. #define B_7 0x18
  157. #define B_8 0x19
  158. #define B_9 0x1A
  159. #define B_10 0x1B
  160. #define B_11 0x1C
  161. #define B_12 0x1D
  162. #define C_1 0x20
  163. #define C_2 0x21
  164. #define C_3 0x22
  165. #define C_4 0x23
  166. #define C_5 0x24
  167. #define C_6 0x25
  168. #define C_7 0x28
  169. #define C_8 0x29
  170. #define C_9 0x2A
  171. #define C_10 0x2B
  172. #define C_11 0x2C
  173. #define C_12 0x2D
  174. #define D_1 0x30
  175. #define D_2 0x31
  176. #define D_3 0x32
  177. #define D_4 0x33
  178. #define D_5 0x34
  179. #define D_6 0x35
  180. #define D_7 0x38
  181. #define D_8 0x39
  182. #define D_9 0x3A
  183. #define D_10 0x3B
  184. #define D_11 0x3C
  185. #define D_12 0x3D
  186. #define E_1 0x40
  187. #define E_2 0x41
  188. #define E_3 0x42
  189. #define E_4 0x43
  190. #define E_5 0x44
  191. #define E_6 0x45
  192. #define E_7 0x48
  193. #define E_8 0x49
  194. #define E_9 0x4A
  195. #define E_10 0x4B
  196. #define E_11 0x4C
  197. #define E_12 0x4D
  198. #define F_1 0x50
  199. #define F_2 0x51
  200. #define F_3 0x52
  201. #define F_4 0x53
  202. #define F_5 0x54
  203. #define F_6 0x55
  204. #define F_7 0x58
  205. #define F_8 0x59
  206. #define F_9 0x5A
  207. #define F_10 0x5B
  208. #define F_11 0x5C
  209. #define F_12 0x5D
  210. #define G_1 0x60
  211. #define G_2 0x61
  212. #define G_3 0x62
  213. #define G_4 0x63
  214. #define G_5 0x64
  215. #define G_6 0x65
  216. #define G_7 0x68
  217. #define G_8 0x69
  218. #define G_9 0x6A
  219. #define G_10 0x6B
  220. #define G_11 0x6C
  221. #define G_12 0x6D
  222. #define H_1 0x70
  223. #define H_2 0x71
  224. #define H_3 0x72
  225. #define H_4 0x73
  226. #define H_5 0x74
  227. #define H_6 0x75
  228. #define H_7 0x78
  229. #define H_8 0x79
  230. #define H_9 0x7A
  231. #define H_10 0x7B
  232. #define H_11 0x7C
  233. #define H_12 0x7D
  234. #define I_1 0x80
  235. #define I_2 0x81
  236. #define I_3 0x82
  237. #define I_4 0x83
  238. #define I_5 0x84
  239. #define I_6 0x85
  240. #define I_7 0x88
  241. #define I_8 0x89
  242. #define I_9 0x8A
  243. #define I_10 0x8B
  244. #define I_11 0x8C
  245. #define I_12 0x8D
  246. #define J_1 0x90
  247. #define J_2 0x91
  248. #define J_3 0x92
  249. #define J_4 0x93
  250. #define J_5 0x94
  251. #define J_6 0x95
  252. #define J_7 0x98
  253. #define J_8 0x99
  254. #define J_9 0x9A
  255. #define J_10 0x9B
  256. #define J_11 0x9C
  257. #define J_12 0x9D
  258. #define K_1 0xA0
  259. #define K_2 0xA1
  260. #define K_3 0xA2
  261. #define K_4 0xA3
  262. #define K_5 0xA4
  263. #define K_6 0xA5
  264. #define K_7 0xA8
  265. #define K_8 0xA9
  266. #define K_9 0xAA
  267. #define K_10 0xAB
  268. #define K_11 0xAC
  269. #define K_12 0xAD
  270. #define L_1 0xB0
  271. #define L_2 0xB1
  272. #define L_3 0xB2
  273. #define L_4 0xB3
  274. #define L_5 0xB4
  275. #define L_6 0xB5
  276. #define L_7 0xB8
  277. #define L_8 0xB9
  278. #define L_9 0xBA
  279. #define L_10 0xBB
  280. #define L_11 0xBC
  281. #define L_12 0xBD