diff options
Diffstat (limited to 'quantum/rgb_matrix.c')
| -rw-r--r-- | quantum/rgb_matrix.c | 446 |
1 files changed, 253 insertions, 193 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 197bc1ac5..2ed36304d 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
| @@ -18,10 +18,10 @@ | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #include "rgb_matrix.h" | 20 | #include "rgb_matrix.h" |
| 21 | #include "i2c_master.h" | ||
| 22 | #include "progmem.h" | 21 | #include "progmem.h" |
| 23 | #include "config.h" | 22 | #include "config.h" |
| 24 | #include "eeprom.h" | 23 | #include "eeprom.h" |
| 24 | #include <string.h> | ||
| 25 | #include <math.h> | 25 | #include <math.h> |
| 26 | 26 | ||
| 27 | rgb_config_t rgb_matrix_config; | 27 | rgb_config_t rgb_matrix_config; |
| @@ -50,6 +50,15 @@ rgb_config_t rgb_matrix_config; | |||
| 50 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255 | 50 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255 |
| 51 | #endif | 51 | #endif |
| 52 | 52 | ||
| 53 | #ifndef RGB_DIGITAL_RAIN_DROPS | ||
| 54 | // lower the number for denser effect/wider keyboard | ||
| 55 | #define RGB_DIGITAL_RAIN_DROPS 24 | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #if !defined(DISABLE_RGB_MATRIX_RAINDROPS) || !defined(DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS) || !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) | ||
| 59 | #define TRACK_PREVIOUS_EFFECT | ||
| 60 | #endif | ||
| 61 | |||
| 53 | bool g_suspend_state = false; | 62 | bool g_suspend_state = false; |
| 54 | 63 | ||
| 55 | // Global tick at 20 Hz | 64 | // Global tick at 20 Hz |
| @@ -74,7 +83,12 @@ void eeconfig_update_rgb_matrix(uint32_t val) { | |||
| 74 | void eeconfig_update_rgb_matrix_default(void) { | 83 | void eeconfig_update_rgb_matrix_default(void) { |
| 75 | dprintf("eeconfig_update_rgb_matrix_default\n"); | 84 | dprintf("eeconfig_update_rgb_matrix_default\n"); |
| 76 | rgb_matrix_config.enable = 1; | 85 | rgb_matrix_config.enable = 1; |
| 86 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 77 | rgb_matrix_config.mode = RGB_MATRIX_CYCLE_LEFT_RIGHT; | 87 | rgb_matrix_config.mode = RGB_MATRIX_CYCLE_LEFT_RIGHT; |
| 88 | #else | ||
| 89 | // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace | ||
| 90 | rgb_matrix_config.mode = RGB_MATRIX_SOLID_COLOR; | ||
| 91 | #endif | ||
| 78 | rgb_matrix_config.hue = 0; | 92 | rgb_matrix_config.hue = 0; |
| 79 | rgb_matrix_config.sat = 255; | 93 | rgb_matrix_config.sat = 255; |
| 80 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | 94 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; |
| @@ -111,29 +125,15 @@ void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t | |||
| 111 | } | 125 | } |
| 112 | 126 | ||
| 113 | void rgb_matrix_update_pwm_buffers(void) { | 127 | void rgb_matrix_update_pwm_buffers(void) { |
| 114 | #ifdef IS31FL3731 | 128 | rgb_matrix_driver.flush(); |
| 115 | IS31FL3731_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 116 | IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 117 | #elif defined(IS31FL3733) | ||
| 118 | IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 119 | IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 120 | #endif | ||
| 121 | } | 129 | } |
| 122 | 130 | ||
| 123 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { | 131 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { |
| 124 | #ifdef IS31FL3731 | 132 | rgb_matrix_driver.set_color(index, red, green, blue); |
| 125 | IS31FL3731_set_color( index, red, green, blue ); | ||
| 126 | #elif defined(IS31FL3733) | ||
| 127 | IS31FL3733_set_color( index, red, green, blue ); | ||
| 128 | #endif | ||
| 129 | } | 133 | } |
| 130 | 134 | ||
| 131 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { | 135 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { |
| 132 | #ifdef IS31FL3731 | 136 | rgb_matrix_driver.set_color_all(red, green, blue); |
| 133 | IS31FL3731_set_color_all( red, green, blue ); | ||
| 134 | #elif defined(IS31FL3733) | ||
| 135 | IS31FL3733_set_color_all( red, green, blue ); | ||
| 136 | #endif | ||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { | 139 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { |
| @@ -196,47 +196,6 @@ void rgb_matrix_test(void) { | |||
| 196 | } | 196 | } |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | // This tests the LEDs | ||
| 200 | // Note that it will change the LED control registers | ||
| 201 | // in the LED drivers, and leave them in an invalid | ||
| 202 | // state for other backlight effects. | ||
| 203 | // ONLY USE THIS FOR TESTING LEDS! | ||
| 204 | void rgb_matrix_single_LED_test(void) { | ||
| 205 | static uint8_t color = 0; // 0,1,2 for R,G,B | ||
| 206 | static uint8_t row = 0; | ||
| 207 | static uint8_t column = 0; | ||
| 208 | |||
| 209 | static uint8_t tick = 0; | ||
| 210 | tick++; | ||
| 211 | |||
| 212 | if ( tick > 2 ) | ||
| 213 | { | ||
| 214 | tick = 0; | ||
| 215 | column++; | ||
| 216 | } | ||
| 217 | if ( column > MATRIX_COLS ) | ||
| 218 | { | ||
| 219 | column = 0; | ||
| 220 | row++; | ||
| 221 | } | ||
| 222 | if ( row > MATRIX_ROWS ) | ||
| 223 | { | ||
| 224 | row = 0; | ||
| 225 | color++; | ||
| 226 | } | ||
| 227 | if ( color > 2 ) | ||
| 228 | { | ||
| 229 | color = 0; | ||
| 230 | } | ||
| 231 | |||
| 232 | uint8_t led[8], led_count; | ||
| 233 | map_row_column_to_led(row,column,led,&led_count); | ||
| 234 | for(uint8_t i = 0; i < led_count; i++) { | ||
| 235 | rgb_matrix_set_color_all( 40, 40, 40 ); | ||
| 236 | rgb_matrix_test_led( led[i], color==0, color==1, color==2 ); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | // All LEDs off | 199 | // All LEDs off |
| 241 | void rgb_matrix_all_off(void) { | 200 | void rgb_matrix_all_off(void) { |
| 242 | rgb_matrix_set_color_all( 0, 0, 0 ); | 201 | rgb_matrix_set_color_all( 0, 0, 0 ); |
| @@ -438,10 +397,12 @@ void rgb_matrix_cycle_up_down(void) { | |||
| 438 | void rgb_matrix_dual_beacon(void) { | 397 | void rgb_matrix_dual_beacon(void) { |
| 439 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 398 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; |
| 440 | RGB rgb; | 399 | RGB rgb; |
| 441 | rgb_led led; | 400 | Point point; |
| 401 | double cos_value = cos(g_tick * PI / 128) / 32; | ||
| 402 | double sin_value = sin(g_tick * PI / 128) / 112; | ||
| 442 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 403 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 443 | led = g_rgb_leds[i]; | 404 | point = g_rgb_leds[i].point; |
| 444 | hsv.h = ((led.point.y - 32.0)* cos(g_tick * PI / 128) / 32 + (led.point.x - 112.0) * sin(g_tick * PI / 128) / (112)) * (180) + rgb_matrix_config.hue; | 405 | hsv.h = ((point.y - 32.0)* cos_value + (point.x - 112.0) * sin_value) * (180) + rgb_matrix_config.hue; |
| 445 | rgb = hsv_to_rgb( hsv ); | 406 | rgb = hsv_to_rgb( hsv ); |
| 446 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 407 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 447 | } | 408 | } |
| @@ -450,10 +411,12 @@ void rgb_matrix_dual_beacon(void) { | |||
| 450 | void rgb_matrix_rainbow_beacon(void) { | 411 | void rgb_matrix_rainbow_beacon(void) { |
| 451 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 412 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; |
| 452 | RGB rgb; | 413 | RGB rgb; |
| 453 | rgb_led led; | 414 | Point point; |
| 415 | double cos_value = cos(g_tick * PI / 128); | ||
| 416 | double sin_value = sin(g_tick * PI / 128); | ||
| 454 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 417 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 455 | led = g_rgb_leds[i]; | 418 | point = g_rgb_leds[i].point; |
| 456 | 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; | 419 | hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.y - 32.0)* cos_value + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.x - 112.0) * sin_value + rgb_matrix_config.hue; |
| 457 | rgb = hsv_to_rgb( hsv ); | 420 | rgb = hsv_to_rgb( hsv ); |
| 458 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 421 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 459 | } | 422 | } |
| @@ -462,10 +425,12 @@ void rgb_matrix_rainbow_beacon(void) { | |||
| 462 | void rgb_matrix_rainbow_pinwheels(void) { | 425 | void rgb_matrix_rainbow_pinwheels(void) { |
| 463 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 426 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; |
| 464 | RGB rgb; | 427 | RGB rgb; |
| 465 | rgb_led led; | 428 | Point point; |
| 429 | double cos_value = cos(g_tick * PI / 128); | ||
| 430 | double sin_value = sin(g_tick * PI / 128); | ||
| 466 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 431 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 467 | led = g_rgb_leds[i]; | 432 | point = g_rgb_leds[i].point; |
| 468 | 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; | 433 | hsv.h = (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.y - 32.0)* cos_value + (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (66 - abs(point.x - 112.0)) * sin_value + rgb_matrix_config.hue; |
| 469 | rgb = hsv_to_rgb( hsv ); | 434 | rgb = hsv_to_rgb( hsv ); |
| 470 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 435 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 471 | } | 436 | } |
| @@ -474,12 +439,14 @@ void rgb_matrix_rainbow_pinwheels(void) { | |||
| 474 | void rgb_matrix_rainbow_moving_chevron(void) { | 439 | void rgb_matrix_rainbow_moving_chevron(void) { |
| 475 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 440 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; |
| 476 | RGB rgb; | 441 | RGB rgb; |
| 477 | rgb_led led; | 442 | Point point; |
| 443 | uint8_t r = 128; | ||
| 444 | double cos_value = cos(r * PI / 128); | ||
| 445 | double sin_value = sin(r * PI / 128); | ||
| 446 | double multiplier = (g_tick / 256.0 * 224); | ||
| 478 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 447 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 479 | led = g_rgb_leds[i]; | 448 | point = g_rgb_leds[i].point; |
| 480 | // uint8_t r = g_tick; | 449 | hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * abs(point.y - 32.0)* sin_value + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.x - multiplier) * cos_value + rgb_matrix_config.hue; |
| 481 | uint8_t r = 128; | ||
| 482 | 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; | ||
| 483 | rgb = hsv_to_rgb( hsv ); | 450 | rgb = hsv_to_rgb( hsv ); |
| 484 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 451 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 485 | } | 452 | } |
| @@ -510,6 +477,68 @@ void rgb_matrix_jellybean_raindrops( bool initialize ) { | |||
| 510 | } | 477 | } |
| 511 | } | 478 | } |
| 512 | 479 | ||
| 480 | void rgb_matrix_digital_rain( const bool initialize ) { | ||
| 481 | // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain | ||
| 482 | const uint8_t drop_ticks = 28; | ||
| 483 | const uint8_t pure_green_intensity = 0xd0; | ||
| 484 | const uint8_t max_brightness_boost = 0xc0; | ||
| 485 | const uint8_t max_intensity = 0xff; | ||
| 486 | |||
| 487 | static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}}; | ||
| 488 | static uint8_t drop = 0; | ||
| 489 | |||
| 490 | if (initialize) { | ||
| 491 | rgb_matrix_set_color_all(0, 0, 0); | ||
| 492 | memset(map, 0, sizeof map); | ||
| 493 | drop = 0; | ||
| 494 | } | ||
| 495 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 496 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 497 | if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { | ||
| 498 | // top row, pixels have just fallen and we're | ||
| 499 | // making a new rain drop in this column | ||
| 500 | map[col][row] = max_intensity; | ||
| 501 | } | ||
| 502 | else if (map[col][row] > 0 && map[col][row] < max_intensity) { | ||
| 503 | // neither fully bright nor dark, decay it | ||
| 504 | map[col][row]--; | ||
| 505 | } | ||
| 506 | // set the pixel colour | ||
| 507 | uint8_t led, led_count; | ||
| 508 | map_row_column_to_led(row, col, &led, &led_count); | ||
| 509 | |||
| 510 | if (map[col][row] > pure_green_intensity) { | ||
| 511 | const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost | ||
| 512 | * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity)); | ||
| 513 | rgb_matrix_set_color(led, boost, max_intensity, boost); | ||
| 514 | } | ||
| 515 | else { | ||
| 516 | const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity); | ||
| 517 | rgb_matrix_set_color(led, 0, green, 0); | ||
| 518 | } | ||
| 519 | } | ||
| 520 | } | ||
| 521 | if (++drop > drop_ticks) { | ||
| 522 | // reset drop timer | ||
| 523 | drop = 0; | ||
| 524 | for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { | ||
| 525 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 526 | // if ths is on the bottom row and bright allow decay | ||
| 527 | if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) { | ||
| 528 | map[col][row]--; | ||
| 529 | } | ||
| 530 | // check if the pixel above is bright | ||
| 531 | if (map[col][row - 1] == max_intensity) { | ||
| 532 | // allow old bright pixel to decay | ||
| 533 | map[col][row - 1]--; | ||
| 534 | // make this pixel bright | ||
| 535 | map[col][row] = max_intensity; | ||
| 536 | } | ||
| 537 | } | ||
| 538 | } | ||
| 539 | } | ||
| 540 | } | ||
| 541 | |||
| 513 | void rgb_matrix_multisplash(void) { | 542 | void rgb_matrix_multisplash(void) { |
| 514 | // if (g_any_key_hit < 0xFF) { | 543 | // if (g_any_key_hit < 0xFF) { |
| 515 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 544 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; |
| @@ -598,11 +627,16 @@ void rgb_matrix_custom(void) { | |||
| 598 | } | 627 | } |
| 599 | 628 | ||
| 600 | void rgb_matrix_task(void) { | 629 | void rgb_matrix_task(void) { |
| 601 | static uint8_t toggle_enable_last = 255; | 630 | #ifdef TRACK_PREVIOUS_EFFECT |
| 631 | static uint8_t toggle_enable_last = 255; | ||
| 632 | #endif | ||
| 602 | if (!rgb_matrix_config.enable) { | 633 | if (!rgb_matrix_config.enable) { |
| 603 | rgb_matrix_all_off(); | 634 | rgb_matrix_all_off(); |
| 604 | toggle_enable_last = rgb_matrix_config.enable; | 635 | rgb_matrix_indicators(); |
| 605 | return; | 636 | #ifdef TRACK_PREVIOUS_EFFECT |
| 637 | toggle_enable_last = rgb_matrix_config.enable; | ||
| 638 | #endif | ||
| 639 | return; | ||
| 606 | } | 640 | } |
| 607 | // delay 1 second before driving LEDs or doing anything else | 641 | // delay 1 second before driving LEDs or doing anything else |
| 608 | static uint8_t startup_tick = 0; | 642 | static uint8_t startup_tick = 0; |
| @@ -637,13 +671,16 @@ void rgb_matrix_task(void) { | |||
| 637 | (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); | 671 | (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); |
| 638 | uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode; | 672 | uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode; |
| 639 | 673 | ||
| 640 | // Keep track of the effect used last time, | 674 | #ifdef TRACK_PREVIOUS_EFFECT |
| 641 | // detect change in effect, so each effect can | 675 | // Keep track of the effect used last time, |
| 642 | // have an optional initialization. | 676 | // detect change in effect, so each effect can |
| 643 | static uint8_t effect_last = 255; | 677 | // have an optional initialization. |
| 644 | bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last); | 678 | |
| 645 | effect_last = effect; | 679 | static uint8_t effect_last = 255; |
| 646 | toggle_enable_last = rgb_matrix_config.enable; | 680 | bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last); |
| 681 | effect_last = effect; | ||
| 682 | toggle_enable_last = rgb_matrix_config.enable; | ||
| 683 | #endif | ||
| 647 | 684 | ||
| 648 | // this gets ticked at 20 Hz. | 685 | // this gets ticked at 20 Hz. |
| 649 | // each effect can opt to do calculations | 686 | // each effect can opt to do calculations |
| @@ -652,56 +689,93 @@ void rgb_matrix_task(void) { | |||
| 652 | case RGB_MATRIX_SOLID_COLOR: | 689 | case RGB_MATRIX_SOLID_COLOR: |
| 653 | rgb_matrix_solid_color(); | 690 | rgb_matrix_solid_color(); |
| 654 | break; | 691 | break; |
| 655 | case RGB_MATRIX_ALPHAS_MODS: | 692 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS |
| 656 | rgb_matrix_alphas_mods(); | 693 | case RGB_MATRIX_ALPHAS_MODS: |
| 657 | break; | 694 | rgb_matrix_alphas_mods(); |
| 658 | case RGB_MATRIX_DUAL_BEACON: | 695 | break; |
| 659 | rgb_matrix_dual_beacon(); | 696 | #endif |
| 660 | break; | 697 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON |
| 661 | case RGB_MATRIX_GRADIENT_UP_DOWN: | 698 | case RGB_MATRIX_DUAL_BEACON: |
| 662 | rgb_matrix_gradient_up_down(); | 699 | rgb_matrix_dual_beacon(); |
| 663 | break; | ||
| 664 | case RGB_MATRIX_RAINDROPS: | ||
| 665 | rgb_matrix_raindrops( initialize ); | ||
| 666 | break; | ||
| 667 | case RGB_MATRIX_CYCLE_ALL: | ||
| 668 | rgb_matrix_cycle_all(); | ||
| 669 | break; | ||
| 670 | case RGB_MATRIX_CYCLE_LEFT_RIGHT: | ||
| 671 | rgb_matrix_cycle_left_right(); | ||
| 672 | break; | ||
| 673 | case RGB_MATRIX_CYCLE_UP_DOWN: | ||
| 674 | rgb_matrix_cycle_up_down(); | ||
| 675 | break; | ||
| 676 | case RGB_MATRIX_RAINBOW_BEACON: | ||
| 677 | rgb_matrix_rainbow_beacon(); | ||
| 678 | break; | ||
| 679 | case RGB_MATRIX_RAINBOW_PINWHEELS: | ||
| 680 | rgb_matrix_rainbow_pinwheels(); | ||
| 681 | break; | ||
| 682 | case RGB_MATRIX_RAINBOW_MOVING_CHEVRON: | ||
| 683 | rgb_matrix_rainbow_moving_chevron(); | ||
| 684 | break; | ||
| 685 | case RGB_MATRIX_JELLYBEAN_RAINDROPS: | ||
| 686 | rgb_matrix_jellybean_raindrops( initialize ); | ||
| 687 | break; | ||
| 688 | #ifdef RGB_MATRIX_KEYPRESSES | ||
| 689 | case RGB_MATRIX_SOLID_REACTIVE: | ||
| 690 | rgb_matrix_solid_reactive(); | ||
| 691 | break; | 700 | break; |
| 692 | case RGB_MATRIX_SPLASH: | 701 | #endif |
| 693 | rgb_matrix_splash(); | 702 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN |
| 703 | case RGB_MATRIX_GRADIENT_UP_DOWN: | ||
| 704 | rgb_matrix_gradient_up_down(); | ||
| 705 | break; | ||
| 706 | #endif | ||
| 707 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS | ||
| 708 | case RGB_MATRIX_RAINDROPS: | ||
| 709 | rgb_matrix_raindrops( initialize ); | ||
| 710 | break; | ||
| 711 | #endif | ||
| 712 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 713 | case RGB_MATRIX_CYCLE_ALL: | ||
| 714 | rgb_matrix_cycle_all(); | ||
| 694 | break; | 715 | break; |
| 695 | case RGB_MATRIX_MULTISPLASH: | 716 | #endif |
| 696 | rgb_matrix_multisplash(); | 717 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT |
| 718 | case RGB_MATRIX_CYCLE_LEFT_RIGHT: | ||
| 719 | rgb_matrix_cycle_left_right(); | ||
| 697 | break; | 720 | break; |
| 698 | case RGB_MATRIX_SOLID_SPLASH: | 721 | #endif |
| 699 | rgb_matrix_solid_splash(); | 722 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN |
| 723 | case RGB_MATRIX_CYCLE_UP_DOWN: | ||
| 724 | rgb_matrix_cycle_up_down(); | ||
| 700 | break; | 725 | break; |
| 701 | case RGB_MATRIX_SOLID_MULTISPLASH: | 726 | #endif |
| 702 | rgb_matrix_solid_multisplash(); | 727 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON |
| 728 | case RGB_MATRIX_RAINBOW_BEACON: | ||
| 729 | rgb_matrix_rainbow_beacon(); | ||
| 703 | break; | 730 | break; |
| 704 | #endif | 731 | #endif |
| 732 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | ||
| 733 | case RGB_MATRIX_RAINBOW_PINWHEELS: | ||
| 734 | rgb_matrix_rainbow_pinwheels(); | ||
| 735 | break; | ||
| 736 | #endif | ||
| 737 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 738 | case RGB_MATRIX_RAINBOW_MOVING_CHEVRON: | ||
| 739 | rgb_matrix_rainbow_moving_chevron(); | ||
| 740 | break; | ||
| 741 | #endif | ||
| 742 | #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | ||
| 743 | case RGB_MATRIX_JELLYBEAN_RAINDROPS: | ||
| 744 | rgb_matrix_jellybean_raindrops( initialize ); | ||
| 745 | break; | ||
| 746 | #endif | ||
| 747 | #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN | ||
| 748 | case RGB_MATRIX_DIGITAL_RAIN: | ||
| 749 | rgb_matrix_digital_rain( initialize ); | ||
| 750 | break; | ||
| 751 | #endif | ||
| 752 | #ifdef RGB_MATRIX_KEYPRESSES | ||
| 753 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE | ||
| 754 | case RGB_MATRIX_SOLID_REACTIVE: | ||
| 755 | rgb_matrix_solid_reactive(); | ||
| 756 | break; | ||
| 757 | #endif | ||
| 758 | #ifndef DISABLE_RGB_MATRIX_SPLASH | ||
| 759 | case RGB_MATRIX_SPLASH: | ||
| 760 | rgb_matrix_splash(); | ||
| 761 | break; | ||
| 762 | #endif | ||
| 763 | #ifndef DISABLE_RGB_MATRIX_MULTISPLASH | ||
| 764 | case RGB_MATRIX_MULTISPLASH: | ||
| 765 | rgb_matrix_multisplash(); | ||
| 766 | break; | ||
| 767 | #endif | ||
| 768 | #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH | ||
| 769 | case RGB_MATRIX_SOLID_SPLASH: | ||
| 770 | rgb_matrix_solid_splash(); | ||
| 771 | break; | ||
| 772 | #endif | ||
| 773 | #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH | ||
| 774 | case RGB_MATRIX_SOLID_MULTISPLASH: | ||
| 775 | rgb_matrix_solid_multisplash(); | ||
| 776 | break; | ||
| 777 | #endif | ||
| 778 | #endif | ||
| 705 | default: | 779 | default: |
| 706 | rgb_matrix_custom(); | 780 | rgb_matrix_custom(); |
| 707 | break; | 781 | break; |
| @@ -743,7 +817,7 @@ void rgb_matrix_indicators_user(void) {} | |||
| 743 | // } | 817 | // } |
| 744 | 818 | ||
| 745 | void rgb_matrix_init(void) { | 819 | void rgb_matrix_init(void) { |
| 746 | rgb_matrix_setup_drivers(); | 820 | rgb_matrix_driver.init(); |
| 747 | 821 | ||
| 748 | // TODO: put the 1 second startup delay here? | 822 | // TODO: put the 1 second startup delay here? |
| 749 | 823 | ||
| @@ -767,41 +841,14 @@ void rgb_matrix_init(void) { | |||
| 767 | eeconfig_debug_rgb_matrix(); // display current eeprom values | 841 | eeconfig_debug_rgb_matrix(); // display current eeprom values |
| 768 | } | 842 | } |
| 769 | 843 | ||
| 770 | void rgb_matrix_setup_drivers(void) { | ||
| 771 | // Initialize TWI | ||
| 772 | i2c_init(); | ||
| 773 | #ifdef IS31FL3731 | ||
| 774 | IS31FL3731_init( DRIVER_ADDR_1 ); | ||
| 775 | IS31FL3731_init( DRIVER_ADDR_2 ); | ||
| 776 | #elif defined (IS31FL3733) | ||
| 777 | IS31FL3733_init( DRIVER_ADDR_1 ); | ||
| 778 | #endif | ||
| 779 | |||
| 780 | for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) { | ||
| 781 | bool enabled = true; | ||
| 782 | // This only caches it for later | ||
| 783 | #ifdef IS31FL3731 | ||
| 784 | IS31FL3731_set_led_control_register( index, enabled, enabled, enabled ); | ||
| 785 | #elif defined (IS31FL3733) | ||
| 786 | IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); | ||
| 787 | #endif | ||
| 788 | } | ||
| 789 | // This actually updates the LED drivers | ||
| 790 | #ifdef IS31FL3731 | ||
| 791 | IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 792 | #elif defined (IS31FL3733) | ||
| 793 | IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 794 | #endif | ||
| 795 | } | ||
| 796 | |||
| 797 | // Deals with the messy details of incrementing an integer | 844 | // Deals with the messy details of incrementing an integer |
| 798 | uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | 845 | static uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { |
| 799 | int16_t new_value = value; | 846 | int16_t new_value = value; |
| 800 | new_value += step; | 847 | new_value += step; |
| 801 | return MIN( MAX( new_value, min ), max ); | 848 | return MIN( MAX( new_value, min ), max ); |
| 802 | } | 849 | } |
| 803 | 850 | ||
| 804 | uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | 851 | static uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { |
| 805 | int16_t new_value = value; | 852 | int16_t new_value = value; |
| 806 | new_value -= step; | 853 | new_value -= step; |
| 807 | return MIN( MAX( new_value, min ), max ); | 854 | return MIN( MAX( new_value, min ), max ); |
| @@ -836,96 +883,109 @@ uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | |||
| 836 | // } | 883 | // } |
| 837 | // } | 884 | // } |
| 838 | 885 | ||
| 839 | void rgb_matrix_test_led( uint8_t index, bool red, bool green, bool blue ) { | ||
| 840 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 841 | { | ||
| 842 | if ( i == index ) | ||
| 843 | { | ||
| 844 | #ifdef IS31FL3731 | ||
| 845 | IS31FL3731_set_led_control_register( i, red, green, blue ); | ||
| 846 | #elif defined (IS31FL3733) | ||
| 847 | IS31FL3733_set_led_control_register( i, red, green, blue ); | ||
| 848 | #endif | ||
| 849 | } | ||
| 850 | else | ||
| 851 | { | ||
| 852 | #ifdef IS31FL3731 | ||
| 853 | IS31FL3731_set_led_control_register( i, false, false, false ); | ||
| 854 | #elif defined (IS31FL3733) | ||
| 855 | IS31FL3733_set_led_control_register( i, false, false, false ); | ||
| 856 | #endif | ||
| 857 | } | ||
| 858 | } | ||
| 859 | } | ||
| 860 | |||
| 861 | uint32_t rgb_matrix_get_tick(void) { | 886 | uint32_t rgb_matrix_get_tick(void) { |
| 862 | return g_tick; | 887 | return g_tick; |
| 863 | } | 888 | } |
| 864 | 889 | ||
| 865 | void rgblight_toggle(void) { | 890 | void rgb_matrix_toggle(void) { |
| 866 | rgb_matrix_config.enable ^= 1; | 891 | rgb_matrix_config.enable ^= 1; |
| 867 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 892 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 868 | } | 893 | } |
| 869 | 894 | ||
| 870 | void rgblight_step(void) { | 895 | void rgb_matrix_enable(void) { |
| 896 | rgb_matrix_config.enable = 1; | ||
| 897 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 898 | } | ||
| 899 | |||
| 900 | void rgb_matrix_enable_noeeprom(void) { | ||
| 901 | rgb_matrix_config.enable = 1; | ||
| 902 | } | ||
| 903 | |||
| 904 | void rgb_matrix_disable(void) { | ||
| 905 | rgb_matrix_config.enable = 0; | ||
| 906 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 907 | } | ||
| 908 | |||
| 909 | void rgb_matrix_disable_noeeprom(void) { | ||
| 910 | rgb_matrix_config.enable = 0; | ||
| 911 | } | ||
| 912 | |||
| 913 | void rgb_matrix_step(void) { | ||
| 871 | rgb_matrix_config.mode++; | 914 | rgb_matrix_config.mode++; |
| 872 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) | 915 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) |
| 873 | rgb_matrix_config.mode = 1; | 916 | rgb_matrix_config.mode = 1; |
| 874 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 917 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 875 | } | 918 | } |
| 876 | 919 | ||
| 877 | void rgblight_step_reverse(void) { | 920 | void rgb_matrix_step_reverse(void) { |
| 878 | rgb_matrix_config.mode--; | 921 | rgb_matrix_config.mode--; |
| 879 | if (rgb_matrix_config.mode < 1) | 922 | if (rgb_matrix_config.mode < 1) |
| 880 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; | 923 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; |
| 881 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 924 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 882 | } | 925 | } |
| 883 | 926 | ||
| 884 | void rgblight_increase_hue(void) { | 927 | void rgb_matrix_increase_hue(void) { |
| 885 | rgb_matrix_config.hue = increment( rgb_matrix_config.hue, 8, 0, 255 ); | 928 | rgb_matrix_config.hue = increment( rgb_matrix_config.hue, 8, 0, 255 ); |
| 886 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 929 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 887 | } | 930 | } |
| 888 | 931 | ||
| 889 | void rgblight_decrease_hue(void) { | 932 | void rgb_matrix_decrease_hue(void) { |
| 890 | rgb_matrix_config.hue = decrement( rgb_matrix_config.hue, 8, 0, 255 ); | 933 | rgb_matrix_config.hue = decrement( rgb_matrix_config.hue, 8, 0, 255 ); |
| 891 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 934 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 892 | } | 935 | } |
| 893 | 936 | ||
| 894 | void rgblight_increase_sat(void) { | 937 | void rgb_matrix_increase_sat(void) { |
| 895 | rgb_matrix_config.sat = increment( rgb_matrix_config.sat, 8, 0, 255 ); | 938 | rgb_matrix_config.sat = increment( rgb_matrix_config.sat, 8, 0, 255 ); |
| 896 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 939 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 897 | } | 940 | } |
| 898 | 941 | ||
| 899 | void rgblight_decrease_sat(void) { | 942 | void rgb_matrix_decrease_sat(void) { |
| 900 | rgb_matrix_config.sat = decrement( rgb_matrix_config.sat, 8, 0, 255 ); | 943 | rgb_matrix_config.sat = decrement( rgb_matrix_config.sat, 8, 0, 255 ); |
| 901 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 944 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 902 | } | 945 | } |
| 903 | 946 | ||
| 904 | void rgblight_increase_val(void) { | 947 | void rgb_matrix_increase_val(void) { |
| 905 | rgb_matrix_config.val = increment( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS ); | 948 | rgb_matrix_config.val = increment( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS ); |
| 906 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 949 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 907 | } | 950 | } |
| 908 | 951 | ||
| 909 | void rgblight_decrease_val(void) { | 952 | void rgb_matrix_decrease_val(void) { |
| 910 | rgb_matrix_config.val = decrement( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS ); | 953 | rgb_matrix_config.val = decrement( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS ); |
| 911 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 954 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 912 | } | 955 | } |
| 913 | 956 | ||
| 914 | void rgblight_increase_speed(void) { | 957 | void rgb_matrix_increase_speed(void) { |
| 915 | rgb_matrix_config.speed = increment( rgb_matrix_config.speed, 1, 0, 3 ); | 958 | rgb_matrix_config.speed = increment( rgb_matrix_config.speed, 1, 0, 3 ); |
| 916 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this | 959 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this |
| 917 | } | 960 | } |
| 918 | 961 | ||
| 919 | void rgblight_decrease_speed(void) { | 962 | void rgb_matrix_decrease_speed(void) { |
| 920 | rgb_matrix_config.speed = decrement( rgb_matrix_config.speed, 1, 0, 3 ); | 963 | rgb_matrix_config.speed = decrement( rgb_matrix_config.speed, 1, 0, 3 ); |
| 921 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this | 964 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this |
| 922 | } | 965 | } |
| 923 | 966 | ||
| 924 | void rgblight_mode(uint8_t mode) { | 967 | void rgb_matrix_mode(uint8_t mode) { |
| 925 | rgb_matrix_config.mode = mode; | 968 | rgb_matrix_config.mode = mode; |
| 926 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 969 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 927 | } | 970 | } |
| 928 | 971 | ||
| 929 | uint32_t rgblight_get_mode(void) { | 972 | void rgb_matrix_mode_noeeprom(uint8_t mode) { |
| 973 | rgb_matrix_config.mode = mode; | ||
| 974 | } | ||
| 975 | |||
| 976 | uint8_t rgb_matrix_get_mode(void) { | ||
| 930 | return rgb_matrix_config.mode; | 977 | return rgb_matrix_config.mode; |
| 931 | } | 978 | } |
| 979 | |||
| 980 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | ||
| 981 | rgb_matrix_config.hue = hue; | ||
| 982 | rgb_matrix_config.sat = sat; | ||
| 983 | rgb_matrix_config.val = val; | ||
| 984 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 985 | } | ||
| 986 | |||
| 987 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | ||
| 988 | rgb_matrix_config.hue = hue; | ||
| 989 | rgb_matrix_config.sat = sat; | ||
| 990 | rgb_matrix_config.val = val; | ||
| 991 | } | ||
