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:
committed by
Florian Didron
parent
66d4c71b03
commit
560d1c5385
@@ -112,7 +112,7 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
|
||||
ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes)
|
||||
OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER
|
||||
else
|
||||
SRC += ws2812.c
|
||||
WS2812_DRIVER_REQUIRED = yes
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -176,7 +176,7 @@ endif
|
||||
|
||||
ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812)
|
||||
OPT_DEFS += -DWS2812
|
||||
SRC += ws2812.c
|
||||
WS2812_DRIVER_REQUIRED = yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(RGB_MATRIX_CUSTOM_KB)), yes)
|
||||
@@ -244,6 +244,26 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
|
||||
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)
|
||||
OPT_DEFS += -DUSE_CIE1931_CURVE
|
||||
LED_TABLES = yes
|
||||
|
||||
1
drivers/arm/ws2812.c
Normal file
1
drivers/arm/ws2812.c
Normal file
@@ -0,0 +1 @@
|
||||
#error("NOT SUPPORTED")
|
||||
1
drivers/arm/ws2812_pwm.c
Normal file
1
drivers/arm/ws2812_pwm.c
Normal file
@@ -0,0 +1 @@
|
||||
#error("NOT SUPPORTED")
|
||||
1
drivers/arm/ws2812_spi.c
Normal file
1
drivers/arm/ws2812_spi.c
Normal file
@@ -0,0 +1 @@
|
||||
#error("NOT SUPPORTED")
|
||||
31
drivers/avr/ws2812_i2c.c
Normal file
31
drivers/avr/ws2812_i2c.c
Normal 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
|
||||
}
|
||||
@@ -14,9 +14,7 @@ EXTRAKEY_ENABLE = yes
|
||||
CONSOLE_ENABLE = yes
|
||||
COMMAND_ENABLE = yes
|
||||
BACKLIGHT_ENABLE = no
|
||||
RGBLIGHT_ENABLE = no
|
||||
RGBLIGHT_CUSTOM_DRIVER = yes
|
||||
RGBLIGHT_ENABLE = yes
|
||||
WS2812_DRIVER = i2c
|
||||
|
||||
OPT_DEFS = -DDEBUG_LEVEL=0
|
||||
|
||||
SRC += i2c_master.c
|
||||
|
||||
@@ -15,44 +15,30 @@
|
||||
*/
|
||||
#include "%KEYBOARD%.h"
|
||||
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
|
||||
# include <string.h>
|
||||
# include "i2c_master.h"
|
||||
# include "rgblight.h"
|
||||
// Optional override functions below.
|
||||
// You can leave any or all of these undefined.
|
||||
// These are only required if you want to perform custom actions.
|
||||
|
||||
extern rgblight_config_t rgblight_config;
|
||||
/*
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
i2c_init();
|
||||
// call user level keymaps, if any
|
||||
matrix_init_user();
|
||||
// put your keyboard start-up code here
|
||||
// runs once when the firmware starts up
|
||||
|
||||
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) {
|
||||
// if LEDs were previously on before poweroff, turn them back on
|
||||
if (rgb_init == false && rgblight_config.enable) {
|
||||
i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
|
||||
rgb_init = true;
|
||||
}
|
||||
// put your looping keyboard code here
|
||||
// runs every cycle (a lot)
|
||||
|
||||
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))
|
||||
void matrix_scan_user(void) {
|
||||
return process_record_user(keycode, record);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
#include "timer.h"
|
||||
#include "uart.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
|
||||
|
||||
@@ -94,6 +99,10 @@ int main(void) {
|
||||
// To prevent failing to configure NOT scan keyboard during configuration
|
||||
if (usbConfiguration && usbInterruptIsReady()) {
|
||||
keyboard_task();
|
||||
|
||||
#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE)
|
||||
rgblight_task();
|
||||
#endif
|
||||
}
|
||||
vusb_transfer_keyboard();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user