WS2812 driver improvements (#20262)

This commit is contained in:
Ryan 2023-03-30 12:21:02 +11:00 committed by GitHub
parent 7e1e662dc7
commit 647c2835e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 68 additions and 77 deletions

View File

@ -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)
@ -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

View File

@ -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},

View File

@ -707,8 +707,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"}
}
}
}

View File

@ -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

View File

@ -1,2 +1,2 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
SRC += color.c

View File

@ -1,3 +1,3 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
SRC += color.c
EXTRAKEY_ENABLE = yes

View File

@ -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)
{

View File

@ -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

View File

@ -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

View File

@ -1,2 +1 @@
# variant for WS2812 LEDs
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes

View File

@ -12,7 +12,7 @@
"pin": "D4"
},
"ws2812": {
"driver": "i2c"
"driver": "custom"
},
"indicators": {
"caps_lock": "D1",

View File

@ -1,33 +0,0 @@
/*
Copyright 2021 MajorKoos <github.com/majorkoos>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vea.h"
void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { vea_setleds(start_led, num_leds); }
void vea_rgb_init(void) { i2c_init(); }
// Setleds for standard RGB
void vea_setleds(LED_TYPE *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
vea_rgb_init();
s_init = true;
}
i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * (leds >> 1), WS2812_TIMEOUT);
i2c_transmit(WS2812_ADDRESS_SPLIT, (uint8_t *)ledarray+(sizeof(LED_TYPE) * (leds >> 1)), sizeof(LED_TYPE) * (leds - (leds >> 1)), WS2812_TIMEOUT);
};

View File

@ -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);
/*
LEFT

View File

@ -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);
}

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -1,2 +1,2 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
EXTRAKEY_ENABLE = yes

View File

@ -1 +1 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes

View File

@ -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) {
@ -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);
}

View File

@ -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);
}