logo

qmk_firmware

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

is31fl3729.h (7984B)


  1. /* Copyright 2024 HorrorTroll <https://github.com/HorrorTroll>
  2. * Copyright 2024 Harrison Chan (Xelus)
  3. * Copyright 2024 Dimitris Mantzouranis <d3xter93@gmail.com>
  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 IS31FL3729_REG_PWM 0x01
  24. #define IS31FL3729_REG_SCALING 0x90
  25. #define IS31FL3729_REG_CONFIGURATION 0xA0
  26. #define IS31FL3729_REG_GLOBAL_CURRENT 0xA1
  27. #define IS31FL3729_REG_PULLDOWNUP 0xB0
  28. #define IS31FL3729_REG_SPREAD_SPECTRUM 0xB1
  29. #define IS31FL3729_REG_PWM_FREQUENCY 0xB2
  30. #define IS31FL3729_REG_RESET 0xCF
  31. #define IS31FL3729_I2C_ADDRESS_GND 0x34
  32. #define IS31FL3729_I2C_ADDRESS_SCL 0x35
  33. #define IS31FL3729_I2C_ADDRESS_SDA 0x36
  34. #define IS31FL3729_I2C_ADDRESS_VCC 0x37
  35. #if defined(RGB_MATRIX_IS31FL3729)
  36. # define IS31FL3729_LED_COUNT RGB_MATRIX_LED_COUNT
  37. #endif
  38. #if defined(IS31FL3729_I2C_ADDRESS_4)
  39. # define IS31FL3729_DRIVER_COUNT 4
  40. #elif defined(IS31FL3729_I2C_ADDRESS_3)
  41. # define IS31FL3729_DRIVER_COUNT 3
  42. #elif defined(IS31FL3729_I2C_ADDRESS_2)
  43. # define IS31FL3729_DRIVER_COUNT 2
  44. #elif defined(IS31FL3729_I2C_ADDRESS_1)
  45. # define IS31FL3729_DRIVER_COUNT 1
  46. #endif
  47. typedef struct is31fl3729_led_t {
  48. uint8_t driver : 2;
  49. uint8_t r;
  50. uint8_t g;
  51. uint8_t b;
  52. } PACKED is31fl3729_led_t;
  53. extern const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT];
  54. void is31fl3729_init_drivers(void);
  55. void is31fl3729_init(uint8_t index);
  56. void is31fl3729_write_register(uint8_t index, uint8_t reg, uint8_t data);
  57. void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
  58. void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
  59. void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
  60. // This should not be called from an interrupt
  61. // (eg. from a timer interrupt).
  62. // Call this while idle (in between matrix scans).
  63. // If the buffer is dirty, it will update the driver with the buffer.
  64. void is31fl3729_update_pwm_buffers(uint8_t index);
  65. void is31fl3729_update_scaling_registers(uint8_t index);
  66. void is31fl3729_flush(void);
  67. #define IS31FL3729_SW_PULLDOWN_0_OHM 0b000
  68. #define IS31FL3729_SW_PULLDOWN_0K5_OHM_SW_OFF 0b001
  69. #define IS31FL3729_SW_PULLDOWN_1K_OHM_SW_OFF 0b010
  70. #define IS31FL3729_SW_PULLDOWN_2K_OHM_SW_OFF 0b011
  71. #define IS31FL3729_SW_PULLDOWN_1K_OHM 0b100
  72. #define IS31FL3729_SW_PULLDOWN_2K_OHM 0b101
  73. #define IS31FL3729_SW_PULLDOWN_4K_OHM 0b110
  74. #define IS31FL3729_SW_PULLDOWN_8K_OHM 0b111
  75. #define IS31FL3729_CS_PULLUP_0_OHM 0b000
  76. #define IS31FL3729_CS_PULLUP_0K5_OHM_CS_OFF 0b001
  77. #define IS31FL3729_CS_PULLUP_1K_OHM_CS_OFF 0b010
  78. #define IS31FL3729_CS_PULLUP_2K_OHM_CS_OFF 0b011
  79. #define IS31FL3729_CS_PULLUP_1K_OHM 0b100
  80. #define IS31FL3729_CS_PULLUP_2K_OHM 0b101
  81. #define IS31FL3729_CS_PULLUP_4K_OHM 0b110
  82. #define IS31FL3729_CS_PULLUP_8K_OHM 0b111
  83. #define IS31FL3729_SPREAD_SPECTRUM_DISABLE 0b0
  84. #define IS31FL3729_SPREAD_SPECTRUM_ENABLE 0b1
  85. #define IS31FL3729_SPREAD_SPECTRUM_RANGE_5_PERCENT 0b00
  86. #define IS31FL3729_SPREAD_SPECTRUM_RANGE_15_PERCENT 0b01
  87. #define IS31FL3729_SPREAD_SPECTRUM_RANGE_24_PERCENT 0b10
  88. #define IS31FL3729_SPREAD_SPECTRUM_RANGE_34_PERCENT 0b11
  89. #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_1980_US 0b00
  90. #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_1200_US 0b01
  91. #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_820_US 0b10
  92. #define IS31FL3729_SPREAD_SPECTRUM_CYCLE_TIME_660_US 0b11
  93. #define IS31FL3729_PWM_FREQUENCY_55K_HZ 0b000
  94. #define IS31FL3729_PWM_FREQUENCY_32K_HZ 0b001
  95. #define IS31FL3729_PWM_FREQUENCY_4K_HZ 0b010
  96. #define IS31FL3729_PWM_FREQUENCY_2K_HZ 0b011
  97. #define IS31FL3729_PWM_FREQUENCY_1K_HZ 0b100
  98. #define IS31FL3729_PWM_FREQUENCY_500_HZ 0b101
  99. #define IS31FL3729_PWM_FREQUENCY_250_HZ 0b110
  100. #define IS31FL3729_PWM_FREQUENCY_80K_HZ 0b111
  101. #define IS31FL3729_CONFIG_SWS_15_9 0x01 // 15 CS x 9 SW matrix
  102. #define IS31FL3729_CONFIG_SWS_16_8 0x11 // 16 CS x 8 SW matrix
  103. #define IS31FL3729_CONFIG_SWS_16_7 0x21 // 16 CS x 7 SW matrix
  104. #define IS31FL3729_CONFIG_SWS_16_6 0x31 // 16 CS x 6 SW matrix
  105. #define IS31FL3729_CONFIG_SWS_16_5 0x41 // 16 CS x 5 SW matrix
  106. #define IS31FL3729_CONFIG_SWS_16_4 0x51 // 16 CS x 4 SW matrix
  107. #define IS31FL3729_CONFIG_SWS_16_3 0x61 // 16 CS x 3 SW matrix
  108. #define IS31FL3729_CONFIG_SWS_16_2 0x71 // 16 CS x 2 SW matrix
  109. #define SW1_CS1 0x00
  110. #define SW1_CS2 0x01
  111. #define SW1_CS3 0x02
  112. #define SW1_CS4 0x03
  113. #define SW1_CS5 0x04
  114. #define SW1_CS6 0x05
  115. #define SW1_CS7 0x06
  116. #define SW1_CS8 0x07
  117. #define SW1_CS9 0x08
  118. #define SW1_CS10 0x09
  119. #define SW1_CS11 0x0A
  120. #define SW1_CS12 0x0B
  121. #define SW1_CS13 0x0C
  122. #define SW1_CS14 0x0D
  123. #define SW1_CS15 0x0E
  124. #define SW1_CS16 0x0F
  125. #define SW2_CS1 0x10
  126. #define SW2_CS2 0x11
  127. #define SW2_CS3 0x12
  128. #define SW2_CS4 0x13
  129. #define SW2_CS5 0x14
  130. #define SW2_CS6 0x15
  131. #define SW2_CS7 0x16
  132. #define SW2_CS8 0x17
  133. #define SW2_CS9 0x18
  134. #define SW2_CS10 0x19
  135. #define SW2_CS11 0x1A
  136. #define SW2_CS12 0x1B
  137. #define SW2_CS13 0x1C
  138. #define SW2_CS14 0x1D
  139. #define SW2_CS15 0x1E
  140. #define SW2_CS16 0x1F
  141. #define SW3_CS1 0x20
  142. #define SW3_CS2 0x21
  143. #define SW3_CS3 0x22
  144. #define SW3_CS4 0x23
  145. #define SW3_CS5 0x24
  146. #define SW3_CS6 0x25
  147. #define SW3_CS7 0x26
  148. #define SW3_CS8 0x27
  149. #define SW3_CS9 0x28
  150. #define SW3_CS10 0x29
  151. #define SW3_CS11 0x2A
  152. #define SW3_CS12 0x2B
  153. #define SW3_CS13 0x2C
  154. #define SW3_CS14 0x2D
  155. #define SW3_CS15 0x2E
  156. #define SW3_CS16 0x2F
  157. #define SW4_CS1 0x30
  158. #define SW4_CS2 0x31
  159. #define SW4_CS3 0x32
  160. #define SW4_CS4 0x33
  161. #define SW4_CS5 0x34
  162. #define SW4_CS6 0x35
  163. #define SW4_CS7 0x36
  164. #define SW4_CS8 0x37
  165. #define SW4_CS9 0x38
  166. #define SW4_CS10 0x39
  167. #define SW4_CS11 0x3A
  168. #define SW4_CS12 0x3B
  169. #define SW4_CS13 0x3C
  170. #define SW4_CS14 0x3D
  171. #define SW4_CS15 0x3E
  172. #define SW4_CS16 0x3F
  173. #define SW5_CS1 0x40
  174. #define SW5_CS2 0x41
  175. #define SW5_CS3 0x42
  176. #define SW5_CS4 0x43
  177. #define SW5_CS5 0x44
  178. #define SW5_CS6 0x45
  179. #define SW5_CS7 0x46
  180. #define SW5_CS8 0x47
  181. #define SW5_CS9 0x48
  182. #define SW5_CS10 0x49
  183. #define SW5_CS11 0x4A
  184. #define SW5_CS12 0x4B
  185. #define SW5_CS13 0x4C
  186. #define SW5_CS14 0x4D
  187. #define SW5_CS15 0x4E
  188. #define SW5_CS16 0x4F
  189. #define SW6_CS1 0x50
  190. #define SW6_CS2 0x51
  191. #define SW6_CS3 0x52
  192. #define SW6_CS4 0x53
  193. #define SW6_CS5 0x54
  194. #define SW6_CS6 0x55
  195. #define SW6_CS7 0x56
  196. #define SW6_CS8 0x57
  197. #define SW6_CS9 0x58
  198. #define SW6_CS10 0x59
  199. #define SW6_CS11 0x5A
  200. #define SW6_CS12 0x5B
  201. #define SW6_CS13 0x5C
  202. #define SW6_CS14 0x5D
  203. #define SW6_CS15 0x5E
  204. #define SW6_CS16 0x5F
  205. #define SW7_CS1 0x60
  206. #define SW7_CS2 0x61
  207. #define SW7_CS3 0x62
  208. #define SW7_CS4 0x63
  209. #define SW7_CS5 0x64
  210. #define SW7_CS6 0x65
  211. #define SW7_CS7 0x66
  212. #define SW7_CS8 0x67
  213. #define SW7_CS9 0x68
  214. #define SW7_CS10 0x69
  215. #define SW7_CS11 0x6A
  216. #define SW7_CS12 0x6B
  217. #define SW7_CS13 0x6C
  218. #define SW7_CS14 0x6D
  219. #define SW7_CS15 0x6E
  220. #define SW7_CS16 0x6F
  221. #define SW8_CS1 0x70
  222. #define SW8_CS2 0x71
  223. #define SW8_CS3 0x72
  224. #define SW8_CS4 0x73
  225. #define SW8_CS5 0x74
  226. #define SW8_CS6 0x75
  227. #define SW8_CS7 0x76
  228. #define SW8_CS8 0x77
  229. #define SW8_CS9 0x78
  230. #define SW8_CS10 0x79
  231. #define SW8_CS11 0x7A
  232. #define SW8_CS12 0x7B
  233. #define SW8_CS13 0x7C
  234. #define SW8_CS14 0x7D
  235. #define SW8_CS15 0x7E
  236. #define SW8_CS16 0x7F
  237. #define SW9_CS1 0x80
  238. #define SW9_CS2 0x81
  239. #define SW9_CS3 0x82
  240. #define SW9_CS4 0x83
  241. #define SW9_CS5 0x84
  242. #define SW9_CS6 0x85
  243. #define SW9_CS7 0x86
  244. #define SW9_CS8 0x87
  245. #define SW9_CS9 0x88
  246. #define SW9_CS10 0x89
  247. #define SW9_CS11 0x8A
  248. #define SW9_CS12 0x8B
  249. #define SW9_CS13 0x8C
  250. #define SW9_CS14 0x8D
  251. #define SW9_CS15 0x8E