updates rgblight implementation, makes non-timer stuff compatible with audio
This commit is contained in:
parent
ad43d450ca
commit
57e08eb8ba
17 changed files with 160 additions and 74 deletions
|
@ -25,9 +25,8 @@
|
|||
|
||||
/* Underlight configuration
|
||||
*/
|
||||
#define ws2812_PORTREG PORTB
|
||||
#define ws2812_DDRREG DDRB
|
||||
#define ws2812_pin 2
|
||||
#define RGB_DI_PIN B2
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 14 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -29,9 +29,8 @@
|
|||
|
||||
/* Underlight configuration
|
||||
*/
|
||||
#define ws2812_PORTREG PORTD
|
||||
#define ws2812_DDRREG DDRD
|
||||
#define ws2812_pin 7
|
||||
#define RGB_DI_PIN D7
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 14 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -69,9 +69,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
/* Underlight configuration
|
||||
*/
|
||||
#define ws2812_PORTREG PORTF
|
||||
#define ws2812_DDRREG DDRF
|
||||
#define ws2812_pin 6
|
||||
#define RGB_DI_PIN F6
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 4 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#include "../../config.h"
|
||||
|
||||
/* WS2812B RGB Underglow LED */
|
||||
#define ws2812_PORTREG PORTF
|
||||
#define ws2812_DDRREG DDRF
|
||||
#define ws2812_pin PF5 // Based on wiring depicted in ws2812_wiring.jpg
|
||||
#define RGB_DI_PIN F5 // Based on wiring depicted in ws2812_wiring.jpg
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 16 // Number of LEDs. Change this to match your use case.
|
||||
#define RGBLIGHT_HUE_STEP 8
|
||||
#define RGBLIGHT_SAT_STEP 8
|
||||
|
|
|
@ -69,9 +69,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
)
|
||||
|
||||
/* ws2812 RGB LED */
|
||||
#define ws2812_PORTREG PORTD
|
||||
#define ws2812_DDRREG DDRD
|
||||
#define ws2812_pin PD1
|
||||
#define RGB_DI_PIN D2
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 28 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -62,9 +62,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
/* Underlight configuration
|
||||
*/
|
||||
#define ws2812_PORTREG PORTE
|
||||
#define ws2812_DDRREG DDRE
|
||||
#define ws2812_pin 2
|
||||
#define RGB_DI_PIN E2
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 20 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -10,12 +10,12 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
|
|||
CONSOLE_ENABLE = no # Console for debug(+400)
|
||||
COMMAND_ENABLE = yes # Commands for debug and configuration
|
||||
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
|
||||
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
|
||||
MIDI_ENABLE = no # MIDI controls
|
||||
AUDIO_ENABLE = yes # Audio output on port C6
|
||||
AUDIO_ENABLE = no # Audio output on port C6
|
||||
UNICODE_ENABLE = no # Unicode
|
||||
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||
RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
|
||||
RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
|
||||
|
||||
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
|
||||
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
|
||||
|
|
|
@ -6,4 +6,12 @@
|
|||
#define LEADER_TIMEOUT 300
|
||||
#define BACKLIGHT_BREATHING
|
||||
|
||||
|
||||
/* ws2812 RGB LED */
|
||||
#define RGB_DI_PIN B1
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 8 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,7 +15,7 @@ extern keymap_config_t keymap_config;
|
|||
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
|
||||
// Layer names don't all need to be of the same length, obviously, and you can also skip them
|
||||
// entirely and just use numbers.
|
||||
#define _QWERTY 0
|
||||
#define _QWERTY 10
|
||||
#define _COLEMAK 1
|
||||
#define _DVORAK 2
|
||||
#define _LOWER 3
|
||||
|
@ -31,7 +31,15 @@ enum planck_keycodes {
|
|||
LOWER,
|
||||
RAISE,
|
||||
BACKLIT,
|
||||
EXT_PLV
|
||||
EXT_PLV,
|
||||
RGBLED_TOGGLE,
|
||||
RGBLED_STEP_MODE,
|
||||
RGBLED_INCREASE_HUE,
|
||||
RGBLED_DECREASE_HUE,
|
||||
RGBLED_INCREASE_SAT,
|
||||
RGBLED_DECREASE_SAT,
|
||||
RGBLED_INCREASE_VAL,
|
||||
RGBLED_DECREASE_VAL,
|
||||
};
|
||||
|
||||
// Fillers to make layering more clear
|
||||
|
@ -39,9 +47,15 @@ enum planck_keycodes {
|
|||
#define XXXXXXX KC_NO
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = {
|
||||
{KC_NO, KC_NO, KC_NO, KC_NO, RGBLED_TOGGLE, RGBLED_STEP_MODE, RGBLED_INCREASE_HUE, RGBLED_DECREASE_HUE, RGBLED_INCREASE_SAT, RGBLED_DECREASE_SAT, RGBLED_INCREASE_VAL, RGBLED_DECREASE_VAL},
|
||||
{KC_NO, KC_NO, KC_NO, KC_NO, RGBLED_TOGGLE, RGBLED_STEP_MODE, RGBLED_INCREASE_HUE, RGBLED_DECREASE_HUE, RGBLED_INCREASE_SAT, RGBLED_DECREASE_SAT, RGBLED_INCREASE_VAL, RGBLED_DECREASE_VAL},
|
||||
{KC_NO, KC_NO, KC_NO, KC_NO, RGBLED_TOGGLE, RGBLED_STEP_MODE, RGBLED_INCREASE_HUE, RGBLED_DECREASE_HUE, RGBLED_INCREASE_SAT, RGBLED_DECREASE_SAT, RGBLED_INCREASE_VAL, RGBLED_DECREASE_VAL},
|
||||
{KC_NO, KC_NO, KC_NO, KC_NO, RGBLED_TOGGLE, RGBLED_STEP_MODE, RGBLED_INCREASE_HUE, RGBLED_DECREASE_HUE, RGBLED_INCREASE_SAT, RGBLED_DECREASE_SAT, RGBLED_INCREASE_VAL, RGBLED_DECREASE_VAL}
|
||||
},
|
||||
|
||||
/* Qwerty
|
||||
* ,-----------------------------------------------------------------------------------.
|
||||
,-----------------------------------------------------------------------------------.
|
||||
* | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
|
||||
* |------+------+------+------+------+-------------+------+------+------+------+------|
|
||||
* | Esc | A | S | D | F | G | H | J | K | L | ; | " |
|
||||
|
@ -292,6 +306,57 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|||
break;
|
||||
return false;
|
||||
|
||||
case RGBLED_TOGGLE:
|
||||
//led operations
|
||||
if (record->event.pressed) {
|
||||
rgblight_toggle();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case RGBLED_INCREASE_HUE:
|
||||
if (record->event.pressed) {
|
||||
rgblight_increase_hue();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case RGBLED_DECREASE_HUE:
|
||||
if (record->event.pressed) {
|
||||
rgblight_decrease_hue();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case RGBLED_INCREASE_SAT:
|
||||
if (record->event.pressed) {
|
||||
rgblight_increase_sat();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case RGBLED_DECREASE_SAT:
|
||||
if (record->event.pressed) {
|
||||
rgblight_decrease_sat();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case RGBLED_INCREASE_VAL:
|
||||
if (record->event.pressed) {
|
||||
rgblight_increase_val();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case RGBLED_DECREASE_VAL:
|
||||
if (record->event.pressed) {
|
||||
rgblight_decrease_val();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case RGBLED_STEP_MODE:
|
||||
if (record->event.pressed) {
|
||||
rgblight_step();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -60,9 +60,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
)
|
||||
|
||||
/* ws2812 RGB LED */
|
||||
#define ws2812_PORTREG PORTD
|
||||
#define ws2812_DDRREG DDRD
|
||||
#define ws2812_pin PD1
|
||||
#define RGB_DI_PIN D1
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 28 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
#include "../../config.h"
|
||||
|
||||
/* ws2812 RGB LED */
|
||||
#define ws2812_PORTREG PORTD
|
||||
#define ws2812_DDRREG DDRD
|
||||
#define ws2812_pin PD1
|
||||
#define RGB_DI_PIN D1
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 28 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -62,9 +62,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
)
|
||||
|
||||
/* ws2812 RGB LED */
|
||||
#define ws2812_PORTREG PORTD
|
||||
#define ws2812_DDRREG DDRD
|
||||
#define ws2812_pin PD1
|
||||
#define RGB_DI_PIN D1
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 28 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -65,9 +65,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
/* Underlight configuration
|
||||
*/
|
||||
#define ws2812_PORTREG PORTE
|
||||
#define ws2812_DDRREG DDRE
|
||||
#define ws2812_pin 2
|
||||
|
||||
#define RGB_DI_PIN E2
|
||||
#define RGBLIGHT_TIMER
|
||||
#define RGBLED_NUM 8 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
|
|
|
@ -19,12 +19,16 @@
|
|||
// Setleds for standard RGB
|
||||
void inline ws2812_setleds(struct cRGB *ledarray, uint16_t leds)
|
||||
{
|
||||
ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
|
||||
// ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
|
||||
ws2812_setleds_pin(ledarray,leds, _BV(RGB_DI_PIN & 0xF));
|
||||
}
|
||||
|
||||
void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pinmask)
|
||||
{
|
||||
ws2812_DDRREG |= pinmask; // Enable DDR
|
||||
// ws2812_DDRREG |= pinmask; // Enable DDR
|
||||
// new universal format (DDR)
|
||||
_SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask;
|
||||
|
||||
ws2812_sendarray_mask((uint8_t*)ledarray,leds+leds+leds,pinmask);
|
||||
_delay_us(50);
|
||||
}
|
||||
|
@ -32,14 +36,17 @@ void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pin
|
|||
// Setleds for SK6812RGBW
|
||||
void inline ws2812_setleds_rgbw(struct cRGBW *ledarray, uint16_t leds)
|
||||
{
|
||||
ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
|
||||
ws2812_sendarray_mask((uint8_t*)ledarray,leds<<2,_BV(ws2812_pin));
|
||||
// ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
|
||||
// new universal format (DDR)
|
||||
_SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF);
|
||||
|
||||
ws2812_sendarray_mask((uint8_t*)ledarray,leds<<2,_BV(RGB_DI_PIN & 0xF));
|
||||
_delay_us(80);
|
||||
}
|
||||
|
||||
void ws2812_sendarray(uint8_t *data,uint16_t datlen)
|
||||
{
|
||||
ws2812_sendarray_mask(data,datlen,_BV(ws2812_pin));
|
||||
ws2812_sendarray_mask(data,datlen,_BV(RGB_DI_PIN & 0xF));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -108,8 +115,10 @@ void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)
|
|||
uint8_t curbyte,ctr,masklo;
|
||||
uint8_t sreg_prev;
|
||||
|
||||
masklo =~maskhi&ws2812_PORTREG;
|
||||
maskhi |= ws2812_PORTREG;
|
||||
// masklo =~maskhi&ws2812_PORTREG;
|
||||
// maskhi |= ws2812_PORTREG;
|
||||
masklo =~maskhi&_SFR_IO8((RGB_DI_PIN >> 4) + 2);
|
||||
maskhi |= _SFR_IO8((RGB_DI_PIN >> 4) + 2);
|
||||
sreg_prev=SREG;
|
||||
cli();
|
||||
|
||||
|
@ -173,7 +182,7 @@ w_nop16
|
|||
" dec %0 \n\t" // '1' [+2] '0' [+2]
|
||||
" brne loop%=\n\t" // '1' [+3] '0' [+4]
|
||||
: "=&d" (ctr)
|
||||
: "r" (curbyte), "I" (_SFR_IO_ADDR(ws2812_PORTREG)), "r" (maskhi), "r" (masklo)
|
||||
: "r" (curbyte), "I" (_SFR_IO_ADDR(_SFR_IO8((RGB_DI_PIN >> 4) + 2))), "r" (maskhi), "r" (masklo)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,9 @@ void rgblight_init(void) {
|
|||
}
|
||||
eeconfig_debug_rgblight(); // display current eeprom values
|
||||
|
||||
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
|
||||
rgblight_timer_init(); // setup the timer
|
||||
#endif
|
||||
|
||||
if (rgblight_config.enable) {
|
||||
rgblight_mode(rgblight_config.mode);
|
||||
|
@ -192,14 +194,19 @@ void rgblight_mode(uint8_t mode) {
|
|||
eeconfig_update_rgblight(rgblight_config.raw);
|
||||
xprintf("rgblight mode: %u\n", rgblight_config.mode);
|
||||
if (rgblight_config.mode == 1) {
|
||||
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
|
||||
rgblight_timer_disable();
|
||||
#endif
|
||||
} else if (rgblight_config.mode >=2 && rgblight_config.mode <=23) {
|
||||
// MODE 2-5, breathing
|
||||
// MODE 6-8, rainbow mood
|
||||
// MODE 9-14, rainbow swirl
|
||||
// MODE 15-20, snake
|
||||
// MODE 21-23, knight
|
||||
|
||||
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
|
||||
rgblight_timer_enable();
|
||||
#endif
|
||||
}
|
||||
rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
|
||||
}
|
||||
|
@ -211,7 +218,10 @@ void rgblight_toggle(void) {
|
|||
if (rgblight_config.enable) {
|
||||
rgblight_mode(rgblight_config.mode);
|
||||
} else {
|
||||
|
||||
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
|
||||
rgblight_timer_disable();
|
||||
#endif
|
||||
_delay_ms(50);
|
||||
rgblight_set();
|
||||
}
|
||||
|
@ -328,6 +338,9 @@ void rgblight_set(void) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
|
||||
|
||||
// Animation timer -- AVR Timer3
|
||||
void rgblight_timer_init(void) {
|
||||
static uint8_t rgblight_timer_is_init = 0;
|
||||
|
@ -503,3 +516,5 @@ void rgblight_effect_knight(uint8_t interval) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef RGBLIGHT_H
|
||||
#define RGBLIGHT_H
|
||||
|
||||
#ifndef RGBLIGHT_MODES
|
||||
|
||||
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
|
||||
#define RGBLIGHT_MODES 23
|
||||
#else
|
||||
#define RGBLIGHT_MODES 1
|
||||
#endif
|
||||
|
||||
#ifndef RGBLIGHT_EFFECT_SNAKE_LENGTH
|
||||
|
|
15
readme.md
15
readme.md
|
@ -704,23 +704,18 @@ For this mod, you need an unused pin wiring to DI of WS2812 strip. After wiring
|
|||
|
||||
RGBLIGHT_ENABLE = yes
|
||||
|
||||
Please note that the underglow is not compatible with audio output. So you cannot enable both of them at the same time.
|
||||
In order to use the underglow timer functions, you need to have `#define RGBLIGHT_TIMER` in your `config.h`, and have audio disabled (`AUDIO_ENABLE = no` in your Makefile).
|
||||
|
||||
Please add the following options into your config.h, and set them up according your hardware configuration. These settings are for the F4 by default:
|
||||
Please add the following options into your config.h, and set them up according your hardware configuration. These settings are for the `F4` pin by default:
|
||||
|
||||
#define ws2812_PORTREG PORTF
|
||||
#define ws2812_DDRREG DDRF
|
||||
#define ws2812_pin PF4
|
||||
#define RGB_DI_PIN F4 // The pin your RGB strip is wired to
|
||||
#define RGBLIGHT_TIMER // Require for fancier stuff (not compatible with audio)
|
||||
#define RGBLED_NUM 14 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 10
|
||||
#define RGBLIGHT_SAT_STEP 17
|
||||
#define RGBLIGHT_VAL_STEP 17
|
||||
|
||||
You'll need to edit `PORTF`, `DDRF`, and `PF4` on the first three lines to the port/pin you have your LED(s) wired to, eg for B3 change things to:
|
||||
|
||||
#define ws2812_PORTREG PORTB
|
||||
#define ws2812_DDRREG DDRB
|
||||
#define ws2812_pin PB3
|
||||
You'll need to edit `RGB_DI_PIN` to the pin you have your `DI` on your RGB strip wired to.
|
||||
|
||||
The firmware supports 5 different light effects, and the color (hue, saturation, brightness) can be customized in most effects. To control the underglow, you need to modify your keymap file to assign those functions to some keys/key combinations. For details, please check this keymap. `keyboards/planck/keymaps/yang/keymap.c`
|
||||
|
||||
|
|
Loading…
Reference in a new issue