diff options
Diffstat (limited to 'quantum/rgb_matrix.c')
| -rw-r--r-- | quantum/rgb_matrix.c | 426 |
1 files changed, 262 insertions, 164 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 70ad1a178..2ed36304d 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | /* Copyright 2017 Jason Williams | 1 | /* Copyright 2017 Jason Williams |
| 2 | * Copyright 2017 Jack Humbert | 2 | * Copyright 2017 Jack Humbert |
| 3 | * Copyright 2018 Yiancar | ||
| 3 | * | 4 | * |
| 4 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
| @@ -17,18 +18,22 @@ | |||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | #include "rgb_matrix.h" | 20 | #include "rgb_matrix.h" |
| 20 | #include <avr/io.h> | ||
| 21 | #include "i2c_master.h" | ||
| 22 | #include <util/delay.h> | ||
| 23 | #include <avr/interrupt.h> | ||
| 24 | #include "progmem.h" | 21 | #include "progmem.h" |
| 25 | #include "config.h" | 22 | #include "config.h" |
| 26 | #include "eeprom.h" | 23 | #include "eeprom.h" |
| 27 | #include "lufa.h" | 24 | #include <string.h> |
| 28 | #include <math.h> | 25 | #include <math.h> |
| 29 | 26 | ||
| 30 | rgb_config_t rgb_matrix_config; | 27 | rgb_config_t rgb_matrix_config; |
| 31 | 28 | ||
| 29 | #ifndef MAX | ||
| 30 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #ifndef MIN | ||
| 34 | #define MIN(a,b) ((a) < (b)? (a): (b)) | ||
| 35 | #endif | ||
| 36 | |||
| 32 | #ifndef RGB_DISABLE_AFTER_TIMEOUT | 37 | #ifndef RGB_DISABLE_AFTER_TIMEOUT |
| 33 | #define RGB_DISABLE_AFTER_TIMEOUT 0 | 38 | #define RGB_DISABLE_AFTER_TIMEOUT 0 |
| 34 | #endif | 39 | #endif |
| @@ -45,6 +50,15 @@ rgb_config_t rgb_matrix_config; | |||
| 45 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255 | 50 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255 |
| 46 | #endif | 51 | #endif |
| 47 | 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 | |||
| 48 | bool g_suspend_state = false; | 62 | bool g_suspend_state = false; |
| 49 | 63 | ||
| 50 | // Global tick at 20 Hz | 64 | // Global tick at 20 Hz |
| @@ -69,7 +83,12 @@ void eeconfig_update_rgb_matrix(uint32_t val) { | |||
| 69 | void eeconfig_update_rgb_matrix_default(void) { | 83 | void eeconfig_update_rgb_matrix_default(void) { |
| 70 | dprintf("eeconfig_update_rgb_matrix_default\n"); | 84 | dprintf("eeconfig_update_rgb_matrix_default\n"); |
| 71 | rgb_matrix_config.enable = 1; | 85 | rgb_matrix_config.enable = 1; |
| 86 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 72 | 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 | ||
| 73 | rgb_matrix_config.hue = 0; | 92 | rgb_matrix_config.hue = 0; |
| 74 | rgb_matrix_config.sat = 255; | 93 | rgb_matrix_config.sat = 255; |
| 75 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | 94 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; |
| @@ -106,16 +125,15 @@ void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t | |||
| 106 | } | 125 | } |
| 107 | 126 | ||
| 108 | void rgb_matrix_update_pwm_buffers(void) { | 127 | void rgb_matrix_update_pwm_buffers(void) { |
| 109 | IS31_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | 128 | rgb_matrix_driver.flush(); |
| 110 | IS31_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 111 | } | 129 | } |
| 112 | 130 | ||
| 113 | 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 ) { |
| 114 | IS31_set_color( index, red, green, blue ); | 132 | rgb_matrix_driver.set_color(index, red, green, blue); |
| 115 | } | 133 | } |
| 116 | 134 | ||
| 117 | 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 ) { |
| 118 | IS31_set_color_all( red, green, blue ); | 136 | rgb_matrix_driver.set_color_all(red, green, blue); |
| 119 | } | 137 | } |
| 120 | 138 | ||
| 121 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { | 139 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { |
| @@ -178,47 +196,6 @@ void rgb_matrix_test(void) { | |||
| 178 | } | 196 | } |
| 179 | } | 197 | } |
| 180 | 198 | ||
| 181 | // This tests the LEDs | ||
| 182 | // Note that it will change the LED control registers | ||
| 183 | // in the LED drivers, and leave them in an invalid | ||
| 184 | // state for other backlight effects. | ||
| 185 | // ONLY USE THIS FOR TESTING LEDS! | ||
| 186 | void rgb_matrix_single_LED_test(void) { | ||
| 187 | static uint8_t color = 0; // 0,1,2 for R,G,B | ||
| 188 | static uint8_t row = 0; | ||
| 189 | static uint8_t column = 0; | ||
| 190 | |||
| 191 | static uint8_t tick = 0; | ||
| 192 | tick++; | ||
| 193 | |||
| 194 | if ( tick > 2 ) | ||
| 195 | { | ||
| 196 | tick = 0; | ||
| 197 | column++; | ||
| 198 | } | ||
| 199 | if ( column > MATRIX_COLS ) | ||
| 200 | { | ||
| 201 | column = 0; | ||
| 202 | row++; | ||
| 203 | } | ||
| 204 | if ( row > MATRIX_ROWS ) | ||
| 205 | { | ||
| 206 | row = 0; | ||
| 207 | color++; | ||
| 208 | } | ||
| 209 | if ( color > 2 ) | ||
| 210 | { | ||
| 211 | color = 0; | ||
| 212 | } | ||
| 213 | |||
| 214 | uint8_t led[8], led_count; | ||
| 215 | map_row_column_to_led(row,column,led,&led_count); | ||
| 216 | for(uint8_t i = 0; i < led_count; i++) { | ||
| 217 | rgb_matrix_set_color_all( 40, 40, 40 ); | ||
| 218 | rgb_matrix_test_led( led[i], color==0, color==1, color==2 ); | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | // All LEDs off | 199 | // All LEDs off |
| 223 | void rgb_matrix_all_off(void) { | 200 | void rgb_matrix_all_off(void) { |
| 224 | rgb_matrix_set_color_all( 0, 0, 0 ); | 201 | rgb_matrix_set_color_all( 0, 0, 0 ); |
| @@ -420,10 +397,12 @@ void rgb_matrix_cycle_up_down(void) { | |||
| 420 | void rgb_matrix_dual_beacon(void) { | 397 | void rgb_matrix_dual_beacon(void) { |
| 421 | 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 }; |
| 422 | RGB rgb; | 399 | RGB rgb; |
| 423 | 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; | ||
| 424 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 403 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 425 | led = g_rgb_leds[i]; | 404 | point = g_rgb_leds[i].point; |
| 426 | 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; |
| 427 | rgb = hsv_to_rgb( hsv ); | 406 | rgb = hsv_to_rgb( hsv ); |
| 428 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 407 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 429 | } | 408 | } |
| @@ -432,10 +411,12 @@ void rgb_matrix_dual_beacon(void) { | |||
| 432 | void rgb_matrix_rainbow_beacon(void) { | 411 | void rgb_matrix_rainbow_beacon(void) { |
| 433 | 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 }; |
| 434 | RGB rgb; | 413 | RGB rgb; |
| 435 | rgb_led led; | 414 | Point point; |
| 415 | double cos_value = cos(g_tick * PI / 128); | ||
| 416 | double sin_value = sin(g_tick * PI / 128); | ||
| 436 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 417 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 437 | led = g_rgb_leds[i]; | 418 | point = g_rgb_leds[i].point; |
| 438 | 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; |
| 439 | rgb = hsv_to_rgb( hsv ); | 420 | rgb = hsv_to_rgb( hsv ); |
| 440 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 421 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 441 | } | 422 | } |
| @@ -444,10 +425,12 @@ void rgb_matrix_rainbow_beacon(void) { | |||
| 444 | void rgb_matrix_rainbow_pinwheels(void) { | 425 | void rgb_matrix_rainbow_pinwheels(void) { |
| 445 | 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 }; |
| 446 | RGB rgb; | 427 | RGB rgb; |
| 447 | rgb_led led; | 428 | Point point; |
| 429 | double cos_value = cos(g_tick * PI / 128); | ||
| 430 | double sin_value = sin(g_tick * PI / 128); | ||
| 448 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 431 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 449 | led = g_rgb_leds[i]; | 432 | point = g_rgb_leds[i].point; |
| 450 | 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; |
| 451 | rgb = hsv_to_rgb( hsv ); | 434 | rgb = hsv_to_rgb( hsv ); |
| 452 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 435 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 453 | } | 436 | } |
| @@ -456,12 +439,14 @@ void rgb_matrix_rainbow_pinwheels(void) { | |||
| 456 | void rgb_matrix_rainbow_moving_chevron(void) { | 439 | void rgb_matrix_rainbow_moving_chevron(void) { |
| 457 | 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 }; |
| 458 | RGB rgb; | 441 | RGB rgb; |
| 459 | 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); | ||
| 460 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 447 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { |
| 461 | led = g_rgb_leds[i]; | 448 | point = g_rgb_leds[i].point; |
| 462 | // 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; |
| 463 | uint8_t r = 32; | ||
| 464 | 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; | ||
| 465 | rgb = hsv_to_rgb( hsv ); | 450 | rgb = hsv_to_rgb( hsv ); |
| 466 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 451 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); |
| 467 | } | 452 | } |
| @@ -492,6 +477,68 @@ void rgb_matrix_jellybean_raindrops( bool initialize ) { | |||
| 492 | } | 477 | } |
| 493 | } | 478 | } |
| 494 | 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 | |||
| 495 | void rgb_matrix_multisplash(void) { | 542 | void rgb_matrix_multisplash(void) { |
| 496 | // if (g_any_key_hit < 0xFF) { | 543 | // if (g_any_key_hit < 0xFF) { |
| 497 | 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 }; |
| @@ -580,11 +627,16 @@ void rgb_matrix_custom(void) { | |||
| 580 | } | 627 | } |
| 581 | 628 | ||
| 582 | void rgb_matrix_task(void) { | 629 | void rgb_matrix_task(void) { |
| 583 | static uint8_t toggle_enable_last = 255; | 630 | #ifdef TRACK_PREVIOUS_EFFECT |
| 631 | static uint8_t toggle_enable_last = 255; | ||
| 632 | #endif | ||
| 584 | if (!rgb_matrix_config.enable) { | 633 | if (!rgb_matrix_config.enable) { |
| 585 | rgb_matrix_all_off(); | 634 | rgb_matrix_all_off(); |
| 586 | toggle_enable_last = rgb_matrix_config.enable; | 635 | rgb_matrix_indicators(); |
| 587 | return; | 636 | #ifdef TRACK_PREVIOUS_EFFECT |
| 637 | toggle_enable_last = rgb_matrix_config.enable; | ||
| 638 | #endif | ||
| 639 | return; | ||
| 588 | } | 640 | } |
| 589 | // delay 1 second before driving LEDs or doing anything else | 641 | // delay 1 second before driving LEDs or doing anything else |
| 590 | static uint8_t startup_tick = 0; | 642 | static uint8_t startup_tick = 0; |
| @@ -619,13 +671,16 @@ void rgb_matrix_task(void) { | |||
| 619 | (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)); |
| 620 | uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode; | 672 | uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode; |
| 621 | 673 | ||
| 622 | // Keep track of the effect used last time, | 674 | #ifdef TRACK_PREVIOUS_EFFECT |
| 623 | // detect change in effect, so each effect can | 675 | // Keep track of the effect used last time, |
| 624 | // have an optional initialization. | 676 | // detect change in effect, so each effect can |
| 625 | static uint8_t effect_last = 255; | 677 | // have an optional initialization. |
| 626 | bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last); | 678 | |
| 627 | effect_last = effect; | 679 | static uint8_t effect_last = 255; |
| 628 | 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 | ||
| 629 | 684 | ||
| 630 | // this gets ticked at 20 Hz. | 685 | // this gets ticked at 20 Hz. |
| 631 | // each effect can opt to do calculations | 686 | // each effect can opt to do calculations |
| @@ -634,56 +689,93 @@ void rgb_matrix_task(void) { | |||
| 634 | case RGB_MATRIX_SOLID_COLOR: | 689 | case RGB_MATRIX_SOLID_COLOR: |
| 635 | rgb_matrix_solid_color(); | 690 | rgb_matrix_solid_color(); |
| 636 | break; | 691 | break; |
| 637 | case RGB_MATRIX_ALPHAS_MODS: | 692 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS |
| 638 | rgb_matrix_alphas_mods(); | 693 | case RGB_MATRIX_ALPHAS_MODS: |
| 639 | break; | 694 | rgb_matrix_alphas_mods(); |
| 640 | case RGB_MATRIX_DUAL_BEACON: | 695 | break; |
| 641 | rgb_matrix_dual_beacon(); | 696 | #endif |
| 642 | break; | 697 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON |
| 643 | case RGB_MATRIX_GRADIENT_UP_DOWN: | 698 | case RGB_MATRIX_DUAL_BEACON: |
| 644 | rgb_matrix_gradient_up_down(); | 699 | rgb_matrix_dual_beacon(); |
| 645 | break; | 700 | break; |
| 646 | case RGB_MATRIX_RAINDROPS: | 701 | #endif |
| 647 | rgb_matrix_raindrops( initialize ); | 702 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN |
| 648 | break; | 703 | case RGB_MATRIX_GRADIENT_UP_DOWN: |
| 649 | case RGB_MATRIX_CYCLE_ALL: | 704 | rgb_matrix_gradient_up_down(); |
| 650 | rgb_matrix_cycle_all(); | 705 | break; |
| 651 | break; | 706 | #endif |
| 652 | case RGB_MATRIX_CYCLE_LEFT_RIGHT: | 707 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS |
| 653 | rgb_matrix_cycle_left_right(); | 708 | case RGB_MATRIX_RAINDROPS: |
| 654 | break; | 709 | rgb_matrix_raindrops( initialize ); |
| 655 | case RGB_MATRIX_CYCLE_UP_DOWN: | ||
| 656 | rgb_matrix_cycle_up_down(); | ||
| 657 | break; | ||
| 658 | case RGB_MATRIX_RAINBOW_BEACON: | ||
| 659 | rgb_matrix_rainbow_beacon(); | ||
| 660 | break; | ||
| 661 | case RGB_MATRIX_RAINBOW_PINWHEELS: | ||
| 662 | rgb_matrix_rainbow_pinwheels(); | ||
| 663 | break; | ||
| 664 | case RGB_MATRIX_RAINBOW_MOVING_CHEVRON: | ||
| 665 | rgb_matrix_rainbow_moving_chevron(); | ||
| 666 | break; | ||
| 667 | case RGB_MATRIX_JELLYBEAN_RAINDROPS: | ||
| 668 | rgb_matrix_jellybean_raindrops( initialize ); | ||
| 669 | break; | ||
| 670 | #ifdef RGB_MATRIX_KEYPRESSES | ||
| 671 | case RGB_MATRIX_SOLID_REACTIVE: | ||
| 672 | rgb_matrix_solid_reactive(); | ||
| 673 | break; | 710 | break; |
| 674 | case RGB_MATRIX_SPLASH: | 711 | #endif |
| 675 | rgb_matrix_splash(); | 712 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL |
| 713 | case RGB_MATRIX_CYCLE_ALL: | ||
| 714 | rgb_matrix_cycle_all(); | ||
| 715 | break; | ||
| 716 | #endif | ||
| 717 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | ||
| 718 | case RGB_MATRIX_CYCLE_LEFT_RIGHT: | ||
| 719 | rgb_matrix_cycle_left_right(); | ||
| 720 | break; | ||
| 721 | #endif | ||
| 722 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | ||
| 723 | case RGB_MATRIX_CYCLE_UP_DOWN: | ||
| 724 | rgb_matrix_cycle_up_down(); | ||
| 676 | break; | 725 | break; |
| 677 | case RGB_MATRIX_MULTISPLASH: | 726 | #endif |
| 678 | rgb_matrix_multisplash(); | 727 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON |
| 728 | case RGB_MATRIX_RAINBOW_BEACON: | ||
| 729 | rgb_matrix_rainbow_beacon(); | ||
| 679 | break; | 730 | break; |
| 680 | case RGB_MATRIX_SOLID_SPLASH: | 731 | #endif |
| 681 | rgb_matrix_solid_splash(); | 732 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS |
| 733 | case RGB_MATRIX_RAINBOW_PINWHEELS: | ||
| 734 | rgb_matrix_rainbow_pinwheels(); | ||
| 682 | break; | 735 | break; |
| 683 | case RGB_MATRIX_SOLID_MULTISPLASH: | 736 | #endif |
| 684 | rgb_matrix_solid_multisplash(); | 737 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON |
| 738 | case RGB_MATRIX_RAINBOW_MOVING_CHEVRON: | ||
| 739 | rgb_matrix_rainbow_moving_chevron(); | ||
| 685 | break; | 740 | break; |
| 686 | #endif | 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 | ||
| 687 | default: | 779 | default: |
| 688 | rgb_matrix_custom(); | 780 | rgb_matrix_custom(); |
| 689 | break; | 781 | break; |
| @@ -725,7 +817,7 @@ void rgb_matrix_indicators_user(void) {} | |||
| 725 | // } | 817 | // } |
| 726 | 818 | ||
| 727 | void rgb_matrix_init(void) { | 819 | void rgb_matrix_init(void) { |
| 728 | rgb_matrix_setup_drivers(); | 820 | rgb_matrix_driver.init(); |
| 729 | 821 | ||
| 730 | // TODO: put the 1 second startup delay here? | 822 | // TODO: put the 1 second startup delay here? |
| 731 | 823 | ||
| @@ -749,29 +841,14 @@ void rgb_matrix_init(void) { | |||
| 749 | eeconfig_debug_rgb_matrix(); // display current eeprom values | 841 | eeconfig_debug_rgb_matrix(); // display current eeprom values |
| 750 | } | 842 | } |
| 751 | 843 | ||
| 752 | void rgb_matrix_setup_drivers(void) { | ||
| 753 | // Initialize TWI | ||
| 754 | i2c_init(); | ||
| 755 | IS31_init( DRIVER_ADDR_1 ); | ||
| 756 | IS31_init( DRIVER_ADDR_2 ); | ||
| 757 | |||
| 758 | for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) { | ||
| 759 | bool enabled = true; | ||
| 760 | // This only caches it for later | ||
| 761 | IS31_set_led_control_register( index, enabled, enabled, enabled ); | ||
| 762 | } | ||
| 763 | // This actually updates the LED drivers | ||
| 764 | IS31_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); | ||
| 765 | } | ||
| 766 | |||
| 767 | // Deals with the messy details of incrementing an integer | 844 | // Deals with the messy details of incrementing an integer |
| 768 | 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 ) { |
| 769 | int16_t new_value = value; | 846 | int16_t new_value = value; |
| 770 | new_value += step; | 847 | new_value += step; |
| 771 | return MIN( MAX( new_value, min ), max ); | 848 | return MIN( MAX( new_value, min ), max ); |
| 772 | } | 849 | } |
| 773 | 850 | ||
| 774 | 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 ) { |
| 775 | int16_t new_value = value; | 852 | int16_t new_value = value; |
| 776 | new_value -= step; | 853 | new_value -= step; |
| 777 | return MIN( MAX( new_value, min ), max ); | 854 | return MIN( MAX( new_value, min ), max ); |
| @@ -806,88 +883,109 @@ uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | |||
| 806 | // } | 883 | // } |
| 807 | // } | 884 | // } |
| 808 | 885 | ||
| 809 | void rgb_matrix_test_led( uint8_t index, bool red, bool green, bool blue ) { | ||
| 810 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 811 | { | ||
| 812 | if ( i == index ) | ||
| 813 | { | ||
| 814 | IS31_set_led_control_register( i, red, green, blue ); | ||
| 815 | } | ||
| 816 | else | ||
| 817 | { | ||
| 818 | IS31_set_led_control_register( i, false, false, false ); | ||
| 819 | } | ||
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | uint32_t rgb_matrix_get_tick(void) { | 886 | uint32_t rgb_matrix_get_tick(void) { |
| 824 | return g_tick; | 887 | return g_tick; |
| 825 | } | 888 | } |
| 826 | 889 | ||
| 827 | void rgblight_toggle(void) { | 890 | void rgb_matrix_toggle(void) { |
| 828 | rgb_matrix_config.enable ^= 1; | 891 | rgb_matrix_config.enable ^= 1; |
| 829 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 892 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 830 | } | 893 | } |
| 831 | 894 | ||
| 832 | 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) { | ||
| 833 | rgb_matrix_config.mode++; | 914 | rgb_matrix_config.mode++; |
| 834 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) | 915 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) |
| 835 | rgb_matrix_config.mode = 1; | 916 | rgb_matrix_config.mode = 1; |
| 836 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 917 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 837 | } | 918 | } |
| 838 | 919 | ||
| 839 | void rgblight_step_reverse(void) { | 920 | void rgb_matrix_step_reverse(void) { |
| 840 | rgb_matrix_config.mode--; | 921 | rgb_matrix_config.mode--; |
| 841 | if (rgb_matrix_config.mode < 1) | 922 | if (rgb_matrix_config.mode < 1) |
| 842 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; | 923 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; |
| 843 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 924 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 844 | } | 925 | } |
| 845 | 926 | ||
| 846 | void rgblight_increase_hue(void) { | 927 | void rgb_matrix_increase_hue(void) { |
| 847 | 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 ); |
| 848 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 929 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 849 | } | 930 | } |
| 850 | 931 | ||
| 851 | void rgblight_decrease_hue(void) { | 932 | void rgb_matrix_decrease_hue(void) { |
| 852 | 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 ); |
| 853 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 934 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 854 | } | 935 | } |
| 855 | 936 | ||
| 856 | void rgblight_increase_sat(void) { | 937 | void rgb_matrix_increase_sat(void) { |
| 857 | 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 ); |
| 858 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 939 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 859 | } | 940 | } |
| 860 | 941 | ||
| 861 | void rgblight_decrease_sat(void) { | 942 | void rgb_matrix_decrease_sat(void) { |
| 862 | 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 ); |
| 863 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 944 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 864 | } | 945 | } |
| 865 | 946 | ||
| 866 | void rgblight_increase_val(void) { | 947 | void rgb_matrix_increase_val(void) { |
| 867 | 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 ); |
| 868 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 949 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 869 | } | 950 | } |
| 870 | 951 | ||
| 871 | void rgblight_decrease_val(void) { | 952 | void rgb_matrix_decrease_val(void) { |
| 872 | 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 ); |
| 873 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 954 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 874 | } | 955 | } |
| 875 | 956 | ||
| 876 | void rgblight_increase_speed(void) { | 957 | void rgb_matrix_increase_speed(void) { |
| 877 | 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 ); |
| 878 | 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 |
| 879 | } | 960 | } |
| 880 | 961 | ||
| 881 | void rgblight_decrease_speed(void) { | 962 | void rgb_matrix_decrease_speed(void) { |
| 882 | 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 ); |
| 883 | 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 |
| 884 | } | 965 | } |
| 885 | 966 | ||
| 886 | void rgblight_mode(uint8_t mode) { | 967 | void rgb_matrix_mode(uint8_t mode) { |
| 887 | rgb_matrix_config.mode = mode; | 968 | rgb_matrix_config.mode = mode; |
| 888 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 969 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 889 | } | 970 | } |
| 890 | 971 | ||
| 891 | 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) { | ||
| 892 | return rgb_matrix_config.mode; | 977 | return rgb_matrix_config.mode; |
| 893 | } | 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 | } | ||
