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.c228
1 files changed, 228 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..6a11d4791
--- /dev/null
+++ b/quantum/rgb_matrix/rgb_matrix_drivers.c
@@ -0,0 +1,228 @@
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# else
69 IS31FL3741_init(DRIVER_ADDR_1);
70# endif
71 for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
72 bool enabled = true;
73 // This only caches it for later
74# ifdef IS31FL3731
75 IS31FL3731_set_led_control_register(index, enabled, enabled, enabled);
76# elif defined(IS31FL3733)
77 IS31FL3733_set_led_control_register(index, enabled, enabled, enabled);
78# elif defined(IS31FL3737)
79 IS31FL3737_set_led_control_register(index, enabled, enabled, enabled);
80# else
81 IS31FL3741_set_led_control_register(index, enabled, enabled, enabled);
82# endif
83 }
84 // This actually updates the LED drivers
85# ifdef IS31FL3731
86 IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0);
87# ifdef DRIVER_ADDR_2
88 IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1);
89# endif
90# ifdef DRIVER_ADDR_3
91 IS31FL3731_update_led_control_registers(DRIVER_ADDR_3, 2);
92# endif
93# ifdef DRIVER_ADDR_4
94 IS31FL3731_update_led_control_registers(DRIVER_ADDR_4, 3);
95# endif
96# elif defined(IS31FL3733)
97 IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
98# ifdef DRIVER_ADDR_2
99 IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
100# endif
101# ifdef DRIVER_ADDR_3
102 IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2);
103# endif
104# ifdef DRIVER_ADDR_4
105 IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3);
106# endif
107# elif defined(IS31FL3737)
108 IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
109# else
110 IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0);
111# endif
112}
113
114# ifdef IS31FL3731
115static void flush(void) {
116 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0);
117# ifdef DRIVER_ADDR_2
118 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1);
119# endif
120# ifdef DRIVER_ADDR_3
121 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_3, 2);
122# endif
123# ifdef DRIVER_ADDR_4
124 IS31FL3731_update_pwm_buffers(DRIVER_ADDR_4, 3);
125# endif
126}
127
128const rgb_matrix_driver_t rgb_matrix_driver = {
129 .init = init,
130 .flush = flush,
131 .set_color = IS31FL3731_set_color,
132 .set_color_all = IS31FL3731_set_color_all,
133};
134# elif defined(IS31FL3733)
135static void flush(void) {
136 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
137# ifdef DRIVER_ADDR_2
138 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
139# endif
140# ifdef DRIVER_ADDR_3
141 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2);
142# endif
143# ifdef DRIVER_ADDR_4
144 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3);
145# endif
146}
147
148const rgb_matrix_driver_t rgb_matrix_driver = {
149 .init = init,
150 .flush = flush,
151 .set_color = IS31FL3733_set_color,
152 .set_color_all = IS31FL3733_set_color_all,
153};
154# elif defined(IS31FL3737)
155static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
156
157const rgb_matrix_driver_t rgb_matrix_driver = {
158 .init = init,
159 .flush = flush,
160 .set_color = IS31FL3737_set_color,
161 .set_color_all = IS31FL3737_set_color_all,
162};
163# else
164static void flush(void) { IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
165
166const rgb_matrix_driver_t rgb_matrix_driver = {
167 .init = init,
168 .flush = flush,
169 .set_color = IS31FL3741_set_color,
170 .set_color_all = IS31FL3741_set_color_all,
171};
172# endif
173
174#elif defined(AW20216)
175# include "spi_master.h"
176static void init(void) {
177 spi_init();
178 AW20216_init();
179}
180
181static void flush(void) { AW20216_update_pwm_buffers(); }
182
183const rgb_matrix_driver_t rgb_matrix_driver = {
184 .init = init,
185 .flush = flush,
186 .set_color = AW20216_set_color,
187 .set_color_all = AW20216_set_color_all,
188};
189
190#elif defined(WS2812)
191# if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_CUSTOM_DRIVER)
192# pragma message "Cannot use RGBLIGHT and RGB Matrix using WS2812 at the same time."
193# pragma message "You need to use a custom driver, or re-implement the WS2812 driver to use a different configuration."
194# endif
195
196// LED color buffer
197LED_TYPE rgb_matrix_ws2812_array[DRIVER_LED_TOTAL];
198
199static void init(void) {}
200
201static void flush(void) {
202 // Assumes use of RGB_DI_PIN
203 ws2812_setleds(rgb_matrix_ws2812_array, DRIVER_LED_TOTAL);
204}
205
206// Set an led in the buffer to a color
207static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
208 rgb_matrix_ws2812_array[i].r = r;
209 rgb_matrix_ws2812_array[i].g = g;
210 rgb_matrix_ws2812_array[i].b = b;
211# ifdef RGBW
212 convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]);
213# endif
214}
215
216static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
217 for (int i = 0; i < sizeof(rgb_matrix_ws2812_array) / sizeof(rgb_matrix_ws2812_array[0]); i++) {
218 setled(i, r, g, b);
219 }
220}
221
222const rgb_matrix_driver_t rgb_matrix_driver = {
223 .init = init,
224 .flush = flush,
225 .set_color = setled,
226 .set_color_all = setled_all,
227};
228#endif