Skip to content

Commit b51f1e0

Browse files
authored
Merge pull request #13 from ErgoDox-EZ/feature/ws2812_matrix
Features/ws2812 matrix driver (qmk#5418)
2 parents 09d1ff9 + 51a682b commit b51f1e0

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

changelog.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
04-12-2019 - Add AltGr/RALT support to Send String (qmk#4046)
1+
04-12-2019 - Add AltGr/RALT support to Send String (qmk#4046)
22
04-12-2019 - Port DIRECT_PINS from split_common/matrix.c to matrix.c (qmk#5091)
3-
04-12-2019 - Enhancement for Eager debouncing (and Ergodox EZ host sleep fix) (qmk#5621)
3+
04-12-2019 - Enhancement for Eager debouncing (and Ergodox EZ host sleep fix) (qmk#5621)
44
04-16-2019 - Fix logic for Combo feature (qmk#5610)
5-
04-16-2019 - Fix info.json for Ergodox EZ
5+
04-16-2019 - Fix info.json for Ergodox EZ
6+
04-16-2019 - Add support for WS2812 based RGB Matrix

common_features.mk

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
114114
endif
115115
endif
116116

117-
VALID_MATRIX_TYPES := yes IS31FL3731 IS31FL3733 IS31FL3737 custom
117+
VALID_MATRIX_TYPES := yes IS31FL3731 IS31FL3733 IS31FL3737 WS2812 custom
118118

119119
LED_MATRIX_ENABLE ?= no
120120
ifneq ($(strip $(LED_MATRIX_ENABLE)), no)
@@ -172,6 +172,11 @@ ifeq ($(strip $(RGB_MATRIX_ENABLE)), IS31FL3737)
172172
SRC += i2c_master.c
173173
endif
174174

175+
ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812)
176+
OPT_DEFS += -DWS2812
177+
SRC += ws2812.c
178+
endif
179+
175180
ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
176181
OPT_DEFS += -DTAP_DANCE_ENABLE
177182
SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c

drivers/avr/ws2812.c

+25
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
#include <util/delay.h>
2828
#include "debug.h"
2929

30+
#if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE)
31+
// LED color buffer
32+
LED_TYPE led[DRIVER_LED_TOTAL];
33+
#define LED_ARRAY led
34+
#endif
35+
3036
#ifdef RGBW_BB_TWI
3137

3238
// Port for the I2C
@@ -141,6 +147,25 @@ unsigned char I2C_Write(unsigned char c)
141147

142148
#endif
143149

150+
#ifdef RGB_MATRIX_ENABLE
151+
// Set an led in the buffer to a color
152+
void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b)
153+
{
154+
led[i].r = r;
155+
led[i].g = g;
156+
led[i].b = b;
157+
}
158+
159+
void ws2812_setled_all (uint8_t r, uint8_t g, uint8_t b)
160+
{
161+
for (int i = 0; i < RGBLED_NUM; i++) {
162+
led[i].r = r;
163+
led[i].g = g;
164+
led[i].b = b;
165+
}
166+
}
167+
#endif
168+
144169
// Setleds for standard RGB
145170
void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds)
146171
{

drivers/avr/ws2812.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "rgblight_types.h"
3232

33-
3433
/* User Interface
3534
*
3635
* Input:
@@ -43,6 +42,10 @@
4342
* - Send out the LED data
4443
* - Wait 50�s to reset the LEDs
4544
*/
45+
#ifdef RGB_MATRIX_ENABLE
46+
void ws2812_setled (int index, uint8_t r, uint8_t g, uint8_t b);
47+
void ws2812_setled_all (uint8_t r, uint8_t g, uint8_t b);
48+
#endif
4649

4750
void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds);
4851
void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);

quantum/rgb_matrix.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
#ifdef IS31FL3731
2929
#include "is31fl3731.h"
3030
#elif defined (IS31FL3733)
31-
#include "is31fl3733.h"
31+
#include "is31fl3733.h"
3232
#elif defined (IS31FL3737)
33-
#include "is31fl3737.h"
33+
#include "is31fl3737.h"
34+
#elif defined (WS2812)
35+
#include "ws2812.h"
3436
#endif
3537

3638
#ifndef RGB_MATRIX_LED_FLUSH_LIMIT

quantum/rgb_matrix_drivers.c

+21
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,25 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
9797
};
9898
#endif
9999

100+
#elif defined(WS2812)
101+
102+
extern LED_TYPE led[RGBLED_NUM];
103+
104+
static void flush( void )
105+
{
106+
// Assumes use of RGB_DI_PIN
107+
ws2812_setleds(led, RGBLED_NUM);
108+
}
109+
110+
static void init( void )
111+
{
112+
113+
}
114+
115+
const rgb_matrix_driver_t rgb_matrix_driver = {
116+
.init = init,
117+
.flush = flush,
118+
.set_color = ws2812_setled,
119+
.set_color_all = ws2812_setled_all,
120+
};
100121
#endif

quantum/rgblight.c

+4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
6363
rgblight_config_t rgblight_config;
6464
bool is_rgblight_initialized = false;
6565

66+
#ifndef LED_ARRAY
6667
LED_TYPE led[RGBLED_NUM];
68+
#define LED_ARRAY led
69+
#endif
70+
6771
bool rgblight_timer_enabled = false;
6872

6973
static uint8_t clipping_start_pos = 0;

0 commit comments

Comments
 (0)