summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Didron <fdidron@users.noreply.github.com>2019-04-18 10:04:32 +0900
committerGitHub <noreply@github.com>2019-04-18 10:04:32 +0900
commitb51f1e0971e4823628f56c1ac4eba3bf780b103a (patch)
treed9e7563bdb7bc6bf98a37d5231a36067c359dbef
parent09d1ff9a326abe8bdb1f44f94b3ff05fcd0184cb (diff)
parent51a682bb9c51a14c2cbe591d8a11d1719b7abb52 (diff)
Merge pull request #13 from ErgoDox-EZ/feature/ws2812_matrix
Features/ws2812 matrix driver (#5418)
-rw-r--r--changelog.md7
-rw-r--r--common_features.mk7
-rw-r--r--drivers/avr/ws2812.c25
-rw-r--r--drivers/avr/ws2812.h5
-rw-r--r--quantum/rgb_matrix.h6
-rw-r--r--quantum/rgb_matrix_drivers.c21
-rw-r--r--quantum/rgblight.c4
7 files changed, 68 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md
index d6fe3b82ed..1277c2f5cd 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,6 @@
-04-12-2019 - Add AltGr/RALT support to Send String (qmk#4046)
+04-12-2019 - Add AltGr/RALT support to Send String (qmk#4046)
04-12-2019 - Port DIRECT_PINS from split_common/matrix.c to matrix.c (qmk#5091)
-04-12-2019 - Enhancement for Eager debouncing (and Ergodox EZ host sleep fix) (qmk#5621)
+04-12-2019 - Enhancement for Eager debouncing (and Ergodox EZ host sleep fix) (qmk#5621)
04-16-2019 - Fix logic for Combo feature (qmk#5610)
-04-16-2019 - Fix info.json for Ergodox EZ \ No newline at end of file
+04-16-2019 - Fix info.json for Ergodox EZ
+04-16-2019 - Add support for WS2812 based RGB Matrix \ No newline at end of file
diff --git a/common_features.mk b/common_features.mk
index c3b6fa9168..bd1685869d 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -114,7 +114,7 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
endif
endif
-VALID_MATRIX_TYPES := yes IS31FL3731 IS31FL3733 IS31FL3737 custom
+VALID_MATRIX_TYPES := yes IS31FL3731 IS31FL3733 IS31FL3737 WS2812 custom
LED_MATRIX_ENABLE ?= no
ifneq ($(strip $(LED_MATRIX_ENABLE)), no)
@@ -172,6 +172,11 @@ ifeq ($(strip $(RGB_MATRIX_ENABLE)), IS31FL3737)
SRC += i2c_master.c
endif
+ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812)
+ OPT_DEFS += -DWS2812
+ SRC += ws2812.c
+endif
+
ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
OPT_DEFS += -DTAP_DANCE_ENABLE
SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c
index 5bd837ec75..b3ed4fd0b0 100644
--- a/drivers/avr/ws2812.c
+++ b/drivers/avr/ws2812.c
@@ -27,6 +27,12 @@
#include <util/delay.h>
#include "debug.h"
+#if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE)
+// LED color buffer
+LED_TYPE led[DRIVER_LED_TOTAL];
+ #define LED_ARRAY led
+#endif
+
#ifdef RGBW_BB_TWI
// Port for the I2C
@@ -141,6 +147,25 @@ unsigned char I2C_Write(unsigned char c)
#endif
+#ifdef RGB_MATRIX_ENABLE
+// Set an led in the buffer to a color
+void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b)
+{
+ led[i].r = r;
+ led[i].g = g;
+ led[i].b = b;
+}
+
+void ws2812_setled_all (uint8_t r, uint8_t g, uint8_t b)
+{
+ for (int i = 0; i < RGBLED_NUM; i++) {
+ led[i].r = r;
+ led[i].g = g;
+ led[i].b = b;
+ }
+}
+#endif
+
// Setleds for standard RGB
void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds)
{
diff --git a/drivers/avr/ws2812.h b/drivers/avr/ws2812.h
index 1f9299ffb5..ecb1dc4d18 100644
--- a/drivers/avr/ws2812.h
+++ b/drivers/avr/ws2812.h
@@ -30,7 +30,6 @@
#include "rgblight_types.h"
-
/* User Interface
*
* Input:
@@ -43,6 +42,10 @@
* - Send out the LED data
* - Wait 50�s to reset the LEDs
*/
+#ifdef RGB_MATRIX_ENABLE
+void ws2812_setled (int index, uint8_t r, uint8_t g, uint8_t b);
+void ws2812_setled_all (uint8_t r, uint8_t g, uint8_t b);
+#endif
void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds);
void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index 0e193dcb2f..0a11f26920 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -28,9 +28,11 @@
#ifdef IS31FL3731
#include "is31fl3731.h"
#elif defined (IS31FL3733)
- #include "is31fl3733.h"
+ #include "is31fl3733.h"
#elif defined (IS31FL3737)
- #include "is31fl3737.h"
+ #include "is31fl3737.h"
+#elif defined (WS2812)
+ #include "ws2812.h"
#endif
#ifndef RGB_MATRIX_LED_FLUSH_LIMIT
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c
index 3b7d58483a..3814dd61fc 100644
--- a/quantum/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix_drivers.c
@@ -97,4 +97,25 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
};
#endif
+#elif defined(WS2812)
+
+extern LED_TYPE led[RGBLED_NUM];
+
+ static void flush( void )
+ {
+ // Assumes use of RGB_DI_PIN
+ ws2812_setleds(led, RGBLED_NUM);
+ }
+
+ static void init( void )
+ {
+
+ }
+
+ const rgb_matrix_driver_t rgb_matrix_driver = {
+ .init = init,
+ .flush = flush,
+ .set_color = ws2812_setled,
+ .set_color_all = ws2812_setled_all,
+ };
#endif
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 08515564bc..e2410424e4 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -63,7 +63,11 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
rgblight_config_t rgblight_config;
bool is_rgblight_initialized = false;
+#ifndef LED_ARRAY
LED_TYPE led[RGBLED_NUM];
+ #define LED_ARRAY led
+#endif
+
bool rgblight_timer_enabled = false;
static uint8_t clipping_start_pos = 0;