Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS2812 driver improvements #20262

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
endif
endif

VALID_WS2812_DRIVER_TYPES := bitbang pwm spi i2c vendor
VALID_WS2812_DRIVER_TYPES := bitbang custom i2c pwm spi vendor

WS2812_DRIVER ?= bitbang
ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)
Expand All @@ -584,15 +584,11 @@ ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)

OPT_DEFS += -DWS2812_DRIVER_$(strip $(shell echo $(WS2812_DRIVER) | tr '[:lower:]' '[:upper:]'))

ifeq ($(strip $(WS2812_DRIVER)), bitbang)
SRC += ws2812.c
else
SRC += ws2812_$(strip $(WS2812_DRIVER)).c
SRC += ws2812_$(strip $(WS2812_DRIVER)).c

ifeq ($(strip $(PLATFORM)), CHIBIOS)
ifeq ($(strip $(WS2812_DRIVER)), pwm)
OPT_DEFS += -DSTM32_DMA_REQUIRED=TRUE
endif
ifeq ($(strip $(PLATFORM)), CHIBIOS)
ifeq ($(strip $(WS2812_DRIVER)), pwm)
OPT_DEFS += -DSTM32_DMA_REQUIRED=TRUE
endif
endif

Expand Down
2 changes: 2 additions & 0 deletions data/mappings/info_config.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
"USB_MAX_POWER_CONSUMPTION": {"info_key": "usb.max_power", "value_type": "int"},
"USB_POLLING_INTERVAL_MS": {"info_key": "usb.polling_interval", "value_type": "int"},
"USB_SUSPEND_WAKEUP_DELAY": {"info_key": "usb.suspend_wakeup_delay", "value_type": "int"},
"WS2812_I2C_ADDRESS": {"info_key": "ws2812.i2c_address", "value_type": "hex"},
"WS2812_I2C_TIMEOUT": {"info_key": "ws2812.i2c_timeout", "value_type": "int"},

// Items we want flagged in lint
"NO_ACTION_MACRO": {"info_key": "_invalid.no_action_macro", "invalid": true},
Expand Down
6 changes: 4 additions & 2 deletions data/schemas/keyboard.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,10 @@
"properties": {
"driver": {
"type": "string",
"enum": ["bitbang", "i2c", "pwm", "spi", "vendor"]
}
"enum": ["bitbang", "custom", "i2c", "pwm", "spi", "vendor"]
},
"i2c_address": {"$ref": "qmk.definitions.v1#/hex_number_2d"},
"i2c_timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/ws2812_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ WS2812_DRIVER = i2c

Configure the hardware via your config.h:
```c
#define WS2812_ADDRESS 0xb0 // default: 0xb0
#define WS2812_TIMEOUT 100 // default: 100
#define WS2812_I2C_ADDRESS 0xB0 // default: 0xB0
#define WS2812_I2C_TIMEOUT 100 // default: 100
```

### SPI
Expand Down
2 changes: 1 addition & 1 deletion keyboards/1k/keymaps/default/rules.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
SRC += color.c
2 changes: 1 addition & 1 deletion keyboards/1k/keymaps/media/rules.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
SRC += color.c
EXTRAKEY_ENABLE = yes
2 changes: 1 addition & 1 deletion keyboards/dp60/keymaps/indicator/led_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define RGB_DI_PIN RGB_INDICATOR_PIN
#define ws2812_setleds indicator_setleds
#define ws2812_setleds_pin indicator_setleds_pin
#include "ws2812.c"
#include "ws2812_bitbang.c"

