aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix/rgb_matrix_drivers.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgb_matrix/rgb_matrix_drivers.c')
-rw-r--r--quantum/rgb_matrix/rgb_matrix_drivers.c239
1 files changed, 239 insertions, 0 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c
new file mode 100644
index 000000000..dfdf45219
--- /dev/null
+++ b/quantum/rgb_matrix/rgb_matrix_drivers.c
@@ -0,0 +1,239 @@
1/* Copyright 2018 James Laird-Wah
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "rgb_matrix.h"
18
19/* Each driver needs to define the struct
20 * const rgb_matrix_driver_t rgb_matrix_driver;
21 * All members must be provided.
22 * Keyboard custom drivers can define this in their own files, it should only
23 * be here if shared between boards.
24 */
25
26#if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) || defined(IS31FL3741)
27
28# include "i2c_master.h"
29
30static void init(void) {
31 i2c_init();
32# ifdef IS31FL3731
33 IS31FL3731_init(DRIVER_ADDR_1);
34# ifdef DRIVER_ADDR_2
35 IS31FL3731_init(DRIVER_ADDR_2);
36# endif
37# ifdef DRIVER_ADDR_3
38 IS31FL3731_init(DRIVER_ADDR_3);
39# endif
40# ifdef DRIVER_ADDR_4
41 IS31FL3731_init(DRIVER_ADDR_4);
42# endif
43# elif defined(IS31FL3733)
44# ifndef DRIVER_SYNC_1
45# define DRIVER_SYNC_1 0
46# endif
47 IS31FL3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1);
48# if defined DRIVER_ADDR_2 && (DRIVER_ADDR_1 != DRIVER_ADDR_2)
49# ifndef DRIVER_SYNC_2
50# define DRIVER_SYNC_2 0
51# endif
52 IS31FL3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2);
53# endif
54# ifdef DRIVER_ADDR_3
55# ifndef DRIVER_SYNC_3
56# define DRIVER_SYNC_3 0
57# endif
58 IS31FL3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3);
59# endif
60# ifdef DRIVER_ADDR_4
61# ifndef DRIVER_SYNC_4
62# define DRIVER_SYNC_4 0
63# endif
64 IS31FL3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4);
65# endif
66# elif defined(IS31FL3737)
67 IS31FL3737_init(DRIVER_ADDR_1);
68# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
69 IS31FL3737_init(DRIVER_ADDR_2);
70# endif
71# else
72 IS31FL3741_init(DRIVER_ADDR_1);
73# endif
74 for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
75 bool enabled = true;
76 // This only caches it for later
77# ifdef IS31FL3731
78 IS31FL3731_set_led_control_register(index, enabled, enabled, enabled);
79# elif defined(IS31FL3733)
80 IS31FL3733_set_led_control_register(index, enabled, enabled, enabled);
81# elif defined(IS31FL3737)
82 IS31FL3737_set_led_control_register(index, enabled, enabled, enabled);
83# else
84 IS31FL3741_set_led_control_register(index, enabled, enabled, enabled);
85# endif
86 }
87 // This actually updates the LED drivers
88# ifdef IS31FL3731
89 IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0);
90# ifdef DRIVER_ADDR_2
91 IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1);
92# endif
93# ifdef DRIVER_ADDR_3
94 IS31FL3731_update_led_control_registers(DRIVER_ADDR_3, 2);
95# endif
96# ifdef DRIVER_ADDR_4
97 IS31FL3731_update_led_control_registers(DRIVER_ADDR_4, 3);
98# endif
99# elif defined(IS31FL3733)
100 IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
101# ifdef DRIVER_ADDR_2
102 IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
103# endif
104# ifdef DRIVER_ADDR_3
105 IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2);
106# endif
107# ifdef DRIVER_ADDR_4
108 IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3);
109# endif
110# elif defined(IS31FL3737)
111 IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, 0);
112# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
113 IS31FL3737_update_led_control_registers(DRIVER_ADDR_2, 1);
114# endif
115# else
116 IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0);
117# endif
118}
119
120# ifdef IS31FL3731
121static void flush(void) {
122 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0);
123# ifdef DRIVER_ADDR_2
124 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1);
125# endif
126# ifdef DRIVER_ADDR_3
127 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_3, 2);
128# endif
129# ifdef DRIVER_ADDR_4
130 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_4, 3);
131# endif
132}
133
134const rgb_matrix_driver_t rgb_matrix_driver = {
135 .init = init,
136 .flush = flush,
137 .set_color = IS31FL3731_set_color,
138 .set_color_all = IS31FL3731_set_color_all,
139};
140# elif defined(IS31FL3733)
141static void flush(void) {
142 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
143# ifdef DRIVER_ADDR_2
144 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
145# endif
146# ifdef DRIVER_ADDR_3
147 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2);
148# endif
149# ifdef DRIVER_ADDR_4
150 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3);
151# endif
152}
153
154const rgb_matrix_driver_t rgb_matrix_driver = {
155 .init = init,
156 .flush = flush,
157 .set_color = IS31FL3733_set_color,
158 .set_color_all = IS31FL3733_set_color_all,
159};
160# elif defined(IS31FL3737)
161static void flush(void) {
162 IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, 0);
163# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
164 IS31FL3737_update_pwm_buffers(DRIVER_ADDR_2, 1);
165# endif
166}
167
168const rgb_matrix_driver_t rgb_matrix_driver = {
169 .init = init,
170 .flush = flush,
171 .set_color = IS31FL3737_set_color,
172 .set_color_all = IS31FL3737_set_color_all,
173};
174# else
175static void flush(void) { IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
176
177const rgb_matrix_driver_t rgb_matrix_driver = {
178 .init = init,
179 .flush = flush,
180 .set_color = IS31FL3741_set_color,
181 .set_color_all = IS31FL3741_set_color_all,
182};
183# endif
184
185#elif defined(AW20216)
186# include "spi_master.h"
187static void init(void) {
188 spi_init();
189 AW20216_init();
190}
191
192static void flush(void) { AW20216_update_pwm_buffers(); }
193
194const rgb_matrix_driver_t rgb_matrix_driver = {
195 .init = init,
196 .flush = flush,
197 .set_color = AW20216_set_color,
198 .set_color_all = AW20216_set_color_all,
199};
200
201#elif defined(WS2812)
202# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_CUSTOM_DRIVER)
203# pragma message "Cannot use RGBLIGHT and RGB Matrix using WS2812 at the same time."
204# pragma message "You need to use a custom driver, or re-implement the WS2812 driver to use a different configuration."
205# endif
206
207// LED color buffer
208LED_TYPE rgb_matrix_ws2812_array[DRIVER_LED_TOTAL];
209
210static void init(void) {}
211
212static void flush(void) {
213 // Assumes use of RGB_DI_PIN
214 ws2812_setleds(rgb_matrix_ws2812_array, DRIVER_LED_TOTAL);
215}
216
217// Set an led in the buffer to a color
218static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
219 rgb_matrix_ws2812_array[i].r = r;
220 rgb_matrix_ws2812_array[i].g = g;
221 rgb_matrix_ws2812_array[i].b = b;
222# ifdef RGBW
223 convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]);
224# endif
225}
226
227static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
228 for (int i = 0; i < sizeof(rgb_matrix_ws2812_array) / sizeof(rgb_matrix_ws2812_array[0]); i++) {
229 setled(i, r, g, b);
230 }
231}
232
233const rgb_matrix_driver_t rgb_matrix_driver = {
234 .init = init,
235 .flush = flush,
236 .set_color = setled,
237 .set_color_all = setled_all,
238};
239#endif