Skip to content

Commit

Permalink
rgb light through midi
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Nov 17, 2016
1 parent 530dd33 commit 3774a7f
Show file tree
Hide file tree
Showing 26 changed files with 126 additions and 31 deletions.
2 changes: 1 addition & 1 deletion keyboards/amj60/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define RGB_DI_PIN E2
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 8 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/clueboard/rev1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* Underlight configuration
*/
#define RGB_DI_PIN B2
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 14 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/clueboard/rev2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/* Underlight configuration
*/
#define RGB_DI_PIN D7
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 14 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/cluecard/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Underlight configuration
*/
#define RGB_DI_PIN E6
//#define RGBLIGHT_TIMER
//#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 4 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/cluecard/keymaps/rgb_effects/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../../config.h"

// place overrides here
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLIGHT_EFFECT_SNAKE_LENGTH 3
#define RGBLIGHT_EFFECT_KNIGHT_LENGTH 2
#define RGBLIGHT_EFFECT_KNIGHT_OFFSET 2
Expand Down
2 changes: 1 addition & 1 deletion keyboards/cluepad/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Underlight configuration
*/
#define RGB_DI_PIN F6
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 4 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
3 changes: 2 additions & 1 deletion keyboards/ergodox/keymaps/jack/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

/* ws2812 RGB LED */
#define RGB_DI_PIN D7
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 15 // Number of LEDs
#define RGBLIGHT_HUE_STEP 12
#define RGBLIGHT_SAT_STEP 255
#define RGBLIGHT_VAL_STEP 12

#define RGB_MIDI
#define RGBW_BB_TWI

#endif
2 changes: 1 addition & 1 deletion keyboards/gh60/keymaps/robotmaxtron/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define ws2812_pin PF4
*/
#define RGB_DI_PIN F4
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 8 // Number of LEDs
#define RGBLIGHT_HUE_STEP 8
#define RGBLIGHT_SAT_STEP 8
Expand Down
2 changes: 1 addition & 1 deletion keyboards/handwired/minorca/keymaps/rgb/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/* ws2812 RGB LED */
#define RGB_DI_PIN D5
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 13 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/jd40/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
)

#define RGB_DI_PIN D3
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 12 // Number of LEDs
#define RGBLIGHT_HUE_STEP 8
#define RGBLIGHT_SAT_STEP 8
Expand Down
2 changes: 1 addition & 1 deletion keyboards/kc60/keymaps/ws2812/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* WS2812B RGB Underglow LED */
#define RGB_DI_PIN F5 // Based on wiring depicted in ws2812_wiring.jpg
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#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
2 changes: 1 addition & 1 deletion keyboards/lets_split/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* ws2812 RGB LED */
#define RGB_DI_PIN D4
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 8 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/lets_split/keymaps/i2c/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* ws2812 RGB LED */
#define RGB_DI_PIN D4
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 8 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/lets_split/keymaps/serial/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* ws2812 RGB LED */
#define RGB_DI_PIN D4
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 8 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/phantom/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Underlight configuration
*/
#define RGB_DI_PIN E2
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 20 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/planck/keymaps/experimental/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/* ws2812 RGB LED */
#define RGB_DI_PIN B1
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 8 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/planck/keymaps/yang/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* ws2812 RGB LED */
#define RGB_DI_PIN D1
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 28 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/preonic/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* ws2812 RGB LED */
#define RGB_DI_PIN D1
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 28 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/preonic/keymaps/kinesis/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* ws2812 RGB LED */
#define RGB_DI_PIN D1
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 28 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/satan/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define RGB_DI_PIN E2
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 8 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 1 addition & 1 deletion keyboards/tada68/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*#define RGB_DI_PIN E2
#define RGBLIGHT_TIMER
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 2 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
Expand Down
2 changes: 0 additions & 2 deletions quantum/light_ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <util/delay.h>
#include "debug.h"

#define RGBW_BB_TWI 1

#ifdef RGBW_BB_TWI

// Port for the I2C
Expand Down
10 changes: 5 additions & 5 deletions quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void rgblight_init(void) {
}
eeconfig_debug_rgblight(); // display current eeprom values

#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_init(); // setup the timer
#endif

