diff options
Diffstat (limited to 'quantum/rgb_matrix_drivers.c')
-rw-r--r-- | quantum/rgb_matrix_drivers.c | 125 |
1 files changed, 67 insertions, 58 deletions
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c index 2a3aa9a5e0..9729a3064e 100644 --- a/quantum/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix_drivers.c @@ -25,58 +25,57 @@ #if defined(IS31FL3731) || defined(IS31FL3733) || defined(IS31FL3737) -#include "i2c_master.h" +# include "i2c_master.h" -static void init( void ) -{ +static void init(void) { i2c_init(); -#ifdef IS31FL3731 - IS31FL3731_init( DRIVER_ADDR_1 ); - IS31FL3731_init( DRIVER_ADDR_2 ); -#elif defined(IS31FL3733) - IS31FL3733_init( DRIVER_ADDR_1, 0 ); -#else - IS31FL3737_init( DRIVER_ADDR_1 ); -#endif - for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) { +# ifdef IS31FL3731 + IS31FL3731_init(DRIVER_ADDR_1); + IS31FL3731_init(DRIVER_ADDR_2); +# elif defined(IS31FL3733) + IS31FL3733_init(DRIVER_ADDR_1, 0); +# else + IS31FL3737_init(DRIVER_ADDR_1); +# endif + for (int index = 0; index < DRIVER_LED_TOTAL; index++) { bool enabled = true; // This only caches it for later -#ifdef IS31FL3731 - IS31FL3731_set_led_control_register( index, enabled, enabled, enabled ); -#elif defined(IS31FL3733) - IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); -#else - IS31FL3737_set_led_control_register( index, enabled, enabled, enabled ); -#endif +# ifdef IS31FL3731 + IS31FL3731_set_led_control_register(index, enabled, enabled, enabled); +# elif defined(IS31FL3733) + IS31FL3733_set_led_control_register(index, enabled, enabled, enabled); +# else + IS31FL3737_set_led_control_register(index, enabled, enabled, enabled); +# endif } // This actually updates the LED drivers -#ifdef IS31FL3731 - IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); -#elif defined(IS31FL3733) - IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, 0 ); - IS31FL3733_update_led_control_registers( DRIVER_ADDR_2, 1 ); -#else - IS31FL3737_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); -#endif +# ifdef IS31FL3731 + IS31FL3731_update_led_control_registers(DRIVER_ADDR_1, 0); + IS31FL3731_update_led_control_registers(DRIVER_ADDR_2, 1); +# elif defined(IS31FL3733) + IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0); + IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1); +# else + IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2); +# endif } -#ifdef IS31FL3731 -static void flush( void ) -{ - IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); +# ifdef IS31FL3731 +static void flush(void) { + IS31FL3731_update_pwm_buffers(DRIVER_ADDR_1, 0); + IS31FL3731_update_pwm_buffers(DRIVER_ADDR_2, 1); } const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = IS31FL3731_set_color, + .init = init, + .flush = flush, + .set_color = IS31FL3731_set_color, .set_color_all = IS31FL3731_set_color_all, }; -#elif defined(IS31FL3733) -static void flush( void ) -{ - IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, 0); - IS31FL3733_update_pwm_buffers( DRIVER_ADDR_2, 1); +# elif defined(IS31FL3733) +static void flush(void) { + IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0); + IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1); } const rgb_matrix_driver_t rgb_matrix_driver = { @@ -85,11 +84,8 @@ const rgb_matrix_driver_t rgb_matrix_driver = { .set_color = IS31FL3733_set_color, .set_color_all = IS31FL3733_set_color_all, }; -#else -static void flush( void ) -{ - IS31FL3737_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); -} +# else +static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); } const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, @@ -97,27 +93,40 @@ const rgb_matrix_driver_t rgb_matrix_driver = { .set_color = IS31FL3737_set_color, .set_color_all = IS31FL3737_set_color_all, }; -#endif +# endif #elif defined(WS2812) -extern LED_TYPE led[DRIVER_LED_TOTAL]; +// LED color buffer +LED_TYPE led[DRIVER_LED_TOTAL]; - static void flush( void ) - { +static void init(void) {} + +static void flush(void) { // Assumes use of RGB_DI_PIN ws2812_setleds(led, DRIVER_LED_TOTAL); - } +} - static void init( void ) - { +// Set an led in the buffer to a color +static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { + led[i].r = r; + led[i].g = g; + led[i].b = b; +# ifdef RGBW + led[i].w = 0; +# endif +} - } +static void setled_all(uint8_t r, uint8_t g, uint8_t b) { + for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) { + setled(i, r, g, b); + } +} - const rgb_matrix_driver_t rgb_matrix_driver = { - .init = init, - .flush = flush, - .set_color = ws2812_setled, - .set_color_all = ws2812_setled_all, - }; +const rgb_matrix_driver_t rgb_matrix_driver = { + .init = init, + .flush = flush, + .set_color = setled, + .set_color_all = setled_all, +}; #endif |