aboutsummaryrefslogtreecommitdiff
path: root/quantum/led_matrix/led_matrix_drivers.c
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-06-22 18:26:23 +1000
committerGitHub <noreply@github.com>2021-06-22 18:26:23 +1000
commitd61e5c0027e289ccf48652afa4c442342e7ccf04 (patch)
treee8edc86d191a190691b4722f05e32bdc40affc58 /quantum/led_matrix/led_matrix_drivers.c
parentc03cb4edd7ff73391a0a64f0c4f5e0755e902908 (diff)
downloadqmk_firmware-d61e5c0027e289ccf48652afa4c442342e7ccf04.tar.gz
qmk_firmware-d61e5c0027e289ccf48652afa4c442342e7ccf04.zip
Move LED/RGB Matrix code into their own directories (#13257)
Diffstat (limited to 'quantum/led_matrix/led_matrix_drivers.c')
-rw-r--r--quantum/led_matrix/led_matrix_drivers.c153
1 files changed, 153 insertions, 0 deletions
diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c
new file mode 100644
index 000000000..1d46b2c50
--- /dev/null
+++ b/quantum/led_matrix/led_matrix_drivers.c
@@ -0,0 +1,153 @@
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 "led_matrix.h"
19
20/* Each driver needs to define a struct:
21 *
22 * const led_matrix_driver_t led_matrix_driver;
23 *
24 * All members must be provided. Keyboard custom drivers must define this
25 * in their own files.
26 */
27
28#if defined(IS31FL3731) || defined(IS31FL3733)
29
30# include "i2c_master.h"
31
32static void init(void) {
33 i2c_init();
34# ifdef IS31FL3731
35# ifdef LED_DRIVER_ADDR_1
36 IS31FL3731_init(LED_DRIVER_ADDR_1);
37# endif
38# ifdef LED_DRIVER_ADDR_2
39 IS31FL3731_init(LED_DRIVER_ADDR_2);
40# endif
41# ifdef LED_DRIVER_ADDR_3
42 IS31FL3731_init(LED_DRIVER_ADDR_3);
43# endif
44# ifdef LED_DRIVER_ADDR_4
45 IS31FL3731_init(LED_DRIVER_ADDR_4);
46# endif
47# else
48# ifdef LED_DRIVER_ADDR_1
49# ifndef LED_DRIVER_SYNC_1
50# define LED_DRIVER_SYNC_1 0
51# endif
52 IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1);
53# endif
54# ifdef LED_DRIVER_ADDR_2
55# ifndef LED_DRIVER_SYNC_2
56# define LED_DRIVER_SYNC_2 0
57# endif
58 IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2);
59# endif
60# ifdef LED_DRIVER_ADDR_3
61# ifndef LED_DRIVER_SYNC_3
62# define LED_DRIVER_SYNC_3 0
63# endif
64 IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3);
65# endif
66# ifdef LED_DRIVER_ADDR_4
67# ifndef LED_DRIVER_SYNC_4
68# define LED_DRIVER_SYNC_4 0
69# endif
70 IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4);
71# endif
72# endif
73
74 for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
75# ifdef IS31FL3731
76 IS31FL3731_set_led_control_register(index, true);
77# else
78 IS31FL3733_set_led_control_register(index, true);
79# endif
80 }
81// This actually updates the LED drivers
82# ifdef IS31FL3731
83# ifdef LED_DRIVER_ADDR_1
84 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
85# endif
86# ifdef LED_DRIVER_ADDR_2
87 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
88# endif
89# ifdef LED_DRIVER_ADDR_3
90 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
91# endif
92# ifdef LED_DRIVER_ADDR_4
93 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
94# endif
95# else
96# ifdef LED_DRIVER_ADDR_1
97 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
98# endif
99# ifdef LED_DRIVER_ADDR_2
100 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
101# endif
102# ifdef LED_DRIVER_ADDR_3
103 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
104# endif
105# ifdef LED_DRIVER_ADDR_4
106 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
107# endif
108# endif
109}
110
111static void flush(void) {
112# ifdef IS31FL3731
113# ifdef LED_DRIVER_ADDR_1
114 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
115# endif
116# ifdef LED_DRIVER_ADDR_2
117 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
118# endif
119# ifdef LED_DRIVER_ADDR_3
120 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
121# endif
122# ifdef LED_DRIVER_ADDR_4
123 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
124# endif
125# else
126# ifdef LED_DRIVER_ADDR_1
127 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
128# endif
129# ifdef LED_DRIVER_ADDR_2
130 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
131# endif
132# ifdef LED_DRIVER_ADDR_3
133 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
134# endif
135# ifdef LED_DRIVER_ADDR_4
136 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
137# endif
138# endif
139}
140
141const led_matrix_driver_t led_matrix_driver = {
142 .init = init,
143 .flush = flush,
144# ifdef IS31FL3731
145 .set_value = IS31FL3731_set_value,
146 .set_value_all = IS31FL3731_set_value_all,
147# else
148 .set_value = IS31FL3733_set_value,
149 .set_value_all = IS31FL3733_set_value_all,
150# endif
151};
152
153#endif