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