aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryiancar <yiangosyiangou@cytanet.com.cy>2018-05-10 05:31:24 +0100
committerJack Humbert <jack.humb@gmail.com>2018-05-10 00:31:24 -0400
commitc89565cc3dda82642a0c6c839176602f05fc56f1 (patch)
tree0dfd9c881bc91396b4854292ab8b047e7fc7c90d
parent03516d546009af0ca4d46989214c8153c70b0712 (diff)
downloadqmk_firmware-c89565cc3dda82642a0c6c839176602f05fc56f1.tar.gz
qmk_firmware-c89565cc3dda82642a0c6c839176602f05fc56f1.zip
General RGB matrix fixes (#2931)
* Added Modular keyboards L,R and NUM Created code modules for the 3 modules of the modular keyboard. Original idea by MechboardsUK. Uses i2c implementation similar to lets split * Remove modular from master This is to fix incorrect branching * General fixes for RGB_matrix - Complited speed support for all effects - Fixed raindrop effects to initialized after toggle - Fixed raindrop effects to use all available LEDs - Fixed effect step reverse function - Moved RGB_MATRIX_SOLID_REACTIVE under correct flag * Documentation update for RGBmatrix * More doc updates
-rw-r--r--docs/feature_rgb_matrix.md4
-rw-r--r--quantum/rgb_matrix.c29
-rw-r--r--quantum/rgb_matrix.h2
3 files changed, 19 insertions, 16 deletions
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 084e87ec4..5d2db3b97 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -81,7 +81,6 @@ These are the effects that are currently available:
81 81
82 enum rgb_matrix_effects { 82 enum rgb_matrix_effects {
83 RGB_MATRIX_SOLID_COLOR = 1, 83 RGB_MATRIX_SOLID_COLOR = 1,
84 RGB_MATRIX_SOLID_REACTIVE,
85 RGB_MATRIX_ALPHAS_MODS, 84 RGB_MATRIX_ALPHAS_MODS,
86 RGB_MATRIX_DUAL_BEACON, 85 RGB_MATRIX_DUAL_BEACON,
87 RGB_MATRIX_GRADIENT_UP_DOWN, 86 RGB_MATRIX_GRADIENT_UP_DOWN,
@@ -94,6 +93,7 @@ These are the effects that are currently available:
94 RGB_MATRIX_RAINBOW_MOVING_CHEVRON, 93 RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
95 RGB_MATRIX_JELLYBEAN_RAINDROPS, 94 RGB_MATRIX_JELLYBEAN_RAINDROPS,
96 #ifdef RGB_MATRIX_KEYPRESSES 95 #ifdef RGB_MATRIX_KEYPRESSES
96 RGB_MATRIX_SOLID_REACTIVE,
97 RGB_MATRIX_SPLASH, 97 RGB_MATRIX_SPLASH,
98 RGB_MATRIX_MULTISPLASH, 98 RGB_MATRIX_MULTISPLASH,
99 RGB_MATRIX_SOLID_SPLASH, 99 RGB_MATRIX_SOLID_SPLASH,
@@ -118,7 +118,7 @@ A similar function works in the keymap as `rgb_matrix_indicators_user`.
118 #define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (not recommened) 118 #define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (not recommened)
119 #define RGB_DISABLE_AFTER_TIMEOUT 0 // number of ticks to wait until disabling effects 119 #define RGB_DISABLE_AFTER_TIMEOUT 0 // number of ticks to wait until disabling effects
120 #define RGB_DISABLE_WHEN_USB_SUSPENDED false // turn off effects when suspended 120 #define RGB_DISABLE_WHEN_USB_SUSPENDED false // turn off effects when suspended
121 #define RGB_MATRIX_SKIP_FRAMES 1 // number of frames to skip when displaying animations (0 is full effect) 121 #define RGB_MATRIX_SKIP_FRAMES 1 // number of frames to skip when displaying animations (0 is full effect) if not defined defaults to 1
122 122
123## EEPROM storage 123## EEPROM storage
124 124
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 558e28dec..f3d012bc3 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -324,8 +324,8 @@ void rgb_matrix_raindrops(bool initialize) {
324 HSV hsv; 324 HSV hsv;
325 RGB rgb; 325 RGB rgb;
326 326
327 // Change one LED every tick 327 // Change one LED every tick, make sure speed is not 0
328 uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % DRIVER_LED_TOTAL : 255; 328 uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255;
329 329
330 for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) 330 for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
331 { 331 {
@@ -432,7 +432,7 @@ void rgb_matrix_rainbow_beacon(void) {
432 rgb_led led; 432 rgb_led led;
433 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { 433 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
434 led = g_rgb_leds[i]; 434 led = g_rgb_leds[i];
435 hsv.h = 1.5 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 1.5 * (led.point.x - 112.0) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; 435 hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.y - 32.0)* cos(g_tick * PI / 128) + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.x - 112.0) * sin(g_tick * PI / 128) + rgb_matrix_config.hue;
436 rgb = hsv_to_rgb( hsv ); 436 rgb = hsv_to_rgb( hsv );
437 rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); 437 rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
438 } 438 }
@@ -444,7 +444,7 @@ void rgb_matrix_rainbow_pinwheels(void) {
444 rgb_led led; 444 rgb_led led;
445 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { 445 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
446 led = g_rgb_leds[i]; 446 led = g_rgb_leds[i];
447 hsv.h = 2 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 2 * (66 - abs(led.point.x - 112.0)) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; 447 hsv.h = (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.y - 32.0)* cos(g_tick * PI / 128) + (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (66 - abs(led.point.x - 112.0)) * sin(g_tick * PI / 128) + rgb_matrix_config.hue;
448 rgb = hsv_to_rgb( hsv ); 448 rgb = hsv_to_rgb( hsv );
449 rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); 449 rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
450 } 450 }
@@ -458,7 +458,7 @@ void rgb_matrix_rainbow_moving_chevron(void) {
458 led = g_rgb_leds[i]; 458 led = g_rgb_leds[i];
459 // uint8_t r = g_tick; 459 // uint8_t r = g_tick;
460 uint8_t r = 32; 460 uint8_t r = 32;
461 hsv.h = 1.5 * abs(led.point.y - 32.0)* sin(r * PI / 128) + 1.5 * (led.point.x - (g_tick / 256.0 * 224)) * cos(r * PI / 128) + rgb_matrix_config.hue; 461 hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * abs(led.point.y - 32.0)* sin(r * PI / 128) + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.x - (g_tick / 256.0 * 224)) * cos(r * PI / 128) + rgb_matrix_config.hue;
462 rgb = hsv_to_rgb( hsv ); 462 rgb = hsv_to_rgb( hsv );
463 rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); 463 rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
464 } 464 }
@@ -469,8 +469,8 @@ void rgb_matrix_jellybean_raindrops( bool initialize ) {
469 HSV hsv; 469 HSV hsv;
470 RGB rgb; 470 RGB rgb;
471 471
472 // Change one LED every tick 472 // Change one LED every tick, make sure speed is not 0
473 uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % DRIVER_LED_TOTAL : 255; 473 uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255;
474 474
475 for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) 475 for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
476 { 476 {
@@ -577,8 +577,10 @@ void rgb_matrix_custom(void) {
577} 577}
578 578
579void rgb_matrix_task(void) { 579void rgb_matrix_task(void) {
580 static uint8_t toggle_enable_last = 255;
580 if (!rgb_matrix_config.enable) { 581 if (!rgb_matrix_config.enable) {
581 rgb_matrix_all_off(); 582 rgb_matrix_all_off();
583 toggle_enable_last = rgb_matrix_config.enable;
582 return; 584 return;
583 } 585 }
584 // delay 1 second before driving LEDs or doing anything else 586 // delay 1 second before driving LEDs or doing anything else
@@ -618,8 +620,9 @@ void rgb_matrix_task(void) {
618 // detect change in effect, so each effect can 620 // detect change in effect, so each effect can
619 // have an optional initialization. 621 // have an optional initialization.
620 static uint8_t effect_last = 255; 622 static uint8_t effect_last = 255;
621 bool initialize = effect != effect_last; 623 bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last);
622 effect_last = effect; 624 effect_last = effect;
625 toggle_enable_last = rgb_matrix_config.enable;
623 626
624 // this gets ticked at 20 Hz. 627 // this gets ticked at 20 Hz.
625 // each effect can opt to do calculations 628 // each effect can opt to do calculations
@@ -628,9 +631,6 @@ void rgb_matrix_task(void) {
628 case RGB_MATRIX_SOLID_COLOR: 631 case RGB_MATRIX_SOLID_COLOR:
629 rgb_matrix_solid_color(); 632 rgb_matrix_solid_color();
630 break; 633 break;
631 case RGB_MATRIX_SOLID_REACTIVE:
632 rgb_matrix_solid_reactive();
633 break;
634 case RGB_MATRIX_ALPHAS_MODS: 634 case RGB_MATRIX_ALPHAS_MODS:
635 rgb_matrix_alphas_mods(); 635 rgb_matrix_alphas_mods();
636 break; 636 break;
@@ -665,6 +665,9 @@ void rgb_matrix_task(void) {
665 rgb_matrix_jellybean_raindrops( initialize ); 665 rgb_matrix_jellybean_raindrops( initialize );
666 break; 666 break;
667 #ifdef RGB_MATRIX_KEYPRESSES 667 #ifdef RGB_MATRIX_KEYPRESSES
668 case RGB_MATRIX_SOLID_REACTIVE:
669 rgb_matrix_solid_reactive();
670 break;
668 case RGB_MATRIX_SPLASH: 671 case RGB_MATRIX_SPLASH:
669 rgb_matrix_splash(); 672 rgb_matrix_splash();
670 break; 673 break;
@@ -830,8 +833,8 @@ void rgblight_step(void) {
830 833
831void rgblight_step_reverse(void) { 834void rgblight_step_reverse(void) {
832 rgb_matrix_config.mode--; 835 rgb_matrix_config.mode--;
833 if (rgb_matrix_config.mode <= 1) 836 if (rgb_matrix_config.mode < 1)
834 rgb_matrix_config.mode = (RGB_MATRIX_EFFECT_MAX - 1); 837 rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
835 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 838 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
836} 839}
837 840
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index 1552d5910..aaa85d5f5 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -64,7 +64,6 @@ typedef union {
64 64
65enum rgb_matrix_effects { 65enum rgb_matrix_effects {
66 RGB_MATRIX_SOLID_COLOR = 1, 66 RGB_MATRIX_SOLID_COLOR = 1,
67 RGB_MATRIX_SOLID_REACTIVE,
68 RGB_MATRIX_ALPHAS_MODS, 67 RGB_MATRIX_ALPHAS_MODS,
69 RGB_MATRIX_DUAL_BEACON, 68 RGB_MATRIX_DUAL_BEACON,
70 RGB_MATRIX_GRADIENT_UP_DOWN, 69 RGB_MATRIX_GRADIENT_UP_DOWN,
@@ -77,6 +76,7 @@ enum rgb_matrix_effects {
77 RGB_MATRIX_RAINBOW_MOVING_CHEVRON, 76 RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
78 RGB_MATRIX_JELLYBEAN_RAINDROPS, 77 RGB_MATRIX_JELLYBEAN_RAINDROPS,
79#ifdef RGB_MATRIX_KEYPRESSES 78#ifdef RGB_MATRIX_KEYPRESSES
79 RGB_MATRIX_SOLID_REACTIVE,
80 RGB_MATRIX_SPLASH, 80 RGB_MATRIX_SPLASH,
81 RGB_MATRIX_MULTISPLASH, 81 RGB_MATRIX_MULTISPLASH,
82 RGB_MATRIX_SOLID_SPLASH, 82 RGB_MATRIX_SOLID_SPLASH,