aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common_features.mk24
-rw-r--r--docs/_summary.md1
-rw-r--r--docs/ws2812_driver.md33
-rw-r--r--drivers/arm/ws2812.c1
-rw-r--r--drivers/arm/ws2812_pwm.c1
-rw-r--r--drivers/arm/ws2812_spi.c1
-rw-r--r--drivers/avr/ws2812_i2c.c31
-rw-r--r--keyboards/jj40/jj40.c37
-rw-r--r--keyboards/jj40/rules.mk4
-rw-r--r--quantum/template/ps2avrgb/keyboard.c38
-rw-r--r--quantum/template/ps2avrgb/rules.mk4
-rw-r--r--tmk_core/protocol/vusb/main.c9
12 files changed, 101 insertions, 83 deletions
diff --git a/common_features.mk b/common_features.mk
index 83b2b51ae..7bb9187bb 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -112,7 +112,7 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
112 ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes) 112 ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes)
113 OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER 113 OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER
114 else 114 else
115 SRC += ws2812.c 115 WS2812_DRIVER_REQUIRED = yes
116 endif 116 endif
117endif 117endif
118 118
@@ -176,7 +176,7 @@ endif
176 176
177ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812) 177ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812)
178 OPT_DEFS += -DWS2812 178 OPT_DEFS += -DWS2812
179 SRC += ws2812.c 179 WS2812_DRIVER_REQUIRED = yes
180endif 180endif
181 181
182ifeq ($(strip $(RGB_MATRIX_CUSTOM_KB)), yes) 182ifeq ($(strip $(RGB_MATRIX_CUSTOM_KB)), yes)
@@ -262,6 +262,26 @@ ifneq ($(strip $(BACKLIGHT_ENABLE)), no)
262 endif 262 endif
263endif 263endif
264 264
265VALID_WS2812_DRIVER_TYPES := bitbang pwm spi i2c
266
267WS2812_DRIVER ?= bitbang
268ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)
269 ifeq ($(filter $(WS2812_DRIVER),$(VALID_WS2812_DRIVER_TYPES)),)
270 $(error WS2812_DRIVER="$(WS2812_DRIVER)" is not a valid WS2812 driver)
271 endif
272
273 ifeq ($(strip $(WS2812_DRIVER)), bitbang)
274 SRC += ws2812.c
275 else
276 SRC += ws2812_$(strip $(WS2812_DRIVER)).c
277 endif
278
279 # add extra deps
280 ifeq ($(strip $(WS2812_DRIVER)), i2c)
281 QUANTUM_LIB_SRC += i2c_master.c
282 endif
283endif
284
265ifeq ($(strip $(CIE1931_CURVE)), yes) 285ifeq ($(strip $(CIE1931_CURVE)), yes)
266 OPT_DEFS += -DUSE_CIE1931_CURVE 286 OPT_DEFS += -DUSE_CIE1931_CURVE
267 LED_TABLES = yes 287 LED_TABLES = yes
diff --git a/docs/_summary.md b/docs/_summary.md
index 65bfa11f0..dc6e88f95 100644
--- a/docs/_summary.md
+++ b/docs/_summary.md
@@ -98,6 +98,7 @@
98 * [ISP Flashing Guide](isp_flashing_guide.md) 98 * [ISP Flashing Guide](isp_flashing_guide.md)
99 * [ARM Debugging Guide](arm_debugging.md) 99 * [ARM Debugging Guide](arm_debugging.md)
100 * [I2C Driver](i2c_driver.md) 100 * [I2C Driver](i2c_driver.md)
101 * [WS2812 Driver](ws2812_driver.md)
101 * [GPIO Controls](internals_gpio_control.md) 102 * [GPIO Controls](internals_gpio_control.md)
102 * [Proton C Conversion](proton_c_conversion.md) 103 * [Proton C Conversion](proton_c_conversion.md)
103 104
diff --git a/docs/ws2812_driver.md b/docs/ws2812_driver.md
new file mode 100644
index 000000000..6fa5d324c
--- /dev/null
+++ b/docs/ws2812_driver.md
@@ -0,0 +1,33 @@
1# WS2812 Driver
2This driver powers the [RGB Lighting](feature_rgblight.md) and [RGB Matrix](feature_rgb_matrix.md) features.
3
4Currently QMK supports the following addressable LEDs on AVR microcontrollers (however, the white LED in RGBW variants is not supported):
5
6 WS2811, WS2812, WS2812B, WS2812C, etc.
7 SK6812, SK6812MINI, SK6805
8
9These LEDs are called "addressable" because instead of using a wire per color, each LED contains a small microchip that understands a special protocol sent over a single wire. The chip passes on the remaining data to the next LED, allowing them to be chained together. In this way, you can easily control the color of the individual LEDs.
10
11## Driver configuration
12
13### Bitbang
14Default driver, the absence of configuration assumes this driver. To configure it, add this to your rules.mk:
15
16```make
17WS2812_DRIVER = bitbang
18```
19
20!> ARM does not yet support WS2182. Progress is being made, but we are not quite there, yet.
21
22### I2C
23Targeting boards where WS2812 support is offloaded to a 2nd MCU. Currently the driver is limited to AVR given the known consumers are ps2avrGB/BMC. To configure it, add this to your rules.mk:
24
25```make
26WS2812_DRIVER = i2c
27```
28
29Configure the hardware via your config.h:
30```c
31#define WS2812_ADDRESS 0xb0 // default: 0xb0
32#define WS2812_TIMEOUT 100 // default: 100
33```
diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c
new file mode 100644
index 000000000..2094e5009
--- /dev/null
+++ b/drivers/arm/ws2812.c
@@ -0,0 +1 @@
#error("NOT SUPPORTED") \ No newline at end of file
diff --git a/drivers/arm/ws2812_pwm.c b/drivers/arm/ws2812_pwm.c
new file mode 100644
index 000000000..2094e5009
--- /dev/null
+++ b/drivers/arm/ws2812_pwm.c
@@ -0,0 +1 @@
#error("NOT SUPPORTED") \ No newline at end of file
diff --git a/drivers/arm/ws2812_spi.c b/drivers/arm/ws2812_spi.c
new file mode 100644
index 000000000..2094e5009
--- /dev/null
+++ b/drivers/arm/ws2812_spi.c
@@ -0,0 +1 @@
#error("NOT SUPPORTED") \ No newline at end of file
diff --git a/drivers/avr/ws2812_i2c.c b/drivers/avr/ws2812_i2c.c
new file mode 100644
index 000000000..8525a026c
--- /dev/null
+++ b/drivers/avr/ws2812_i2c.c
@@ -0,0 +1,31 @@
1#include "ws2812.h"
2#include "i2c_master.h"
3
4#ifndef WS2812_ADDRESS
5# define WS2812_ADDRESS 0xb0
6#endif
7
8#ifndef WS2812_TIMEOUT
9# define WS2812_TIMEOUT 100
10#endif
11
12void ws2812_init(void) { i2c_init(); }
13
14// Setleds for standard RGB
15void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
16 static bool s_init = false;
17 if (!s_init) {
18 ws2812_init();
19 s_init = true;
20 }
21
22 i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
23}
24
25// Setleds for SK6812RGBW
26void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
27// not supported - for now error out if its enabled
28#ifdef RGBW
29# error "RGBW not supported"
30#endif
31}
diff --git a/keyboards/jj40/jj40.c b/keyboards/jj40/jj40.c
index 26cfa6c06..894ed4907 100644
--- a/keyboards/jj40/jj40.c
+++ b/keyboards/jj40/jj40.c
@@ -17,40 +17,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
18 18
19#include "jj40.h" 19#include "jj40.h"
20
21#ifdef RGBLIGHT_ENABLE
22
23#include <string.h>
24#include "i2c_master.h"
25#include "rgblight.h"
26
27extern rgblight_config_t rgblight_config;
28
29void matrix_init_kb(void) {
30 i2c_init();
31 // call user level keymaps, if any
32 matrix_init_user();
33}
34// custom RGB driver
35void rgblight_set(void) {
36 if (!rgblight_config.enable) {
37 memset(led, 0, 3 * RGBLED_NUM);
38 }
39
40 i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
41}
42
43bool rgb_init = false;
44
45void matrix_scan_kb(void) {
46 // if LEDs were previously on before poweroff, turn them back on
47 if (rgb_init == false && rgblight_config.enable) {
48 i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
49 rgb_init = true;
50 }
51
52 rgblight_task();
53 matrix_scan_user();
54}
55
56#endif
diff --git a/keyboards/jj40/rules.mk b/keyboards/jj40/rules.mk
index b0bf574bd..8e0e8c864 100644
--- a/keyboards/jj40/rules.mk
+++ b/keyboards/jj40/rules.mk
@@ -40,7 +40,7 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
40NKRO_ENABLE = no # USB Nkey Rollover 40NKRO_ENABLE = no # USB Nkey Rollover
41BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality on B7 by default 41BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality on B7 by default
42RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow 42RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
43RGBLIGHT_CUSTOM_DRIVER = yes 43WS2812_DRIVER = i2c
44MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) 44MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
45UNICODE_ENABLE = no # Unicode 45UNICODE_ENABLE = no # Unicode
46BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID 46BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
@@ -48,6 +48,4 @@ AUDIO_ENABLE = no # Audio output on port C6
48FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches 48FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
49HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400) 49HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
50 50
51SRC += i2c_master.c
52
53LAYOUTS = ortho_4x12 planck_mit 51LAYOUTS = ortho_4x12 planck_mit
diff --git a/quantum/template/ps2avrgb/keyboard.c b/quantum/template/ps2avrgb/keyboard.c
index efc851748..73cd668f8 100644
--- a/quantum/template/ps2avrgb/keyboard.c
+++ b/quantum/template/ps2avrgb/keyboard.c
@@ -16,44 +16,6 @@
16 16
17#include "%KEYBOARD%.h" 17#include "%KEYBOARD%.h"
18 18
19#ifdef RGBLIGHT_ENABLE
20
21# include <string.h>
22# include "i2c_master.h"
23# include "rgblight.h"
24
25extern rgblight_config_t rgblight_config;
26
27void matrix_init_kb(void) {
28 i2c_init();
29 // call user level keymaps, if any
30 matrix_init_user();
31}
32
33// custom RGB driver
34void rgblight_set(void) {
35 if (!rgblight_config.enable) {
36 memset(led, 0, 3 * RGBLED_NUM);
37 }
38
39 i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
40}
41
42bool rgb_init = false;
43
44void matrix_scan_kb(void) {
45 // if LEDs were previously on before poweroff, turn them back on
46 if (rgb_init == false && rgblight_config.enable) {
47 i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
48 rgb_init = true;
49 }
50
51 rgblight_task();
52 matrix_scan_user();
53}
54
55#endif
56
57// Optional override functions below. 19// Optional override functions below.
58// You can leave any or all of these undefined. 20// You can leave any or all of these undefined.
59// These are only required if you want to perform custom actions. 21// These are only required if you want to perform custom actions.
diff --git a/quantum/template/ps2avrgb/rules.mk b/quantum/template/ps2avrgb/rules.mk
index bda115db5..ec57b03dc 100644
--- a/quantum/template/ps2avrgb/rules.mk
+++ b/quantum/template/ps2avrgb/rules.mk
@@ -19,8 +19,6 @@ CONSOLE_ENABLE = yes
19COMMAND_ENABLE = yes 19COMMAND_ENABLE = yes
20BACKLIGHT_ENABLE = no 20BACKLIGHT_ENABLE = no
21RGBLIGHT_ENABLE = yes 21RGBLIGHT_ENABLE = yes
22RGBLIGHT_CUSTOM_DRIVER = yes 22WS2812_DRIVER = i2c
23 23
24OPT_DEFS = -DDEBUG_LEVEL=0 24OPT_DEFS = -DDEBUG_LEVEL=0
25
26SRC += i2c_master.c
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index f8322d94a..8cc736497 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -20,6 +20,11 @@
20#include "timer.h" 20#include "timer.h"
21#include "uart.h" 21#include "uart.h"
22#include "debug.h" 22#include "debug.h"
23#include "rgblight_reconfig.h"
24
25#if (defined(RGB_MIDI) | defined(RGBLIGHT_ANIMATIONS)) & defined(RGBLIGHT_ENABLE)
26# include "rgblight.h"
27#endif
23 28
24#define UART_BAUD_RATE 115200 29#define UART_BAUD_RATE 115200
25 30
@@ -94,6 +99,10 @@ int main(void) {
94 // To prevent failing to configure NOT scan keyboard during configuration 99 // To prevent failing to configure NOT scan keyboard during configuration
95 if (usbConfiguration && usbInterruptIsReady()) { 100 if (usbConfiguration && usbInterruptIsReady()) {
96 keyboard_task(); 101 keyboard_task();
102
103#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE)
104 rgblight_task();
105#endif
97 } 106 }
98 vusb_transfer_keyboard(); 107 vusb_transfer_keyboard();
99 } 108 }