Selaa lähdekoodia

Add support for WS2812 LEDs

Yang Liu 10 vuotta sitten
vanhempi
commit
0a40654b82

+ 10 - 3
keyboard/planck/Makefile

@@ -27,7 +27,7 @@
 # make flip-ee = Download the eeprom file to the device, using Atmel FLIP
 #                (must have Atmel FLIP installed).
 #
-# make debug = Start either simulavr or avarice as specified for debugging, 
+# make debug = Start either simulavr or avarice as specified for debugging,
 #              with avr-gdb or avr-insight as the front end for debugging.
 #
 # make filename.s = Just compile filename.c into the assembler code only.
@@ -137,17 +137,25 @@ CONSOLE_ENABLE = yes	# Console for debug(+400)
 COMMAND_ENABLE = yes    # Commands for debug and configuration
 # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
 # SLEEP_LED_ENABLE = yes  # Breathing sleep LED during USB suspend
-# NKRO_ENABLE = yes		# USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
+NKRO_ENABLE = yes		# USB 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
 # MIDI_ENABLE = YES 		# MIDI controls
 # AUDIO_ENABLE = YES 		# Audio output on port C6
 # UNICODE_ENABLE = YES 		# Unicode
 # BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
+RGBLIGHT_ENABLE = yes # Enable WS2812 bottom RGB light
 
 ifdef BACKLIGHT_ENABLE
 	SRC += backlight.c
 endif
 
+ifdef RGBLIGHT_ENABLE
+	SRC += light_ws2812.c
+	SRC += rgblight.c
+	OPT_DEFS += -DRGBLIGHT_ENABLE
+endif
+
+
 # Optimize size but this may cause error "relocation truncated to fit"
 #EXTRALDFLAGS = -Wl,--relax
 
@@ -157,4 +165,3 @@ VPATH += $(TOP_DIR)
 VPATH += $(TMK_DIR)
 
 include $(TOP_DIR)/quantum/quantum.mk
-

+ 15 - 0
keyboard/planck/config.h

@@ -58,6 +58,21 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
     keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
 )
 
