logo

qmk_firmware

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

is31fl3731.h (6089B)


  1. /* Copyright 2017 Jason Williams
  2. * Copyright 2018 Jack Humbert
  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. #define IS31FL3731_REG_COMMAND 0xFD
  23. #define IS31FL3731_COMMAND_FRAME_1 0x00
  24. #define IS31FL3731_COMMAND_FRAME_2 0x01
  25. #define IS31FL3731_COMMAND_FRAME_3 0x02
  26. #define IS31FL3731_COMMAND_FRAME_4 0x03
  27. #define IS31FL3731_COMMAND_FRAME_5 0x04
  28. #define IS31FL3731_COMMAND_FRAME_6 0x05
  29. #define IS31FL3731_COMMAND_FRAME_7 0x06
  30. #define IS31FL3731_COMMAND_FRAME_8 0x07
  31. #define IS31FL3731_COMMAND_FUNCTION 0x0B
  32. #define IS31FL3731_FRAME_REG_LED_CONTROL 0x00
  33. #define IS31FL3731_FRAME_REG_BLINK_CONTROL 0x12
  34. #define IS31FL3731_FRAME_REG_PWM 0x24
  35. #define IS31FL3731_FUNCTION_REG_CONFIG 0x00
  36. #define IS31FL3731_CONFIG_MODE_PICTURE 0x00
  37. #define IS31FL3731_CONFIG_MODE_AUTO_PLAY 0x08
  38. #define IS31FL3731_CONFIG_MODE_AUDIO_PLAY 0x18
  39. #define IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY 0x01
  40. #define IS31FL3731_FUNCTION_REG_AUDIO_SYNC 0x06
  41. #define IS31FL3731_FUNCTION_REG_SHUTDOWN 0x0A
  42. // Not defined in the datasheet -- See AN for IC
  43. #define IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION 0xC2
  44. #define IS31FL3731_GHOST_IMAGE_PREVENTION_GEN 0x10
  45. #define IS31FL3731_I2C_ADDRESS_GND 0x74
  46. #define IS31FL3731_I2C_ADDRESS_SCL 0x75
  47. #define IS31FL3731_I2C_ADDRESS_SDA 0x76
  48. #define IS31FL3731_I2C_ADDRESS_VCC 0x77
  49. #if defined(RGB_MATRIX_IS31FL3731)
  50. # define IS31FL3731_LED_COUNT RGB_MATRIX_LED_COUNT
  51. #endif
  52. #if defined(IS31FL3731_I2C_ADDRESS_4)
  53. # define IS31FL3731_DRIVER_COUNT 4
  54. #elif defined(IS31FL3731_I2C_ADDRESS_3)
  55. # define IS31FL3731_DRIVER_COUNT 3
  56. #elif defined(IS31FL3731_I2C_ADDRESS_2)
  57. # define IS31FL3731_DRIVER_COUNT 2
  58. #elif defined(IS31FL3731_I2C_ADDRESS_1)
  59. # define IS31FL3731_DRIVER_COUNT 1
  60. #endif
  61. typedef struct is31fl3731_led_t {
  62. uint8_t driver : 2;
  63. uint8_t r;
  64. uint8_t g;
  65. uint8_t b;
  66. } PACKED is31fl3731_led_t;
  67. extern const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT];
  68. void is31fl3731_init_drivers(void);
  69. void is31fl3731_init(uint8_t index);
  70. void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data);
  71. void is31fl3731_select_page(uint8_t index, uint8_t page);
  72. void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
  73. void is31fl3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
  74. void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue);
  75. // This should not be called from an interrupt
  76. // (eg. from a timer interrupt).
  77. // Call this while idle (in between matrix scans).
  78. // If the buffer is dirty, it will update the driver with the buffer.
  79. void is31fl3731_update_pwm_buffers(uint8_t index);
  80. void is31fl3731_update_led_control_registers(uint8_t index);
  81. void is31fl3731_flush(void);
  82. #define C1_1 0x00
  83. #define C1_2 0x01
  84. #define C1_3 0x02
  85. #define C1_4 0x03
  86. #define C1_5 0x04
  87. #define C1_6 0x05
  88. #define C1_7 0x06
  89. #define C1_8 0x07
  90. #define C1_9 0x08
  91. #define C1_10 0x09
  92. #define C1_11 0x0A
  93. #define C1_12 0x0B
  94. #define C1_13 0x0C
  95. #define C1_14 0x0D
  96. #define C1_15 0x0E
  97. #define C1_16 0x0F
  98. #define C2_1 0x10
  99. #define C2_2 0x11
  100. #define C2_3 0x12
  101. #define C2_4 0x13
  102. #define C2_5 0x14
  103. #define C2_6 0x15
  104. #define C2_7 0x16
  105. #define C2_8 0x17
  106. #define C2_9 0x18
  107. #define C2_10 0x19
  108. #define C2_11 0x1A
  109. #define C2_12 0x1B
  110. #define C2_13 0x1C
  111. #define C2_14 0x1D
  112. #define C2_15 0x1E
  113. #define C2_16 0x1F
  114. #define C3_1 0x20
  115. #define C3_2 0x21
  116. #define C3_3 0x22
  117. #define C3_4 0x23
  118. #define C3_5 0x24
  119. #define C3_6 0x25
  120. #define C3_7 0x26
  121. #define C3_8 0x27
  122. #define C3_9 0x28
  123. #define C3_10 0x29
  124. #define C3_11 0x2A
  125. #define C3_12 0x2B
  126. #define C3_13 0x2C
  127. #define C3_14 0x2D
  128. #define C3_15 0x2E
  129. #define C3_16 0x2F
  130. #define C4_1 0x30
  131. #define C4_2 0x31
  132. #define C4_3 0x32
  133. #define C4_4 0x33
  134. #define C4_5 0x34
  135. #define C4_6 0x35
  136. #define C4_7 0x36
  137. #define C4_8 0x37
  138. #define C4_9 0x38
  139. #define C4_10 0x39
  140. #define C4_11 0x3A
  141. #define C4_12 0x3B
  142. #define C4_13 0x3C
  143. #define C4_14 0x3D
  144. #define C4_15 0x3E
  145. #define C4_16 0x3F
  146. #define C5_1 0x40
  147. #define C5_2 0x41
  148. #define C5_3 0x42
  149. #define C5_4 0x43
  150. #define C5_5 0x44
  151. #define C5_6 0x45
  152. #define C5_7 0x46
  153. #define C5_8 0x47
  154. #define C5_9 0x48
  155. #define C5_10 0x49
  156. #define C5_11 0x4A
  157. #define C5_12 0x4B
  158. #define C5_13 0x4C
  159. #define C5_14 0x4D
  160. #define C5_15 0x4E
  161. #define C5_16 0x4F
  162. #define C6_1 0x50
  163. #define C6_2 0x51
  164. #define C6_3 0x52
  165. #define C6_4 0x53
  166. #define C6_5 0x54
  167. #define C6_6 0x55
  168. #define C6_7 0x56
  169. #define C6_8 0x57
  170. #define C6_9 0x58
  171. #define C6_10 0x59
  172. #define C6_11 0x5A
  173. #define C6_12 0x5B
  174. #define C6_13 0x5C
  175. #define C6_14 0x5D
  176. #define C6_15 0x5E
  177. #define C6_16 0x5F
  178. #define C7_1 0x60
  179. #define C7_2 0x61
  180. #define C7_3 0x62
  181. #define C7_4 0x63
  182. #define C7_5 0x64
  183. #define C7_6 0x65
  184. #define C7_7 0x66
  185. #define C7_8 0x67
  186. #define C7_9 0x68
  187. #define C7_10 0x69
  188. #define C7_11 0x6A
  189. #define C7_12 0x6B
  190. #define C7_13 0x6C
  191. #define C7_14 0x6D
  192. #define C7_15 0x6E
  193. #define C7_16 0x6F
  194. #define C8_1 0x70
  195. #define C8_2 0x71
  196. #define C8_3 0x72
  197. #define C8_4 0x73
  198. #define C8_5 0x74
  199. #define C8_6 0x75
  200. #define C8_7 0x76
  201. #define C8_8 0x77
  202. #define C8_9 0x78
  203. #define C8_10 0x79
  204. #define C8_11 0x7A
  205. #define C8_12 0x7B
  206. #define C8_13 0x7C
  207. #define C8_14 0x7D
  208. #define C8_15 0x7E
  209. #define C8_16 0x7F
  210. #define C9_1 0x80
  211. #define C9_2 0x81
  212. #define C9_3 0x82
  213. #define C9_4 0x83
  214. #define C9_5 0x84
  215. #define C9_6 0x85
  216. #define C9_7 0x86
  217. #define C9_8 0x87
  218. #define C9_9 0x88
  219. #define C9_10 0x89
  220. #define C9_11 0x8A
  221. #define C9_12 0x8B
  222. #define C9_13 0x8C
  223. #define C9_14 0x8D
  224. #define C9_15 0x8E
  225. #define C9_16 0x8F