]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
updates rgblight implementation, makes non-timer stuff compatible with audio
authorJack Humbert <jack.humb@gmail.com>
Thu, 7 Jul 2016 15:33:32 +0000 (11:33 -0400)
committerJack Humbert <jack.humb@gmail.com>
Thu, 7 Jul 2016 15:33:34 +0000 (11:33 -0400)
17 files changed:
keyboards/clueboard/rev1/config.h
keyboards/clueboard/rev2/config.h
keyboards/cluepad/config.h
keyboards/kc60/keymaps/ws2812/config.h
keyboards/lets_split/config.h
keyboards/phantom/config.h
keyboards/planck/keymaps/experimental/Makefile
keyboards/planck/keymaps/experimental/config.h
keyboards/planck/keymaps/experimental/keymap.c
keyboards/planck/keymaps/pvc/config.h
keyboards/planck/keymaps/yang/config.h
keyboards/preonic/config.h
keyboards/satan/config.h
quantum/light_ws2812.c
quantum/rgblight.c
quantum/rgblight.h
readme.md

index 9bb58f56e82bb8f0f87387ceaea97acbd43c92aa..8c949723247bf654dcab4e521ab989aa5f40fa5a 100644 (file)
@@ -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
index e2f8336beb113ddac6f26f90a668009de7bef2b5..02982ff29994fc3f36096861c151d71afecc28d6 100644 (file)
@@ -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
index 0955e0f7026791e552816ee2ca5753d287c238d3..bae05fade38ae99b8ee11c7c2d1fb8b96b9ac5bb 100644 (file)
@@ -69,13 +69,12 @@ 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 RGBLED_NUM 4     // Number of LEDs
- #define RGBLIGHT_HUE_STEP 10
- #define RGBLIGHT_SAT_STEP 17
- #define RGBLIGHT_VAL_STEP 17
+#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
+#define RGBLIGHT_VAL_STEP 17
 
 /*
  * Feature disable options
index 933bb0d2d1a8fdacbe31269ed78cc3dde635bb7d..2f39ea8e55ecb607d2c7dc24ec1099a25986fad0 100644 (file)
@@ -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
index 6f90997ab49533dd3fb326aec40169e671595224..833818ce60edb32b647e84605b807038fc6c4ce9 100644 (file)
@@ -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
index d5878766f0a2f155fc266c9d086f53fbcf4c5341..983a1d73f29868ac4c7a10e74559f7067b5fe068 100644 (file)
@@ -62,13 +62,12 @@ 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 RGBLED_NUM 20     // Number of LEDs
- #define RGBLIGHT_HUE_STEP 10
- #define RGBLIGHT_SAT_STEP 17
- #define RGBLIGHT_VAL_STEP 17
+#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
+#define RGBLIGHT_VAL_STEP 17
 
 /*
  * Feature disable options
index 581e08cd02aab5f0c0519f0a8c2a43486274fa39..877c4aed0ea55733160b627a5cb4fff3257c797b 100644 (file)
@@ -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
index 985e250ab54d62d7a671c84e96f15ca697b5cbb7..52acd1905ebebcdc69822434889b0935565096d5 100644 (file)
@@ -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
index 8ec335d7d26d44fb5d03a7ac421699d0501609fb..d9303fcae5940bf37e450aaafa89401ca5e1145c 100644 (file)
@@ -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,14 +47,20 @@ 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  |   ;  |  "   |
  * |------+------+------+------+------+------|------+------+------+------+------+------|
- * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   /  |Enter |
+ * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |,  |   .  |   /  |Enter |
  * |------+------+------+------+------+------+------+------+------+------+------+------|
  * | Brite| Ctrl | Alt  | GUI  |Lower |    Space    |Raise | Left | Down |  Up  |Right |
  * `-----------------------------------------------------------------------------------'
@@ -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;
 };
index b6489310819c78adcf8ab9e930fbda06a5acbe9c..c857a3e89dbea44c7b4ed80fd26becd75da09ac6 100644 (file)
@@ -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
index 5921e9377c42d1ae9245064395559c4e97c4a160..feb5a11901393757eca9df17e4501041e063116c 100644 (file)
@@ -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
index 04946f7fbbf3443363497bf383d96a35df1add91..3fb978c2f6bafe89b7b2262534004c804c802434 100644 (file)
@@ -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
index a7ea8f904c0e24ec57ad12d62640e4140832f099..7e9f91cc829c40a9267c1f8b3dc390b52d115ed7 100644 (file)
@@ -65,13 +65,13 @@ 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 RGBLED_NUM 8     // Number of LEDs
- #define RGBLIGHT_HUE_STEP 10
- #define RGBLIGHT_SAT_STEP 17
- #define RGBLIGHT_VAL_STEP 17
+
+#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
+#define RGBLIGHT_VAL_STEP 17
 
 /*
  * Feature disable options
index f20043067e105c75511e6f75cacf0c3e22f86360..401845e8552bd6cee3f53596e4c05610c4d15e4f 100755 (executable)
 // 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)
     );
   }
 
index c29ffedc38ce3460f3730de7be7ffa4c30a296b6..b1b0f035d58d48bc53035db4655c04963d385b48 100644 (file)
@@ -146,7 +146,9 @@ void rgblight_init(void) {
        }
        eeconfig_debug_rgblight(); // display current eeprom values
 
-       rgblight_timer_init(); // setup the timer
+       #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) {
-               rgblight_timer_disable();
+               #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
-               rgblight_timer_enable();
+
+               #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 {
-               rgblight_timer_disable();
+
+               #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
\ No newline at end of file
index 64f92523e030d68b2dc8cdc6d7a9177814648646..def26c428cdf270ba14dc7f7e75ac4ed8fa25010 100644 (file)
@@ -1,8 +1,11 @@
 #ifndef RGBLIGHT_H
 #define RGBLIGHT_H
 
-#ifndef RGBLIGHT_MODES
-#define RGBLIGHT_MODES 23
+
+#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
+       #define RGBLIGHT_MODES 23
+#else
+       #define RGBLIGHT_MODES 1
 #endif
 
 #ifndef RGBLIGHT_EFFECT_SNAKE_LENGTH
index c24d951d8df63833e4344261885abc0d85342504..e874812515452b5cf0f501ced3b5730e363df99c 100644 (file)
--- a/readme.md
+++ b/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:
-
-    #define ws2812_PORTREG  PORTF
-    #define ws2812_DDRREG   DDRF
-    #define ws2812_pin PF4
+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 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`