Refactor ps2avrgb i2c ws2812 to core (#7183)

* Refactor ps2avrgb i2c ws2812 to core

* Refactor jj40 to use ws2812 i2c driver

* Refactor ps2avrgb template to use ws2812 i2c driver

* Add ws2812 stub files

* clang-format and driver config

* Add ws2812 driver docs

* Fix default config values

* Update tmk_core/protocol/vusb/main.c

Co-Authored-By: Drashna Jaelre <drashna@live.com>
This commit is contained in:
Joel Challis
2019-10-29 22:53:11 +00:00
committed by Florian Didron
parent 66d4c71b03
commit 560d1c5385
8 changed files with 82 additions and 35 deletions

View File

@@ -112,7 +112,7 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes) ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes)
OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER
else else
SRC += ws2812.c WS2812_DRIVER_REQUIRED = yes
endif endif
endif endif
@@ -176,7 +176,7 @@ endif
ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812) ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812)
OPT_DEFS += -DWS2812 OPT_DEFS += -DWS2812
SRC += ws2812.c WS2812_DRIVER_REQUIRED = yes
endif endif
ifeq ($(strip $(RGB_MATRIX_CUSTOM_KB)), yes) ifeq ($(strip $(RGB_MATRIX_CUSTOM_KB)), yes)
@@ -244,6 +244,26 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
endif endif
endif endif
VALID_WS2812_DRIVER_TYPES := bitbang pwm spi i2c
WS2812_DRIVER ?= bitbang
ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)
ifeq ($(filter $(WS2812_DRIVER),$(VALID_WS2812_DRIVER_TYPES)),)
$(error WS2812_DRIVER="$(WS2812_DRIVER)" is not a valid WS2812 driver)
endif
ifeq ($(strip $(WS2812_DRIVER)), bitbang)
SRC += ws2812.c
else
SRC += ws2812_$(strip $(WS2812_DRIVER)).c
endif
# add extra deps
ifeq ($(strip $(WS2812_DRIVER)), i2c)
QUANTUM_LIB_SRC += i2c_master.c
endif
endif
ifeq ($(strip $(CIE1931_CURVE)), yes) ifeq ($(strip $(CIE1931_CURVE)), yes)
OPT_DEFS += -DUSE_CIE1931_CURVE OPT_DEFS += -DUSE_CIE1931_CURVE
LED_TABLES = yes LED_TABLES = yes

1
drivers/arm/ws2812.c Normal file
View File

@@ -0,0 +1 @@
#error("NOT SUPPORTED")

1
drivers/arm/ws2812_pwm.c Normal file
View File

@@ -0,0 +1 @@
#error("NOT SUPPORTED")

1
drivers/arm/ws2812_spi.c Normal file
View File

@@ -0,0 +1 @@
#error("NOT SUPPORTED")

31
drivers/avr/ws2812_i2c.c Normal file
View File

@@ -0,0 +1,31 @@
#include "ws2812.h"
#include "i2c_master.h"
#ifndef WS2812_ADDRESS
# define WS2812_ADDRESS 0xb0
#endif
#ifndef WS2812_TIMEOUT
# define WS2812_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_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
}
// Setleds for SK6812RGBW
void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
// not supported - for now error out if its enabled
#ifdef RGBW
# error "RGBW not supported"
#endif
}

View File

@@ -14,9 +14,7 @@ EXTRAKEY_ENABLE = yes
CONSOLE_ENABLE = yes CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = no BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = no RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0 OPT_DEFS = -DDEBUG_LEVEL=0
SRC += i2c_master.c

View File

@@ -15,44 +15,30 @@
*/ */
#include "%KEYBOARD%.h" #include "%KEYBOARD%.h"
#ifdef RGBLIGHT_ENABLE
# include <string.h> // Optional override functions below.
# include "i2c_master.h" // You can leave any or all of these undefined.
# include "rgblight.h" // These are only required if you want to perform custom actions.
extern rgblight_config_t rgblight_config; /*
void matrix_init_kb(void) { void matrix_init_kb(void) {
i2c_init(); // put your keyboard start-up code here
// call user level keymaps, if any // runs once when the firmware starts up
matrix_init_user(); matrix_init_user();
} }
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
memset(led, 0, 3 * RGBLED_NUM);
}
i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
}
bool rgb_init = false;
void matrix_scan_kb(void) { void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on // put your looping keyboard code here
if (rgb_init == false && rgblight_config.enable) { // runs every cycle (a lot)
i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
rgb_init = true;
}
rgblight_task();
matrix_scan_user(); matrix_scan_user();
} }
#endif bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
// put your per-action keyboard code here
// runs for every action, just before processing by the firmware
__attribute__ ((weak)) return process_record_user(keycode, record);
void matrix_scan_user(void) {
} }

View File

@@ -20,6 +20,11 @@
#include "timer.h" #include "timer.h"
#include "uart.h" #include "uart.h"
#include "debug.h" #include "debug.h"
#include "rgblight_reconfig.h"
#if (defined(RGB_MIDI) | defined(RGBLIGHT_ANIMATIONS)) & defined(RGBLIGHT_ENABLE)
# include "rgblight.h"
#endif
#define UART_BAUD_RATE 115200 #define UART_BAUD_RATE 115200
@@ -94,6 +99,10 @@ int main(void) {
// To prevent failing to configure NOT scan keyboard during configuration // To prevent failing to configure NOT scan keyboard during configuration
if (usbConfiguration && usbInterruptIsReady()) { if (usbConfiguration && usbInterruptIsReady()) {
keyboard_task(); keyboard_task();
#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE)
rgblight_task();
#endif
} }
vusb_transfer_keyboard(); vusb_transfer_keyboard();
} }