summaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix_drivers.c
diff options
context:
space:
mode:
authorWilliam Chang <william@factual.com>2019-11-20 22:17:07 -0800
committerWilliam Chang <william@factual.com>2019-11-20 22:17:07 -0800
commite7f4d56592b3975c38af329e77b4efd9108495e8 (patch)
tree0a416bccbf70bfdbdb9ffcdb3bf136b47378c014 /quantum/rgb_matrix_drivers.c
parent71493b2f9bbd5f3d18373c518fa14ccafcbf48fc (diff)
parent8416a94ad27b3ff058576f09f35f0704a8b39ff3 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'quantum/rgb_matrix_drivers.c')
-rw-r--r--quantum/rgb_matrix_drivers.c125
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