]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/led_matrix_drivers.c
21e8a14c66f68d43d9b28f893755c82e0b7beaab
[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(LED_DRIVER_ADDR_1);
43         #endif
44         #ifdef LED_DRIVER_ADDR_2
45             IS31FL3731_init(LED_DRIVER_ADDR_2);
46         #endif
47         #ifdef LED_DRIVER_ADDR_3
48             IS31FL3731_init(LED_DRIVER_ADDR_3);
49         #endif
50         #ifdef LED_DRIVER_ADDR_4
51             IS31FL3731_init(LED_DRIVER_ADDR_4);
52         #endif
53     #else
54         #ifdef LED_DRIVER_ADDR_1
55             IS31FL3733_init(LED_DRIVER_ADDR_1);
56         #endif
57         #ifdef LED_DRIVER_ADDR_2
58             IS31FL3733_init(LED_DRIVER_ADDR_2);
59         #endif
60         #ifdef LED_DRIVER_ADDR_3
61             IS31FL3733_init(LED_DRIVER_ADDR_3);
62         #endif
63         #ifdef LED_DRIVER_ADDR_4
64             IS31FL3733_init(LED_DRIVER_ADDR_4);
65         #endif
66     #endif
67
68     for (int index = 0; index < LED_DRIVER_LED_COUNT; index++) {
69         #ifdef IS31FL3731
70             IS31FL3731_set_led_control_register(index, true);
71         #else
72             IS31FL3733_set_led_control_register(index, true);
73         #endif
74     }
75     // This actually updates the LED drivers
76     #ifdef IS31FL3731
77         #ifdef LED_DRIVER_ADDR_1
78             IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
79         #endif
80         #ifdef LED_DRIVER_ADDR_2
81             IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
82         #endif
83         #ifdef LED_DRIVER_ADDR_3
84             IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
85         #endif
86         #ifdef LED_DRIVER_ADDR_4
87             IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
88         #endif
89     #else
90         #ifdef LED_DRIVER_ADDR_1
91             IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
92         #endif
93         #ifdef LED_DRIVER_ADDR_2
94             IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
95         #endif
96         #ifdef LED_DRIVER_ADDR_3
97             IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
98         #endif
99         #ifdef LED_DRIVER_ADDR_4
100             IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
101         #endif
102     #endif
103 }
104
105 static void flush(void) {
106     #ifdef IS31FL3731
107         #ifdef LED_DRIVER_ADDR_1
108             IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
109         #endif
110         #ifdef LED_DRIVER_ADDR_2
111             IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
112         #endif
113         #ifdef LED_DRIVER_ADDR_3
114             IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
115         #endif
116         #ifdef LED_DRIVER_ADDR_4
117             IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
118         #endif
119     #else
120         #ifdef LED_DRIVER_ADDR_1
121             IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
122         #endif
123         #ifdef LED_DRIVER_ADDR_2
124             IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
125         #endif
126         #ifdef LED_DRIVER_ADDR_3
127             IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
128         #endif
129         #ifdef LED_DRIVER_ADDR_4
130             IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
131         #endif
132     #endif
133 }
134
135 const led_matrix_driver_t led_matrix_driver = {
136     .init = init,
137     .flush = flush,
138 #ifdef IS31FL3731
139     .set_value = IS31FL3731_set_value,
140     .set_value_all = IS31FL3731_set_value_all,
141 #else
142     .set_value = IS31FL3733_set_value,
143     .set_value_all = IS31FL3733_set_value_all,
144 #endif
145 };
146
147
148 #endif