~ruther/qmk_firmware

647c2835e65995339fb9380830c53725a62f6299 — Ryan 2 years ago 7e1e662
WS2812 driver improvements (#20262)

M builddefs/common_features.mk => builddefs/common_features.mk +5 -9
@@ 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


M data/mappings/info_config.hjson => data/mappings/info_config.hjson +2 -0
@@ 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},

M data/schemas/keyboard.jsonschema => data/schemas/keyboard.jsonschema +4 -2
@@ 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"}
            }
        }
    }

M docs/ws2812_driver.md => docs/ws2812_driver.md +2 -2
@@ 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

M keyboards/1k/keymaps/default/rules.mk => keyboards/1k/keymaps/default/rules.mk +1 -1
@@ 1,2 1,2 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
SRC += color.c

M keyboards/1k/keymaps/media/rules.mk => keyboards/1k/keymaps/media/rules.mk +1 -1
@@ 1,3 1,3 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
SRC += color.c
EXTRAKEY_ENABLE = yes

M keyboards/dp60/keymaps/indicator/led_driver.c => keyboards/dp60/keymaps/indicator/led_driver.c +1 -1
@@ 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)
{

M keyboards/handwired/promethium/rules.mk => keyboards/handwired/promethium/rules.mk +1 -1
@@ 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

M keyboards/matrix/noah/rules.mk => keyboards/matrix/noah/rules.mk +2 -1
@@ 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

M keyboards/mschwingen/modelm/led_ws2812/rules.mk => keyboards/mschwingen/modelm/led_ws2812/rules.mk +1 -2
@@ 1,2 1,1 @@
# variant for WS2812 LEDs
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes

M keyboards/oddforge/vea/info.json => keyboards/oddforge/vea/info.json +1 -1
@@ 12,7 12,7 @@
        "pin": "D4"
    },
    "ws2812": {
        "driver": "i2c"
        "driver": "custom"
    },
    "indicators": {
        "caps_lock": "D1",

D keyboards/oddforge/vea/vea.c => keyboards/oddforge/vea/vea.c +0 -33
@@ 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);
};

M keyboards/oddforge/vea/vea.h => keyboards/oddforge/vea/vea.h +1 -10
@@ 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

A keyboards/oddforge/vea/ws2812_custom.c => keyboards/oddforge/vea/ws2812_custom.c +34 -0
@@ 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);
}

M keyboards/work_louder/rgb_functions.c => keyboards/work_louder/rgb_functions.c +1 -1
@@ 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);

M keyboards/xelus/dawn60/rev1/rules.mk => keyboards/xelus/dawn60/rev1/rules.mk +2 -2
@@ 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

M keyboards/xelus/dawn60/rev1_qmk/rules.mk => keyboards/xelus/dawn60/rev1_qmk/rules.mk +2 -2
@@ 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 


M keyboards/xiudi/xd002/keymaps/multilayer_rgb/rules.mk => keyboards/xiudi/xd002/keymaps/multilayer_rgb/rules.mk +1 -1
@@ 1,2 1,2 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes
EXTRAKEY_ENABLE = yes

M keyboards/xiudi/xd002/keymaps/rgb_lite/rules.mk => keyboards/xiudi/xd002/keymaps/rgb_lite/rules.mk +1 -1
@@ 1,1 1,1 @@
SRC += ws2812.c
WS2812_DRIVER_REQUIRED = yes

R platforms/avr/drivers/ws2812.c => platforms/avr/drivers/ws2812_bitbang.c +0 -0
M platforms/avr/drivers/ws2812_i2c.c => platforms/avr/drivers/ws2812_i2c.c +5 -5
@@ 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);
}

R platforms/chibios/drivers/ws2812.c => platforms/chibios/drivers/ws2812_bitbang.c +0 -0
M quantum/rgb_matrix/rgb_matrix_drivers.c => quantum/rgb_matrix/rgb_matrix_drivers.c +0 -1
@@ 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);
}