aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix.c
diff options
context:
space:
mode:
authorJames Laird-Wah <james@laird-wah.net>2018-09-28 00:40:18 +1000
committerJack Humbert <jack.humb@gmail.com>2018-09-27 10:40:18 -0400
commitf70f45ee677a2a39a759052a356e0c5d82e25424 (patch)
treec0d6a6d5a5791a57309b3deb398ca1dfcc499f78 /quantum/rgb_matrix.c
parent12ad59f99de0ecd2c81b92587c2858b3fb39523c (diff)
downloadqmk_firmware-f70f45ee677a2a39a759052a356e0c5d82e25424.tar.gz
qmk_firmware-f70f45ee677a2a39a759052a356e0c5d82e25424.zip
RGB Matrix refactoring to open up for new drivers (#3913)
* rgb_matrix: use a driver ops struct This is intended to avoid #ifdef proliferation on adding more drivers, eg. model01, which use different architectures. * rgb_matrix: document driver struct members * rgb_matrix: remove unused LED testing code * rgb_matrix: don't build into IS31x drivers unless being used * rgb_matrix: refactor make config options This ensures that the necessary files are included for any custom RGB_MATRIX_ENABLE value, without having to add entries here for specific boards. This particularly affects model01 because its controller is integrated and won't be used anywhere else, so it's preferable not to put it in common_features.mk. This now validates the value of RGB_MATRIX_ENABLE. It was necessary to fix an error in ergodox_ez rules.mk using the wrong comment separator, yielding an invalid value. * IS31x drivers: don't write the control registers all the time This is only needed when they are changed. This is done in init() and board- or keymap-specific code is free to make further changes. * rgb_matrix: move structs from chip drivers to rgb_matrix_drivers.c This approach is specific to the rgb_matrix functionality, so keep it neatly separated from the raw chip drivers.
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r--quantum/rgb_matrix.c113
1 files changed, 4 insertions, 109 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 5fb59af8c..807e4d62d 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -18,7 +18,6 @@
18 18
19 19
20#include "rgb_matrix.h" 20#include "rgb_matrix.h"
21#include "i2c_master.h"
22#include "progmem.h" 21#include "progmem.h"
23#include "config.h" 22#include "config.h"
24#include "eeprom.h" 23#include "eeprom.h"
@@ -111,29 +110,15 @@ void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t
111} 110}
112 111
113void rgb_matrix_update_pwm_buffers(void) { 112void rgb_matrix_update_pwm_buffers(void) {
114#ifdef IS31FL3731 113 rgb_matrix_driver.flush();
115 IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
116 IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
117#elif defined(IS31FL3733)
118 IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
119 IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
120#endif
121} 114}
122 115
123void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { 116void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
124#ifdef IS31FL3731 117 rgb_matrix_driver.set_color(index, red, green, blue);
125 IS31FL3731_set_color( index, red, green, blue );
126#elif defined(IS31FL3733)
127 IS31FL3733_set_color( index, red, green, blue );
128#endif
129} 118}
130 119
131void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { 120void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
132#ifdef IS31FL3731 121 rgb_matrix_driver.set_color_all(red, green, blue);
133 IS31FL3731_set_color_all( red, green, blue );
134#elif defined(IS31FL3733)
135 IS31FL3733_set_color_all( red, green, blue );
136#endif
137} 122}
138 123
139bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { 124bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
@@ -196,47 +181,6 @@ void rgb_matrix_test(void) {
196 } 181 }
197} 182}
198 183
199// This tests the LEDs
200// Note that it will change the LED control registers
201// in the LED drivers, and leave them in an invalid
202// state for other backlight effects.
203// ONLY USE THIS FOR TESTING LEDS!
204void rgb_matrix_single_LED_test(void) {
205 static uint8_t color = 0; // 0,1,2 for R,G,B
206 static uint8_t row = 0;
207 static uint8_t column = 0;
208
209 static uint8_t tick = 0;
210 tick++;
211
212 if ( tick > 2 )
213 {
214 tick = 0;
215 column++;
216 }
217 if ( column > MATRIX_COLS )
218 {
219 column = 0;
220 row++;
221 }
222 if ( row > MATRIX_ROWS )
223 {
224 row = 0;
225 color++;
226 }
227 if ( color > 2 )
228 {
229 color = 0;
230 }
231
232 uint8_t led[8], led_count;
233 map_row_column_to_led(row,column,led,&led_count);
234 for(uint8_t i = 0; i < led_count; i++) {
235 rgb_matrix_set_color_all( 40, 40, 40 );
236 rgb_matrix_test_led( led[i], color==0, color==1, color==2 );
237 }
238}
239
240// All LEDs off 184// All LEDs off
241void rgb_matrix_all_off(void) { 185void rgb_matrix_all_off(void) {
242 rgb_matrix_set_color_all( 0, 0, 0 ); 186 rgb_matrix_set_color_all( 0, 0, 0 );
@@ -817,7 +761,7 @@ void rgb_matrix_indicators_user(void) {}
817// } 761// }
818 762
819void rgb_matrix_init(void) { 763void rgb_matrix_init(void) {
820 rgb_matrix_setup_drivers(); 764 rgb_matrix_driver.init();
821 765
822 // TODO: put the 1 second startup delay here? 766 // TODO: put the 1 second startup delay here?
823 767
@@ -841,33 +785,6 @@ void rgb_matrix_init(void) {
841 eeconfig_debug_rgb_matrix(); // display current eeprom values 785 eeconfig_debug_rgb_matrix(); // display current eeprom values
842} 786}
843 787
844void rgb_matrix_setup_drivers(void) {
845 // Initialize TWI
846 i2c_init();
847#ifdef IS31FL3731
848 IS31FL3731_init( DRIVER_ADDR_1 );
849 IS31FL3731_init( DRIVER_ADDR_2 );
850#elif defined (IS31FL3733)
851 IS31FL3733_init( DRIVER_ADDR_1 );
852#endif
853
854 for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) {
855 bool enabled = true;
856 // This only caches it for later
857#ifdef IS31FL3731
858 IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
859#elif defined (IS31FL3733)
860 IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
861#endif
862 }
863 // This actually updates the LED drivers
864#ifdef IS31FL3731
865 IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
866#elif defined (IS31FL3733)
867 IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
868#endif
869}
870
871// Deals with the messy details of incrementing an integer 788// Deals with the messy details of incrementing an integer
872uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { 789uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
873 int16_t new_value = value; 790 int16_t new_value = value;
@@ -910,28 +827,6 @@ uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
910// } 827// }
911// } 828// }
912 829
913void rgb_matrix_test_led( uint8_t index, bool red, bool green, bool blue ) {
914 for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
915 {
916 if ( i == index )
917 {
918#ifdef IS31FL3731
919 IS31FL3731_set_led_control_register( i, red, green, blue );
920#elif defined (IS31FL3733)
921 IS31FL3733_set_led_control_register( i, red, green, blue );
922#endif
923 }
924 else
925 {
926#ifdef IS31FL3731
927 IS31FL3731_set_led_control_register( i, false, false, false );
928#elif defined (IS31FL3733)
929 IS31FL3733_set_led_control_register( i, false, false, false );
930#endif
931 }
932 }
933}
934
935uint32_t rgb_matrix_get_tick(void) { 830uint32_t rgb_matrix_get_tick(void) {
936 return g_tick; 831 return g_tick;
937} 832}