+/* ws2812 RGB LED */
+#define ws2812_PORTREG  PORTD
+#define ws2812_DDRREG   DDRD
+#define ws2812_pin PD1
+#define RGBLED_NUM 28     // Number of LEDs
+#ifndef RGBLIGHT_HUE_STEP
+#define RGBLIGHT_HUE_STEP 10
+#endif
+#ifndef RGBLIGHT_SAT_STEP
+#define RGBLIGHT_SAT_STEP 17
+#endif
+#ifndef RGBLIGHT_VAL_STEP
+#define RGBLIGHT_VAL_STEP 17
+#endif
+
 /*
  * Feature disable options
  *  These options are also useful to firmware size reduction.

+ 146 - 0
keyboard/planck/keymaps/yang/keymap.c

@@ -0,0 +1,146 @@
+// This is the canonical layout file for the Quantum project. If you want to add another keyboard,
+// this is the style you want to emulate.
+
+#include "planck.h"
+#ifdef BACKLIGHT_ENABLE
+  #include "backlight.h"
+#endif
+
+// Each layer gets a name for readability, which is then used in the keymap matrix below.
+// 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 _QW 0
+#define _CM 1
+#define _DV 2
+#define _LW 3
+#define _RS 4
+#define _RGB 5
+
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+[_QW] = { /* Qwerty */
+  {KC_TAB,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC},
+  {KC_ESC,  KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_QUOT},
+  {KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_ENT },
+  {M(0),    KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), F(0),    F(0),    MO(_RS), KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT}
+},
+[_CM] = { /* Colemak */
+  {KC_TAB,  KC_Q,    KC_W,    KC_F,    KC_P,    KC_G,    KC_J,    KC_L,    KC_U,    KC_Y,    KC_SCLN, KC_BSPC},
+  {KC_ESC,  KC_A,    KC_R,    KC_S,    KC_T,    KC_D,    KC_H,    KC_N,    KC_E,    KC_I,    KC_O,    KC_QUOT},
+  {KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_K,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_ENT },
+  {M(0),    KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), F(0),    F(0),    MO(_RS), KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT}
+},
+[_DV] = { /* Dvorak */
+  {KC_TAB,  KC_QUOT, KC_COMM, KC_DOT,  KC_P,    KC_Y,    KC_F,    KC_G,    KC_C,    KC_R,    KC_L,    KC_BSPC},
+  {KC_ESC,  KC_A,    KC_O,    KC_E,    KC_U,    KC_I,    KC_D,    KC_H,    KC_T,    KC_N,    KC_S,    KC_SLSH},
+  {KC_LSFT, KC_SCLN, KC_Q,    KC_J,    KC_K,    KC_X,    KC_B,    KC_M,    KC_W,    KC_V,    KC_Z,    KC_ENT },
+  {M(0),    KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), F(0),    F(0),    MO(_RS), KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT}
+},
+[_RS] = { /* RAISE */
+  {KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_BSPC},
+  {KC_TRNS, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSLS},
+  {KC_TRNS, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  DF(_QW), DF(_CM), DF(_DV), RESET,   KC_TRNS},
+  {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
+},
+[_LW] = { /* LOWER */
+  {KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
+  {KC_TRNS, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
+  {KC_TRNS, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  DF(_QW), DF(_CM), DF(_DV), RESET,   KC_TRNS},
+  {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
+},
+[_RGB] = { /* RGBLIGHT */
+  {KC_TRNS,  KC_PGUP,  KC_UP,    KC_PGDN,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_DEL},
+  {KC_TRNS,  KC_LEFT,  KC_DOWN,  KC_RGHT,  KC_TRNS,  KC_HOME,  KC_LEFT,  KC_DOWN,  KC_UP,    KC_RGHT,  KC_END,   KC_TRNS},
+  {KC_TRNS,  F(1),     F(2),     F(3),     F(4),     F(5),     F(6),     F(7),     F(8),     KC_TRNS,  KC_TRNS,  KC_TRNS},
+  {KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS,  KC_TRNS}
+
+}
+};
+
+enum function_id {
+    RGBLED_TOGGLE,
+    RGBLED_STEP_MODE,
+    RGBLED_INCREASE_HUE,
+    RGBLED_DECREASE_HUE,
+    RGBLED_INCREASE_SAT,
+    RGBLED_DECREASE_SAT,
+    RGBLED_INCREASE_VAL,
+    RGBLED_DECREASE_VAL,
+};
+
+const uint16_t PROGMEM fn_actions[] = {
+  [0]  = ACTION_LAYER_TAP_KEY(_RGB, KC_SPC),
+  [1]  = ACTION_FUNCTION(RGBLED_TOGGLE),
+  [2]  = ACTION_FUNCTION(RGBLED_STEP_MODE),
+  [3]  = ACTION_FUNCTION(RGBLED_INCREASE_HUE),
+  [4]  = ACTION_FUNCTION(RGBLED_DECREASE_HUE),
+  [5]  = ACTION_FUNCTION(RGBLED_INCREASE_SAT),
+  [6]  = ACTION_FUNCTION(RGBLED_DECREASE_SAT),
+  [7]  = ACTION_FUNCTION(RGBLED_INCREASE_VAL),
+  [8]  = ACTION_FUNCTION(RGBLED_DECREASE_VAL),
+};
+
+const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
+{
+  // MACRODOWN only works in this function
+      switch(id) {
+        case 0:
+          if (record->event.pressed) {
+            register_code(KC_RSFT);
+            #ifdef BACKLIGHT_ENABLE
+              backlight_step();
+            #endif
+          } else {
+            unregister_code(KC_RSFT);
+          }
+        break;
+      }
+    return MACRO_NONE;
+};
+
+void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
+  switch (id) {
+    case RGBLED_TOGGLE:
+      //led operations
+      if (record->event.pressed) {
+        rgblight_toggle();
+      }
+
+      break;
+    case RGBLED_INCREASE_HUE:
+      if (record->event.pressed) {
+        rgblight_increase_hue();
+      }
+      break;
+    case RGBLED_DECREASE_HUE:
+      if (record->event.pressed) {
+        rgblight_decrease_hue();
+      }
+      break;
+    case RGBLED_INCREASE_SAT:
+      if (record->event.pressed) {
+        rgblight_increase_sat();
+      }
+      break;
+    case RGBLED_DECREASE_SAT:
+      if (record->event.pressed) {
+        rgblight_decrease_sat();
+      }
+      break;
+      case RGBLED_INCREASE_VAL:
+        if (record->event.pressed) {
+          rgblight_increase_val();
+        }
+        break;
+      case RGBLED_DECREASE_VAL:
+        if (record->event.pressed) {
+          rgblight_decrease_val();
+        }
+        break;
+      case RGBLED_STEP_MODE:
+        if (record->event.pressed) {
+          rgblight_step();
+        }
+        break;
+  }
+}

+ 181 - 0
keyboard/planck/light_ws2812.c

@@ -0,0 +1,181 @@
+/*
+* light weight WS2812 lib V2.0b
+*
+* Controls WS2811/WS2812/WS2812B RGB-LEDs
+* Author: Tim (cpldcpu@gmail.com)
+*
+* Jan 18th, 2014  v2.0b Initial Version
+* Nov 29th, 2015  v2.3  Added SK6812RGBW support
+*
+* License: GNU GPL v2 (see License.txt)
+*/
+
+#include "light_ws2812.h"
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include <util/delay.h>
+#include "debug.h"
+
+// Setleds for standard RGB
+void inline ws2812_setleds(struct cRGB *ledarray, uint16_t leds)
+{
+   ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
+}
+
+void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pinmask)
+{
+  ws2812_DDRREG |= pinmask; // Enable DDR
+  ws2812_sendarray_mask((uint8_t*)ledarray,leds+leds+leds,pinmask);
+  _delay_us(50);
+}
+
+// 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));
+  _delay_us(80);
+}
+
+void ws2812_sendarray(uint8_t *data,uint16_t datlen)
+{
+  ws2812_sendarray_mask(data,datlen,_BV(ws2812_pin));
+}
+
+/*
+  This routine writes an array of bytes with RGB values to the Dataout pin
+  using the fast 800kHz clockless WS2811/2812 protocol.
+*/
+
+// Timing in ns
+#define w_zeropulse   350
+#define w_onepulse    900
+#define w_totalperiod 1250
+
+// Fixed cycles used by the inner loop
+#define w_fixedlow    2
+#define w_fixedhigh   4
+#define w_fixedtotal  8
+
+// Insert NOPs to match the timing, if possible
+#define w_zerocycles    (((F_CPU/1000)*w_zeropulse          )/1000000)
+#define w_onecycles     (((F_CPU/1000)*w_onepulse    +500000)/1000000)
+#define w_totalcycles   (((F_CPU/1000)*w_totalperiod +500000)/1000000)
+
+// w1 - nops between rising edge and falling edge - low
+#define w1 (w_zerocycles-w_fixedlow)
+// w2   nops between fe low and fe high
+#define w2 (w_onecycles-w_fixedhigh-w1)
+// w3   nops to complete loop
+#define w3 (w_totalcycles-w_fixedtotal-w1-w2)
+
+#if w1>0
+  #define w1_nops w1
+#else
+  #define w1_nops  0
+#endif
+
+// The only critical timing parameter is the minimum pulse length of the "0"
+// Warn or throw error if this timing can not be met with current F_CPU settings.
+#define w_lowtime ((w1_nops+w_fixedlow)*1000000)/(F_CPU/1000)
+#if w_lowtime>550
+   #error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?"
+#elif w_lowtime>450
+   #warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)."
+   #warning "Please consider a higher clockspeed, if possible"
+#endif
+
+#if w2>0
+#define w2_nops w2
+#else
+#define w2_nops  0
+#endif
+
+#if w3>0
+#define w3_nops w3
+#else
+#define w3_nops  0
+#endif
+
+#define w_nop1  "nop      \n\t"
+#define w_nop2  "rjmp .+0 \n\t"
+#define w_nop4  w_nop2 w_nop2
+#define w_nop8  w_nop4 w_nop4
+#define w_nop16 w_nop8 w_nop8
+
+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;
+  sreg_prev=SREG;
+  cli();
+
+  while (datlen--) {
+    curbyte=*data++;
+
+    asm volatile(
+    "       ldi   %0,8  \n\t"
+    "loop%=:            \n\t"
+    "       out   %2,%3 \n\t"    //  '1' [01] '0' [01] - re
+#if (w1_nops&1)
+w_nop1
+#endif
+#if (w1_nops&2)
+w_nop2
+#endif
+#if (w1_nops&4)
+w_nop4
+#endif
+#if (w1_nops&8)
+w_nop8
+#endif
+#if (w1_nops&16)
+w_nop16
+#endif
+    "       sbrs  %1,7  \n\t"    //  '1' [03] '0' [02]
+    "       out   %2,%4 \n\t"    //  '1' [--] '0' [03] - fe-low
+    "       lsl   %1    \n\t"    //  '1' [04] '0' [04]
+#if (w2_nops&1)
+  w_nop1
+#endif
+#if (w2_nops&2)
+  w_nop2
+#endif
+#if (w2_nops&4)
+  w_nop4
+#endif
+#if (w2_nops&8)
+  w_nop8
+#endif
+#if (w2_nops&16)
+  w_nop16
+#endif
+    "       out   %2,%4 \n\t"    //  '1' [+1] '0' [+1] - fe-high
+#if (w3_nops&1)
+w_nop1
+#endif
+#if (w3_nops&2)
+w_nop2
+#endif
+#if (w3_nops&4)
+w_nop4
+#endif
+#if (w3_nops&8)
+w_nop8
+#endif
+#if (w3_nops&16)
+w_nop16
+#endif
+
+    "       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)
+    );
+  }
+
+  SREG=sreg_prev;
+}

