Skip to content

Commit

Permalink
updates rgblight implementation, makes non-timer stuff compatible wit…
Browse files Browse the repository at this point in the history
…h audio
  • Loading branch information
jackhumbert committed Jul 7, 2016
1 parent ad43d45 commit 57e08eb
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 74 deletions.
5 changes: 2 additions & 3 deletions keyboards/clueboard/rev1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions keyboards/clueboard/rev2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions keyboards/cluepad/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions keyboards/kc60/keymaps/ws2812/config.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions keyboards/lets_split/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions keyboards/phantom/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions keyboards/planck/keymaps/experimental/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions keyboards/planck/keymaps/experimental/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
73 changes: 69 additions & 4 deletions keyboards/planck/keymaps/experimental/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,22 +31,36 @@ 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
#define _______ KC_TRNS
#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 |
* `-----------------------------------------------------------------------------------'
Expand Down Expand Up @@ -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;
};
Expand Down
5 changes: 2 additions & 3 deletions keyboards/planck/keymaps/pvc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions keyboards/planck/keymaps/yang/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions keyboards/preonic/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions keyboards/satan/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions quantum/light_ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,34 @@
// 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);
}

// 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));
}

/*
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
);
}

Expand Down
Loading

0 comments on commit 57e08eb

Please sign in to comment.