Allow RGBLIGHT_ANIMATIONS to work on keebio/iris configurator builds (#8482)
[jackhill/qmk/firmware.git] / quantum / led_matrix_drivers.c
1 /* Copyright 2018 James Laird-Wah
2 * Copyright 2019 Clueboard
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
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include "quantum.h"
21 #include "ledmatrix.h"
22
23 /* Each driver needs to define a struct:
24 *
25 * const led_matrix_driver_t led_matrix_driver;
26 *
27 * All members must be provided. Keyboard custom drivers must define this
28 * in their own files.
29 */
30
31 #if defined(IS31FL3731) || defined(IS31FL3733)
32
33 # if defined(IS31FL3731)
34 # include "is31fl3731-simple.h"
35 # endif
36
37 # include "i2c_master.h"
38
39 static void init(void) {
40 i2c_init();
41 # ifdef IS31FL3731
42 # ifdef LED_DRIVER_ADDR_1
43 IS31FL3731_init(LED_DRIVER_ADDR_1);
44 # endif
45 # ifdef LED_DRIVER_ADDR_2
46 IS31FL3731_init(LED_DRIVER_ADDR_2);
47 # endif
48 # ifdef LED_DRIVER_ADDR_3
49 IS31FL3731_init(LED_DRIVER_ADDR_3);
50 # endif
51 # ifdef LED_DRIVER_ADDR_4
52 IS31FL3731_init(LED_DRIVER_ADDR_4);
53 # endif
54 # else
55 # ifdef LED_DRIVER_ADDR_1
56 IS31FL3733_init(LED_DRIVER_ADDR_1, 0);
57 # endif
58 # ifdef LED_DRIVER_ADDR_2
59 IS31FL3733_init(LED_DRIVER_ADDR_2, 0);
60 # endif
61 # ifdef LED_DRIVER_ADDR_3
62 IS31FL3733_init(LED_DRIVER_ADDR_3, 0);
63 # endif
64 # ifdef LED_DRIVER_ADDR_4
65 IS31FL3733_init(LED_DRIVER_ADDR_4, 0);
66 # endif
67 # endif
68
69 for (int index = 0; index < LED_DRIVER_LED_COUNT; index++) {
70 # ifdef IS31FL3731
71 IS31FL3731_set_led_control_register(index, true);
72 # else
73 IS31FL3733_set_led_control_register(index, true);
74 # endif
75 }
76 // This actually updates the LED drivers
77 # ifdef IS31FL3731
78 # ifdef LED_DRIVER_ADDR_1
79 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
80 # endif
81 # ifdef LED_DRIVER_ADDR_2
82 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
83 # endif
84 # ifdef LED_DRIVER_ADDR_3
85 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
86 # endif
87 # ifdef LED_DRIVER_ADDR_4
88 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
89 # endif
90 # else
91 # ifdef LED_DRIVER_ADDR_1
92 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
93 # endif
94 # ifdef LED_DRIVER_ADDR_2
95 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
96 # endif
97 # ifdef LED_DRIVER_ADDR_3
98 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
99 # endif
100 # ifdef LED_DRIVER_ADDR_4
101 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
102 # endif
103 # endif
104 }
105
106 static void flush(void) {
107 # ifdef IS31FL3731
108 # ifdef LED_DRIVER_ADDR_1
109 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
110 # endif
111 # ifdef LED_DRIVER_ADDR_2
112 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
113 # endif
114 # ifdef LED_DRIVER_ADDR_3
115 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
116 # endif
117 # ifdef LED_DRIVER_ADDR_4
118 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
119 # endif
120 # else
121 # ifdef LED_DRIVER_ADDR_1
122 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
123 # endif
124 # ifdef LED_DRIVER_ADDR_2
125 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
126 # endif
127 # ifdef LED_DRIVER_ADDR_3
128 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
129 # endif
130 # ifdef LED_DRIVER_ADDR_4
131 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
132 # endif
133 # endif
134 }
135
136 const led_matrix_driver_t led_matrix_driver = {
137 .init = init,
138 .flush = flush,
139 # ifdef IS31FL3731
140 .set_value = IS31FL3731_set_value,
141 .set_value_all = IS31FL3731_set_value_all,
142 # else
143 .set_value = IS31FL3733_set_value,
144 .set_value_all = IS31FL3733_set_value_all,
145 # endif
146 };
147
148 #endif