+ 73 - 0
keyboard/planck/light_ws2812.h

@@ -0,0 +1,73 @@
+/*
+ * light weight WS2812 lib include
+ *
+ * Version 2.3  - Nev 29th 2015
+ * Author: Tim (cpldcpu@gmail.com)
+ *
+ * Please do not change this file! All configuration is handled in "ws2812_config.h"
+ *
+ * License: GNU GPL v2 (see License.txt)
+ +
+ */
+
+#ifndef LIGHT_WS2812_H_
+#define LIGHT_WS2812_H_
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+//#include "ws2812_config.h"
+
+/*
+ *  Structure of the LED array
+ *
+ * cRGB:     RGB  for WS2812S/B/C/D, SK6812, SK6812Mini, SK6812WWA, APA104, APA106
+ * cRGBW:    RGBW for SK6812RGBW
+ */
+
+struct cRGB  { uint8_t g; uint8_t r; uint8_t b; };
+struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;};
+
+
+
+/* User Interface
+ *
+ * Input:
+ *         ledarray:           An array of GRB data describing the LED colors
+ *         number_of_leds:     The number of LEDs to write
+ *         pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0)
+ *
+ * The functions will perform the following actions:
+ *         - Set the data-out pin as output
+ *         - Send out the LED data
+ *         - Wait 50�s to reset the LEDs
+ */
+
+void ws2812_setleds     (struct cRGB  *ledarray, uint16_t number_of_leds);
+void ws2812_setleds_pin (struct cRGB  *ledarray, uint16_t number_of_leds,uint8_t pinmask);
+void ws2812_setleds_rgbw(struct cRGBW *ledarray, uint16_t number_of_leds);
+
+/*
+ * Old interface / Internal functions
+ *
+ * The functions take a byte-array and send to the data output as WS2812 bitstream.
+ * The length is the number of bytes to send - three per LED.
+ */
+
+void ws2812_sendarray     (uint8_t *array,uint16_t length);
+void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
+
+
+/*
+ * Internal defines
+ */
+#ifndef CONCAT
+#define CONCAT(a, b)            a ## b
+#endif
+#ifndef CONCAT_EXP
+#define CONCAT_EXP(a, b)   CONCAT(a, b)
+#endif
+
+// #define ws2812_PORTREG  CONCAT_EXP(PORT,ws2812_port)
+// #define ws2812_DDRREG   CONCAT_EXP(DDR,ws2812_port)
+
+#endif /* LIGHT_WS2812_H_ */

