aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXScorpion2 <rcalt2vt@gmail.com>2019-04-14 20:50:35 -0400
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-04-14 17:50:35 -0700
commit5fcd744ddba591829a129560992b2e43fb615d4d (patch)
tree33b78133af1563f5dfa1e125a37f86e30a7df1cb
parentd7ba190cd9b90bce3a00dfa2a9afe4b3bf0a1dbb (diff)
downloadqmk_firmware-5fcd744ddba591829a129560992b2e43fb615d4d.tar.gz
qmk_firmware-5fcd744ddba591829a129560992b2e43fb615d4d.zip
Features/ws2812 matrix driver (#5418)
* WS2812 driver implementation for RGB Matrix * Added driver configuration docs
-rw-r--r--common_features.mk7
-rw-r--r--docs/feature_rgb_matrix.md24
-rw-r--r--drivers/avr/ws2812.c25
-rw-r--r--drivers/avr/ws2812.h5
-rw-r--r--keyboards/sol/keymaps/kageurufu/rules.mk7
-rw-r--r--keyboards/sol/rev1/config.h6
-rw-r--r--keyboards/sol/rev1/rev1.c83
-rw-r--r--quantum/rgb_matrix.h6
-rw-r--r--quantum/rgb_matrix_drivers.c21
-rw-r--r--quantum/rgblight.c4
-rw-r--r--users/kageurufu/rules.mk2
11 files changed, 177 insertions, 13 deletions
diff --git a/common_features.mk b/common_features.mk
index c3b6fa916..bd1685869 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -114,7 +114,7 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
114 endif 114 endif
115endif 115endif
116 116
117VALID_MATRIX_TYPES := yes IS31FL3731 IS31FL3733 IS31FL3737 custom 117VALID_MATRIX_TYPES := yes IS31FL3731 IS31FL3733 IS31FL3737 WS2812 custom
118 118
119LED_MATRIX_ENABLE ?= no 119LED_MATRIX_ENABLE ?= no
120ifneq ($(strip $(LED_MATRIX_ENABLE)), no) 120ifneq ($(strip $(LED_MATRIX_ENABLE)), no)
@@ -172,6 +172,11 @@ ifeq ($(strip $(RGB_MATRIX_ENABLE)), IS31FL3737)
172 SRC += i2c_master.c 172 SRC += i2c_master.c
173endif 173endif
174 174
175ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812)
176 OPT_DEFS += -DWS2812
177 SRC += ws2812.c
178endif
179
175ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) 180ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
176 OPT_DEFS += -DTAP_DANCE_ENABLE 181 OPT_DEFS += -DTAP_DANCE_ENABLE
177 SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c 182 SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 36d9d0113..e744ecc49 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -5,7 +5,7 @@ This feature allows you to use RGB LED matrices driven by external drivers. It h
5If you want to use single color LED's you should use the [LED Matrix Subsystem](feature_led_matrix.md) instead. 5If you want to use single color LED's you should use the [LED Matrix Subsystem](feature_led_matrix.md) instead.
6 6
7## Driver configuration 7## Driver configuration
8 8---
9### IS31FL3731 9### IS31FL3731
10 10
11There is basic support for addressable RGB matrix lighting with the I2C IS31FL3731 RGB controller. To enable it, add this to your `rules.mk`: 11There is basic support for addressable RGB matrix lighting with the I2C IS31FL3731 RGB controller. To enable it, add this to your `rules.mk`:
@@ -52,6 +52,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
52 52
53Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0` or `1` right now). 53Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0` or `1` right now).
54 54
55---
55### IS31FL3733/IS31FL3737 56### IS31FL3733/IS31FL3737
56 57
57!> For the IS31FL3737, replace all instances of `IS31FL3733` below with `IS31FL3737`. 58!> For the IS31FL3737, replace all instances of `IS31FL3733` below with `IS31FL3737`.
@@ -102,6 +103,27 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
102 103
103Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now). 104Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now).
104 105
106---
107
108### WS2812 (AVR only)
109
110There is basic support for addressable RGB matrix lighting with a WS2811/WS2812{a,b,c} addressable LED strand. To enable it, add this to your `rules.mk`:
111
112```C
113RGB_MATRIX_ENABLE = WS2812
114```
115
116Configure the hardware via your `config.h`:
117
118```C
119// The pin connected to the data pin of the LEDs
120#define RGB_DI_PIN D7
121// The number of LEDs connected
122#define DRIVER_LED_TOTAL 70
123```
124
125---
126
105From this point forward the configuration is the same for all the drivers. 127From this point forward the configuration is the same for all the drivers.
106 128
107```C 129```C
diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c
index 5bd837ec7..b3ed4fd0b 100644
--- a/drivers/avr/ws2812.c
+++ b/drivers/avr/ws2812.c
@@ -27,6 +27,12 @@
27#include <util/delay.h> 27#include <util/delay.h>
28#include "debug.h" 28#include "debug.h"
29 29
30#if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE)
31// LED color buffer
32LED_TYPE led[DRIVER_LED_TOTAL];
33 #define LED_ARRAY led
34#endif
35
30#ifdef RGBW_BB_TWI 36#ifdef RGBW_BB_TWI
31 37
32// Port for the I2C 38// Port for the I2C
@@ -141,6 +147,25 @@ unsigned char I2C_Write(unsigned char c)
141 147
142#endif 148#endif
143 149
150#ifdef RGB_MATRIX_ENABLE
151// Set an led in the buffer to a color
152void 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
159void 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
144// Setleds for standard RGB 169// Setleds for standard RGB
145void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) 170void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds)
146{ 171{
diff --git a/drivers/avr/ws2812.h b/drivers/avr/ws2812.h
index 1f9299ffb..ecb1dc4d1 100644
--- a/drivers/avr/ws2812.h
+++ b/drivers/avr/ws2812.h
@@ -30,7 +30,6 @@
30 30
31#include "rgblight_types.h" 31#include "rgblight_types.h"
32 32
33
34/* User Interface 33/* User Interface
35 * 34 *
36 * Input: 35 * Input:
@@ -43,6 +42,10 @@
43 * - Send out the LED data 42 * - Send out the LED data
44 * - Wait 50�s to reset the LEDs 43 * - Wait 50�s to reset the LEDs
45 */ 44 */
45#ifdef RGB_MATRIX_ENABLE
46void ws2812_setled (int index, uint8_t r, uint8_t g, uint8_t b);
47void ws2812_setled_all (uint8_t r, uint8_t g, uint8_t b);
48#endif
46 49
47void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds); 50void ws2812_setleds (LED_TYPE *ledarray, uint16_t number_of_leds);
48void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask); 51void ws2812_setleds_pin (LED_TYPE *ledarray, uint16_t number_of_leds,uint8_t pinmask);
diff --git a/keyboards/sol/keymaps/kageurufu/rules.mk b/keyboards/sol/keymaps/kageurufu/rules.mk
index d098168fd..bb502be00 100644
--- a/keyboards/sol/keymaps/kageurufu/rules.mk
+++ b/keyboards/sol/keymaps/kageurufu/rules.mk
@@ -4,14 +4,15 @@
4# 4#
5BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) 5BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
6MOUSEKEY_ENABLE = no # Mouse keys(+4700) 6MOUSEKEY_ENABLE = no # Mouse keys(+4700)
7
7EXTRAKEY_ENABLE = yes # Audio control and System control(+450) 8EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
8CONSOLE_ENABLE = yes # Console for debug(+400) 9CONSOLE_ENABLE = yes # Console for debug(+400)
9COMMAND_ENABLE = yes # Commands for debug and configuration 10COMMAND_ENABLE = yes # Commands for debug and configuration
10NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 11NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
11RGBLIGHT_ENABLE = yes # Enable global lighting effects. Do not enable with RGB Matrix 12RGBLIGHT_ENABLE = no # Enable global lighting effects. Do not enable with RGB Matrix
12LED_ANIMATIONS = yes # LED animations 13RGBLIGHT_ANIMATIONS = no # LED animations
13LED_MIRRORED = no # Mirror LEDs across halves (enable DIP 1 on slave, and DIP 2 and 3 on master) 14LED_MIRRORED = no # Mirror LEDs across halves (enable DIP 1 on slave, and DIP 2 and 3 on master)
14RGB_MATRIX_ENABLE = no # Enable per-key coordinate based RGB effects. Do not enable with RGBlight (+8500) 15RGB_MATRIX_ENABLE = WS2812 # Enable per-key coordinate based RGB effects. Do not enable with RGBlight (+8500)
15RGB_MATRIX_KEYPRESSES = no # Enable reactive per-key effects. Can be very laggy (+1500) 16RGB_MATRIX_KEYPRESSES = no # Enable reactive per-key effects. Can be very laggy (+1500)
16RGBLIGHT_FULL_POWER = no # Allow maximum RGB brightness. Otherwise, limited to a safe level for a normal USB-A port 17RGBLIGHT_FULL_POWER = no # Allow maximum RGB brightness. Otherwise, limited to a safe level for a normal USB-A port
17UNICODE_ENABLE = no # Unicode 18UNICODE_ENABLE = no # Unicode
diff --git a/keyboards/sol/rev1/config.h b/keyboards/sol/rev1/config.h
index bfdadf9f6..1ef373f96 100644
--- a/keyboards/sol/rev1/config.h
+++ b/keyboards/sol/rev1/config.h
@@ -81,8 +81,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
81#define ws2812_PORTREG PORTD 81#define ws2812_PORTREG PORTD
82#define ws2812_DDRREG DDRD 82#define ws2812_DDRREG DDRD
83 83
84#define DRIVER_COUNT 2 84#define DRIVER_COUNT 1
85#define DRIVER_LED_TOTAL 70
86// #define RGB_MATRIX_KEYPRESSES 85// #define RGB_MATRIX_KEYPRESSES
87#define BACKLIGHT_PIN B7 86#define BACKLIGHT_PIN B7
88#define BACKLIGHT_LEVELS 5 87#define BACKLIGHT_LEVELS 5
@@ -92,6 +91,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
92#else 91#else
93 #define RGBLED_NUM 70 92 #define RGBLED_NUM 70
94#endif 93#endif
94#define DRIVER_LED_TOTAL RGBLED_NUM
95 95
96#define RGBLIGHT_RAINBOW_SWIRL_RANGE 1950 96#define RGBLIGHT_RAINBOW_SWIRL_RANGE 1950
97 97
@@ -112,6 +112,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
112 112
113#define RGBLIGHT_ANIMATIONS 113#define RGBLIGHT_ANIMATIONS
114 114
115#define LED_HITS_TO_REMEMBER 5
116
115#if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE) 117#if defined(RGBLIGHT_ENABLE) && !defined(IOS_DEVICE_ENABLE)
116// USB_MAX_POWER_CONSUMPTION value for Helix keyboard 118// USB_MAX_POWER_CONSUMPTION value for Helix keyboard
117// 120 RGBoff, OLEDoff 119// 120 RGBoff, OLEDoff
diff --git a/keyboards/sol/rev1/rev1.c b/keyboards/sol/rev1/rev1.c
index 01ab577d4..9d869a4af 100644
--- a/keyboards/sol/rev1/rev1.c
+++ b/keyboards/sol/rev1/rev1.c
@@ -1,6 +1,5 @@
1#include "sol.h" 1#include "sol.h"
2 2
3
4#ifdef SSD1306OLED 3#ifdef SSD1306OLED
5void led_set_kb(uint8_t usb_led) { 4void led_set_kb(uint8_t usb_led) {
6 // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here 5 // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
@@ -8,8 +7,88 @@ void led_set_kb(uint8_t usb_led) {
8} 7}
9#endif 8#endif
10 9
11void matrix_init_kb(void) { 10#ifdef RGB_MATRIX_ENABLE
11 const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
12 // Left Hand Mapped Left to Right
13 { { 0 | (0 << 4) }, { 0, 0 }, 1},
14 { { 0 | (1 << 4) }, { 22, 0 }, 0},
15 { { 0 | (2 << 4) }, { 37, 0 }, 0},
16 { { 0 | (3 << 4) }, { 37, 0 }, 0},
17 { { 0 | (4 << 4) }, { 67, 0 }, 0},
18 { { 0 | (5 << 4) }, { 82, 0 }, 0},
19 { { 0 | (6 << 4) }, { 104, 0 }, 1},
20 { { 1 | (0 << 4) }, { 0, 16 }, 1},
21 { { 1 | (1 << 4) }, { 22, 16 }, 0},
22 { { 1 | (2 << 4) }, { 37, 16 }, 0},
23 { { 1 | (3 << 4) }, { 37, 16 }, 0},
24 { { 1 | (4 << 4) }, { 67, 16 }, 0},
25 { { 1 | (5 << 4) }, { 82, 16 }, 0},
26 { { 1 | (6 << 4) }, { 104, 16 }, 1},
27 { { 2 | (0 << 4) }, { 0, 32 }, 1},
28 { { 2 | (1 << 4) }, { 22, 32 }, 0},
29 { { 2 | (2 << 4) }, { 37, 32 }, 0},
30 { { 2 | (3 << 4) }, { 37, 32 }, 0},
31 { { 2 | (4 << 4) }, { 67, 32 }, 0},
32 { { 2 | (5 << 4) }, { 82, 32 }, 0},
33 { { 2 | (6 << 4) }, { 104, 32 }, 1},
34 { { 3 | (0 << 4) }, { 0, 48 }, 1},
35 { { 3 | (1 << 4) }, { 22, 48 }, 0},
36 { { 3 | (2 << 4) }, { 37, 48 }, 0},
37 { { 3 | (3 << 4) }, { 37, 48 }, 0},
38 { { 3 | (4 << 4) }, { 67, 48 }, 0},
39 { { 3 | (5 << 4) }, { 82, 48 }, 0},
40 { { 3 | (6 << 4) }, { 104, 48 }, 1},
41 { { 4 | (0 << 4) }, { 0, 64 }, 1},
42 { { 4 | (1 << 4) }, { 22, 64 }, 1},
43 { { 4 | (2 << 4) }, { 37, 64 }, 1},
44 { { 4 | (3 << 4) }, { 37, 64 }, 1},
45 { { 4 | (4 << 4) }, { 67, 64 }, 1},
46 // These two control the 4 LEDs in the thumb cluster
47 // Top keys are { 4 | (5 << 4) & { 4 | (6 << 4)
48 { { 5 | (5 << 4) }, { 89, 45 }, 1},
49 { { 5 | (6 << 4) }, { 97, 55 }, 1},
50 // Left Hand Mapped Right to Left
51 { { 6 | (0 << 4) }, { 224, 0 }, 1},
52 { { 6 | (1 << 4) }, { 202, 0 }, 0},
53 { { 6 | (2 << 4) }, { 187, 0 }, 0},
54 { { 6 | (3 << 4) }, { 172, 0 }, 0},
55 { { 6 | (4 << 4) }, { 157, 0 }, 0},
56 { { 6 | (5 << 4) }, { 142, 0 }, 0},
57 { { 6 | (6 << 4) }, { 120, 0 }, 1},
58 { { 7 | (0 << 4) }, { 224, 16 }, 1},
59 { { 7 | (1 << 4) }, { 202, 16 }, 0},
60 { { 7 | (2 << 4) }, { 187, 16 }, 0},
61 { { 7 | (3 << 4) }, { 172, 16 }, 0},
62 { { 7 | (4 << 4) }, { 157, 16 }, 0},
63 { { 7 | (5 << 4) }, { 142, 16 }, 0},
64 { { 7 | (6 << 4) }, { 120, 16 }, 1},
65 { { 8 | (0 << 4) }, { 224, 32 }, 1},
66 { { 8 | (1 << 4) }, { 202, 32 }, 0},
67 { { 8 | (2 << 4) }, { 187, 32 }, 0},
68 { { 8 | (3 << 4) }, { 172, 32 }, 0},
69 { { 8 | (4 << 4) }, { 157, 32 }, 0},
70 { { 8 | (5 << 4) }, { 142, 32 }, 0},
71 { { 8 | (6 << 4) }, { 120, 32 }, 1},
72 { { 9 | (0 << 4) }, { 224, 48 }, 1},
73 { { 9 | (1 << 4) }, { 202, 48 }, 0},
74 { { 9 | (2 << 4) }, { 187, 48 }, 0},
75 { { 9 | (3 << 4) }, { 172, 48 }, 0},
76 { { 9 | (4 << 4) }, { 157, 48 }, 0},
77 { { 9 | (5 << 4) }, { 142, 48 }, 0},
78 { { 9 | (6 << 4) }, { 120, 48 }, 1},
79 { { 10 | (0 << 4) }, { 224, 64 }, 1},
80 { { 10 | (1 << 4) }, { 202, 64 }, 1},
81 { { 10 | (2 << 4) }, { 187, 64 }, 1},
82 { { 10 | (3 << 4) }, { 172, 64 }, 1},
83 { { 10 | (4 << 4) }, { 157, 64 }, 1},
84 // These two control the 4 LEDs in the thumb cluster
85 // Top keys are { 10 | (5 << 4) & { 10 | (6 << 4)
86 { { 11 | (5 << 4) }, { 135, 45 }, 1},
87 { { 11 | (6 << 4) }, { 127, 55 }, 1}
88 };
89#endif
12 90
91void matrix_init_kb(void) {
13 matrix_init_user(); 92 matrix_init_user();
14}; 93};
15 94
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index 0e193dcb2..0a11f2692 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -28,9 +28,11 @@
28#ifdef IS31FL3731 28#ifdef IS31FL3731
29 #include "is31fl3731.h" 29 #include "is31fl3731.h"
30#elif defined (IS31FL3733) 30#elif defined (IS31FL3733)
31 #include "is31fl3733.h" 31 #include "is31fl3733.h"
32#elif defined (IS31FL3737) 32#elif defined (IS31FL3737)
33 #include "is31fl3737.h" 33 #include "is31fl3737.h"
34#elif defined (WS2812)
35 #include "ws2812.h"
34#endif 36#endif
35 37
36#ifndef RGB_MATRIX_LED_FLUSH_LIMIT 38#ifndef RGB_MATRIX_LED_FLUSH_LIMIT
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c
index 3b7d58483..3814dd61f 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 = {
97}; 97};
98#endif 98#endif
99 99
100#elif defined(WS2812)
101
102extern 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 };
100#endif 121#endif
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 08515564b..e2410424e 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};
63rgblight_config_t rgblight_config; 63rgblight_config_t rgblight_config;
64bool is_rgblight_initialized = false; 64bool is_rgblight_initialized = false;
65 65
66#ifndef LED_ARRAY
66LED_TYPE led[RGBLED_NUM]; 67LED_TYPE led[RGBLED_NUM];
68 #define LED_ARRAY led
69#endif
70
67bool rgblight_timer_enabled = false; 71bool rgblight_timer_enabled = false;
68 72
69static uint8_t clipping_start_pos = 0; 73static uint8_t clipping_start_pos = 0;
diff --git a/users/kageurufu/rules.mk b/users/kageurufu/rules.mk
index 1bd16e262..df9ae559a 100644
--- a/users/kageurufu/rules.mk
+++ b/users/kageurufu/rules.mk
@@ -11,5 +11,5 @@ MOUSEKEY_ENABLE = no
11EXTRAKEY_ENABLE = yes 11EXTRAKEY_ENABLE = yes
12COMMAND_ENABLE = yes 12COMMAND_ENABLE = yes
13CONSOLE_ENABLE = yes 13CONSOLE_ENABLE = yes
14RGBLIGHT_ENABLE = yes 14RGBLIGHT_ENABLE = no
15RGBLIGHT_ANIMATIONS = yes 15RGBLIGHT_ANIMATIONS = yes