Expand Down Expand Up @@ -221,7 +221,7 @@ 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)
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_disable();
#endif
} else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 23) {
Expand All @@ -231,7 +231,7 @@ void rgblight_mode(uint8_t mode) {
// MODE 15-20, snake
// MODE 21-23, knight

#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_enable();
#endif
}
Expand All @@ -245,7 +245,7 @@ void rgblight_toggle(void) {
if (rgblight_config.enable) {
rgblight_mode(rgblight_config.mode);
} else {
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_disable();
#endif
_delay_ms(50);
Expand Down Expand Up @@ -371,7 +371,7 @@ void rgblight_set(void) {
}
}

#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
#ifdef RGBLIGHT_ANIMATIONS

// Animation timer -- AVR Timer3
void rgblight_timer_init(void) {
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgblight.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef RGBLIGHT_H
#define RGBLIGHT_H

#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
#ifdef RGBLIGHT_ANIMATIONS
#define RGBLIGHT_MODES 23
#else
#define RGBLIGHT_MODES 1
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1135,12 +1135,12 @@ For this mod, you need an unused pin wiring to DI of WS2812 strip. After wiring

RGBLIGHT_ENABLE = yes

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).
In order to use the underglow animation functions, you need to have `#define RGBLIGHT_ANIMATIONS` in your `config.h`.

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 RGBLIGHT_ANIMATIONS // 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
Expand Down
96 changes: 96 additions & 0 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#include "descriptor.h"
#include "lufa.h"
#include "quantum.h"

#ifdef NKRO_ENABLE
#include "keycode_config.h"
Expand Down Expand Up @@ -1111,9 +1112,104 @@ void cc_callback(MidiDevice * device,
#endif
}

void send_dword(uint32_t number) {
uint16_t word = (number >> 16);
send_word(word);
send_word(number & 0xFFFFUL);
}

void send_word(uint16_t number) {
uint8_t byte = number >> 8;
send_byte(byte);
send_byte(number & 0xFF);
}

void send_byte(uint8_t number) {
uint8_t nibble = number >> 4;
send_nibble(nibble);
send_nibble(number & 0xF);
}

void send_nibble(uint8_t number) {
switch (number) {
case 0:
register_code(KC_0);
unregister_code(KC_0);
break;
case 1 ... 9:
register_code(KC_1 + (number - 1));
unregister_code(KC_1 + (number - 1));
break;
case 0xA ... 0xF:
register_code(KC_A + (number - 0xA));
unregister_code(KC_A + (number - 0xA));
break;
}
}

uint8_t midi_buffer[16] = {0};

void sysex_callback(MidiDevice * device,
uint16_t start, uint8_t length, uint8_t * data) {
// for (int i = 0; i < length; i++)
// midi_send_cc(device, 15, 0x7F & data[i], 0x7F & (start + i));
// if (start == 0x27) {
// SEND_STRING("\n");
// send_word(start);
// SEND_STRING(": ");
for (uint8_t place = 0; place < length; place++) {
// send_byte(*data);
midi_buffer[start + place] = *data;
if (*data == 0xF7)
sysex_buffer_callback(start + place, &midi_buffer);
// SEND_STRING(" ");
data++;
}
// }

}

void sysex_buffer_callback(uint8_t length, uint8_t * data) {
uint8_t * pointer_copy = data;

if (*data++ != 0xF0)
return
data++;
data++;
data++;
data++;

switch (*data++) {
case 0x27: ; // RGB LED functions
switch (*data++)
case 0x00: ; // Update HSV
uint32_t part1 = *data++;
uint32_t part2 = *data++;
uint32_t part3 = *data++;
uint32_t part4 = *data++;
uint32_t part5 = *data++;
uint32_t chunk = ((part1 & 0x1FUL) << 28) | (part2 << 21) | (part3 << 14) | (part4 << 7) | part5;
// SEND_STRING("\nCHUNK: ");
// send_dword(chunk);
rgblight_sethsv(((chunk >> 16) & 0xFFFF) % 360, (chunk >> 8) & 0xFF, chunk & 0xFF);
// SEND_STRING("\nHUE: ");
// send_word(((chunk >> 16) & 0xFFFF) % 360);
// SEND_STRING("\nSAT: ");
// send_word((chunk >> 8) & 0xFF);
// SEND_STRING("\nVAL: ");
// send_word(chunk & 0xFF);
break;
case 0x01: ; // Update RGB
break;
break;
}

// SEND_STRING("\nDATA:\n");
// while (*pointer_copy != 0xF7) {
// send_byte(*pointer_copy++);
// SEND_STRING(" ");
// }

}

#endif

0 comments on commit 3774a7f

Please sign in to comment.