+ 6 - 1
keyboard/planck/planck.c

@@ -15,6 +15,11 @@ void * matrix_init_kb(void) {
     	backlight_init_ports();
 	#endif
 
+	#ifdef RGBLIGHT_ENABLE
+		rgblight_init();
+	#endif
+
+
     // Turn status LED on
     DDRE |= (1<<6);
     PORTE |= (1<<6);
@@ -28,4 +33,4 @@ void * matrix_scan_kb(void) {
 	if (matrix_scan_user) {
 		(*matrix_scan_user)();
 	}
-};
+};

+ 6 - 3
keyboard/planck/planck.h

@@ -6,6 +6,9 @@
 #ifdef BACKLIGHT_ENABLE
 	#include "backlight.h"
 #endif
+#ifdef RGBLIGHT_ENABLE
+  #include "rgblight.h"
+#endif
 #include <stddef.h>
 #ifdef MIDI_ENABLE
 	#include <keymap_midi.h>
@@ -22,7 +25,7 @@
 	{ k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b }, \
 	{ k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b }, \
 	{ k30, k31, k32, k33, k34, k35, k35, k37, k38, k39, k3a, k3b } \
-} 
+}
 
 #define PLANCK_GRID( \
 	k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \
@@ -35,9 +38,9 @@
 	{ k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b }, \
 	{ k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b }, \
 	{ k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b } \
