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