logo

qmk_firmware

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

is31fl3741-mono.h (12146B)


  1. /* Copyright 2017 Jason Williams
  2. * Copyright 2018 Jack Humbert
  3. * Copyright 2018 Yiancar
  4. * Copyright 2020 MelGeek
  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. #define IS31FL3741_REG_INTERRUPT_MASK 0xF0
  25. #define IS31FL3741_REG_INTERRUPT_STATUS 0xF1
  26. #define IS31FL3741_REG_ID 0xFC
  27. #define IS31FL3741_REG_COMMAND 0xFD
  28. #define IS31FL3741_COMMAND_PWM_0 0x00
  29. #define IS31FL3741_COMMAND_PWM_1 0x01
  30. #define IS31FL3741_COMMAND_SCALING_0 0x02
  31. #define IS31FL3741_COMMAND_SCALING_1 0x03
  32. #define IS31FL3741_COMMAND_FUNCTION 0x04
  33. #define IS31FL3741_FUNCTION_REG_CONFIGURATION 0x00
  34. #define IS31FL3741_FUNCTION_REG_GLOBAL_CURRENT 0x01
  35. #define IS31FL3741_FUNCTION_REG_PULLDOWNUP 0x02
  36. #define IS31FL3741_FUNCTION_REG_PWM_FREQUENCY 0x36
  37. #define IS31FL3741_FUNCTION_REG_RESET 0x3F
  38. #define IS31FL3741_REG_COMMAND_WRITE_LOCK 0xFE
  39. #define IS31FL3741_COMMAND_WRITE_LOCK_MAGIC 0xC5
  40. #define IS31FL3741_I2C_ADDRESS_GND 0x30
  41. #define IS31FL3741_I2C_ADDRESS_SCL 0x31
  42. #define IS31FL3741_I2C_ADDRESS_SDA 0x32
  43. #define IS31FL3741_I2C_ADDRESS_VCC 0x33
  44. #if defined(LED_MATRIX_IS31FL3741)
  45. # define IS31FL3741_LED_COUNT LED_MATRIX_LED_COUNT
  46. #endif
  47. #if defined(IS31FL3741_I2C_ADDRESS_4)
  48. # define IS31FL3741_DRIVER_COUNT 4
  49. #elif defined(IS31FL3741_I2C_ADDRESS_3)
  50. # define IS31FL3741_DRIVER_COUNT 3
  51. #elif defined(IS31FL3741_I2C_ADDRESS_2)
  52. # define IS31FL3741_DRIVER_COUNT 2
  53. #elif defined(IS31FL3741_I2C_ADDRESS_1)
  54. # define IS31FL3741_DRIVER_COUNT 1
  55. #endif
  56. typedef struct is31fl3741_led_t {
  57. uint8_t driver : 2;
  58. uint16_t v : 9;
  59. } PACKED is31fl3741_led_t;
  60. extern const is31fl3741_led_t PROGMEM g_is31fl3741_leds[IS31FL3741_LED_COUNT];
  61. void is31fl3741_init_drivers(void);
  62. void is31fl3741_init(uint8_t index);
  63. void is31fl3741_write_register(uint8_t index, uint8_t reg, uint8_t data);
  64. void is31fl3741_select_page(uint8_t index, uint8_t page);
  65. void is31fl3741_set_value(int index, uint8_t value);
  66. void is31fl3741_set_value_all(uint8_t value);
  67. void is31fl3741_set_led_control_register(uint8_t index, bool value);
  68. // This should not be called from an interrupt
  69. // (eg. from a timer interrupt).
  70. // Call this while idle (in between matrix scans).
  71. // If the buffer is dirty, it will update the driver with the buffer.
  72. void is31fl3741_update_pwm_buffers(uint8_t index);
  73. void is31fl3741_update_led_control_registers(uint8_t index);
  74. void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t value);
  75. void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t value);
  76. void is31fl3741_flush(void);
  77. #define IS31FL3741_PDR_0_OHM 0b000 // No pull-down resistor
  78. #define IS31FL3741_PDR_0K5_OHM 0b001 // 0.5 kOhm resistor
  79. #define IS31FL3741_PDR_1K_OHM 0b010 // 1 kOhm resistor
  80. #define IS31FL3741_PDR_2K_OHM 0b011 // 2 kOhm resistor
  81. #define IS31FL3741_PDR_4K_OHM 0b100 // 4 kOhm resistor
  82. #define IS31FL3741_PDR_8K_OHM 0b101 // 8 kOhm resistor
  83. #define IS31FL3741_PDR_16K_OHM 0b110 // 16 kOhm resistor
  84. #define IS31FL3741_PDR_32K_OHM 0b111 // 32 kOhm resistor
  85. #define IS31FL3741_PUR_0_OHM 0b000 // No pull-up resistor
  86. #define IS31FL3741_PUR_0K5_OHM 0b001 // 0.5 kOhm resistor
  87. #define IS31FL3741_PUR_1K_OHM 0b010 // 1 kOhm resistor
  88. #define IS31FL3741_PUR_2K_OHM 0b011 // 2 kOhm resistor
  89. #define IS31FL3741_PUR_4K_OHM 0b100 // 4 kOhm resistor
  90. #define IS31FL3741_PUR_8K_OHM 0b101 // 8 kOhm resistor
  91. #define IS31FL3741_PUR_16K_OHM 0b110 // 16 kOhm resistor
  92. #define IS31FL3741_PUR_32K_OHM 0b111 // 32 kOhm resistor
  93. #define IS31FL3741_PWM_FREQUENCY_29K_HZ 0b0000
  94. #define IS31FL3741_PWM_FREQUENCY_3K6_HZ 0b0011
  95. #define IS31FL3741_PWM_FREQUENCY_1K8_HZ 0b0111
  96. #define IS31FL3741_PWM_FREQUENCY_900_HZ 0b1011
  97. #define SW1_CS1 0x00
  98. #define SW1_CS2 0x01
  99. #define SW1_CS3 0x02
  100. #define SW1_CS4 0x03
  101. #define SW1_CS5 0x04
  102. #define SW1_CS6 0x05
  103. #define SW1_CS7 0x06
  104. #define SW1_CS8 0x07
  105. #define SW1_CS9 0x08
  106. #define SW1_CS10 0x09
  107. #define SW1_CS11 0x0A
  108. #define SW1_CS12 0x0B
  109. #define SW1_CS13 0x0C
  110. #define SW1_CS14 0x0D
  111. #define SW1_CS15 0x0E
  112. #define SW1_CS16 0x0F
  113. #define SW1_CS17 0x10
  114. #define SW1_CS18 0x11
  115. #define SW1_CS19 0x12
  116. #define SW1_CS20 0x13
  117. #define SW1_CS21 0x14
  118. #define SW1_CS22 0x15
  119. #define SW1_CS23 0x16
  120. #define SW1_CS24 0x17
  121. #define SW1_CS25 0x18
  122. #define SW1_CS26 0x19
  123. #define SW1_CS27 0x1A
  124. #define SW1_CS28 0x1B
  125. #define SW1_CS29 0x1C
  126. #define SW1_CS30 0x1D
  127. #define SW2_CS1 0x1E
  128. #define SW2_CS2 0x1F
  129. #define SW2_CS3 0x20
  130. #define SW2_CS4 0x21
  131. #define SW2_CS5 0x22
  132. #define SW2_CS6 0x23
  133. #define SW2_CS7 0x24
  134. #define SW2_CS8 0x25
  135. #define SW2_CS9 0x26
  136. #define SW2_CS10 0x27
  137. #define SW2_CS11 0x28
  138. #define SW2_CS12 0x29
  139. #define SW2_CS13 0x2A
  140. #define SW2_CS14 0x2B
  141. #define SW2_CS15 0x2C
  142. #define SW2_CS16 0x2D
  143. #define SW2_CS17 0x2E
  144. #define SW2_CS18 0x2F
  145. #define SW2_CS19 0x30
  146. #define SW2_CS20 0x31
  147. #define SW2_CS21 0x32
  148. #define SW2_CS22 0x33
  149. #define SW2_CS23 0x34
  150. #define SW2_CS24 0x35
  151. #define SW2_CS25 0x36
  152. #define SW2_CS26 0x37
  153. #define SW2_CS27 0x38
  154. #define SW2_CS28 0x39
  155. #define SW2_CS29 0x3A
  156. #define SW2_CS30 0x3B
  157. #define SW3_CS1 0x3C
  158. #define SW3_CS2 0x3D
  159. #define SW3_CS3 0x3E
  160. #define SW3_CS4 0x3F
  161. #define SW3_CS5 0x40
  162. #define SW3_CS6 0x41
  163. #define SW3_CS7 0x42
  164. #define SW3_CS8 0x43
  165. #define SW3_CS9 0x44
  166. #define SW3_CS10 0x45
  167. #define SW3_CS11 0x46
  168. #define SW3_CS12 0x47
  169. #define SW3_CS13 0x48
  170. #define SW3_CS14 0x49
  171. #define SW3_CS15 0x4A
  172. #define SW3_CS16 0x4B
  173. #define SW3_CS17 0x4C
  174. #define SW3_CS18 0x4D
  175. #define SW3_CS19 0x4E
  176. #define SW3_CS20 0x4F
  177. #define SW3_CS21 0x50
  178. #define SW3_CS22 0x51
  179. #define SW3_CS23 0x52
  180. #define SW3_CS24 0x53
  181. #define SW3_CS25 0x54
  182. #define SW3_CS26 0x55
  183. #define SW3_CS27 0x56
  184. #define SW3_CS28 0x57
  185. #define SW3_CS29 0x58
  186. #define SW3_CS30 0x59
  187. #define SW4_CS1 0x5A
  188. #define SW4_CS2 0x5B
  189. #define SW4_CS3 0x5C
  190. #define SW4_CS4 0x5D
  191. #define SW4_CS5 0x5E
  192. #define SW4_CS6 0x5F
  193. #define SW4_CS7 0x60
  194. #define SW4_CS8 0x61
  195. #define SW4_CS9 0x62
  196. #define SW4_CS10 0x63
  197. #define SW4_CS11 0x64
  198. #define SW4_CS12 0x65
  199. #define SW4_CS13 0x66
  200. #define SW4_CS14 0x67
  201. #define SW4_CS15 0x68
  202. #define SW4_CS16 0x69
  203. #define SW4_CS17 0x6A
  204. #define SW4_CS18 0x6B
  205. #define SW4_CS19 0x6C
  206. #define SW4_CS20 0x6D
  207. #define SW4_CS21 0x6E
  208. #define SW4_CS22 0x6F
  209. #define SW4_CS23 0x70
  210. #define SW4_CS24 0x71
  211. #define SW4_CS25 0x72
  212. #define SW4_CS26 0x73
  213. #define SW4_CS27 0x74
  214. #define SW4_CS28 0x75
  215. #define SW4_CS29 0x76
  216. #define SW4_CS30 0x77
  217. #define SW5_CS1 0x78
  218. #define SW5_CS2 0x79
  219. #define SW5_CS3 0x7A
  220. #define SW5_CS4 0x7B
  221. #define SW5_CS5 0x7C
  222. #define SW5_CS6 0x7D
  223. #define SW5_CS7 0x7E
  224. #define SW5_CS8 0x7F
  225. #define SW5_CS9 0x80
  226. #define SW5_CS10 0x81
  227. #define SW5_CS11 0x82
  228. #define SW5_CS12 0x83
  229. #define SW5_CS13 0x84
  230. #define SW5_CS14 0x85
  231. #define SW5_CS15 0x86
  232. #define SW5_CS16 0x87
  233. #define SW5_CS17 0x88
  234. #define SW5_CS18 0x89
  235. #define SW5_CS19 0x8A
  236. #define SW5_CS20 0x8B
  237. #define SW5_CS21 0x8C
  238. #define SW5_CS22 0x8D
  239. #define SW5_CS23 0x8E
  240. #define SW5_CS24 0x8F
  241. #define SW5_CS25 0x90
  242. #define SW5_CS26 0x91
  243. #define SW5_CS27 0x92
  244. #define SW5_CS28 0x93
  245. #define SW5_CS29 0x94
  246. #define SW5_CS30 0x95
  247. #define SW6_CS1 0x96
  248. #define SW6_CS2 0x97
  249. #define SW6_CS3 0x98
  250. #define SW6_CS4 0x99
  251. #define SW6_CS5 0x9A
  252. #define SW6_CS6 0x9B
  253. #define SW6_CS7 0x9C
  254. #define SW6_CS8 0x9D
  255. #define SW6_CS9 0x9E
  256. #define SW6_CS10 0x9F
  257. #define SW6_CS11 0xA0
  258. #define SW6_CS12 0xA1
  259. #define SW6_CS13 0xA2
  260. #define SW6_CS14 0xA3
  261. #define SW6_CS15 0xA4
  262. #define SW6_CS16 0xA5
  263. #define SW6_CS17 0xA6
  264. #define SW6_CS18 0xA7
  265. #define SW6_CS19 0xA8
  266. #define SW6_CS20 0xA9
  267. #define SW6_CS21 0xAA
  268. #define SW6_CS22 0xAB
  269. #define SW6_CS23 0xAC
  270. #define SW6_CS24 0xAD
  271. #define SW6_CS25 0xAE
  272. #define SW6_CS26 0xAF
  273. #define SW6_CS27 0xB0
  274. #define SW6_CS28 0xB1
  275. #define SW6_CS29 0xB2
  276. #define SW6_CS30 0xB3
  277. #define SW7_CS1 0x100
  278. #define SW7_CS2 0x101
  279. #define SW7_CS3 0x102
  280. #define SW7_CS4 0x103
  281. #define SW7_CS5 0x104
  282. #define SW7_CS6 0x105
  283. #define SW7_CS7 0x106
  284. #define SW7_CS8 0x107
  285. #define SW7_CS9 0x108
  286. #define SW7_CS10 0x109
  287. #define SW7_CS11 0x10A
  288. #define SW7_CS12 0x10B
  289. #define SW7_CS13 0x10C
  290. #define SW7_CS14 0x10D
  291. #define SW7_CS15 0x10E
  292. #define SW7_CS16 0x10F
  293. #define SW7_CS17 0x110
  294. #define SW7_CS18 0x111
  295. #define SW7_CS19 0x112
  296. #define SW7_CS20 0x113
  297. #define SW7_CS21 0x114
  298. #define SW7_CS22 0x115
  299. #define SW7_CS23 0x116
  300. #define SW7_CS24 0x117
  301. #define SW7_CS25 0x118
  302. #define SW7_CS26 0x119
  303. #define SW7_CS27 0x11A
  304. #define SW7_CS28 0x11B
  305. #define SW7_CS29 0x11C
  306. #define SW7_CS30 0x11D
  307. #define SW8_CS1 0x11E
  308. #define SW8_CS2 0x11F
  309. #define SW8_CS3 0x120
  310. #define SW8_CS4 0x121
  311. #define SW8_CS5 0x122
  312. #define SW8_CS6 0x123
  313. #define SW8_CS7 0x124
  314. #define SW8_CS8 0x125
  315. #define SW8_CS9 0x126
  316. #define SW8_CS10 0x127
  317. #define SW8_CS11 0x128
  318. #define SW8_CS12 0x129
  319. #define SW8_CS13 0x12A
  320. #define SW8_CS14 0x12B
  321. #define SW8_CS15 0x12C
  322. #define SW8_CS16 0x12D
  323. #define SW8_CS17 0x12E
  324. #define SW8_CS18 0x12F
  325. #define SW8_CS19 0x130
  326. #define SW8_CS20 0x131
  327. #define SW8_CS21 0x132
  328. #define SW8_CS22 0x133
  329. #define SW8_CS23 0x134
  330. #define SW8_CS24 0x135
  331. #define SW8_CS25 0x136
  332. #define SW8_CS26 0x137
  333. #define SW8_CS27 0x138
  334. #define SW8_CS28 0x139
  335. #define SW8_CS29 0x13A
  336. #define SW8_CS30 0x13B
  337. #define SW9_CS1 0x13C
  338. #define SW9_CS2 0x13D
  339. #define SW9_CS3 0x13E
  340. #define SW9_CS4 0x13F
  341. #define SW9_CS5 0x140
  342. #define SW9_CS6 0x141
  343. #define SW9_CS7 0x142
  344. #define SW9_CS8 0x143
  345. #define SW9_CS9 0x144
  346. #define SW9_CS10 0x145
  347. #define SW9_CS11 0x146
  348. #define SW9_CS12 0x147
  349. #define SW9_CS13 0x148
  350. #define SW9_CS14 0x149
  351. #define SW9_CS15 0x14A
  352. #define SW9_CS16 0x14B
  353. #define SW9_CS17 0x14C
  354. #define SW9_CS18 0x14D
  355. #define SW9_CS19 0x14E
  356. #define SW9_CS20 0x14F
  357. #define SW9_CS21 0x150
  358. #define SW9_CS22 0x151
  359. #define SW9_CS23 0x152
  360. #define SW9_CS24 0x153
  361. #define SW9_CS25 0x154
  362. #define SW9_CS26 0x155
  363. #define SW9_CS27 0x156
  364. #define SW9_CS28 0x157
  365. #define SW9_CS29 0x158
  366. #define SW9_CS30 0x159
  367. #define SW1_CS31 0x15A
  368. #define SW1_CS32 0x15B
  369. #define SW1_CS33 0x15C
  370. #define SW1_CS34 0x15D
  371. #define SW1_CS35 0x15E
  372. #define SW1_CS36 0x15F
  373. #define SW1_CS37 0x160
  374. #define SW1_CS38 0x161
  375. #define SW1_CS39 0x162
  376. #define SW2_CS31 0x163
  377. #define SW2_CS32 0x164
  378. #define SW2_CS33 0x165
  379. #define SW2_CS34 0x166
  380. #define SW2_CS35 0x167
  381. #define SW2_CS36 0x168
  382. #define SW2_CS37 0x169
  383. #define SW2_CS38 0x16A
  384. #define SW2_CS39 0x16B
  385. #define SW3_CS31 0x16C
  386. #define SW3_CS32 0x16D
  387. #define SW3_CS33 0x16E
  388. #define SW3_CS34 0x16F
  389. #define SW3_CS35 0x170
  390. #define SW3_CS36 0x171
  391. #define SW3_CS37 0x172
  392. #define SW3_CS38 0x173
  393. #define SW3_CS39 0x174
  394. #define SW4_CS31 0x175
  395. #define SW4_CS32 0x176
  396. #define SW4_CS33 0x177
  397. #define SW4_CS34 0x178
  398. #define SW4_CS35 0x179
  399. #define SW4_CS36 0x17A
  400. #define SW4_CS37 0x17B
  401. #define SW4_CS38 0x17C
  402. #define SW4_CS39 0x17D
  403. #define SW5_CS31 0x17E
  404. #define SW5_CS32 0x17F
  405. #define SW5_CS33 0x180
  406. #define SW5_CS34 0x181
  407. #define SW5_CS35 0x182
  408. #define SW5_CS36 0x183
  409. #define SW5_CS37 0x184
  410. #define SW5_CS38 0x185
  411. #define SW5_CS39 0x186
  412. #define SW6_CS31 0x187
  413. #define SW6_CS32 0x188
  414. #define SW6_CS33 0x189
  415. #define SW6_CS34 0x18A
  416. #define SW6_CS35 0x18B
  417. #define SW6_CS36 0x18C
  418. #define SW6_CS37 0x18D
  419. #define SW6_CS38 0x18E
  420. #define SW6_CS39 0x18F
  421. #define SW7_CS31 0x190
  422. #define SW7_CS32 0x191
  423. #define SW7_CS33 0x192
  424. #define SW7_CS34 0x193
  425. #define SW7_CS35 0x194
  426. #define SW7_CS36 0x195
  427. #define SW7_CS37 0x196
  428. #define SW7_CS38 0x197
  429. #define SW7_CS39 0x198
  430. #define SW8_CS31 0x199
  431. #define SW8_CS32 0x19A
  432. #define SW8_CS33 0x19B
  433. #define SW8_CS34 0x19C
  434. #define SW8_CS35 0x19D
  435. #define SW8_CS36 0x19E
  436. #define SW8_CS37 0x19F
  437. #define SW8_CS38 0x1A0
  438. #define SW8_CS39 0x1A1
  439. #define SW9_CS31 0x1A2
  440. #define SW9_CS32 0x1A3
  441. #define SW9_CS33 0x1A4
  442. #define SW9_CS34 0x1A5
  443. #define SW9_CS35 0x1A6
  444. #define SW9_CS36 0x1A7
  445. #define SW9_CS37 0x1A8
  446. #define SW9_CS38 0x1A9
  447. #define SW9_CS39 0x1AA