1
0
Fork 0

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 Drashna Jaelre
parent 908aede957
commit 64b7cfe735
12 changed files with 101 additions and 83 deletions

View file

@ -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)
@ -262,6 +262,26 @@ ifneq ($(strip $(BACKLIGHT_ENABLE)), no)
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

View file

@ -98,6 +98,7 @@
* [ISP Flashing Guide](isp_flashing_guide.md)
* [ARM Debugging Guide](arm_debugging.md)
* [I2C Driver](i2c_driver.md)
* [WS2812 Driver](ws2812_driver.md)
* [GPIO Controls](internals_gpio_control.md)
* [Proton C Conversion](proton_c_conversion.md)

33
docs/ws2812_driver.md Normal file
View file

@ -0,0 +1,33 @@
# WS2812 Driver
This driver powers the [RGB Lighting](feature_rgblight.md) and [RGB Matrix](feature_rgb_matrix.md) features.
Currently QMK supports the following addressable LEDs on AVR microcontrollers (however, the white LED in RGBW variants is not supported):
WS2811, WS2812, WS2812B, WS2812C, etc.
SK6812, SK6812MINI, SK6805
These LEDs are called "addressable" because instead of using a wire per color, each LED contains a small microchip that understands a special protocol sent over a single wire. The chip passes on the remaining data to the next LED, allowing them to be chained together. In this way, you can easily control the color of the individual LEDs.
## Driver configuration
### Bitbang
Default driver, the absence of configuration assumes this driver. To configure it, add this to your rules.mk:
```make
WS2812_DRIVER = bitbang
```
!> ARM does not yet support WS2182. Progress is being made, but we are not quite there, yet.
### I2C
Targeting boards where WS2812 support is offloaded to a 2nd MCU. Currently the driver is limited to AVR given the known consumers are ps2avrGB/BMC. To configure it, add this to your rules.mk:
```make
WS2812_DRIVER = i2c
```
Configure the hardware via your config.h:
```c
#define WS2812_ADDRESS 0xb0 // default: 0xb0
#define WS2812_TIMEOUT 100 // default: 100
```

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

@ -17,40 +17,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "jj40.h"
#ifdef RGBLIGHT_ENABLE
#include <string.h>
#include "i2c_master.h"
#include "rgblight.h"
extern rgblight_config_t rgblight_config;
void matrix_init_kb(void) {
i2c_init();
// call user level keymaps, if any
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;
}
rgblight_task();
matrix_scan_user();
}
#endif

View file

@ -40,7 +40,7 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
NKRO_ENABLE = no # USB Nkey Rollover
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality on B7 by default
RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
@ -48,6 +48,4 @@ AUDIO_ENABLE = no # Audio output on port C6
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
SRC += i2c_master.c
LAYOUTS = ortho_4x12 planck_mit

View file

@ -16,44 +16,6 @@
#include "%KEYBOARD%.h"
#ifdef RGBLIGHT_ENABLE
# include <string.h>
# include "i2c_master.h"
# include "rgblight.h"
extern rgblight_config_t rgblight_config;
void matrix_init_kb(void) {
i2c_init();
// call user level keymaps, if any
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;
}
rgblight_task();
matrix_scan_user();
}
#endif
// Optional override functions below.
// You can leave any or all of these undefined.
// These are only required if you want to perform custom actions.

View file

@ -19,8 +19,6 @@ CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0
SRC += i2c_master.c

View file

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