-} 
+}
 
 void * matrix_init_user(void);
 void * matrix_scan_user(void);
 
-#endif
+#endif

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 505 - 0
keyboard/planck/rgblight.c


+ 87 - 0
keyboard/planck/rgblight.h

@@ -0,0 +1,87 @@
+#ifndef RGBLIGHT_H
+#define RGBLIGHT_H
+
+#ifndef RGBLIGHT_MODES
+#define RGBLIGHT_MODES 23
+#endif
+
+#ifndef RGBLIGHT_EFFECT_SNAKE_LENGTH
+#define RGBLIGHT_EFFECT_SNAKE_LENGTH 7
+#endif
+
+#ifndef RGBLIGHT_EFFECT_KNIGHT_LENGTH
+#define RGBLIGHT_EFFECT_KNIGHT_LENGTH 7
+#endif
+#ifndef RGBLIGHT_EFFECT_KNIGHT_OFFSET
+#define RGBLIGHT_EFFECT_KNIGHT_OFFSET 11
+#endif
+
+#ifndef RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH
+#define RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH 4
+#endif
+
+#ifndef RGBLIGHT_HUE_STEP
+#define RGBLIGHT_HUE_STEP 10
+#endif
+#ifndef RGBLIGHT_SAT_STEP
+#define RGBLIGHT_SAT_STEP 17
+#endif
+#ifndef RGBLIGHT_VAL_STEP
+#define RGBLIGHT_VAL_STEP 17
+#endif
+
+#define RGBLED_TIMER_TOP F_CPU/(256*64)
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "eeconfig.h"
+#include "light_ws2812.h"
+
+typedef union {
+  uint32_t raw;
+  struct {
+    bool     enable  :1;
+    uint8_t  mode    :6;
+    uint16_t hue     :9;
+    uint8_t  sat     :8;
+    uint8_t  val     :8;
+  };
+} rgblight_config_t;
+
+void rgblight_init(void);
+void rgblight_increase(void);
+void rgblight_decrease(void);
+void rgblight_toggle(void);
+void rgblight_step(void);
+void rgblight_mode(uint8_t mode);
+void rgblight_set(void);
+void rgblight_increase_hue(void);
+void rgblight_decrease_hue(void);
+void rgblight_increase_sat(void);
+void rgblight_decrease_sat(void);
+void rgblight_increase_val(void);
+void rgblight_decrease_val(void);
+void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
+void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b);
+
+#define EECONFIG_RGBLIGHT (uint8_t *)7
+uint32_t eeconfig_read_rgblight(void);
+void eeconfig_write_rgblight(uint32_t val);
+void eeconfig_write_rgblight_default(void);
+void eeconfig_debug_rgblight(void);
+
+void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1);
+void setrgb(uint8_t r, uint8_t g, uint8_t b, struct cRGB *led1);
+void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
+
+void rgblight_timer_init(void);
+void rgblight_timer_enable(void);
+void rgblight_timer_disable(void);
+void rgblight_timer_toggle(void);
+void rgblight_effect_breathing(uint8_t interval);
+void rgblight_effect_rainbow_mood(uint8_t interval);
+void rgblight_effect_rainbow_swirl(uint8_t interval);
+void rgblight_effect_snake(uint8_t interval);
+void rgblight_effect_knight(uint8_t interval);
+
+#endif