void indicator_write(LED_TYPE *start_led, uint8_t num_leds)
{
Expand Down
2 changes: 1 addition & 1 deletion keyboards/handwired/promethium/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ PS2_DRIVER = interrupt
CUSTOM_MATRIX = yes
BLUETOOTH_ENABLE = yes
BLUETOOTH_DRIVER = BluefruitLE
WS2812_DRIVER_REQUIRED = yes

SRC += ws2812.c
SRC += rgbsps.c
SRC += analog.c
SRC += matrix.c
Expand Down
3 changes: 2 additions & 1 deletion keyboards/matrix/noah/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ RGB_MATRIX_DRIVER = IS31FL3731

RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER_REQUIRED = yes

CUSTOM_MATRIX = yes
# project specific files
SRC += ws2812.c matrix.c
SRC += matrix.c
3 changes: 1 addition & 2 deletions keyboards/mschwingen/modelm/led_ws2812/rules.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# variant for WS2812 LEDs
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
2 changes: 1 addition & 1 deletion keyboards/oddforge/vea/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"pin": "D4"
},
"ws2812": {
"driver": "i2c"
"driver": "custom"
},
"indicators": {
"caps_lock": "D1",
Expand Down
33 changes: 0 additions & 33 deletions keyboards/oddforge/vea/vea.c

This file was deleted.

11 changes: 1 addition & 10 deletions keyboards/oddforge/vea/vea.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include "quantum.h"
#include "i2c_master.h"
#include "rgblight.h"
#include "ws2812.h"
#include "led.h"

#define WS2812_ADDRESS 0xb0
#define WS2812_ADDRESS_SPLIT 0xb8
#define WS2812_TIMEOUT 100

void vea_setleds(LED_TYPE *ledarray, uint16_t leds);
#include "quantum.h"

/*
LEFT
Expand Down
34 changes: 34 additions & 0 deletions keyboards/oddforge/vea/ws2812_custom.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "ws2812.h"
#include "i2c_master.h"

#ifdef RGBW
# error "RGBW not supported"
#endif

#ifndef WS2812_I2C_ADDRESS
# define WS2812_I2C_ADDRESS 0xB0
#endif

#ifndef WS2812_I2C_ADDRESS_RIGHT
# define WS2812_I2C_ADDRESS_RIGHT 0xB8
#endif

#ifndef WS2812_I2C_TIMEOUT
# define WS2812_I2C_TIMEOUT 100
#endif

void ws2812_init(void) {
i2c_init();
}

// Setleds for standard RGB
void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}

i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * (leds >> 1), WS2812_I2C_TIMEOUT);
i2c_transmit(WS2812_I2C_ADDRESS_RIGHT, (uint8_t *)ledarray+(sizeof(LED_TYPE) * (leds >> 1)), sizeof(LED_TYPE) * (leds - (leds >> 1)), WS2812_I2C_TIMEOUT);
}
2 changes: 1 addition & 1 deletion keyboards/work_louder/rgb_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define ws2812_setleds ws2812_rgb_setleds

#include "ws2812.c"
#include "ws2812_bitbang.c"

void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) {
ws2812_setleds(start_led, num_leds);
Expand Down
4 changes: 2 additions & 2 deletions keyboards/xelus/dawn60/rev1/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ AUDIO_ENABLE = no # Audio output
RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. - We have custom RGB underglow

CIE1931_CURVE = yes
WS2812_DRIVER_REQUIRED = yes


# project specific files
SRC += keyboards/wilba_tech/wt_main.c \
keyboards/wilba_tech/wt_rgb_backlight.c \
quantum/color.c \
drivers/led/issi/is31fl3731.c \
ws2812.c
drivers/led/issi/is31fl3731.c

QUANTUM_LIB_SRC += i2c_master.c
4 changes: 2 additions & 2 deletions keyboards/xelus/dawn60/rev1_qmk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. - We have custom RGB

RGB_MATRIX_ENABLE = yes # Enable RGB matrix effects.
RGB_MATRIX_DRIVER = custom # Enable RGB matrix effects.
WS2812_DRIVER_REQUIRED = yes

COMMON_VPATH += $(DRIVER_PATH)/issi

# project specific files
SRC += drivers/led/issi/is31fl3731.c \
ws2812.c
SRC += drivers/led/issi/is31fl3731.c

QUANTUM_LIB_SRC += i2c_master.c

Expand Down
2 changes: 1 addition & 1 deletion keyboards/xiudi/xd002/keymaps/multilayer_rgb/rules.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
EXTRAKEY_ENABLE = yes
2 changes: 1 addition & 1 deletion keyboards/xiudi/xd002/keymaps/rgb_lite/rules.mk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
File renamed without changes.
10 changes: 5 additions & 5 deletions platforms/avr/drivers/ws2812_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# error "RGBW not supported"
#endif

#ifndef WS2812_ADDRESS
# define WS2812_ADDRESS 0xb0
#ifndef WS2812_I2C_ADDRESS
# define WS2812_I2C_ADDRESS 0xB0
#endif

#ifndef WS2812_TIMEOUT
# define WS2812_TIMEOUT 100
#ifndef WS2812_I2C_TIMEOUT
# define WS2812_I2C_TIMEOUT 100
#endif

void ws2812_init(void) {
Expand All @@ -25,5 +25,5 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
s_init = true;
}

i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_I2C_TIMEOUT);
}
1 change: 0 additions & 1 deletion quantum/rgb_matrix/rgb_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ LED_TYPE rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT];
static void init(void) {}

static void flush(void) {
// Assumes use of RGB_DI_PIN
ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT);
}

Expand Down