diff options
Diffstat (limited to 'quantum')
23 files changed, 1091 insertions, 887 deletions
diff --git a/quantum/color.c b/quantum/color.c index 8ede053e7..c49877592 100644 --- a/quantum/color.c +++ b/quantum/color.c | |||
| @@ -78,9 +78,11 @@ RGB hsv_to_rgb( HSV hsv ) | |||
| 78 | break; | 78 | break; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | #ifdef USE_CIE1931_CURVE | ||
| 81 | rgb.r = pgm_read_byte( &CIE1931_CURVE[rgb.r] ); | 82 | rgb.r = pgm_read_byte( &CIE1931_CURVE[rgb.r] ); |
| 82 | rgb.g = pgm_read_byte( &CIE1931_CURVE[rgb.g] ); | 83 | rgb.g = pgm_read_byte( &CIE1931_CURVE[rgb.g] ); |
| 83 | rgb.b = pgm_read_byte( &CIE1931_CURVE[rgb.b] ); | 84 | rgb.b = pgm_read_byte( &CIE1931_CURVE[rgb.b] ); |
| 85 | #endif | ||
| 84 | 86 | ||
| 85 | return rgb; | 87 | return rgb; |
| 86 | } | 88 | } |
diff --git a/quantum/quantum.c b/quantum/quantum.c index 8316d1f06..8c928441c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -274,10 +274,10 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 274 | #ifdef HAPTIC_ENABLE | 274 | #ifdef HAPTIC_ENABLE |
| 275 | process_haptic(keycode, record) && | 275 | process_haptic(keycode, record) && |
| 276 | #endif //HAPTIC_ENABLE | 276 | #endif //HAPTIC_ENABLE |
| 277 | process_record_kb(keycode, record) && | 277 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYREACTIVE_ENABLED) |
| 278 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES) | ||
| 279 | process_rgb_matrix(keycode, record) && | 278 | process_rgb_matrix(keycode, record) && |
| 280 | #endif | 279 | #endif |
| 280 | process_record_kb(keycode, record) && | ||
| 281 | #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) | 281 | #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) |
| 282 | process_midi(keycode, record) && | 282 | process_midi(keycode, record) && |
| 283 | #endif | 283 | #endif |
| @@ -1049,12 +1049,6 @@ void matrix_init_quantum() { | |||
| 1049 | matrix_init_kb(); | 1049 | matrix_init_kb(); |
| 1050 | } | 1050 | } |
| 1051 | 1051 | ||
| 1052 | uint8_t rgb_matrix_task_counter = 0; | ||
| 1053 | |||
| 1054 | #ifndef RGB_MATRIX_SKIP_FRAMES | ||
| 1055 | #define RGB_MATRIX_SKIP_FRAMES 1 | ||
| 1056 | #endif | ||
| 1057 | |||
| 1058 | void matrix_scan_quantum() { | 1052 | void matrix_scan_quantum() { |
| 1059 | #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) | 1053 | #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) |
| 1060 | matrix_scan_music(); | 1054 | matrix_scan_music(); |
| @@ -1078,10 +1072,6 @@ void matrix_scan_quantum() { | |||
| 1078 | 1072 | ||
| 1079 | #ifdef RGB_MATRIX_ENABLE | 1073 | #ifdef RGB_MATRIX_ENABLE |
| 1080 | rgb_matrix_task(); | 1074 | rgb_matrix_task(); |
| 1081 | if (rgb_matrix_task_counter == 0) { | ||
| 1082 | rgb_matrix_update_pwm_buffers(); | ||
| 1083 | } | ||
| 1084 | rgb_matrix_task_counter = ((rgb_matrix_task_counter + 1) % (RGB_MATRIX_SKIP_FRAMES + 1)); | ||
| 1085 | #endif | 1075 | #endif |
| 1086 | 1076 | ||
| 1087 | #ifdef ENCODER_ENABLE | 1077 | #ifdef ENCODER_ENABLE |
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 56a97e3c7..0728e2431 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
| @@ -24,62 +24,80 @@ | |||
| 24 | #include <string.h> | 24 | #include <string.h> |
| 25 | #include <math.h> | 25 | #include <math.h> |
| 26 | 26 | ||
| 27 | rgb_config_t rgb_matrix_config; | 27 | #include "lib/lib8tion/lib8tion.h" |
| 28 | |||
| 29 | #include "rgb_matrix_animations/solid_color_anim.h" | ||
| 30 | #include "rgb_matrix_animations/alpha_mods_anim.h" | ||
| 31 | #include "rgb_matrix_animations/dual_beacon_anim.h" | ||
| 32 | #include "rgb_matrix_animations/gradient_up_down_anim.h" | ||
| 33 | #include "rgb_matrix_animations/raindrops_anim.h" | ||
| 34 | #include "rgb_matrix_animations/cycle_all_anim.h" | ||
| 35 | #include "rgb_matrix_animations/cycle_left_right_anim.h" | ||
| 36 | #include "rgb_matrix_animations/cycle_up_down_anim.h" | ||
| 37 | #include "rgb_matrix_animations/rainbow_beacon_anim.h" | ||
| 38 | #include "rgb_matrix_animations/rainbow_pinwheels_anim.h" | ||
| 39 | #include "rgb_matrix_animations/rainbow_moving_chevron_anim.h" | ||
| 40 | #include "rgb_matrix_animations/jellybean_raindrops_anim.h" | ||
| 41 | #include "rgb_matrix_animations/digital_rain_anim.h" | ||
| 42 | #include "rgb_matrix_animations/solid_reactive_simple_anim.h" | ||
| 43 | #include "rgb_matrix_animations/solid_reactive_anim.h" | ||
| 44 | #include "rgb_matrix_animations/splash_anim.h" | ||
| 45 | #include "rgb_matrix_animations/solid_splash_anim.h" | ||
| 46 | #include "rgb_matrix_animations/breathing_anim.h" | ||
| 28 | 47 | ||
| 29 | #ifndef MAX | 48 | #ifndef RGB_DISABLE_AFTER_TIMEOUT |
| 30 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) | 49 | #define RGB_DISABLE_AFTER_TIMEOUT 0 |
| 31 | #endif | 50 | #endif |
| 32 | 51 | ||
| 33 | #ifndef MIN | 52 | #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED |
| 34 | #define MIN(a,b) ((a) < (b)? (a): (b)) | 53 | #define RGB_DISABLE_WHEN_USB_SUSPENDED false |
| 35 | #endif | 54 | #endif |
| 36 | 55 | ||
| 37 | #ifndef RGB_DISABLE_AFTER_TIMEOUT | 56 | #ifndef EECONFIG_RGB_MATRIX |
| 38 | #define RGB_DISABLE_AFTER_TIMEOUT 0 | 57 | #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT |
| 39 | #endif | 58 | #endif |
| 40 | 59 | ||
| 41 | #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED | 60 | #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX |
| 42 | #define RGB_DISABLE_WHEN_USB_SUSPENDED false | 61 | #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS |
| 62 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX | ||
| 43 | #endif | 63 | #endif |
| 44 | 64 | ||
| 45 | #ifndef EECONFIG_RGB_MATRIX | 65 | #if !defined(RGB_MATRIX_HUE_STEP) |
| 46 | #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT | 66 | #define RGB_MATRIX_HUE_STEP 8 |
| 47 | #endif | 67 | #endif |
| 48 | 68 | ||
| 49 | #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > 255 | 69 | #if !defined(RGB_MATRIX_SAT_STEP) |
| 50 | #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255 | 70 | #define RGB_MATRIX_SAT_STEP 16 |
| 51 | #endif | 71 | #endif |
| 52 | 72 | ||
| 53 | #ifndef RGB_DIGITAL_RAIN_DROPS | 73 | #if !defined(RGB_MATRIX_VAL_STEP) |
| 54 | // lower the number for denser effect/wider keyboard | 74 | #define RGB_MATRIX_VAL_STEP 16 |
| 55 | #define RGB_DIGITAL_RAIN_DROPS 24 | ||
| 56 | #endif | 75 | #endif |
| 57 | 76 | ||
| 58 | #if !defined(DISABLE_RGB_MATRIX_RAINDROPS) || !defined(DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS) || !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) | 77 | #if !defined(RGB_MATRIX_SPD_STEP) |
| 59 | #define TRACK_PREVIOUS_EFFECT | 78 | #define RGB_MATRIX_SPD_STEP 16 |
| 60 | #endif | 79 | #endif |
| 61 | 80 | ||
| 62 | bool g_suspend_state = false; | 81 | bool g_suspend_state = false; |
| 63 | 82 | ||
| 64 | // Global tick at 20 Hz | 83 | rgb_config_t rgb_matrix_config; |
| 65 | uint32_t g_tick = 0; | ||
| 66 | |||
| 67 | // Ticks since this key was last hit. | ||
| 68 | uint8_t g_key_hit[DRIVER_LED_TOTAL]; | ||
| 69 | 84 | ||
| 70 | // Ticks since any key was last hit. | 85 | rgb_counters_t g_rgb_counters; |
| 71 | uint32_t g_any_key_hit = 0; | 86 | static uint32_t rgb_counters_buffer; |
| 72 | 87 | ||
| 73 | #ifndef PI | 88 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 74 | #define PI 3.14159265 | 89 | last_hit_t g_last_hit_tracker; |
| 75 | #endif | 90 | static last_hit_t last_hit_buffer; |
| 91 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 76 | 92 | ||
| 77 | uint32_t eeconfig_read_rgb_matrix(void) { | 93 | uint32_t eeconfig_read_rgb_matrix(void) { |
| 78 | return eeprom_read_dword(EECONFIG_RGB_MATRIX); | 94 | return eeprom_read_dword(EECONFIG_RGB_MATRIX); |
| 79 | } | 95 | } |
| 96 | |||
| 80 | void eeconfig_update_rgb_matrix(uint32_t val) { | 97 | void eeconfig_update_rgb_matrix(uint32_t val) { |
| 81 | eeprom_update_dword(EECONFIG_RGB_MATRIX, val); | 98 | eeprom_update_dword(EECONFIG_RGB_MATRIX, val); |
| 82 | } | 99 | } |
| 100 | |||
| 83 | void eeconfig_update_rgb_matrix_default(void) { | 101 | void eeconfig_update_rgb_matrix_default(void) { |
| 84 | dprintf("eeconfig_update_rgb_matrix_default\n"); | 102 | dprintf("eeconfig_update_rgb_matrix_default\n"); |
| 85 | rgb_matrix_config.enable = 1; | 103 | rgb_matrix_config.enable = 1; |
| @@ -90,11 +108,12 @@ void eeconfig_update_rgb_matrix_default(void) { | |||
| 90 | rgb_matrix_config.mode = RGB_MATRIX_SOLID_COLOR; | 108 | rgb_matrix_config.mode = RGB_MATRIX_SOLID_COLOR; |
| 91 | #endif | 109 | #endif |
| 92 | rgb_matrix_config.hue = 0; | 110 | rgb_matrix_config.hue = 0; |
| 93 | rgb_matrix_config.sat = 255; | 111 | rgb_matrix_config.sat = UINT8_MAX; |
| 94 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | 112 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; |
| 95 | rgb_matrix_config.speed = 0; | 113 | rgb_matrix_config.speed = UINT8_MAX / 2; |
| 96 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 114 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 97 | } | 115 | } |
| 116 | |||
| 98 | void eeconfig_debug_rgb_matrix(void) { | 117 | void eeconfig_debug_rgb_matrix(void) { |
| 99 | dprintf("rgb_matrix_config eprom\n"); | 118 | dprintf("rgb_matrix_config eprom\n"); |
| 100 | dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); | 119 | dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); |
| @@ -105,710 +124,330 @@ void eeconfig_debug_rgb_matrix(void) { | |||
| 105 | dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); | 124 | dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); |
| 106 | } | 125 | } |
| 107 | 126 | ||
| 108 | // Last led hit | 127 | uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { |
| 109 | #define LED_HITS_TO_REMEMBER 8 | 128 | // TODO: This is kinda expensive, fix this soonish |
| 110 | uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; | 129 | uint8_t led_count = 0; |
| 111 | uint8_t g_last_led_count = 0; | 130 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL && led_count < LED_HITS_TO_REMEMBER; i++) { |
| 112 | 131 | matrix_co_t matrix_co = g_rgb_leds[i].matrix_co; | |
| 113 | void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) { | 132 | if (row == matrix_co.row && column == matrix_co.col) { |
| 114 | rgb_led led; | 133 | led_i[led_count] = i; |
| 115 | *led_count = 0; | 134 | led_count++; |
| 116 | |||
| 117 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 118 | // map_index_to_led(i, &led); | ||
| 119 | led = g_rgb_leds[i]; | ||
| 120 | if (row == led.matrix_co.row && column == led.matrix_co.col) { | ||
| 121 | led_i[*led_count] = i; | ||
| 122 | (*led_count)++; | ||
| 123 | } | ||
| 124 | } | 135 | } |
| 136 | } | ||
| 137 | return led_count; | ||
| 125 | } | 138 | } |
| 126 | 139 | ||
| 127 | void rgb_matrix_update_pwm_buffers(void) { | 140 | void rgb_matrix_update_pwm_buffers(void) { |
| 128 | rgb_matrix_driver.flush(); | 141 | rgb_matrix_driver.flush(); |
| 129 | } | 142 | } |
| 130 | 143 | ||
| 131 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { | 144 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) { |
| 132 | rgb_matrix_driver.set_color(index, red, green, blue); | 145 | rgb_matrix_driver.set_color(index, red, green, blue); |
| 133 | } | 146 | } |
| 134 | 147 | ||
| 135 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { | 148 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) { |
| 136 | rgb_matrix_driver.set_color_all(red, green, blue); | 149 | rgb_matrix_driver.set_color_all(red, green, blue); |
| 137 | } | 150 | } |
| 138 | 151 | ||
| 139 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { | 152 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { |
| 140 | if ( record->event.pressed ) { | 153 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 141 | uint8_t led[8], led_count; | 154 | uint8_t led[LED_HITS_TO_REMEMBER]; |
| 142 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); | 155 | uint8_t led_count = 0; |
| 143 | if (led_count > 0) { | 156 | |
| 144 | for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { | 157 | #if defined(RGB_MATRIX_KEYRELEASES) |
| 145 | g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; | 158 | if (!record->event.pressed) { |
| 146 | } | 159 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); |
| 147 | g_last_led_hit[0] = led[0]; | 160 | g_rgb_counters.any_key_hit = 0; |
| 148 | g_last_led_count = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1); | 161 | } |
| 149 | } | 162 | #elif defined(RGB_MATRIX_KEYPRESSES) |
| 150 | for(uint8_t i = 0; i < led_count; i++) | 163 | if (record->event.pressed) { |
| 151 | g_key_hit[led[i]] = 0; | 164 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); |
| 152 | g_any_key_hit = 0; | 165 | g_rgb_counters.any_key_hit = 0; |
| 153 | } else { | 166 | } |
| 154 | #ifdef RGB_MATRIX_KEYRELEASES | 167 | #endif // defined(RGB_MATRIX_KEYRELEASES) |
| 155 | uint8_t led[8], led_count; | 168 | |
| 156 | map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); | 169 | if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { |
| 157 | for(uint8_t i = 0; i < led_count; i++) | 170 | memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); |
| 158 | g_key_hit[led[i]] = 255; | 171 | memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count); |
| 159 | 172 | memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit | |
| 160 | g_any_key_hit = 255; | 173 | memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count); |
| 161 | #endif | 174 | last_hit_buffer.count--; |
| 162 | } | 175 | } |
| 163 | return true; | ||
| 164 | } | ||
| 165 | 176 | ||
| 166 | void rgb_matrix_set_suspend_state(bool state) { | 177 | for(uint8_t i = 0; i < led_count; i++) { |
| 167 | g_suspend_state = state; | 178 | uint8_t index = last_hit_buffer.count; |
| 179 | last_hit_buffer.x[index] = g_rgb_leds[led[i]].point.x; | ||
| 180 | last_hit_buffer.y[index] = g_rgb_leds[led[i]].point.y; | ||
| 181 | last_hit_buffer.index[index] = led[i]; | ||
| 182 | last_hit_buffer.tick[index] = 0; | ||
| 183 | last_hit_buffer.count++; | ||
| 184 | } | ||
| 185 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 186 | return true; | ||
| 168 | } | 187 | } |
| 169 | 188 | ||
| 170 | void rgb_matrix_test(void) { | 189 | void rgb_matrix_test(void) { |
| 171 | // Mask out bits 4 and 5 | 190 | // Mask out bits 4 and 5 |
| 172 | // Increase the factor to make the test animation slower (and reduce to make it faster) | 191 | // Increase the factor to make the test animation slower (and reduce to make it faster) |
| 173 | uint8_t factor = 10; | 192 | uint8_t factor = 10; |
| 174 | switch ( (g_tick & (0b11 << factor)) >> factor ) | 193 | switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor ) |
| 175 | { | 194 | { |
| 176 | case 0: | 195 | case 0: { |
| 177 | { | 196 | rgb_matrix_set_color_all( 20, 0, 0 ); |
| 178 | rgb_matrix_set_color_all( 20, 0, 0 ); | 197 | break; |
| 179 | break; | ||
| 180 | } | ||
| 181 | case 1: | ||
| 182 | { | ||
| 183 | rgb_matrix_set_color_all( 0, 20, 0 ); | ||
| 184 | break; | ||
| 185 | } | ||
| 186 | case 2: | ||
| 187 | { | ||
| 188 | rgb_matrix_set_color_all( 0, 0, 20 ); | ||
| 189 | break; | ||
| 190 | } | ||
| 191 | case 3: | ||
| 192 | { | ||
| 193 | rgb_matrix_set_color_all( 20, 20, 20 ); | ||
| 194 | break; | ||
| 195 | } | ||
| 196 | } | 198 | } |
| 197 | } | 199 | case 1: { |
| 198 | 200 | rgb_matrix_set_color_all( 0, 20, 0 ); | |
| 199 | // All LEDs off | 201 | break; |
| 200 | void rgb_matrix_all_off(void) { | ||
| 201 | rgb_matrix_set_color_all( 0, 0, 0 ); | ||
| 202 | } | ||
| 203 | |||
| 204 | // Solid color | ||
| 205 | void rgb_matrix_solid_color(void) { | ||
| 206 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | ||
| 207 | RGB rgb = hsv_to_rgb( hsv ); | ||
| 208 | rgb_matrix_set_color_all( rgb.r, rgb.g, rgb.b ); | ||
| 209 | } | ||
| 210 | |||
| 211 | void rgb_matrix_solid_reactive(void) { | ||
| 212 | // Relies on hue being 8-bit and wrapping | ||
| 213 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 214 | { | ||
| 215 | uint16_t offset2 = g_key_hit[i]<<2; | ||
| 216 | offset2 = (offset2<=130) ? (130-offset2) : 0; | ||
| 217 | |||
| 218 | HSV hsv = { .h = rgb_matrix_config.hue+offset2, .s = 255, .v = rgb_matrix_config.val }; | ||
| 219 | RGB rgb = hsv_to_rgb( hsv ); | ||
| 220 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | void rgb_matrix_solid_reactive_simple(void) | ||
| 225 | { | ||
| 226 | HSV hsv = {.h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val}; | ||
| 227 | RGB rgb; | ||
| 228 | |||
| 229 | for (int i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 230 | uint16_t offset2 = g_key_hit[i] << 2; | ||
| 231 | offset2 = (offset2 <= 255) ? (255 - offset2) : 0; | ||
| 232 | hsv.v = offset2 * rgb_matrix_config.val / RGB_MATRIX_MAXIMUM_BRIGHTNESS; | ||
| 233 | rgb = hsv_to_rgb(hsv); | ||
| 234 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | // alphas = color1, mods = color2 | ||
| 239 | void rgb_matrix_alphas_mods(void) { | ||
| 240 | |||
| 241 | RGB rgb1 = hsv_to_rgb( (HSV){ .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); | ||
| 242 | RGB rgb2 = hsv_to_rgb( (HSV){ .h = (rgb_matrix_config.hue + 180) % 360, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); | ||
| 243 | |||
| 244 | rgb_led led; | ||
| 245 | for (int i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 246 | led = g_rgb_leds[i]; | ||
| 247 | if ( led.matrix_co.raw < 0xFF ) { | ||
| 248 | if ( led.modifier ) | ||
| 249 | { | ||
| 250 | rgb_matrix_set_color( i, rgb2.r, rgb2.g, rgb2.b ); | ||
| 251 | } | ||
| 252 | else | ||
| 253 | { | ||
| 254 | rgb_matrix_set_color( i, rgb1.r, rgb1.g, rgb1.b ); | ||
| 255 | } | ||
| 256 | } | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | void rgb_matrix_gradient_up_down(void) { | ||
| 261 | int16_t h1 = rgb_matrix_config.hue; | ||
| 262 | int16_t h2 = (rgb_matrix_config.hue + 180) % 360; | ||
| 263 | int16_t deltaH = h2 - h1; | ||
| 264 | |||
| 265 | // Take the shortest path between hues | ||
| 266 | if ( deltaH > 127 ) | ||
| 267 | { | ||
| 268 | deltaH -= 256; | ||
| 269 | } | ||
| 270 | else if ( deltaH < -127 ) | ||
| 271 | { | ||
| 272 | deltaH += 256; | ||
| 273 | } | ||
| 274 | // Divide delta by 4, this gives the delta per row | ||
| 275 | deltaH /= 4; | ||
| 276 | |||
| 277 | int16_t s1 = rgb_matrix_config.sat; | ||
| 278 | int16_t s2 = rgb_matrix_config.hue; | ||
| 279 | int16_t deltaS = ( s2 - s1 ) / 4; | ||
| 280 | |||
| 281 | HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val }; | ||
| 282 | RGB rgb; | ||
| 283 | Point point; | ||
| 284 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 285 | { | ||
| 286 | // map_led_to_point( i, &point ); | ||
| 287 | point = g_rgb_leds[i].point; | ||
| 288 | // The y range will be 0..64, map this to 0..4 | ||
| 289 | uint8_t y = (point.y>>4); | ||
| 290 | // Relies on hue being 8-bit and wrapping | ||
| 291 | hsv.h = rgb_matrix_config.hue + ( deltaH * y ); | ||
| 292 | hsv.s = rgb_matrix_config.sat + ( deltaS * y ); | ||
| 293 | rgb = hsv_to_rgb( hsv ); | ||
| 294 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | void rgb_matrix_raindrops(bool initialize) { | ||
| 299 | int16_t h1 = rgb_matrix_config.hue; | ||
| 300 | int16_t h2 = (rgb_matrix_config.hue + 180) % 360; | ||
| 301 | int16_t deltaH = h2 - h1; | ||
| 302 | deltaH /= 4; | ||
| 303 | |||
| 304 | // Take the shortest path between hues | ||
| 305 | if ( deltaH > 127 ) | ||
| 306 | { | ||
| 307 | deltaH -= 256; | ||
| 308 | } | 202 | } |
| 309 | else if ( deltaH < -127 ) | 203 | case 2: { |
| 310 | { | 204 | rgb_matrix_set_color_all( 0, 0, 20 ); |
| 311 | deltaH += 256; | 205 | break; |
| 312 | } | 206 | } |
| 313 | 207 | case 3: { | |
| 314 | int16_t s1 = rgb_matrix_config.sat; | 208 | rgb_matrix_set_color_all( 20, 20, 20 ); |
| 315 | int16_t s2 = rgb_matrix_config.sat; | 209 | break; |
| 316 | int16_t deltaS = ( s2 - s1 ) / 4; | ||
| 317 | |||
| 318 | HSV hsv; | ||
| 319 | RGB rgb; | ||
| 320 | |||
| 321 | // Change one LED every tick, make sure speed is not 0 | ||
| 322 | uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255; | ||
| 323 | |||
| 324 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 325 | { | ||
| 326 | // If initialize, all get set to random colors | ||
| 327 | // If not, all but one will stay the same as before. | ||
| 328 | if ( initialize || i == led_to_change ) | ||
| 329 | { | ||
| 330 | hsv.h = h1 + ( deltaH * ( rand() & 0x03 ) ); | ||
| 331 | hsv.s = s1 + ( deltaS * ( rand() & 0x03 ) ); | ||
| 332 | // Override brightness with global brightness control | ||
| 333 | hsv.v = rgb_matrix_config.val; | ||
| 334 | |||
| 335 | rgb = hsv_to_rgb( hsv ); | ||
| 336 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 337 | } | ||
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | void rgb_matrix_cycle_all(void) { | ||
| 342 | uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF; | ||
| 343 | |||
| 344 | rgb_led led; | ||
| 345 | |||
| 346 | // Relies on hue being 8-bit and wrapping | ||
| 347 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 348 | { | ||
| 349 | // map_index_to_led(i, &led); | ||
| 350 | led = g_rgb_leds[i]; | ||
| 351 | if (led.matrix_co.raw < 0xFF) { | ||
| 352 | uint16_t offset2 = g_key_hit[i]<<2; | ||
| 353 | offset2 = (offset2<=63) ? (63-offset2) : 0; | ||
| 354 | |||
| 355 | HSV hsv = { .h = offset+offset2, .s = 255, .v = rgb_matrix_config.val }; | ||
| 356 | RGB rgb = hsv_to_rgb( hsv ); | ||
| 357 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 358 | } | ||
| 359 | } | ||
| 360 | } | ||
| 361 | |||
| 362 | void rgb_matrix_cycle_left_right(void) { | ||
| 363 | uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF; | ||
| 364 | HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val }; | ||
| 365 | RGB rgb; | ||
| 366 | Point point; | ||
| 367 | rgb_led led; | ||
| 368 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 369 | { | ||
| 370 | // map_index_to_led(i, &led); | ||
| 371 | led = g_rgb_leds[i]; | ||
| 372 | if (led.matrix_co.raw < 0xFF) { | ||
| 373 | uint16_t offset2 = g_key_hit[i]<<2; | ||
| 374 | offset2 = (offset2<=63) ? (63-offset2) : 0; | ||
| 375 | |||
| 376 | // map_led_to_point( i, &point ); | ||
| 377 | point = g_rgb_leds[i].point; | ||
| 378 | // Relies on hue being 8-bit and wrapping | ||
| 379 | hsv.h = point.x + offset + offset2; | ||
| 380 | rgb = hsv_to_rgb( hsv ); | ||
| 381 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 382 | } | ||
| 383 | } | ||
| 384 | } | ||
| 385 | |||
| 386 | void rgb_matrix_cycle_up_down(void) { | ||
| 387 | uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF; | ||
| 388 | HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val }; | ||
| 389 | RGB rgb; | ||
| 390 | Point point; | ||
| 391 | rgb_led led; | ||
| 392 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 393 | { | ||
| 394 | // map_index_to_led(i, &led); | ||
| 395 | led = g_rgb_leds[i]; | ||
| 396 | if (led.matrix_co.raw < 0xFF) { | ||
| 397 | uint16_t offset2 = g_key_hit[i]<<2; | ||
| 398 | offset2 = (offset2<=63) ? (63-offset2) : 0; | ||
| 399 | |||
| 400 | // map_led_to_point( i, &point ); | ||
| 401 | point = g_rgb_leds[i].point; | ||
| 402 | // Relies on hue being 8-bit and wrapping | ||
| 403 | hsv.h = point.y + offset + offset2; | ||
| 404 | rgb = hsv_to_rgb( hsv ); | ||
| 405 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 406 | } | ||
| 407 | } | 210 | } |
| 211 | } | ||
| 408 | } | 212 | } |
| 409 | 213 | ||
| 214 | static bool rgb_matrix_none(effect_params_t* params) { | ||
| 215 | if (!params->init) { | ||
| 216 | return false; | ||
| 217 | } | ||
| 410 | 218 | ||
| 411 | void rgb_matrix_dual_beacon(void) { | 219 | RGB_MATRIX_USE_LIMITS(led_min, led_max); |
| 412 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 220 | for (uint8_t i = led_min; i < led_max; i++) { |
| 413 | RGB rgb; | 221 | rgb_matrix_set_color(i, 0, 0, 0); |
| 414 | Point point; | 222 | } |
| 415 | double cos_value = cos(g_tick * PI / 128) / 32; | 223 | return led_max < DRIVER_LED_TOTAL; |
| 416 | double sin_value = sin(g_tick * PI / 128) / 112; | ||
| 417 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 418 | point = g_rgb_leds[i].point; | ||
| 419 | hsv.h = ((point.y - 32.0)* cos_value + (point.x - 112.0) * sin_value) * (180) + rgb_matrix_config.hue; | ||
| 420 | rgb = hsv_to_rgb( hsv ); | ||
| 421 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 422 | } | ||
| 423 | } | 224 | } |
| 424 | 225 | ||
| 425 | void rgb_matrix_rainbow_beacon(void) { | 226 | static uint8_t rgb_last_enable = UINT8_MAX; |
| 426 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 227 | static uint8_t rgb_last_effect = UINT8_MAX; |
| 427 | RGB rgb; | 228 | static effect_params_t rgb_effect_params = { 0, 0 }; |
| 428 | Point point; | 229 | static rgb_task_states rgb_task_state = SYNCING; |
| 429 | double cos_value = cos(g_tick * PI / 128); | ||
| 430 | double sin_value = sin(g_tick * PI / 128); | ||
| 431 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 432 | point = g_rgb_leds[i].point; | ||
| 433 | 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; | ||
| 434 | rgb = hsv_to_rgb( hsv ); | ||
| 435 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 436 | } | ||
| 437 | } | ||
| 438 | 230 | ||
| 439 | void rgb_matrix_rainbow_pinwheels(void) { | 231 | static void rgb_task_timers(void) { |
| 440 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 232 | // Update double buffer timers |
| 441 | RGB rgb; | 233 | uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer); |
| 442 | Point point; | 234 | rgb_counters_buffer = timer_read32(); |
| 443 | double cos_value = cos(g_tick * PI / 128); | 235 | if (g_rgb_counters.any_key_hit < UINT32_MAX) { |
| 444 | double sin_value = sin(g_tick * PI / 128); | 236 | if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) { |
| 445 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | 237 | g_rgb_counters.any_key_hit = UINT32_MAX; |
| 446 | point = g_rgb_leds[i].point; | 238 | } else { |
| 447 | 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; | 239 | g_rgb_counters.any_key_hit += deltaTime; |
| 448 | rgb = hsv_to_rgb( hsv ); | ||
| 449 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 450 | } | 240 | } |
| 451 | } | 241 | } |
| 452 | 242 | ||
| 453 | void rgb_matrix_rainbow_moving_chevron(void) { | 243 | // Update double buffer last hit timers |
| 454 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | 244 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 455 | RGB rgb; | 245 | uint8_t count = last_hit_buffer.count; |
| 456 | Point point; | 246 | for (uint8_t i = 0; i < count; ++i) { |
| 457 | uint8_t r = 128; | 247 | if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { |
| 458 | double cos_value = cos(r * PI / 128); | 248 | last_hit_buffer.count--; |
| 459 | double sin_value = sin(r * PI / 128); | 249 | continue; |
| 460 | double multiplier = (g_tick / 256.0 * 224); | ||
| 461 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 462 | point = g_rgb_leds[i].point; | ||
| 463 | 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; | ||
| 464 | rgb = hsv_to_rgb( hsv ); | ||
| 465 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 466 | } | 250 | } |
| 467 | } | 251 | last_hit_buffer.tick[i] += deltaTime; |
| 468 | 252 | } | |
| 469 | 253 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | |
| 470 | void rgb_matrix_jellybean_raindrops( bool initialize ) { | 254 | } |
| 471 | HSV hsv; | 255 | |
| 472 | RGB rgb; | 256 | static void rgb_task_sync(void) { |
| 257 | // next task | ||
| 258 | if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT) | ||
| 259 | rgb_task_state = STARTING; | ||
| 260 | } | ||
| 261 | |||
| 262 | static void rgb_task_start(void) { | ||
| 263 | // reset iter | ||
| 264 | rgb_effect_params.iter = 0; | ||
| 265 | |||
| 266 | // update double buffers | ||
| 267 | g_rgb_counters.tick = rgb_counters_buffer; | ||
| 268 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 269 | g_last_hit_tracker = last_hit_buffer; | ||
| 270 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 271 | |||
| 272 | // next task | ||
| 273 | rgb_task_state = RENDERING; | ||
| 274 | } | ||
| 275 | |||
| 276 | static void rgb_task_render(uint8_t effect) { | ||
| 277 | bool rendering = false; | ||
| 278 | rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); | ||
| 279 | |||
| 280 | // each effect can opt to do calculations | ||
| 281 | // and/or request PWM buffer updates. | ||
| 282 | switch (effect) { | ||
| 283 | case RGB_MATRIX_NONE: | ||
| 284 | rendering = rgb_matrix_none(&rgb_effect_params); | ||
| 285 | break; | ||
| 286 | |||
| 287 | case RGB_MATRIX_SOLID_COLOR: | ||
| 288 | rendering = rgb_matrix_solid_color(&rgb_effect_params); // Max 1ms Avg 0ms | ||
| 289 | break; | ||
| 290 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS | ||
| 291 | case RGB_MATRIX_ALPHAS_MODS: | ||
| 292 | rendering = rgb_matrix_alphas_mods(&rgb_effect_params); // Max 2ms Avg 1ms | ||
| 293 | break; | ||
| 294 | #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS | ||
| 295 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN | ||
| 296 | case RGB_MATRIX_GRADIENT_UP_DOWN: | ||
| 297 | rendering = rgb_matrix_gradient_up_down(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 298 | break; | ||
| 299 | #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN | ||
| 300 | #ifndef DISABLE_RGB_MATRIX_BREATHING | ||
| 301 | case RGB_MATRIX_BREATHING: | ||
| 302 | rendering = rgb_matrix_breathing(&rgb_effect_params); // Max 1ms Avg 0ms | ||
| 303 | break; | ||
| 304 | #endif // DISABLE_RGB_MATRIX_BREATHING | ||
| 305 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 306 | case RGB_MATRIX_CYCLE_ALL: | ||
| 307 | rendering = rgb_matrix_cycle_all(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 308 | break; | ||
| 309 | #endif // DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 310 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | ||
| 311 | case RGB_MATRIX_CYCLE_LEFT_RIGHT: | ||
| 312 | rendering = rgb_matrix_cycle_left_right(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 313 | break; | ||
| 314 | #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | ||
| 315 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | ||
| 316 | case RGB_MATRIX_CYCLE_UP_DOWN: | ||
| 317 | rendering = rgb_matrix_cycle_up_down(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 318 | break; | ||
| 319 | #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | ||
| 320 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 321 | case RGB_MATRIX_RAINBOW_MOVING_CHEVRON: | ||
| 322 | rendering = rgb_matrix_rainbow_moving_chevron(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 323 | break; | ||
| 324 | #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 325 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 326 | case RGB_MATRIX_DUAL_BEACON: | ||
| 327 | rendering = rgb_matrix_dual_beacon(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 328 | break; | ||
| 329 | #endif // DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 330 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON | ||
| 331 | case RGB_MATRIX_RAINBOW_BEACON: | ||
| 332 | rendering = rgb_matrix_rainbow_beacon(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 333 | break; | ||
| 334 | #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON | ||
| 335 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | ||
| 336 | case RGB_MATRIX_RAINBOW_PINWHEELS: | ||
| 337 | rendering = rgb_matrix_rainbow_pinwheels(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 338 | break; | ||
| 339 | #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | ||
| 340 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS | ||
| 341 | case RGB_MATRIX_RAINDROPS: | ||
| 342 | rendering = rgb_matrix_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms | ||
| 343 | break; | ||
| 344 | #endif // DISABLE_RGB_MATRIX_RAINDROPS | ||
| 345 | #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | ||
| 346 | case RGB_MATRIX_JELLYBEAN_RAINDROPS: | ||
| 347 | rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms | ||
| 348 | break; | ||
| 349 | #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | ||
| 350 | #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN | ||
| 351 | case RGB_MATRIX_DIGITAL_RAIN: | ||
| 352 | rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it | ||
| 353 | break; | ||
| 354 | #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN | ||
| 355 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 356 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 357 | case RGB_MATRIX_SOLID_REACTIVE_SIMPLE: | ||
| 358 | rendering = rgb_matrix_solid_reactive_simple(&rgb_effect_params);// Max 4ms Avg 3ms | ||
| 359 | break; | ||
| 360 | #endif | ||
| 361 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE | ||
| 362 | case RGB_MATRIX_SOLID_REACTIVE: | ||
| 363 | rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms | ||
| 364 | break; | ||
| 365 | #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE | ||
| 366 | #ifndef DISABLE_RGB_MATRIX_SPLASH | ||
| 367 | case RGB_MATRIX_SPLASH: | ||
| 368 | rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms | ||
| 369 | break; | ||
| 370 | #endif // DISABLE_RGB_MATRIX_SPLASH | ||
| 371 | #ifndef DISABLE_RGB_MATRIX_MULTISPLASH | ||
| 372 | case RGB_MATRIX_MULTISPLASH: | ||
| 373 | rendering = rgb_matrix_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms | ||
| 374 | break; | ||
| 375 | #endif // DISABLE_RGB_MATRIX_MULTISPLASH | ||
| 376 | #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH | ||
| 377 | case RGB_MATRIX_SOLID_SPLASH: | ||
| 378 | rendering = rgb_matrix_solid_splash(&rgb_effect_params); // Max 5ms Avg 3ms | ||
| 379 | break; | ||
| 380 | #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH | ||
| 381 | #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH | ||
| 382 | case RGB_MATRIX_SOLID_MULTISPLASH: | ||
| 383 | rendering = rgb_matrix_solid_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms | ||
| 384 | break; | ||
| 385 | #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH | ||
| 386 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 473 | 387 | ||
| 474 | // Change one LED every tick, make sure speed is not 0 | 388 | // Factory default magic value |
| 475 | uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255; | 389 | case UINT8_MAX: { |
| 390 | rgb_matrix_test(); | ||
| 391 | rgb_task_state = FLUSHING; | ||
| 392 | } | ||
| 393 | return; | ||
| 394 | } | ||
| 476 | 395 | ||
| 477 | for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | 396 | rgb_effect_params.iter++; |
| 478 | { | ||
| 479 | // If initialize, all get set to random colors | ||
| 480 | // If not, all but one will stay the same as before. | ||
| 481 | if ( initialize || i == led_to_change ) | ||
| 482 | { | ||
| 483 | hsv.h = rand() & 0xFF; | ||
| 484 | hsv.s = rand() & 0xFF; | ||
| 485 | // Override brightness with global brightness control | ||
| 486 | hsv.v = rgb_matrix_config.val; | ||
| 487 | 397 | ||
| 488 | rgb = hsv_to_rgb( hsv ); | 398 | // next task |
| 489 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | 399 | if (!rendering) { |
| 490 | } | 400 | rgb_task_state = FLUSHING; |
| 401 | if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) { | ||
| 402 | // We only need to flush once if we are RGB_MATRIX_NONE | ||
| 403 | rgb_task_state = SYNCING; | ||
| 491 | } | 404 | } |
| 405 | } | ||
| 492 | } | 406 | } |
| 493 | 407 | ||
| 494 | void rgb_matrix_digital_rain( const bool initialize ) { | 408 | static void rgb_task_flush(uint8_t effect) { |
| 495 | // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain | 409 | // update last trackers after the first full render so we can init over several frames |
| 496 | const uint8_t drop_ticks = 28; | 410 | rgb_last_effect = effect; |
| 497 | const uint8_t pure_green_intensity = 0xd0; | 411 | rgb_last_enable = rgb_matrix_config.enable; |
| 498 | const uint8_t max_brightness_boost = 0xc0; | ||
| 499 | const uint8_t max_intensity = 0xff; | ||
| 500 | 412 | ||
| 501 | static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}}; | 413 | // update pwm buffers |
| 502 | static uint8_t drop = 0; | 414 | rgb_matrix_update_pwm_buffers(); |
| 503 | |||
| 504 | if (initialize) { | ||
| 505 | rgb_matrix_set_color_all(0, 0, 0); | ||
| 506 | memset(map, 0, sizeof map); | ||
| 507 | drop = 0; | ||
| 508 | } | ||
| 509 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 510 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 511 | if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { | ||
| 512 | // top row, pixels have just fallen and we're | ||
| 513 | // making a new rain drop in this column | ||
| 514 | map[col][row] = max_intensity; | ||
| 515 | } | ||
| 516 | else if (map[col][row] > 0 && map[col][row] < max_intensity) { | ||
| 517 | // neither fully bright nor dark, decay it | ||
| 518 | map[col][row]--; | ||
| 519 | } | ||
| 520 | // set the pixel colour | ||
| 521 | uint8_t led, led_count; | ||
| 522 | map_row_column_to_led(row, col, &led, &led_count); | ||
| 523 | |||
| 524 | if (map[col][row] > pure_green_intensity) { | ||
| 525 | const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost | ||
| 526 | * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity)); | ||
| 527 | rgb_matrix_set_color(led, boost, max_intensity, boost); | ||
| 528 | } | ||
| 529 | else { | ||
| 530 | const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity); | ||
| 531 | rgb_matrix_set_color(led, 0, green, 0); | ||
| 532 | } | ||
| 533 | } | ||
| 534 | } | ||
| 535 | if (++drop > drop_ticks) { | ||
| 536 | // reset drop timer | ||
| 537 | drop = 0; | ||
| 538 | for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { | ||
| 539 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 540 | // if ths is on the bottom row and bright allow decay | ||
| 541 | if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) { | ||
| 542 | map[col][row]--; | ||
| 543 | } | ||
| 544 | // check if the pixel above is bright | ||
| 545 | if (map[col][row - 1] == max_intensity) { | ||
| 546 | // allow old bright pixel to decay | ||
| 547 | map[col][row - 1]--; | ||
| 548 | // make this pixel bright | ||
| 549 | map[col][row] = max_intensity; | ||
| 550 | } | ||
| 551 | } | ||
| 552 | } | ||
| 553 | } | ||
| 554 | } | ||
| 555 | 415 | ||
| 556 | void rgb_matrix_multisplash(void) { | 416 | // next task |
| 557 | // if (g_any_key_hit < 0xFF) { | 417 | rgb_task_state = SYNCING; |
| 558 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | ||
| 559 | RGB rgb; | ||
| 560 | rgb_led led; | ||
| 561 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 562 | led = g_rgb_leds[i]; | ||
| 563 | uint16_t c = 0, d = 0; | ||
| 564 | rgb_led last_led; | ||
| 565 | // if (g_last_led_count) { | ||
| 566 | for (uint8_t last_i = 0; last_i < g_last_led_count; last_i++) { | ||
| 567 | last_led = g_rgb_leds[g_last_led_hit[last_i]]; | ||
| 568 | uint16_t dist = (uint16_t)sqrt(pow(led.point.x - last_led.point.x, 2) + pow(led.point.y - last_led.point.y, 2)); | ||
| 569 | uint16_t effect = (g_key_hit[g_last_led_hit[last_i]] << 2) - dist; | ||
| 570 | c += MIN(MAX(effect, 0), 255); | ||
| 571 | d += 255 - MIN(MAX(effect, 0), 255); | ||
| 572 | } | ||
| 573 | // } else { | ||
| 574 | // d = 255; | ||
| 575 | // } | ||
| 576 | hsv.h = (rgb_matrix_config.hue + c) % 256; | ||
| 577 | hsv.v = MAX(MIN(d, 255), 0); | ||
| 578 | rgb = hsv_to_rgb( hsv ); | ||
| 579 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 580 | } | ||
| 581 | // } else { | ||
| 582 | // rgb_matrix_set_color_all( 0, 0, 0 ); | ||
| 583 | // } | ||
| 584 | } | ||
| 585 | |||
| 586 | |||
| 587 | void rgb_matrix_splash(void) { | ||
| 588 | g_last_led_count = MIN(g_last_led_count, 1); | ||
| 589 | rgb_matrix_multisplash(); | ||
| 590 | } | ||
| 591 | |||
| 592 | |||
| 593 | void rgb_matrix_solid_multisplash(void) { | ||
| 594 | // if (g_any_key_hit < 0xFF) { | ||
| 595 | HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; | ||
| 596 | RGB rgb; | ||
| 597 | rgb_led led; | ||
| 598 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 599 | led = g_rgb_leds[i]; | ||
| 600 | uint16_t d = 0; | ||
| 601 | rgb_led last_led; | ||
| 602 | // if (g_last_led_count) { | ||
| 603 | for (uint8_t last_i = 0; last_i < g_last_led_count; last_i++) { | ||
| 604 | last_led = g_rgb_leds[g_last_led_hit[last_i]]; | ||
| 605 | uint16_t dist = (uint16_t)sqrt(pow(led.point.x - last_led.point.x, 2) + pow(led.point.y - last_led.point.y, 2)); | ||
| 606 | uint16_t effect = (g_key_hit[g_last_led_hit[last_i]] << 2) - dist; | ||
| 607 | d += 255 - MIN(MAX(effect, 0), 255); | ||
| 608 | } | ||
| 609 | // } else { | ||
| 610 | // d = 255; | ||
| 611 | // } | ||
| 612 | hsv.v = MAX(MIN(d, 255), 0); | ||
| 613 | rgb = hsv_to_rgb( hsv ); | ||
| 614 | rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 615 | } | ||
| 616 | // } else { | ||
| 617 | // rgb_matrix_set_color_all( 0, 0, 0 ); | ||
| 618 | // } | ||
| 619 | } | ||
| 620 | |||
| 621 | |||
| 622 | void rgb_matrix_solid_splash(void) { | ||
| 623 | g_last_led_count = MIN(g_last_led_count, 1); | ||
| 624 | rgb_matrix_solid_multisplash(); | ||
| 625 | } | ||
| 626 | |||
| 627 | |||
| 628 | // Needs eeprom access that we don't have setup currently | ||
| 629 | |||
| 630 | void rgb_matrix_custom(void) { | ||
| 631 | // HSV hsv; | ||
| 632 | // RGB rgb; | ||
| 633 | // for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) | ||
| 634 | // { | ||
| 635 | // backlight_get_key_color(i, &hsv); | ||
| 636 | // // Override brightness with global brightness control | ||
| 637 | // hsv.v = rgb_matrix_config.val; | ||
| 638 | // rgb = hsv_to_rgb( hsv ); | ||
| 639 | // rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); | ||
| 640 | // } | ||
| 641 | } | 418 | } |
| 642 | 419 | ||
| 643 | void rgb_matrix_task(void) { | 420 | void rgb_matrix_task(void) { |
| 644 | #ifdef TRACK_PREVIOUS_EFFECT | 421 | rgb_task_timers(); |
| 645 | static uint8_t toggle_enable_last = 255; | 422 | |
| 646 | #endif | 423 | // Ideally we would also stop sending zeros to the LED driver PWM buffers |
| 647 | if (!rgb_matrix_config.enable) { | 424 | // while suspended and just do a software shutdown. This is a cheap hack for now. |
| 648 | rgb_matrix_all_off(); | 425 | bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); |
| 649 | rgb_matrix_indicators(); | 426 | uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; |
| 650 | #ifdef TRACK_PREVIOUS_EFFECT | 427 | |
| 651 | toggle_enable_last = rgb_matrix_config.enable; | 428 | switch (rgb_task_state) { |
| 652 | #endif | 429 | case STARTING: |
| 653 | return; | 430 | rgb_task_start(); |
| 654 | } | 431 | break; |
| 655 | // delay 1 second before driving LEDs or doing anything else | 432 | case RENDERING: |
| 656 | static uint8_t startup_tick = 0; | 433 | rgb_task_render(effect); |
| 657 | if ( startup_tick < 20 ) { | 434 | break; |
| 658 | startup_tick++; | 435 | case FLUSHING: |
| 659 | return; | 436 | rgb_task_flush(effect); |
| 660 | } | 437 | break; |
| 661 | 438 | case SYNCING: | |
| 662 | g_tick++; | 439 | rgb_task_sync(); |
| 663 | 440 | break; | |
| 664 | if ( g_any_key_hit < 0xFFFFFFFF ) { | 441 | } |
| 665 | g_any_key_hit++; | ||
| 666 | } | ||
| 667 | |||
| 668 | for ( int led = 0; led < DRIVER_LED_TOTAL; led++ ) { | ||
| 669 | if ( g_key_hit[led] < 255 ) { | ||
| 670 | if (g_key_hit[led] == 254) | ||
| 671 | g_last_led_count = MAX(g_last_led_count - 1, 0); | ||
| 672 | g_key_hit[led]++; | ||
| 673 | } | ||
| 674 | } | ||
| 675 | |||
| 676 | // Factory default magic value | ||
| 677 | if ( rgb_matrix_config.mode == 255 ) { | ||
| 678 | rgb_matrix_test(); | ||
| 679 | return; | ||
| 680 | } | ||
| 681 | |||
| 682 | // Ideally we would also stop sending zeros to the LED driver PWM buffers | ||
| 683 | // while suspended and just do a software shutdown. This is a cheap hack for now. | ||
| 684 | bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || | ||
| 685 | (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); | ||
| 686 | uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode; | ||
| 687 | |||
| 688 | #ifdef TRACK_PREVIOUS_EFFECT | ||
| 689 | // Keep track of the effect used last time, | ||
| 690 | // detect change in effect, so each effect can | ||
| 691 | // have an optional initialization. | ||
| 692 | |||
| 693 | static uint8_t effect_last = 255; | ||
| 694 | bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last); | ||
| 695 | effect_last = effect; | ||
| 696 | toggle_enable_last = rgb_matrix_config.enable; | ||
| 697 | #endif | ||
| 698 | |||
| 699 | // this gets ticked at 20 Hz. | ||
| 700 | // each effect can opt to do calculations | ||
| 701 | // and/or request PWM buffer updates. | ||
| 702 | switch ( effect ) { | ||
| 703 | case RGB_MATRIX_SOLID_COLOR: | ||
| 704 | rgb_matrix_solid_color(); | ||
| 705 | break; | ||
| 706 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS | ||
| 707 | case RGB_MATRIX_ALPHAS_MODS: | ||
| 708 | rgb_matrix_alphas_mods(); | ||
| 709 | break; | ||
| 710 | #endif | ||
| 711 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 712 | case RGB_MATRIX_DUAL_BEACON: | ||
| 713 | rgb_matrix_dual_beacon(); | ||
| 714 | break; | ||
| 715 | #endif | ||
| 716 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN | ||
| 717 | case RGB_MATRIX_GRADIENT_UP_DOWN: | ||
| 718 | rgb_matrix_gradient_up_down(); | ||
| 719 | break; | ||
| 720 | #endif | ||
| 721 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS | ||
| 722 | case RGB_MATRIX_RAINDROPS: | ||
| 723 | rgb_matrix_raindrops( initialize ); | ||
| 724 | break; | ||
| 725 | #endif | ||
| 726 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 727 | case RGB_MATRIX_CYCLE_ALL: | ||
| 728 | rgb_matrix_cycle_all(); | ||
| 729 | break; | ||
| 730 | #endif | ||
| 731 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | ||
| 732 | case RGB_MATRIX_CYCLE_LEFT_RIGHT: | ||
| 733 | rgb_matrix_cycle_left_right(); | ||
| 734 | break; | ||
| 735 | #endif | ||
| 736 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | ||
| 737 | case RGB_MATRIX_CYCLE_UP_DOWN: | ||
| 738 | rgb_matrix_cycle_up_down(); | ||
| 739 | break; | ||
| 740 | #endif | ||
| 741 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON | ||
| 742 | case RGB_MATRIX_RAINBOW_BEACON: | ||
| 743 | rgb_matrix_rainbow_beacon(); | ||
| 744 | break; | ||
| 745 | #endif | ||
| 746 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | ||
| 747 | case RGB_MATRIX_RAINBOW_PINWHEELS: | ||
| 748 | rgb_matrix_rainbow_pinwheels(); | ||
| 749 | break; | ||
| 750 | #endif | ||
| 751 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 752 | case RGB_MATRIX_RAINBOW_MOVING_CHEVRON: | ||
| 753 | rgb_matrix_rainbow_moving_chevron(); | ||
| 754 | break; | ||
| 755 | #endif | ||
| 756 | #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | ||
| 757 | case RGB_MATRIX_JELLYBEAN_RAINDROPS: | ||
| 758 | rgb_matrix_jellybean_raindrops( initialize ); | ||
| 759 | break; | ||
| 760 | #endif | ||
| 761 | #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN | ||
| 762 | case RGB_MATRIX_DIGITAL_RAIN: | ||
| 763 | rgb_matrix_digital_rain( initialize ); | ||
| 764 | break; | ||
| 765 | #endif | ||
| 766 | #ifdef RGB_MATRIX_KEYPRESSES | ||
| 767 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE | ||
| 768 | case RGB_MATRIX_SOLID_REACTIVE: | ||
| 769 | rgb_matrix_solid_reactive(); | ||
| 770 | break; | ||
| 771 | #endif | ||
| 772 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 773 | case RGB_MATRIX_SOLID_REACTIVE_SIMPLE: | ||
| 774 | rgb_matrix_solid_reactive_simple(); | ||
| 775 | break; | ||
| 776 | #endif | ||
| 777 | #ifndef DISABLE_RGB_MATRIX_SPLASH | ||
| 778 | case RGB_MATRIX_SPLASH: | ||
| 779 | rgb_matrix_splash(); | ||
| 780 | break; | ||
| 781 | #endif | ||
| 782 | #ifndef DISABLE_RGB_MATRIX_MULTISPLASH | ||
| 783 | case RGB_MATRIX_MULTISPLASH: | ||
| 784 | rgb_matrix_multisplash(); | ||
| 785 | break; | ||
| 786 | #endif | ||
| 787 | #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH | ||
| 788 | case RGB_MATRIX_SOLID_SPLASH: | ||
| 789 | rgb_matrix_solid_splash(); | ||
| 790 | break; | ||
| 791 | #endif | ||
| 792 | #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH | ||
| 793 | case RGB_MATRIX_SOLID_MULTISPLASH: | ||
| 794 | rgb_matrix_solid_multisplash(); | ||
| 795 | break; | ||
| 796 | #endif | ||
| 797 | #endif | ||
| 798 | default: | ||
| 799 | rgb_matrix_custom(); | ||
| 800 | break; | ||
| 801 | } | ||
| 802 | |||
| 803 | if ( ! suspend_backlight ) { | ||
| 804 | rgb_matrix_indicators(); | ||
| 805 | } | ||
| 806 | 442 | ||
| 443 | if (!suspend_backlight) { | ||
| 444 | rgb_matrix_indicators(); | ||
| 445 | } | ||
| 807 | } | 446 | } |
| 808 | 447 | ||
| 809 | void rgb_matrix_indicators(void) { | 448 | void rgb_matrix_indicators(void) { |
| 810 | rgb_matrix_indicators_kb(); | 449 | rgb_matrix_indicators_kb(); |
| 811 | rgb_matrix_indicators_user(); | 450 | rgb_matrix_indicators_user(); |
| 812 | } | 451 | } |
| 813 | 452 | ||
| 814 | __attribute__((weak)) | 453 | __attribute__((weak)) |
| @@ -817,103 +456,54 @@ void rgb_matrix_indicators_kb(void) {} | |||
| 817 | __attribute__((weak)) | 456 | __attribute__((weak)) |
| 818 | void rgb_matrix_indicators_user(void) {} | 457 | void rgb_matrix_indicators_user(void) {} |
| 819 | 458 | ||
| 820 | |||
| 821 | // void rgb_matrix_set_indicator_index( uint8_t *index, uint8_t row, uint8_t column ) | ||
| 822 | // { | ||
| 823 | // if ( row >= MATRIX_ROWS ) | ||
| 824 | // { | ||
| 825 | // // Special value, 255=none, 254=all | ||
| 826 | // *index = row; | ||
| 827 | // } | ||
| 828 | // else | ||
| 829 | // { | ||
| 830 | // // This needs updated to something like | ||
| 831 | // // uint8_t led[8], led_count; | ||
| 832 | // // map_row_column_to_led(row,column,led,&led_count); | ||
| 833 | // // for(uint8_t i = 0; i < led_count; i++) | ||
| 834 | // map_row_column_to_led( row, column, index ); | ||
| 835 | // } | ||
| 836 | // } | ||
| 837 | |||
| 838 | void rgb_matrix_init(void) { | 459 | void rgb_matrix_init(void) { |
| 839 | rgb_matrix_driver.init(); | 460 | rgb_matrix_driver.init(); |
| 840 | 461 | ||
| 841 | // TODO: put the 1 second startup delay here? | 462 | // TODO: put the 1 second startup delay here? |
| 842 | 463 | ||
| 843 | // clear the key hits | 464 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 844 | for ( int led=0; led<DRIVER_LED_TOTAL; led++ ) { | 465 | g_last_hit_tracker.count = 0; |
| 845 | g_key_hit[led] = 255; | 466 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { |
| 467 | g_last_hit_tracker.tick[i] = UINT16_MAX; | ||
| 846 | } | 468 | } |
| 847 | 469 | ||
| 470 | last_hit_buffer.count = 0; | ||
| 471 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { | ||
| 472 | last_hit_buffer.tick[i] = UINT16_MAX; | ||
| 473 | } | ||
| 474 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 848 | 475 | ||
| 849 | if (!eeconfig_is_enabled()) { | 476 | if (!eeconfig_is_enabled()) { |
| 850 | dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); | 477 | dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n"); |
| 851 | eeconfig_init(); | 478 | eeconfig_init(); |
| 852 | eeconfig_update_rgb_matrix_default(); | 479 | eeconfig_update_rgb_matrix_default(); |
| 853 | } | 480 | } |
| 481 | |||
| 854 | rgb_matrix_config.raw = eeconfig_read_rgb_matrix(); | 482 | rgb_matrix_config.raw = eeconfig_read_rgb_matrix(); |
| 483 | rgb_matrix_config.speed = UINT8_MAX / 2; //EECONFIG needs to be increased to support this | ||
| 855 | if (!rgb_matrix_config.mode) { | 484 | if (!rgb_matrix_config.mode) { |
| 856 | dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); | 485 | dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); |
| 857 | eeconfig_update_rgb_matrix_default(); | 486 | eeconfig_update_rgb_matrix_default(); |
| 858 | rgb_matrix_config.raw = eeconfig_read_rgb_matrix(); | 487 | rgb_matrix_config.raw = eeconfig_read_rgb_matrix(); |
| 859 | } | 488 | } |
| 860 | eeconfig_debug_rgb_matrix(); // display current eeprom values | 489 | eeconfig_debug_rgb_matrix(); // display current eeprom values |
| 861 | } | 490 | } |
| 862 | 491 | ||
| 863 | // Deals with the messy details of incrementing an integer | 492 | void rgb_matrix_set_suspend_state(bool state) { |
| 864 | static uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | 493 | g_suspend_state = state; |
| 865 | int16_t new_value = value; | ||
| 866 | new_value += step; | ||
| 867 | return MIN( MAX( new_value, min ), max ); | ||
| 868 | } | ||
| 869 | |||
| 870 | static uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | ||
| 871 | int16_t new_value = value; | ||
| 872 | new_value -= step; | ||
| 873 | return MIN( MAX( new_value, min ), max ); | ||
| 874 | } | ||
| 875 | |||
| 876 | // void *backlight_get_custom_key_color_eeprom_address( uint8_t led ) | ||
| 877 | // { | ||
| 878 | // // 3 bytes per color | ||
| 879 | // return EECONFIG_RGB_MATRIX + ( led * 3 ); | ||
| 880 | // } | ||
| 881 | |||
| 882 | // void backlight_get_key_color( uint8_t led, HSV *hsv ) | ||
| 883 | // { | ||
| 884 | // void *address = backlight_get_custom_key_color_eeprom_address( led ); | ||
| 885 | // hsv->h = eeprom_read_byte(address); | ||
| 886 | // hsv->s = eeprom_read_byte(address+1); | ||
| 887 | // hsv->v = eeprom_read_byte(address+2); | ||
| 888 | // } | ||
| 889 | |||
| 890 | // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv ) | ||
| 891 | // { | ||
| 892 | // uint8_t led[8], led_count; | ||
| 893 | // map_row_column_to_led(row,column,led,&led_count); | ||
| 894 | // for(uint8_t i = 0; i < led_count; i++) { | ||
| 895 | // if ( led[i] < DRIVER_LED_TOTAL ) | ||
| 896 | // { | ||
| 897 | // void *address = backlight_get_custom_key_color_eeprom_address(led[i]); | ||
| 898 | // eeprom_update_byte(address, hsv.h); | ||
| 899 | // eeprom_update_byte(address+1, hsv.s); | ||
| 900 | // eeprom_update_byte(address+2, hsv.v); | ||
| 901 | // } | ||
| 902 | // } | ||
| 903 | // } | ||
| 904 | |||
| 905 | uint32_t rgb_matrix_get_tick(void) { | ||
| 906 | return g_tick; | ||
| 907 | } | 494 | } |
| 908 | 495 | ||
| 909 | void rgb_matrix_toggle(void) { | 496 | void rgb_matrix_toggle(void) { |
| 910 | rgb_matrix_config.enable ^= 1; | 497 | rgb_matrix_config.enable ^= 1; |
| 911 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 498 | if (!rgb_matrix_config.enable) { |
| 499 | rgb_task_state = STARTING; | ||
| 500 | } | ||
| 501 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 912 | } | 502 | } |
| 913 | 503 | ||
| 914 | void rgb_matrix_enable(void) { | 504 | void rgb_matrix_enable(void) { |
| 915 | rgb_matrix_config.enable = 1; | 505 | rgb_matrix_config.enable = 1; |
| 916 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 506 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 917 | } | 507 | } |
| 918 | 508 | ||
| 919 | void rgb_matrix_enable_noeeprom(void) { | 509 | void rgb_matrix_enable_noeeprom(void) { |
| @@ -922,7 +512,7 @@ void rgb_matrix_enable_noeeprom(void) { | |||
| 922 | 512 | ||
| 923 | void rgb_matrix_disable(void) { | 513 | void rgb_matrix_disable(void) { |
| 924 | rgb_matrix_config.enable = 0; | 514 | rgb_matrix_config.enable = 0; |
| 925 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 515 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 926 | } | 516 | } |
| 927 | 517 | ||
| 928 | void rgb_matrix_disable_noeeprom(void) { | 518 | void rgb_matrix_disable_noeeprom(void) { |
| @@ -930,76 +520,79 @@ void rgb_matrix_disable_noeeprom(void) { | |||
| 930 | } | 520 | } |
| 931 | 521 | ||
| 932 | void rgb_matrix_step(void) { | 522 | void rgb_matrix_step(void) { |
| 933 | rgb_matrix_config.mode++; | 523 | rgb_matrix_config.mode++; |
| 934 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) | 524 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) |
| 935 | rgb_matrix_config.mode = 1; | 525 | rgb_matrix_config.mode = 1; |
| 936 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 526 | rgb_task_state = STARTING; |
| 527 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 937 | } | 528 | } |
| 938 | 529 | ||
| 939 | void rgb_matrix_step_reverse(void) { | 530 | void rgb_matrix_step_reverse(void) { |
| 940 | rgb_matrix_config.mode--; | 531 | rgb_matrix_config.mode--; |
| 941 | if (rgb_matrix_config.mode < 1) | 532 | if (rgb_matrix_config.mode < 1) |
| 942 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; | 533 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; |
| 943 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 534 | rgb_task_state = STARTING; |
| 535 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 944 | } | 536 | } |
| 945 | 537 | ||
| 946 | void rgb_matrix_increase_hue(void) { | 538 | void rgb_matrix_increase_hue(void) { |
| 947 | rgb_matrix_config.hue = increment( rgb_matrix_config.hue, 8, 0, 255 ); | 539 | rgb_matrix_config.hue += RGB_MATRIX_HUE_STEP; |
| 948 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 540 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 949 | } | 541 | } |
| 950 | 542 | ||
| 951 | void rgb_matrix_decrease_hue(void) { | 543 | void rgb_matrix_decrease_hue(void) { |
| 952 | rgb_matrix_config.hue = decrement( rgb_matrix_config.hue, 8, 0, 255 ); | 544 | rgb_matrix_config.hue -= RGB_MATRIX_HUE_STEP; |
| 953 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 545 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 954 | } | 546 | } |
| 955 | 547 | ||
| 956 | void rgb_matrix_increase_sat(void) { | 548 | void rgb_matrix_increase_sat(void) { |
| 957 | rgb_matrix_config.sat = increment( rgb_matrix_config.sat, 8, 0, 255 ); | 549 | rgb_matrix_config.sat = qadd8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP); |
| 958 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 550 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 959 | } | 551 | } |
| 960 | 552 | ||
| 961 | void rgb_matrix_decrease_sat(void) { | 553 | void rgb_matrix_decrease_sat(void) { |
| 962 | rgb_matrix_config.sat = decrement( rgb_matrix_config.sat, 8, 0, 255 ); | 554 | rgb_matrix_config.sat = qsub8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP); |
| 963 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 555 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 964 | } | 556 | } |
| 965 | 557 | ||
| 966 | void rgb_matrix_increase_val(void) { | 558 | void rgb_matrix_increase_val(void) { |
| 967 | rgb_matrix_config.val = increment( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS ); | 559 | rgb_matrix_config.val = qadd8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP); |
| 968 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 560 | if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) |
| 561 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | ||
| 562 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 969 | } | 563 | } |
| 970 | 564 | ||
| 971 | void rgb_matrix_decrease_val(void) { | 565 | void rgb_matrix_decrease_val(void) { |
| 972 | rgb_matrix_config.val = decrement( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS ); | 566 | rgb_matrix_config.val = qsub8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP); |
| 973 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 567 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 974 | } | 568 | } |
| 975 | 569 | ||
| 976 | void rgb_matrix_increase_speed(void) { | 570 | void rgb_matrix_increase_speed(void) { |
| 977 | rgb_matrix_config.speed = increment( rgb_matrix_config.speed, 1, 0, 3 ); | 571 | rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); |
| 978 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this | 572 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this |
| 979 | } | 573 | } |
| 980 | 574 | ||
| 981 | void rgb_matrix_decrease_speed(void) { | 575 | void rgb_matrix_decrease_speed(void) { |
| 982 | rgb_matrix_config.speed = decrement( rgb_matrix_config.speed, 1, 0, 3 ); | 576 | rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); |
| 983 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this | 577 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this |
| 984 | } | 578 | } |
| 985 | 579 | ||
| 986 | void rgb_matrix_mode(uint8_t mode) { | 580 | void rgb_matrix_mode(uint8_t mode) { |
| 987 | rgb_matrix_config.mode = mode; | 581 | rgb_matrix_config.mode = mode; |
| 988 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 582 | rgb_task_state = STARTING; |
| 583 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | ||
| 989 | } | 584 | } |
| 990 | 585 | ||
| 991 | void rgb_matrix_mode_noeeprom(uint8_t mode) { | 586 | void rgb_matrix_mode_noeeprom(uint8_t mode) { |
| 992 | rgb_matrix_config.mode = mode; | 587 | rgb_matrix_config.mode = mode; |
| 993 | } | 588 | } |
| 994 | 589 | ||
| 995 | uint8_t rgb_matrix_get_mode(void) { | 590 | uint8_t rgb_matrix_get_mode(void) { |
| 996 | return rgb_matrix_config.mode; | 591 | return rgb_matrix_config.mode; |
| 997 | } | 592 | } |
| 998 | 593 | ||
| 999 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | 594 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { |
| 1000 | rgb_matrix_config.hue = hue; | 595 | rgb_matrix_sethsv_noeeprom(hue, sat, val); |
| 1001 | rgb_matrix_config.sat = sat; | ||
| 1002 | rgb_matrix_config.val = val; | ||
| 1003 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); | 596 | eeconfig_update_rgb_matrix(rgb_matrix_config.raw); |
| 1004 | } | 597 | } |
| 1005 | 598 | ||
| @@ -1007,4 +600,6 @@ void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | |||
| 1007 | rgb_matrix_config.hue = hue; | 600 | rgb_matrix_config.hue = hue; |
| 1008 | rgb_matrix_config.sat = sat; | 601 | rgb_matrix_config.sat = sat; |
| 1009 | rgb_matrix_config.val = val; | 602 | rgb_matrix_config.val = val; |
| 603 | if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) | ||
| 604 | rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | ||
| 1010 | } | 605 | } |
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index e6acd2d4b..855ea0323 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h | |||
| @@ -21,32 +21,33 @@ | |||
| 21 | 21 | ||
| 22 | #include <stdint.h> | 22 | #include <stdint.h> |
| 23 | #include <stdbool.h> | 23 | #include <stdbool.h> |
| 24 | #include "rgb_matrix_types.h" | ||
| 24 | #include "color.h" | 25 | #include "color.h" |
| 25 | #include "quantum.h" | 26 | #include "quantum.h" |
| 26 | 27 | ||
| 27 | #ifdef IS31FL3731 | 28 | #ifdef IS31FL3731 |
| 28 | #include "is31fl3731.h" | 29 | #include "is31fl3731.h" |
| 29 | #elif defined (IS31FL3733) | 30 | #elif defined (IS31FL3733) |
| 30 | #include "is31fl3733.h" | 31 | #include "is31fl3733.h" |
| 31 | #endif | 32 | #endif |
| 32 | 33 | ||
| 33 | typedef struct Point { | 34 | #ifndef RGB_MATRIX_LED_FLUSH_LIMIT |
| 34 | uint8_t x; | 35 | #define RGB_MATRIX_LED_FLUSH_LIMIT 16 |
| 35 | uint8_t y; | 36 | #endif |
| 36 | } __attribute__((packed)) Point; | ||
| 37 | 37 | ||
| 38 | typedef struct rgb_led { | 38 | #ifndef RGB_MATRIX_LED_PROCESS_LIMIT |
| 39 | union { | 39 | #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 |
| 40 | uint8_t raw; | 40 | #endif |
| 41 | struct { | ||
| 42 | uint8_t row:4; // 16 max | ||
| 43 | uint8_t col:4; // 16 max | ||
| 44 | }; | ||
| 45 | } matrix_co; | ||
| 46 | Point point; | ||
| 47 | uint8_t modifier:1; | ||
| 48 | } __attribute__((packed)) rgb_led; | ||
| 49 | 41 | ||
| 42 | #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL | ||
| 43 | #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ | ||
| 44 | uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ | ||
| 45 | if (max > DRIVER_LED_TOTAL) \ | ||
| 46 | max = DRIVER_LED_TOTAL; | ||
| 47 | #else | ||
| 48 | #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \ | ||
| 49 | uint8_t max = DRIVER_LED_TOTAL; | ||
| 50 | #endif | ||
| 50 | 51 | ||
| 51 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | 52 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; |
| 52 | 53 | ||
| @@ -56,79 +57,73 @@ typedef struct | |||
| 56 | uint8_t index; | 57 | uint8_t index; |
| 57 | } rgb_indicator; | 58 | } rgb_indicator; |
| 58 | 59 | ||
| 59 | typedef union { | ||
| 60 | uint32_t raw; | ||
| 61 | struct { | ||
| 62 | bool enable :1; | ||
| 63 | uint8_t mode :6; | ||
| 64 | uint16_t hue :9; | ||
| 65 | uint8_t sat :8; | ||
| 66 | uint8_t val :8; | ||
| 67 | uint8_t speed :8;//EECONFIG needs to be increased to support this | ||
| 68 | }; | ||
| 69 | } rgb_config_t; | ||
| 70 | |||
| 71 | enum rgb_matrix_effects { | 60 | enum rgb_matrix_effects { |
| 61 | RGB_MATRIX_NONE = 0, | ||
| 72 | RGB_MATRIX_SOLID_COLOR = 1, | 62 | RGB_MATRIX_SOLID_COLOR = 1, |
| 73 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS | 63 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS |
| 74 | RGB_MATRIX_ALPHAS_MODS, | 64 | RGB_MATRIX_ALPHAS_MODS, |
| 75 | #endif | 65 | #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS |
| 76 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 77 | RGB_MATRIX_DUAL_BEACON, | ||
| 78 | #endif | ||
| 79 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN | 66 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN |
| 80 | RGB_MATRIX_GRADIENT_UP_DOWN, | 67 | RGB_MATRIX_GRADIENT_UP_DOWN, |
| 81 | #endif | 68 | #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN |
| 82 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS | 69 | #ifndef DISABLE_RGB_MATRIX_BREATHING |
| 83 | RGB_MATRIX_RAINDROPS, | 70 | RGB_MATRIX_BREATHING, |
| 84 | #endif | 71 | #endif // DISABLE_RGB_MATRIX_BREATHING |
| 85 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | 72 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL |
| 86 | RGB_MATRIX_CYCLE_ALL, | 73 | RGB_MATRIX_CYCLE_ALL, |
| 87 | #endif | 74 | #endif // DISABLE_RGB_MATRIX_CYCLE_ALL |
| 88 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | 75 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT |
| 89 | RGB_MATRIX_CYCLE_LEFT_RIGHT, | 76 | RGB_MATRIX_CYCLE_LEFT_RIGHT, |
| 90 | #endif | 77 | #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT |
| 91 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | 78 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN |
| 92 | RGB_MATRIX_CYCLE_UP_DOWN, | 79 | RGB_MATRIX_CYCLE_UP_DOWN, |
| 93 | #endif | 80 | #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN |
| 81 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 82 | RGB_MATRIX_RAINBOW_MOVING_CHEVRON, | ||
| 83 | #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 84 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 85 | RGB_MATRIX_DUAL_BEACON, | ||
| 86 | #endif // DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 94 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON | 87 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON |
| 95 | RGB_MATRIX_RAINBOW_BEACON, | 88 | RGB_MATRIX_RAINBOW_BEACON, |
| 96 | #endif | 89 | #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON |
| 97 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | 90 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS |
| 98 | RGB_MATRIX_RAINBOW_PINWHEELS, | 91 | RGB_MATRIX_RAINBOW_PINWHEELS, |
| 99 | #endif | 92 | #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS |
| 100 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | 93 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS |
| 101 | RGB_MATRIX_RAINBOW_MOVING_CHEVRON, | 94 | RGB_MATRIX_RAINDROPS, |
| 102 | #endif | 95 | #endif // DISABLE_RGB_MATRIX_RAINDROPS |
| 103 | #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | 96 | #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS |
| 104 | RGB_MATRIX_JELLYBEAN_RAINDROPS, | 97 | RGB_MATRIX_JELLYBEAN_RAINDROPS, |
| 105 | #endif | 98 | #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS |
| 106 | #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN | 99 | #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN |
| 107 | RGB_MATRIX_DIGITAL_RAIN, | 100 | RGB_MATRIX_DIGITAL_RAIN, |
| 108 | #endif | 101 | #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN |
| 109 | #ifdef RGB_MATRIX_KEYPRESSES | 102 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 110 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE | 103 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE |
| 111 | RGB_MATRIX_SOLID_REACTIVE, | 104 | RGB_MATRIX_SOLID_REACTIVE_SIMPLE, |
| 112 | #endif | 105 | #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE |
| 113 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE | 106 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE |
| 114 | RGB_MATRIX_SOLID_REACTIVE_SIMPLE, | 107 | RGB_MATRIX_SOLID_REACTIVE, |
| 115 | #endif | 108 | #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE |
| 116 | #ifndef DISABLE_RGB_MATRIX_SPLASH | 109 | #ifndef DISABLE_RGB_MATRIX_SPLASH |
| 117 | RGB_MATRIX_SPLASH, | 110 | RGB_MATRIX_SPLASH, |
| 118 | #endif | 111 | #endif // DISABLE_RGB_MATRIX_SPLASH |
| 119 | #ifndef DISABLE_RGB_MATRIX_MULTISPLASH | 112 | #ifndef DISABLE_RGB_MATRIX_MULTISPLASH |
| 120 | RGB_MATRIX_MULTISPLASH, | 113 | RGB_MATRIX_MULTISPLASH, |
| 121 | #endif | 114 | #endif // DISABLE_RGB_MATRIX_MULTISPLASH |
| 122 | #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH | 115 | #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH |
| 123 | RGB_MATRIX_SOLID_SPLASH, | 116 | RGB_MATRIX_SOLID_SPLASH, |
| 124 | #endif | 117 | #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH |
| 125 | #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH | 118 | #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH |
| 126 | RGB_MATRIX_SOLID_MULTISPLASH, | 119 | RGB_MATRIX_SOLID_MULTISPLASH, |
| 127 | #endif | 120 | #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH |
| 128 | #endif | 121 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
| 129 | RGB_MATRIX_EFFECT_MAX | 122 | RGB_MATRIX_EFFECT_MAX |
| 130 | }; | 123 | }; |
| 131 | 124 | ||
| 125 | uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i); | ||
| 126 | |||
| 132 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ); | 127 | void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ); |
| 133 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ); | 128 | void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ); |
| 134 | 129 | ||
| @@ -162,8 +157,6 @@ void rgb_matrix_decrease(void); | |||
| 162 | // void backlight_get_key_color( uint8_t led, HSV *hsv ); | 157 | // void backlight_get_key_color( uint8_t led, HSV *hsv ); |
| 163 | // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv ); | 158 | // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv ); |
| 164 | 159 | ||
| 165 | uint32_t rgb_matrix_get_tick(void); | ||
| 166 | |||
| 167 | void rgb_matrix_toggle(void); | 160 | void rgb_matrix_toggle(void); |
| 168 | void rgb_matrix_enable(void); | 161 | void rgb_matrix_enable(void); |
| 169 | void rgb_matrix_enable_noeeprom(void); | 162 | void rgb_matrix_enable_noeeprom(void); |
| @@ -212,7 +205,6 @@ uint8_t rgb_matrix_get_mode(void); | |||
| 212 | typedef struct { | 205 | typedef struct { |
| 213 | /* Perform any initialisation required for the other driver functions to work. */ | 206 | /* Perform any initialisation required for the other driver functions to work. */ |
| 214 | void (*init)(void); | 207 | void (*init)(void); |
| 215 | |||
| 216 | /* Set the colour of a single LED in the buffer. */ | 208 | /* Set the colour of a single LED in the buffer. */ |
| 217 | void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b); | 209 | void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b); |
| 218 | /* Set the colour of all LEDS on the keyboard in the buffer. */ | 210 | /* Set the colour of all LEDS on the keyboard in the buffer. */ |
diff --git a/quantum/rgb_matrix_animations/alpha_mods_anim.h b/quantum/rgb_matrix_animations/alpha_mods_anim.h new file mode 100644 index 000000000..cc1914d7f --- /dev/null +++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS | ||
| 3 | |||
| 4 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | |||
| 7 | // alphas = color1, mods = color2 | ||
| 8 | bool rgb_matrix_alphas_mods(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | RGB rgb1 = hsv_to_rgb(hsv); | ||
| 13 | hsv.h += rgb_matrix_config.speed; | ||
| 14 | RGB rgb2 = hsv_to_rgb(hsv); | ||
| 15 | |||
| 16 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 17 | if (g_rgb_leds[i].modifier) { | ||
| 18 | rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b); | ||
| 19 | } else { | ||
| 20 | rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b); | ||
| 21 | } | ||
| 22 | } | ||
| 23 | return led_max < DRIVER_LED_TOTAL; | ||
| 24 | } | ||
| 25 | |||
| 26 | #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS | ||
diff --git a/quantum/rgb_matrix_animations/breathing_anim.h b/quantum/rgb_matrix_animations/breathing_anim.h new file mode 100644 index 000000000..fb90b66bd --- /dev/null +++ b/quantum/rgb_matrix_animations/breathing_anim.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_BREATHING | ||
| 3 | |||
| 4 | extern rgb_config_t rgb_matrix_config; | ||
| 5 | |||
| 6 | bool rgb_matrix_breathing(effect_params_t* params) { | ||
| 7 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 8 | |||
| 9 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 8); | ||
| 10 | uint8_t val = scale8(abs8(sin8(time) - 128) * 2, rgb_matrix_config.val); | ||
| 11 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, val }; | ||
| 12 | RGB rgb = hsv_to_rgb(hsv); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 15 | } | ||
| 16 | return led_max < DRIVER_LED_TOTAL; | ||
| 17 | } | ||
| 18 | |||
| 19 | #endif // DISABLE_RGB_MATRIX_BREATHING | ||
diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h new file mode 100644 index 000000000..5c18cfa0c --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_all_anim.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_cycle_all(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | hsv.h = time; | ||
| 15 | RGB rgb = hsv_to_rgb(hsv); | ||
| 16 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 17 | } | ||
| 18 | return led_max < DRIVER_LED_TOTAL; | ||
| 19 | } | ||
| 20 | |||
| 21 | #endif // DISABLE_RGB_MATRIX_CYCLE_ALL | ||
diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h new file mode 100644 index 000000000..f519aeb47 --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_cycle_left_right(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | point_t point = g_rgb_leds[i].point; | ||
| 15 | hsv.h = point.x - time; | ||
| 16 | RGB rgb = hsv_to_rgb(hsv); | ||
| 17 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 18 | } | ||
| 19 | return led_max < DRIVER_LED_TOTAL; | ||
| 20 | } | ||
| 21 | |||
| 22 | #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT | ||
diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h new file mode 100644 index 000000000..8b91d890d --- /dev/null +++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_cycle_up_down(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | point_t point = g_rgb_leds[i].point; | ||
| 15 | hsv.h = point.y - time; | ||
| 16 | RGB rgb = hsv_to_rgb(hsv); | ||
| 17 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 18 | } | ||
| 19 | return led_max < DRIVER_LED_TOTAL; | ||
| 20 | } | ||
| 21 | |||
| 22 | #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN | ||
diff --git a/quantum/rgb_matrix_animations/digital_rain_anim.h b/quantum/rgb_matrix_animations/digital_rain_anim.h new file mode 100644 index 000000000..4ba3c1c87 --- /dev/null +++ b/quantum/rgb_matrix_animations/digital_rain_anim.h | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN | ||
| 3 | |||
| 4 | #ifndef RGB_DIGITAL_RAIN_DROPS | ||
| 5 | // lower the number for denser effect/wider keyboard | ||
| 6 | #define RGB_DIGITAL_RAIN_DROPS 24 | ||
| 7 | #endif | ||
| 8 | |||
| 9 | bool rgb_matrix_digital_rain(effect_params_t* params) { | ||
| 10 | // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain | ||
| 11 | const uint8_t drop_ticks = 28; | ||
| 12 | const uint8_t pure_green_intensity = 0xd0; | ||
| 13 | const uint8_t max_brightness_boost = 0xc0; | ||
| 14 | const uint8_t max_intensity = 0xff; | ||
| 15 | |||
| 16 | static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}}; | ||
| 17 | static uint8_t drop = 0; | ||
| 18 | |||
| 19 | if (params->init) { | ||
| 20 | rgb_matrix_set_color_all(0, 0, 0); | ||
| 21 | memset(map, 0, sizeof map); | ||
| 22 | drop = 0; | ||
| 23 | } | ||
| 24 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 25 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 26 | if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { | ||
| 27 | // top row, pixels have just fallen and we're | ||
| 28 | // making a new rain drop in this column | ||
| 29 | map[col][row] = max_intensity; | ||
| 30 | } | ||
| 31 | else if (map[col][row] > 0 && map[col][row] < max_intensity) { | ||
| 32 | // neither fully bright nor dark, decay it | ||
| 33 | map[col][row]--; | ||
| 34 | } | ||
| 35 | // set the pixel colour | ||
| 36 | uint8_t led[LED_HITS_TO_REMEMBER]; | ||
| 37 | uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led); | ||
| 38 | |||
| 39 | // TODO: multiple leds are supported mapped to the same row/column | ||
| 40 | if (led_count > 0) { | ||
| 41 | if (map[col][row] > pure_green_intensity) { | ||
| 42 | const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity)); | ||
| 43 | rgb_matrix_set_color(led[0], boost, max_intensity, boost); | ||
| 44 | } | ||
| 45 | else { | ||
| 46 | const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity); | ||
| 47 | rgb_matrix_set_color(led[0], 0, green, 0); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | if (++drop > drop_ticks) { | ||
| 53 | // reset drop timer | ||
| 54 | drop = 0; | ||
| 55 | for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { | ||
| 56 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 57 | // if ths is on the bottom row and bright allow decay | ||
| 58 | if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) { | ||
| 59 | map[col][row]--; | ||
| 60 | } | ||
| 61 | // check if the pixel above is bright | ||
| 62 | if (map[col][row - 1] == max_intensity) { | ||
| 63 | // allow old bright pixel to decay | ||
| 64 | map[col][row - 1]--; | ||
| 65 | // make this pixel bright | ||
| 66 | map[col][row] = max_intensity; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | return false; | ||
| 72 | } | ||
| 73 | |||
| 74 | #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN | ||
diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h new file mode 100644 index 000000000..dda315780 --- /dev/null +++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_dual_beacon(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | int8_t cos_value = cos8(time) - 128; | ||
| 14 | int8_t sin_value = sin8(time) - 128; | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * sin_value) / 128 + rgb_matrix_config.hue; | ||
| 18 | RGB rgb = hsv_to_rgb(hsv); | ||
| 19 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 20 | } | ||
| 21 | return led_max < DRIVER_LED_TOTAL; | ||
| 22 | } | ||
| 23 | |||
| 24 | #endif // DISABLE_RGB_MATRIX_DUAL_BEACON | ||
diff --git a/quantum/rgb_matrix_animations/gradient_up_down_anim.h b/quantum/rgb_matrix_animations/gradient_up_down_anim.h new file mode 100644 index 000000000..11498e22f --- /dev/null +++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN | ||
| 3 | |||
| 4 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | |||
| 7 | bool rgb_matrix_gradient_up_down(effect_params_t* params) { | ||
| 8 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 9 | |||
| 10 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 11 | uint8_t scale = scale8(64, rgb_matrix_config.speed); | ||
| 12 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 13 | point_t point = g_rgb_leds[i].point; | ||
| 14 | // The y range will be 0..64, map this to 0..4 | ||
| 15 | // Relies on hue being 8-bit and wrapping | ||
| 16 | hsv.h = rgb_matrix_config.hue + scale * (point.y >> 4); | ||
| 17 | RGB rgb = hsv_to_rgb(hsv); | ||
| 18 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 19 | } | ||
| 20 | return led_max < DRIVER_LED_TOTAL; | ||
| 21 | } | ||
| 22 | #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN | ||
diff --git a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h new file mode 100644 index 000000000..01ff5c230 --- /dev/null +++ b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | static void jellybean_raindrops_set_color(int i) { | ||
| 9 | HSV hsv = { rand() & 0xFF , rand() & 0xFF, rgb_matrix_config.val }; | ||
| 10 | RGB rgb = hsv_to_rgb(hsv); | ||
| 11 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 12 | } | ||
| 13 | |||
| 14 | bool rgb_matrix_jellybean_raindrops(effect_params_t* params) { | ||
| 15 | if (!params->init) { | ||
| 16 | // Change one LED every tick, make sure speed is not 0 | ||
| 17 | if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { | ||
| 18 | jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL); | ||
| 19 | } | ||
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 24 | for (int i = led_min; i < led_max; i++) { | ||
| 25 | jellybean_raindrops_set_color(i); | ||
| 26 | } | ||
| 27 | return led_max < DRIVER_LED_TOTAL; | ||
| 28 | } | ||
| 29 | |||
| 30 | #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS | ||
diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h new file mode 100644 index 000000000..3c15e64ab --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_rainbow_beacon(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | int16_t cos_value = 2 * (cos8(time) - 128); | ||
| 14 | int16_t sin_value = 2 * (sin8(time) - 128); | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * sin_value) / 128 + rgb_matrix_config.hue; | ||
| 18 | RGB rgb = hsv_to_rgb(hsv); | ||
| 19 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 20 | } | ||
| 21 | return led_max < DRIVER_LED_TOTAL; | ||
| 22 | } | ||
| 23 | |||
| 24 | #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON | ||
diff --git a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h new file mode 100644 index 000000000..0d11d5280 --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 14 | point_t point = g_rgb_leds[i].point; | ||
| 15 | hsv.h = abs8(point.y - 32) + (point.x - time) + rgb_matrix_config.hue; | ||
| 16 | RGB rgb = hsv_to_rgb(hsv); | ||
| 17 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 18 | } | ||
| 19 | return led_max < DRIVER_LED_TOTAL; | ||
| 20 | } | ||
| 21 | |||
| 22 | #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h new file mode 100644 index 000000000..d7cd42cbe --- /dev/null +++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | ||
| 3 | |||
| 4 | extern rgb_counters_t g_rgb_counters; | ||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 12 | uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4); | ||
| 13 | int16_t cos_value = 3 * (cos8(time) - 128); | ||
| 14 | int16_t sin_value = 3 * (sin8(time) - 128); | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | hsv.h = ((point.y - 32) * cos_value + (56 - abs8(point.x - 112)) * sin_value) / 128 + rgb_matrix_config.hue; | ||
| 18 | RGB rgb = hsv_to_rgb(hsv); | ||
| 19 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 20 | } | ||
| 21 | return led_max < DRIVER_LED_TOTAL; | ||
| 22 | } | ||
| 23 | |||
| 24 | #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS | ||
diff --git a/quantum/rgb_matrix_animations/raindrops_anim.h b/quantum/rgb_matrix_animations/raindrops_anim.h new file mode 100644 index 000000000..fc721375b --- /dev/null +++ b/quantum/rgb_matrix_animations/raindrops_anim.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifndef DISABLE_RGB_MATRIX_RAINDROPS | ||
| 3 | #include "rgb_matrix_types.h" | ||
| 4 | |||
| 5 | extern rgb_counters_t g_rgb_counters; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | |||
| 8 | static void raindrops_set_color(int i) { | ||
| 9 | HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 10 | |||
| 11 | // Take the shortest path between hues | ||
| 12 | int16_t deltaH = ((rgb_matrix_config.hue + 180) % 360 - rgb_matrix_config.hue) / 4; | ||
| 13 | if (deltaH > 127) { | ||
| 14 | deltaH -= 256; | ||
| 15 | } else if (deltaH < -127) { | ||
| 16 | deltaH += 256; | ||
| 17 | } | ||
| 18 | |||
| 19 | hsv.h = rgb_matrix_config.hue + (deltaH * (rand() & 0x03)); | ||
| 20 | RGB rgb = hsv_to_rgb(hsv); | ||
| 21 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 22 | } | ||
| 23 | |||
| 24 | bool rgb_matrix_raindrops(effect_params_t* params) { | ||
| 25 | if (!params->init) { | ||
| 26 | // Change one LED every tick, make sure speed is not 0 | ||
| 27 | if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { | ||
| 28 | raindrops_set_color(rand() % DRIVER_LED_TOTAL); | ||
| 29 | } | ||
| 30 | return false; | ||
| 31 | } | ||
| 32 | |||
| 33 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 34 | for (int i = led_min; i < led_max; i++) { | ||
| 35 | raindrops_set_color(i); | ||
| 36 | } | ||
| 37 | return led_max < DRIVER_LED_TOTAL; | ||
| 38 | } | ||
| 39 | |||
| 40 | #endif // DISABLE_RGB_MATRIX_RAINDROPS | ||
diff --git a/quantum/rgb_matrix_animations/solid_color_anim.h b/quantum/rgb_matrix_animations/solid_color_anim.h new file mode 100644 index 000000000..24a197beb --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_color_anim.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | extern rgb_config_t rgb_matrix_config; | ||
| 4 | |||
| 5 | bool rgb_matrix_solid_color(effect_params_t* params) { | ||
| 6 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 7 | |||
| 8 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val }; | ||
| 9 | RGB rgb = hsv_to_rgb(hsv); | ||
| 10 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 11 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 12 | } | ||
| 13 | return led_max < DRIVER_LED_TOTAL; | ||
| 14 | } | ||
diff --git a/quantum/rgb_matrix_animations/solid_reactive_anim.h b/quantum/rgb_matrix_animations/solid_reactive_anim.h new file mode 100644 index 000000000..220e54233 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #pragma once | ||
| 2 | #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) | ||
| 3 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE | ||
| 4 | |||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | extern last_hit_t g_last_hit_tracker; | ||
| 7 | |||
| 8 | bool rgb_matrix_solid_reactive(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val }; | ||
| 12 | // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 | ||
| 13 | uint16_t max_tick = 65535 / rgb_matrix_config.speed; | ||
| 14 | // Relies on hue being 8-bit and wrapping | ||
| 15 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 16 | uint16_t tick = max_tick; | ||
| 17 | for(uint8_t j = 0; j < g_last_hit_tracker.count; j++) { | ||
| 18 | if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { | ||
| 19 | tick = g_last_hit_tracker.tick[j]; | ||
| 20 | break; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); | ||
| 25 | hsv.h = rgb_matrix_config.hue + qsub8(130, offset); | ||
| 26 | RGB rgb = hsv_to_rgb(hsv); | ||
| 27 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 28 | } | ||
| 29 | return led_max < DRIVER_LED_TOTAL; | ||
| 30 | } | ||
| 31 | |||
| 32 | #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON | ||
| 33 | #endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) | ||
diff --git a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h new file mode 100644 index 000000000..e84cd6939 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 3 | #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 4 | |||
| 5 | extern rgb_config_t rgb_matrix_config; | ||
| 6 | extern last_hit_t g_last_hit_tracker; | ||
| 7 | |||
| 8 | bool rgb_matrix_solid_reactive_simple(effect_params_t* params) { | ||
| 9 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 10 | |||
| 11 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; | ||
| 12 | // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255 | ||
| 13 | uint16_t max_tick = 65535 / rgb_matrix_config.speed; | ||
| 14 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 15 | uint16_t tick = max_tick; | ||
| 16 | for(uint8_t j = 0; j < g_last_hit_tracker.count; j++) { | ||
| 17 | if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { | ||
| 18 | tick = g_last_hit_tracker.tick[j]; | ||
| 19 | break; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | uint16_t offset = scale16by8(tick, rgb_matrix_config.speed); | ||
| 24 | hsv.v = scale8(255 - offset, rgb_matrix_config.val); | ||
| 25 | RGB rgb = hsv_to_rgb(hsv); | ||
| 26 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 27 | } | ||
| 28 | return led_max < DRIVER_LED_TOTAL; | ||
| 29 | } | ||
| 30 | |||
| 31 | #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE | ||
| 32 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/rgb_matrix_animations/solid_splash_anim.h b/quantum/rgb_matrix_animations/solid_splash_anim.h new file mode 100644 index 000000000..82ac055b8 --- /dev/null +++ b/quantum/rgb_matrix_animations/solid_splash_anim.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 3 | #if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH) | ||
| 4 | |||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | extern last_hit_t g_last_hit_tracker; | ||
| 8 | |||
| 9 | static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* params) { | ||
| 10 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 11 | |||
| 12 | HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 }; | ||
| 13 | uint8_t count = g_last_hit_tracker.count; | ||
| 14 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 15 | hsv.v = 0; | ||
| 16 | point_t point = g_rgb_leds[i].point; | ||
| 17 | for (uint8_t j = start; j < count; j++) { | ||
| 18 | int16_t dx = point.x - g_last_hit_tracker.x[j]; | ||
| 19 | int16_t dy = point.y - g_last_hit_tracker.y[j]; | ||
| 20 | uint8_t dist = sqrt16(dx * dx + dy * dy); | ||
| 21 | uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; | ||
| 22 | if (effect > 255) | ||
| 23 | effect = 255; | ||
| 24 | hsv.v = qadd8(hsv.v, 255 - effect); | ||
| 25 | } | ||
| 26 | hsv.v = scale8(hsv.v, rgb_matrix_config.val); | ||
| 27 | RGB rgb = hsv_to_rgb(hsv); | ||
| 28 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 29 | } | ||
| 30 | return led_max < DRIVER_LED_TOTAL; | ||
| 31 | } | ||
| 32 | |||
| 33 | bool rgb_matrix_solid_multisplash(effect_params_t* params) { | ||
| 34 | return rgb_matrix_solid_multisplash_range(0, params); | ||
| 35 | } | ||
| 36 | |||
| 37 | bool rgb_matrix_solid_splash(effect_params_t* params) { | ||
| 38 | return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); | ||
| 39 | } | ||
| 40 | |||
| 41 | #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH) | ||
| 42 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/rgb_matrix_animations/splash_anim.h b/quantum/rgb_matrix_animations/splash_anim.h new file mode 100644 index 000000000..829d30eef --- /dev/null +++ b/quantum/rgb_matrix_animations/splash_anim.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #pragma once | ||
| 2 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 3 | #if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) | ||
| 4 | |||
| 5 | extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL]; | ||
| 6 | extern rgb_config_t rgb_matrix_config; | ||
| 7 | extern last_hit_t g_last_hit_tracker; | ||
| 8 | |||
| 9 | static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) { | ||
| 10 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | ||
| 11 | |||
| 12 | HSV hsv = { 0, rgb_matrix_config.sat, 0 }; | ||
| 13 | uint8_t count = g_last_hit_tracker.count; | ||
| 14 | for (uint8_t i = led_min; i < led_max; i++) { | ||
| 15 | hsv.h = rgb_matrix_config.hue; | ||
| 16 | hsv.v = 0; | ||
| 17 | point_t point = g_rgb_leds[i].point; | ||
| 18 | for (uint8_t j = start; j < count; j++) { | ||
| 19 | int16_t dx = point.x - g_last_hit_tracker.x[j]; | ||
| 20 | int16_t dy = point.y - g_last_hit_tracker.y[j]; | ||
| 21 | uint8_t dist = sqrt16(dx * dx + dy * dy); | ||
| 22 | uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist; | ||
| 23 | if (effect > 255) | ||
| 24 | effect = 255; | ||
| 25 | hsv.h += effect; | ||
| 26 | hsv.v = qadd8(hsv.v, 255 - effect); | ||
| 27 | } | ||
| 28 | hsv.v = scale8(hsv.v, rgb_matrix_config.val); | ||
| 29 | RGB rgb = hsv_to_rgb(hsv); | ||
| 30 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 31 | } | ||
| 32 | return led_max < DRIVER_LED_TOTAL; | ||
| 33 | } | ||
| 34 | |||
| 35 | bool rgb_matrix_multisplash(effect_params_t* params) { | ||
| 36 | return rgb_matrix_multisplash_range(0, params); | ||
| 37 | } | ||
| 38 | |||
| 39 | bool rgb_matrix_splash(effect_params_t* params) { | ||
| 40 | return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params); | ||
| 41 | } | ||
| 42 | |||
| 43 | #endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH) | ||
| 44 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h new file mode 100644 index 000000000..f7643d2b0 --- /dev/null +++ b/quantum/rgb_matrix_types.h | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stdint.h> | ||
| 4 | #include <stdbool.h> | ||
| 5 | |||
| 6 | #if defined(__GNUC__) | ||
| 7 | #define PACKED __attribute__ ((__packed__)) | ||
| 8 | #else | ||
| 9 | #define PACKED | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #if defined(_MSC_VER) | ||
| 13 | #pragma pack( push, 1 ) | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #if defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES) | ||
| 17 | #define RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 18 | #endif | ||
| 19 | |||
| 20 | // Last led hit | ||
| 21 | #ifndef LED_HITS_TO_REMEMBER | ||
| 22 | #define LED_HITS_TO_REMEMBER 8 | ||
| 23 | #endif // LED_HITS_TO_REMEMBER | ||
| 24 | |||
| 25 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 26 | typedef struct PACKED { | ||
| 27 | uint8_t count; | ||
| 28 | uint8_t x[LED_HITS_TO_REMEMBER]; | ||
| 29 | uint8_t y[LED_HITS_TO_REMEMBER]; | ||
| 30 | uint8_t index[LED_HITS_TO_REMEMBER]; | ||
| 31 | uint16_t tick[LED_HITS_TO_REMEMBER]; | ||
| 32 | } last_hit_t; | ||
| 33 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 34 | |||
| 35 | typedef enum rgb_task_states { | ||
| 36 | STARTING, | ||
| 37 | RENDERING, | ||
| 38 | FLUSHING, | ||
| 39 | SYNCING | ||
| 40 | } rgb_task_states; | ||
| 41 | |||
| 42 | typedef uint8_t led_flags_t; | ||
| 43 | |||
| 44 | typedef struct PACKED { | ||
| 45 | uint8_t iter; | ||
| 46 | led_flags_t flags; | ||
| 47 | bool init; | ||
| 48 | } effect_params_t; | ||
| 49 | |||
| 50 | typedef struct PACKED { | ||
| 51 | // Global tick at 20 Hz | ||
| 52 | uint32_t tick; | ||
| 53 | // Ticks since this key was last hit. | ||
| 54 | uint32_t any_key_hit; | ||
| 55 | } rgb_counters_t; | ||
| 56 | |||
| 57 | typedef struct PACKED { | ||
| 58 | uint8_t x; | ||
| 59 | uint8_t y; | ||
| 60 | } point_t; | ||
| 61 | |||
| 62 | typedef union { | ||
| 63 | uint8_t raw; | ||
| 64 | struct { | ||
| 65 | uint8_t row:4; // 16 max | ||
| 66 | uint8_t col:4; // 16 max | ||
| 67 | }; | ||
| 68 | } matrix_co_t; | ||
| 69 | |||
| 70 | typedef struct PACKED { | ||
| 71 | matrix_co_t matrix_co; | ||
| 72 | point_t point; | ||
| 73 | uint8_t modifier:1; | ||
| 74 | } rgb_led; | ||
| 75 | |||
| 76 | typedef union { | ||
| 77 | uint32_t raw; | ||
| 78 | struct PACKED { | ||
| 79 | bool enable :1; | ||
| 80 | uint8_t mode :7; | ||
| 81 | uint8_t hue :8; | ||
| 82 | uint8_t sat :8; | ||
| 83 | uint8_t val :8; | ||
| 84 | uint8_t speed :8;//EECONFIG needs to be increased to support this | ||
| 85 | }; | ||
| 86 | } rgb_config_t; | ||
| 87 | |||
| 88 | #if defined(_MSC_VER) | ||
| 89 | #pragma pack( pop ) | ||
| 90 | #endif | ||
