]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/rgb_matrix_drivers.c
[Keymap] Jarred's Plaid keymap (#6049)
[qmk_firmware.git] / quantum / rgb_matrix_drivers.c
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
26 #if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737)
27
28 #include "i2c_master.h"
29
30 static void init( void )
31 {
32     i2c_init();
33 #ifdef IS31FL3731
34     IS31FL3731_init( DRIVER_ADDR_1 );
35     IS31FL3731_init( DRIVER_ADDR_2 );
36 #elif defined(IS31FL3733)
37     IS31FL3733_init( DRIVER_ADDR_1, 0 );
38 #else
39     IS31FL3737_init( DRIVER_ADDR_1 );
40 #endif
41     for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) {
42         bool enabled = true;
43         // This only caches it for later
44 #ifdef IS31FL3731
45         IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
46 #elif defined(IS31FL3733)
47         IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
48 #else
49         IS31FL3737_set_led_control_register( index, enabled, enabled, enabled );
50 #endif
51     }
52     // This actually updates the LED drivers
53 #ifdef IS31FL3731
54     IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, 0 );
55     IS31FL3731_update_led_control_registers( DRIVER_ADDR_2, 1 );
56 #elif defined(IS31FL3733)
57     IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, 0 );
58     IS31FL3733_update_led_control_registers( DRIVER_ADDR_2, 1 );
59 #else
60     IS31FL3737_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
61 #endif
62 }
63
64 #ifdef IS31FL3731
65 static void flush( void )
66 {
67     IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, 0 ); 
68     IS31FL3731_update_pwm_buffers( DRIVER_ADDR_2, 1 );
69 }
70
71 const rgb_matrix_driver_t rgb_matrix_driver = {
72     .init = init,
73     .flush = flush,
74     .set_color = IS31FL3731_set_color,
75     .set_color_all = IS31FL3731_set_color_all,
76 };
77 #elif defined(IS31FL3733)
78 static void flush( void )
79 {
80     IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, 0);
81     IS31FL3733_update_pwm_buffers( DRIVER_ADDR_2, 1);
82 }
83
84 const rgb_matrix_driver_t rgb_matrix_driver = {
85     .init = init,
86     .flush = flush,
87     .set_color = IS31FL3733_set_color,
88     .set_color_all = IS31FL3733_set_color_all,
89 };
90 #else
91 static void flush( void )
92 {
93     IS31FL3737_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
94 }
95
96 const rgb_matrix_driver_t rgb_matrix_driver = {
97     .init = init,
98     .flush = flush,
99     .set_color = IS31FL3737_set_color,
100     .set_color_all = IS31FL3737_set_color_all,
101 };
102 #endif
103
104 #elif defined(WS2812)
105
106 extern LED_TYPE led[DRIVER_LED_TOTAL];
107
108   static void flush( void )
109   {
110     // Assumes use of RGB_DI_PIN
111     ws2812_setleds(led, DRIVER_LED_TOTAL);
112   }
113
114   static void init( void )
115   {
116
117   }
118
119   const rgb_matrix_driver_t rgb_matrix_driver = {
120       .init = init,
121       .flush = flush,
122       .set_color = ws2812_setled,
123       .set_color_all = ws2812_setled_all,
124   };
125 #endif