Commit | Line | Data |
---|---|---|
f70f45ee JLW |
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 | ||
fa4052c2 | 26 | #if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) |
f70f45ee | 27 | |
b624f32f | 28 | # include "i2c_master.h" |
f70f45ee | 29 | |
b624f32f | 30 | static void init(void) { |
f70f45ee | 31 | i2c_init(); |
b624f32f | 32 | # ifdef IS31FL3731 |
33 | IS31FL3731_init(DRIVER_ADDR_1); | |
34 | IS31FL3731_init(DRIVER_ADDR_2); | |
35 | # elif defined(IS31FL3733) | |
36 | IS31FL3733_init(DRIVER_ADDR_1, 0); | |
37 | # else | |
38 | IS31FL3737_init(DRIVER_ADDR_1); | |
39 | # endif | |
40 | for (int index = 0; index < DRIVER_LED_TOTAL; index++) { | |
f70f45ee JLW |
41 | bool enabled = true; |
42 | // This only caches it for later | |
b624f32f | 43 | # ifdef IS31FL3731 |
44 | IS31FL3731_set_led_control_register(index, enabled, enabled, enabled); | |
45 | # elif defined(IS31FL3733) | |
46 | IS31FL3733_set_led_control_register(index, enabled, enabled, enabled); | |
47 | # else | |
48 | IS31FL3737_set_led_control_register(index, enabled, enabled, enabled); | |
49 | # endif | |
f70f45ee JLW |
50 | } |
51 | // This actually updates the LED drivers | |
b624f32f | 52 | # ifdef IS31FL3731 |
53 | IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0); | |
54 | IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1); | |
55 | # elif defined(IS31FL3733) | |
56 | IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0); | |
57 | IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1); | |
58 | # else | |
59 | IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2); | |
60 | # endif | |
f70f45ee JLW |
61 | } |
62 | ||
b624f32f | 63 | # ifdef IS31FL3731 |
64 | static void flush(void) { | |
65 | IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0); | |
66 | IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1); | |
f70f45ee JLW |
67 | } |
68 | ||
69 | const rgb_matrix_driver_t rgb_matrix_driver = { | |
b624f32f | 70 | .init = init, |
71 | .flush = flush, | |
72 | .set_color = IS31FL3731_set_color, | |
f70f45ee JLW |
73 | .set_color_all = IS31FL3731_set_color_all, |
74 | }; | |
b624f32f | 75 | # elif defined(IS31FL3733) |
76 | static void flush(void) { | |
77 | IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0); | |
78 | IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1); | |
f70f45ee JLW |
79 | } |
80 | ||
81 | const rgb_matrix_driver_t rgb_matrix_driver = { | |
82 | .init = init, | |
83 | .flush = flush, | |
84 | .set_color = IS31FL3733_set_color, | |
85 | .set_color_all = IS31FL3733_set_color_all, | |
86 | }; | |
b624f32f | 87 | # else |
88 | static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); } | |
fa4052c2 JH |
89 | |
90 | const rgb_matrix_driver_t rgb_matrix_driver = { | |
91 | .init = init, | |
92 | .flush = flush, | |
93 | .set_color = IS31FL3737_set_color, | |
94 | .set_color_all = IS31FL3737_set_color_all, | |
95 | }; | |
b624f32f | 96 | # endif |
f70f45ee | 97 | |
5fcd744d X |
98 | #elif defined(WS2812) |
99 | ||
e48fdebe JC |
100 | // LED color buffer |
101 | LED_TYPE led[DRIVER_LED_TOTAL]; | |
102 | ||
103 | static void init(void) {} | |
5fcd744d | 104 | |
b624f32f | 105 | static void flush(void) { |
5fcd744d | 106 | // Assumes use of RGB_DI_PIN |
50bc2dbe | 107 | ws2812_setleds(led, DRIVER_LED_TOTAL); |
b624f32f | 108 | } |
5fcd744d | 109 | |
e48fdebe JC |
110 | // Set an led in the buffer to a color |
111 | static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { | |
112 | led[i].r = r; | |
113 | led[i].g = g; | |
114 | led[i].b = b; | |
60e49213 | 115 | # ifdef RGBW |
7ba6456c | 116 | convert_rgb_to_rgbw(led[i]); |
60e49213 | 117 | # endif |
e48fdebe JC |
118 | } |
119 | ||
120 | static void setled_all(uint8_t r, uint8_t g, uint8_t b) { | |
121 | for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) { | |
122 | setled(i, r, g, b); | |
123 | } | |
124 | } | |
5fcd744d | 125 | |
b624f32f | 126 | const rgb_matrix_driver_t rgb_matrix_driver = { |
127 | .init = init, | |
128 | .flush = flush, | |
e48fdebe JC |
129 | .set_color = setled, |
130 | .set_color_all = setled_all, | |
b624f32f | 131 | }; |
f70f45ee | 132 | #endif |