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.

334 lines
8.1 KiB

  1. /* Copyright 2017 Jason Williams
  2. * Copyright 2018 Jack Humbert
  3. * Copyright 2018 Yiancar
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <stdint.h>
  20. #include <stdbool.h>
  21. #include "progmem.h"
  22. #include "util.h"
  23. #define IS31FL3733_REG_INTERRUPT_MASK 0xF0
  24. #define IS31FL3733_REG_INTERRUPT_STATUS 0xF1
  25. #define IS31FL3733_REG_COMMAND 0xFD
  26. #define IS31FL3733_COMMAND_LED_CONTROL 0x00
  27. #define IS31FL3733_COMMAND_PWM 0x01
  28. #define IS31FL3733_COMMAND_AUTO_BREATH 0x02
  29. #define IS31FL3733_COMMAND_FUNCTION 0x03
  30. #define IS31FL3733_FUNCTION_REG_CONFIGURATION 0x00
  31. #define IS31FL3733_FUNCTION_REG_GLOBAL_CURRENT 0x01
  32. #define IS31FL3733_FUNCTION_REG_SW_PULLUP 0x0F
  33. #define IS31FL3733_FUNCTION_REG_CS_PULLDOWN 0x10
  34. #define IS31FL3733_FUNCTION_REG_RESET 0x11
  35. #define IS31FL3733_REG_COMMAND_WRITE_LOCK 0xFE
  36. #define IS31FL3733_COMMAND_WRITE_LOCK_MAGIC 0xC5
  37. #define IS31FL3733_I2C_ADDRESS_GND_GND 0x50
  38. #define IS31FL3733_I2C_ADDRESS_GND_SCL 0x51
  39. #define IS31FL3733_I2C_ADDRESS_GND_SDA 0x52
  40. #define IS31FL3733_I2C_ADDRESS_GND_VCC 0x53
  41. #define IS31FL3733_I2C_ADDRESS_SCL_GND 0x54
  42. #define IS31FL3733_I2C_ADDRESS_SCL_SCL 0x55
  43. #define IS31FL3733_I2C_ADDRESS_SCL_SDA 0x56
  44. #define IS31FL3733_I2C_ADDRESS_SCL_VCC 0x57
  45. #define IS31FL3733_I2C_ADDRESS_SDA_GND 0x58
  46. #define IS31FL3733_I2C_ADDRESS_SDA_SCL 0x59
  47. #define IS31FL3733_I2C_ADDRESS_SDA_SDA 0x5A
  48. #define IS31FL3733_I2C_ADDRESS_SDA_VCC 0x5B
  49. #define IS31FL3733_I2C_ADDRESS_VCC_GND 0x5C
  50. #define IS31FL3733_I2C_ADDRESS_VCC_SCL 0x5D
  51. #define IS31FL3733_I2C_ADDRESS_VCC_SDA 0x5E
  52. #define IS31FL3733_I2C_ADDRESS_VCC_VCC 0x5F
  53. #if !defined(IS31FL3733_LED_COUNT)
  54. # define IS31FL3733_LED_COUNT RGB_MATRIX_LED_COUNT
  55. #endif
  56. #if defined(IS31FL3733_I2C_ADDRESS_4)
  57. # define IS31FL3733_DRIVER_COUNT 4
  58. #elif defined(IS31FL3733_I2C_ADDRESS_3)
  59. # define IS31FL3733_DRIVER_COUNT 3
  60. #elif defined(IS31FL3733_I2C_ADDRESS_2)
  61. # define IS31FL3733_DRIVER_COUNT 2
  62. #elif defined(IS31FL3733_I2C_ADDRESS_1)
  63. # define IS31FL3733_DRIVER_COUNT 1
  64. #endif
  65. typedef struct is31fl3733_led_t {
  66. uint8_t driver : 2;
  67. uint8_t r;
  68. uint8_t g;
  69. uint8_t b;
  70. } PACKED is31fl3733_led_t;
  71. extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT];
  72. void is31fl3733_init_drivers(void);
  73. void is31fl3733_init(uint8_t bus, uint8_t index);
  74. void is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data);
  75. void is31fl3733_select_page(uint8_t index, uint8_t addr, uint8_t page);
  76. void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
  77. void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
  78. void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
  79. // This should not be called from an interrupt
  80. // (eg. from a timer interrupt).
  81. // Call this while idle (in between matrix scans).
  82. // If the buffer is dirty, it will update the driver with the buffer.
  83. void is31fl3733_update_pwm_buffers(uint8_t bus, uint8_t index);
  84. void is31fl3733_update_led_control_registers(uint8_t bus, uint8_t index);
  85. void is31fl3733_flush(void);
  86. #define IS31FL3733_PDR_0_OHM 0b000 // No pull-down resistor
  87. #define IS31FL3733_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor
  88. #define IS31FL3733_PDR_1K_OHM 0b010 // 1 kOhm resistor
  89. #define IS31FL3733_PDR_2K_OHM 0b011 // 2 kOhm resistor
  90. #define IS31FL3733_PDR_4K_OHM 0b100 // 4 kOhm resistor
  91. #define IS31FL3733_PDR_8K_OHM 0b101 // 8 kOhm resistor
  92. #define IS31FL3733_PDR_16K_OHM 0b110 // 16 kOhm resistor
  93. #define IS31FL3733_PDR_32K_OHM 0b111 // 32 kOhm resistor
  94. #define IS31FL3733_PUR_0_OHM 0b000 // No pull-up resistor
  95. #define IS31FL3733_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor
  96. #define IS31FL3733_PUR_1K_OHM 0b010 // 1 kOhm resistor
  97. #define IS31FL3733_PUR_2K_OHM 0b011 // 2 kOhm resistor
  98. #define IS31FL3733_PUR_4K_OHM 0b100 // 4 kOhm resistor
  99. #define IS31FL3733_PUR_8K_OHM 0b101 // 8 kOhm resistor
  100. #define IS31FL3733_PUR_16K_OHM 0b110 // 16 kOhm resistor
  101. #define IS31FL3733_PUR_32K_OHM 0b111 // 32 kOhm resistor
  102. #define IS31FL3733_PWM_FREQUENCY_8K4_HZ 0b000
  103. #define IS31FL3733_PWM_FREQUENCY_4K2_HZ 0b001
  104. #define IS31FL3733_PWM_FREQUENCY_26K7_HZ 0b010
  105. #define IS31FL3733_PWM_FREQUENCY_2K1_HZ 0b011
  106. #define IS31FL3733_PWM_FREQUENCY_1K05_HZ 0b100
  107. #define IS31FL3733_SYNC_NONE 0b00
  108. #define IS31FL3733_SYNC_MASTER 0b01
  109. #define IS31FL3733_SYNC_SLAVE 0b10
  110. #define A_1 0x00
  111. #define A_2 0x01
  112. #define A_3 0x02
  113. #define A_4 0x03
  114. #define A_5 0x04
  115. #define A_6 0x05
  116. #define A_7 0x06
  117. #define A_8 0x07
  118. #define A_9 0x08
  119. #define A_10 0x09
  120. #define A_11 0x0A
  121. #define A_12 0x0B
  122. #define A_13 0x0C
  123. #define A_14 0x0D
  124. #define A_15 0x0E
  125. #define A_16 0x0F
  126. #define B_1 0x10
  127. #define B_2 0x11
  128. #define B_3 0x12
  129. #define B_4 0x13
  130. #define B_5 0x14
  131. #define B_6 0x15
  132. #define B_7 0x16
  133. #define B_8 0x17
  134. #define B_9 0x18
  135. #define B_10 0x19
  136. #define B_11 0x1A
  137. #define B_12 0x1B
  138. #define B_13 0x1C
  139. #define B_14 0x1D
  140. #define B_15 0x1E
  141. #define B_16 0x1F
  142. #define C_1 0x20
  143. #define C_2 0x21
  144. #define C_3 0x22
  145. #define C_4 0x23
  146. #define C_5 0x24
  147. #define C_6 0x25
  148. #define C_7 0x26
  149. #define C_8 0x27
  150. #define C_9 0x28
  151. #define C_10 0x29
  152. #define C_11 0x2A
  153. #define C_12 0x2B
  154. #define C_13 0x2C
  155. #define C_14 0x2D
  156. #define C_15 0x2E
  157. #define C_16 0x2F
  158. #define D_1 0x30
  159. #define D_2 0x31
  160. #define D_3 0x32
  161. #define D_4 0x33
  162. #define D_5 0x34
  163. #define D_6 0x35
  164. #define D_7 0x36
  165. #define D_8 0x37
  166. #define D_9 0x38
  167. #define D_10 0x39
  168. #define D_11 0x3A
  169. #define D_12 0x3B
  170. #define D_13 0x3C
  171. #define D_14 0x3D
  172. #define D_15 0x3E
  173. #define D_16 0x3F
  174. #define E_1 0x40
  175. #define E_2 0x41
  176. #define E_3 0x42
  177. #define E_4 0x43
  178. #define E_5 0x44
  179. #define E_6 0x45
  180. #define E_7 0x46
  181. #define E_8 0x47
  182. #define E_9 0x48
  183. #define E_10 0x49
  184. #define E_11 0x4A
  185. #define E_12 0x4B
  186. #define E_13 0x4C
  187. #define E_14 0x4D
  188. #define E_15 0x4E
  189. #define E_16 0x4F
  190. #define F_1 0x50
  191. #define F_2 0x51
  192. #define F_3 0x52
  193. #define F_4 0x53
  194. #define F_5 0x54
  195. #define F_6 0x55
  196. #define F_7 0x56
  197. #define F_8 0x57
  198. #define F_9 0x58
  199. #define F_10 0x59
  200. #define F_11 0x5A
  201. #define F_12 0x5B
  202. #define F_13 0x5C
  203. #define F_14 0x5D
  204. #define F_15 0x5E
  205. #define F_16 0x5F
  206. #define G_1 0x60
  207. #define G_2 0x61
  208. #define G_3 0x62
  209. #define G_4 0x63
  210. #define G_5 0x64
  211. #define G_6 0x65
  212. #define G_7 0x66
  213. #define G_8 0x67
  214. #define G_9 0x68
  215. #define G_10 0x69
  216. #define G_11 0x6A
  217. #define G_12 0x6B
  218. #define G_13 0x6C
  219. #define G_14 0x6D
  220. #define G_15 0x6E
  221. #define G_16 0x6F
  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 0x76
  229. #define H_8 0x77
  230. #define H_9 0x78
  231. #define H_10 0x79
  232. #define H_11 0x7A
  233. #define H_12 0x7B
  234. #define H_13 0x7C
  235. #define H_14 0x7D
  236. #define H_15 0x7E
  237. #define H_16 0x7F
  238. #define I_1 0x80
  239. #define I_2 0x81
  240. #define I_3 0x82
  241. #define I_4 0x83
  242. #define I_5 0x84
  243. #define I_6 0x85
  244. #define I_7 0x86
  245. #define I_8 0x87
  246. #define I_9 0x88
  247. #define I_10 0x89
  248. #define I_11 0x8A
  249. #define I_12 0x8B
  250. #define I_13 0x8C
  251. #define I_14 0x8D
  252. #define I_15 0x8E
  253. #define I_16 0x8F
  254. #define J_1 0x90
  255. #define J_2 0x91
  256. #define J_3 0x92
  257. #define J_4 0x93
  258. #define J_5 0x94
  259. #define J_6 0x95
  260. #define J_7 0x96
  261. #define J_8 0x97
  262. #define J_9 0x98
  263. #define J_10 0x99
  264. #define J_11 0x9A
  265. #define J_12 0x9B
  266. #define J_13 0x9C
  267. #define J_14 0x9D
  268. #define J_15 0x9E
  269. #define J_16 0x9F
  270. #define K_1 0xA0
  271. #define K_2 0xA1
  272. #define K_3 0xA2
  273. #define K_4 0xA3
  274. #define K_5 0xA4
  275. #define K_6 0xA5
  276. #define K_7 0xA6
  277. #define K_8 0xA7
  278. #define K_9 0xA8
  279. #define K_10 0xA9
  280. #define K_11 0xAA
  281. #define K_12 0xAB
  282. #define K_13 0xAC
  283. #define K_14 0xAD
  284. #define K_15 0xAE
  285. #define K_16 0xAF
  286. #define L_1 0xB0
  287. #define L_2 0xB1
  288. #define L_3 0xB2
  289. #define L_4 0xB3
  290. #define L_5 0xB4
  291. #define L_6 0xB5
  292. #define L_7 0xB6
  293. #define L_8 0xB7
  294. #define L_9 0xB8
  295. #define L_10 0xB9
  296. #define L_11 0xBA
  297. #define L_12 0xBB
  298. #define L_13 0xBC
  299. #define L_14 0xBD
  300. #define L_15 0xBE
  301. #define L_16 0xBF