aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-07-06 20:30:58 +0300
committerFred Sundvik <fsundvik@gmail.com>2016-07-06 20:30:58 +0300
commit6c296557909501b71fe344ce379e74094cf77c8e (patch)
treee02fdb7bb85a16de027c6c1946817e96d5304ab3
parentf727801bc69b3db28f84b7b8986756193bbfd21e (diff)
parent73d890a2c9c34b905cd5e74e7146fdd4578dcb96 (diff)
downloadqmk_firmware-6c296557909501b71fe344ce379e74094cf77c8e.tar.gz
qmk_firmware-6c296557909501b71fe344ce379e74094cf77c8e.zip
Merge commit '73d890a2c9c34b905cd5e74e7146fdd4578dcb96' into add_visualizer
-rw-r--r--quantum/visualizer/led_test.c170
-rw-r--r--quantum/visualizer/led_test.h41
-rw-r--r--quantum/visualizer/visualizer.c104
-rw-r--r--quantum/visualizer/visualizer.h24
-rw-r--r--quantum/visualizer/visualizer.mk28
5 files changed, 342 insertions, 25 deletions
diff --git a/quantum/visualizer/led_test.c b/quantum/visualizer/led_test.c
new file mode 100644
index 000000000..c2ea30b55
--- /dev/null
+++ b/quantum/visualizer/led_test.c
@@ -0,0 +1,170 @@
1/*
2The MIT License (MIT)
3
4Copyright (c) 2016 Fred Sundvik
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24#include "led_test.h"
25#include "gfx.h"
26#include "math.h"
27
28#define CROSSFADE_TIME 1000
29#define GRADIENT_TIME 3000
30
31keyframe_animation_t led_test_animation = {
32 .num_frames = 14,
33 .loop = true,
34 .frame_lengths = {
35 gfxMillisecondsToTicks(1000), // fade in
36 gfxMillisecondsToTicks(1000), // no op (leds on)
37 gfxMillisecondsToTicks(1000), // fade out
38 gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
39 gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in)
40 gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
41 gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
42 0, // mirror leds
43 gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
44 gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out)
45 gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
46 gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
47 0, // normal leds
48 gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
49
50 },
51 .frame_functions = {
52 keyframe_fade_in_all_leds,
53 keyframe_no_operation,
54 keyframe_fade_out_all_leds,
55 keyframe_led_crossfade,
56 keyframe_led_left_to_right_gradient,
57 keyframe_led_crossfade,
58 keyframe_led_top_to_bottom_gradient,
59 keyframe_mirror_led_orientation,
60 keyframe_led_crossfade,
61 keyframe_led_left_to_right_gradient,
62 keyframe_led_crossfade,
63 keyframe_led_top_to_bottom_gradient,
64 keyframe_normal_led_orientation,
65 keyframe_led_crossfade,
66 },
67};
68
69static uint8_t fade_led_color(keyframe_animation_t* animation, int from, int to) {
70 int frame_length = animation->frame_lengths[animation->current_frame];
71 int current_pos = frame_length - animation->time_left_in_frame;
72 int delta = to - from;
73 int luma = (delta * current_pos) / frame_length;
74 luma += from;
75 return luma;
76}
77
78static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint8_t from, uint8_t to) {
79 uint8_t luma = fade_led_color(animation, from, to);
80 color_t color = LUMA2COLOR(luma);
81 gdispGClear(LED_DISPLAY, color);
82}
83
84// TODO: Should be customizable per keyboard
85#define NUM_ROWS 7
86#define NUM_COLS 7
87
88static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS];
89static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS];
90
91static uint8_t compute_gradient_color(float t, float index, float num) {
92 const float two_pi = 2.0f * PI;
93 float normalized_index = (1.0f - index / (num - 1)) * two_pi;
94 float x = t * two_pi + normalized_index;
95 float v = 0.5 * (cosf(x) + 1.0f);
96 return (uint8_t)(255.0f * v);
97}
98
99bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
100 (void)state;
101 keyframe_fade_all_leds_from_to(animation, 0, 255);
102 return true;
103}
104
105bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
106 (void)state;
107 keyframe_fade_all_leds_from_to(animation, 255, 0);
108 return true;
109}
110
111bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
112 (void)state;
113 float frame_length = animation->frame_lengths[animation->current_frame];
114 float current_pos = frame_length - animation->time_left_in_frame;
115 float t = current_pos / frame_length;
116 for (int i=0; i< NUM_COLS; i++) {
117 uint8_t color = compute_gradient_color(t, i, NUM_COLS);
118 gdispGDrawLine(LED_DISPLAY, i, 0, i, NUM_ROWS - 1, LUMA2COLOR(color));
119 }
120 return true;
121}
122
123bool keyframe_led_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
124 (void)state;
125 float frame_length = animation->frame_lengths[animation->current_frame];
126 float current_pos = frame_length - animation->time_left_in_frame;
127 float t = current_pos / frame_length;
128 for (int i=0; i< NUM_ROWS; i++) {
129 uint8_t color = compute_gradient_color(t, i, NUM_ROWS);
130 gdispGDrawLine(LED_DISPLAY, 0, i, NUM_COLS - 1, i, LUMA2COLOR(color));
131 }
132 return true;
133}
134
135static void copy_current_led_state(uint8_t* dest) {
136 for (int i=0;i<NUM_ROWS;i++) {
137 for (int j=0;j<NUM_COLS;j++) {
138 dest[i*NUM_COLS + j] = gdispGGetPixelColor(LED_DISPLAY, j, i);
139 }
140 }
141}
142bool keyframe_led_crossfade(keyframe_animation_t* animation, visualizer_state_t* state) {
143 (void)state;
144 if (animation->first_update_of_frame) {
145 copy_current_led_state(&crossfade_start_frame[0][0]);
146 run_next_keyframe(animation, state);
147 copy_current_led_state(&crossfade_end_frame[0][0]);
148 }
149 for (int i=0;i<NUM_ROWS;i++) {
150 for (int j=0;j<NUM_COLS;j++) {
151 color_t color = LUMA2COLOR(fade_led_color(animation, crossfade_start_frame[i][j], crossfade_end_frame[i][j]));
152 gdispGDrawPixel(LED_DISPLAY, j, i, color);
153 }
154 }
155 return true;
156}
157
158bool keyframe_mirror_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
159 (void)state;
160 (void)animation;
161 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_180);
162 return false;
163}
164
165bool keyframe_normal_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
166 (void)state;
167 (void)animation;
168 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0);
169 return false;
170}
diff --git a/quantum/visualizer/led_test.h b/quantum/visualizer/led_test.h
new file mode 100644
index 000000000..5e2325753
--- /dev/null
+++ b/quantum/visualizer/led_test.h
@@ -0,0 +1,41 @@
1/*
2The MIT License (MIT)
3
4Copyright (c) 2016 Fred Sundvik
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef TMK_VISUALIZER_LED_TEST_H_
26#define TMK_VISUALIZER_LED_TEST_H_
27
28#include "visualizer.h"
29
30bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
31bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
32bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
33bool keyframe_led_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
34bool keyframe_led_crossfade(keyframe_animation_t* animation, visualizer_state_t* state);
35bool keyframe_mirror_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
36bool keyframe_normal_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
37
38extern keyframe_animation_t led_test_animation;
39
40
41#endif /* TMK_VISUALIZER_LED_TEST_H_ */
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 605be3059..c24073405 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -23,9 +23,11 @@ SOFTWARE.
23*/ 23*/
24 24
25#include "visualizer.h" 25#include "visualizer.h"
26#include "ch.h"
27#include "config.h" 26#include "config.h"
28#include <string.h> 27#include <string.h>
28#ifdef PROTOCOL_CHIBIOS
29#include "ch.h"
30#endif
29 31
30#ifdef LCD_ENABLE 32#ifdef LCD_ENABLE
31#include "gfx.h" 33#include "gfx.h"
@@ -68,7 +70,6 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa
68 status1->suspended == status2->suspended; 70 status1->suspended == status2->suspended;
69} 71}
70 72
71static event_source_t layer_changed_event;
72static bool visualizer_enabled = false; 73static bool visualizer_enabled = false;
73 74
74#define MAX_SIMULTANEOUS_ANIMATIONS 4 75#define MAX_SIMULTANEOUS_ANIMATIONS 4
@@ -83,6 +84,18 @@ static remote_object_t* remote_objects[] = {
83 84
84#endif 85#endif
85 86
87GDisplay* LCD_DISPLAY = 0;
88GDisplay* LED_DISPLAY = 0;
89
90__attribute__((weak))
91GDisplay* get_lcd_display(void) {
92 return gdispGetDisplay(0);
93}
94
95__attribute__((weak))
96GDisplay* get_led_display(void) {
97 return gdispGetDisplay(1);
98}
86 99
87void start_keyframe_animation(keyframe_animation_t* animation) { 100void start_keyframe_animation(keyframe_animation_t* animation) {
88 animation->current_frame = -1; 101 animation->current_frame = -1;
@@ -106,6 +119,8 @@ void stop_keyframe_animation(keyframe_animation_t* animation) {
106 animation->current_frame = animation->num_frames; 119 animation->current_frame = animation->num_frames;
107 animation->time_left_in_frame = 0; 120 animation->time_left_in_frame = 0;
108 animation->need_update = true; 121 animation->need_update = true;
122 animation->first_update_of_frame = false;
123 animation->last_update_of_frame = false;
109 for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) { 124 for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
110 if (animations[i] == animation) { 125 if (animations[i] == animation) {
111 animations[i] = NULL; 126 animations[i] = NULL;
@@ -120,12 +135,15 @@ void stop_all_keyframe_animations(void) {
120 animations[i]->current_frame = animations[i]->num_frames; 135 animations[i]->current_frame = animations[i]->num_frames;
121 animations[i]->time_left_in_frame = 0; 136 animations[i]->time_left_in_frame = 0;
122 animations[i]->need_update = true; 137 animations[i]->need_update = true;
138 animations[i]->first_update_of_frame = false;
139 animations[i]->last_update_of_frame = false;
123 animations[i] = NULL; 140 animations[i] = NULL;
124 } 141 }
125 } 142 }
126} 143}
127 144
128static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systime_t delta, systime_t* sleep_time) { 145static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) {
146 // TODO: Clean up this messy code
129 dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, 147 dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame,
130 animation->time_left_in_frame, delta); 148 animation->time_left_in_frame, delta);
131 if (animation->current_frame == animation->num_frames) { 149 if (animation->current_frame == animation->num_frames) {
@@ -136,16 +154,20 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize
136 animation->current_frame = 0; 154 animation->current_frame = 0;
137 animation->time_left_in_frame = animation->frame_lengths[0]; 155 animation->time_left_in_frame = animation->frame_lengths[0];
138 animation->need_update = true; 156 animation->need_update = true;
157 animation->first_update_of_frame = true;
139 } else { 158 } else {
140 animation->time_left_in_frame -= delta; 159 animation->time_left_in_frame -= delta;
141 while (animation->time_left_in_frame <= 0) { 160 while (animation->time_left_in_frame <= 0) {
142 int left = animation->time_left_in_frame; 161 int left = animation->time_left_in_frame;
143 if (animation->need_update) { 162 if (animation->need_update) {
144 animation->time_left_in_frame = 0; 163 animation->time_left_in_frame = 0;
164 animation->last_update_of_frame = true;
145 (*animation->frame_functions[animation->current_frame])(animation, state); 165 (*animation->frame_functions[animation->current_frame])(animation, state);
166 animation->last_update_of_frame = false;
146 } 167 }
147 animation->current_frame++; 168 animation->current_frame++;
148 animation->need_update = true; 169 animation->need_update = true;
170 animation->first_update_of_frame = true;
149 if (animation->current_frame == animation->num_frames) { 171 if (animation->current_frame == animation->num_frames) {
150 if (animation->loop) { 172 if (animation->loop) {
151 animation->current_frame = 0; 173 animation->current_frame = 0;
@@ -162,16 +184,32 @@ static bool update_keyframe_animation(keyframe_animation_t* animation, visualize
162 } 184 }
163 if (animation->need_update) { 185 if (animation->need_update) {
164 animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state); 186 animation->need_update = (*animation->frame_functions[animation->current_frame])(animation, state);
187 animation->first_update_of_frame = false;
165 } 188 }
166 189
167 int wanted_sleep = animation->need_update ? 10 : animation->time_left_in_frame; 190 systemticks_t wanted_sleep = animation->need_update ? gfxMillisecondsToTicks(10) : (unsigned)animation->time_left_in_frame;
168 if ((unsigned)wanted_sleep < *sleep_time) { 191 if (wanted_sleep < *sleep_time) {
169 *sleep_time = wanted_sleep; 192 *sleep_time = wanted_sleep;
170 } 193 }
171 194
172 return true; 195 return true;
173} 196}
174 197
198void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state) {
199 int next_frame = animation->current_frame + 1;
200 if (next_frame == animation->num_frames) {
201 next_frame = 0;
202 }
203 keyframe_animation_t temp_animation = *animation;
204 temp_animation.current_frame = next_frame;
205 temp_animation.time_left_in_frame = animation->frame_lengths[next_frame];
206 temp_animation.first_update_of_frame = true;
207 temp_animation.last_update_of_frame = false;
208 temp_animation.need_update = false;
209 visualizer_state_t temp_state = *state;
210 (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state);
211}
212
175bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) { 213bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) {
176 (void)animation; 214 (void)animation;
177 (void)state; 215 (void)state;
@@ -303,12 +341,13 @@ bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* s
303} 341}
304 342
305// TODO: Optimize the stack size, this is probably way too big 343// TODO: Optimize the stack size, this is probably way too big
306static THD_WORKING_AREA(visualizerThreadStack, 1024); 344static DECLARE_THREAD_STACK(visualizerThreadStack, 1024);
307static THD_FUNCTION(visualizerThread, arg) { 345static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
308 (void)arg; 346 (void)arg;
309 347
310 event_listener_t event_listener; 348 GListener event_listener;
311 chEvtRegister(&layer_changed_event, &event_listener, 0); 349 geventListenerInit(&event_listener);
350 geventAttachSource(&event_listener, (GSourceHandle)&current_status, 0);
312 351
313 visualizer_keyboard_status_t initial_status = { 352 visualizer_keyboard_status_t initial_status = {
314 .default_layer = 0xFFFFFFFF, 353 .default_layer = 0xFFFFFFFF,
@@ -335,12 +374,12 @@ static THD_FUNCTION(visualizerThread, arg) {
335 LCD_INT(state.current_lcd_color)); 374 LCD_INT(state.current_lcd_color));
336#endif 375#endif
337 376
338 systime_t sleep_time = TIME_INFINITE; 377 systemticks_t sleep_time = TIME_INFINITE;
339 systime_t current_time = chVTGetSystemTimeX(); 378 systemticks_t current_time = gfxSystemTicks();
340 379
341 while(true) { 380 while(true) {
342 systime_t new_time = chVTGetSystemTimeX(); 381 systemticks_t new_time = gfxSystemTicks();
343 systime_t delta = new_time - current_time; 382 systemticks_t delta = new_time - current_time;
344 current_time = new_time; 383 current_time = new_time;
345 bool enabled = visualizer_enabled; 384 bool enabled = visualizer_enabled;
346 if (!same_status(&state.status, &current_status)) { 385 if (!same_status(&state.status, &current_status)) {
@@ -373,6 +412,13 @@ static THD_FUNCTION(visualizerThread, arg) {
373 update_keyframe_animation(animations[i], &state, delta, &sleep_time); 412 update_keyframe_animation(animations[i], &state, delta, &sleep_time);
374 } 413 }
375 } 414 }
415#ifdef LED_ENABLE
416 gdispGFlush(LED_DISPLAY);
417#endif
418
419#ifdef EMULATOR
420 draw_emulator();
421#endif
376 // The animation can enable the visualizer 422 // The animation can enable the visualizer
377 // And we might need to update the state when that happens 423 // And we might need to update the state when that happens
378 // so don't sleep 424 // so don't sleep
@@ -380,7 +426,7 @@ static THD_FUNCTION(visualizerThread, arg) {
380 sleep_time = 0; 426 sleep_time = 0;
381 } 427 }
382 428
383 systime_t after_update = chVTGetSystemTimeX(); 429 systemticks_t after_update = gfxSystemTicks();
384 unsigned update_delta = after_update - current_time; 430 unsigned update_delta = after_update - current_time;
385 if (sleep_time != TIME_INFINITE) { 431 if (sleep_time != TIME_INFINITE) {
386 if (sleep_time > update_delta) { 432 if (sleep_time > update_delta) {
@@ -391,12 +437,24 @@ static THD_FUNCTION(visualizerThread, arg) {
391 } 437 }
392 } 438 }
393 dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time); 439 dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time);
394 chEvtWaitOneTimeout(EVENT_MASK(0), sleep_time); 440#ifdef PROTOCOL_CHIBIOS
441 // The gEventWait function really takes milliseconds, even if the documentation says ticks.
442 // Unfortunately there's no generic ugfx conversion from system time to milliseconds,
443 // so let's do it in a platform dependent way.
444
445 // On windows the system ticks is the same as milliseconds anyway
446 if (sleep_time != TIME_INFINITE) {
447 sleep_time = ST2MS(sleep_time);
448 }
449#endif
450 geventEventWait(&event_listener, sleep_time);
395 } 451 }
396#ifdef LCD_ENABLE 452#ifdef LCD_ENABLE
397 gdispCloseFont(state.font_fixed5x8); 453 gdispCloseFont(state.font_fixed5x8);
398 gdispCloseFont(state.font_dejavusansbold12); 454 gdispCloseFont(state.font_dejavusansbold12);
399#endif 455#endif
456
457 return 0;
400} 458}
401 459
402void visualizer_init(void) { 460void visualizer_init(void) {
@@ -411,16 +469,26 @@ void visualizer_init(void) {
411#ifdef USE_SERIAL_LINK 469#ifdef USE_SERIAL_LINK
412 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) ); 470 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
413#endif 471#endif
472
473#ifdef LCD_ENABLE
474 LCD_DISPLAY = get_lcd_display();
475#endif
476#ifdef LED_ENABLE
477 LED_DISPLAY = get_led_display();
478#endif
479
414 // We are using a low priority thread, the idea is to have it run only 480 // We are using a low priority thread, the idea is to have it run only
415 // when the main thread is sleeping during the matrix scanning 481 // when the main thread is sleeping during the matrix scanning
416 chEvtObjectInit(&layer_changed_event); 482 gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
417 (void)chThdCreateStatic(visualizerThreadStack, sizeof(visualizerThreadStack),
418 VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL); 483 VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
419} 484}
420 485
421void update_status(bool changed) { 486void update_status(bool changed) {
422 if (changed) { 487 if (changed) {
423 chEvtBroadcast(&layer_changed_event); 488 GSourceListener* listener = geventGetSourceListener((GSourceHandle)&current_status, NULL);
489 if (listener) {
490 geventSendEvent(listener);
491 }
424 } 492 }
425#ifdef USE_SERIAL_LINK 493#ifdef USE_SERIAL_LINK
426 static systime_t last_update = 0; 494 static systime_t last_update = 0;
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index 22798cda6..45cfa9aa9 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -45,8 +45,18 @@ void visualizer_suspend(void);
45// This should be called when the keyboard wakes up from suspend state 45// This should be called when the keyboard wakes up from suspend state
46void visualizer_resume(void); 46void visualizer_resume(void);
47 47
48// If you need support for more than 8 keyframes per animation, you can change this 48// These functions are week, so they can be overridden by the keyboard
49#define MAX_VISUALIZER_KEY_FRAMES 8 49// if needed
50GDisplay* get_lcd_display(void);
51GDisplay* get_led_display(void);
52
53// For emulator builds, this function need to be implemented
54#ifdef EMULATOR
55void draw_emulator(void);
56#endif
57
58// If you need support for more than 16 keyframes per animation, you can change this
59#define MAX_VISUALIZER_KEY_FRAMES 16
50 60
51struct keyframe_animation_t; 61struct keyframe_animation_t;
52 62
@@ -95,12 +105,20 @@ typedef struct keyframe_animation_t {
95 // keyframe update functions 105 // keyframe update functions
96 int current_frame; 106 int current_frame;
97 int time_left_in_frame; 107 int time_left_in_frame;
108 bool first_update_of_frame;
109 bool last_update_of_frame;
98 bool need_update; 110 bool need_update;
99 111
100} keyframe_animation_t; 112} keyframe_animation_t;
101 113
114extern GDisplay* LCD_DISPLAY;
115extern GDisplay* LED_DISPLAY;
116
102void start_keyframe_animation(keyframe_animation_t* animation); 117void start_keyframe_animation(keyframe_animation_t* animation);
103void stop_keyframe_animation(keyframe_animation_t* animation); 118void stop_keyframe_animation(keyframe_animation_t* animation);
119// This runs the next keyframe, but does not update the animation state
120// Useful for crossfades for example
121void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state);
104 122
105// Some predefined keyframe functions that can be used by the user code 123// Some predefined keyframe functions that can be used by the user code
106// Does nothing, useful for adding delays 124// Does nothing, useful for adding delays
@@ -121,7 +139,7 @@ bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualiz
121// directly from the initalize_user_visualizer function (the animation can be null) 139// directly from the initalize_user_visualizer function (the animation can be null)
122bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); 140bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state);
123 141
124// These two functions have to be implemented by the user 142// These functions have to be implemented by the user
125void initialize_user_visualizer(visualizer_state_t* state); 143void initialize_user_visualizer(visualizer_state_t* state);
126void update_user_visualizer_state(visualizer_state_t* state); 144void update_user_visualizer_state(visualizer_state_t* state);
127void user_visualizer_suspend(visualizer_state_t* state); 145void user_visualizer_suspend(visualizer_state_t* state);
diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk
index 13c5d3158..56525ffd9 100644
--- a/quantum/visualizer/visualizer.mk
+++ b/quantum/visualizer/visualizer.mk
@@ -21,21 +21,41 @@
21# SOFTWARE. 21# SOFTWARE.
22 22
23GFXLIB = $(VISUALIZER_DIR)/ugfx 23GFXLIB = $(VISUALIZER_DIR)/ugfx
24SRC += $(VISUALIZER_DIR)/visualizer.c
25UINCDIR += $(GFXINC) $(VISUALIZER_DIR)
26
24ifdef LCD_ENABLE 27ifdef LCD_ENABLE
25include $(GFXLIB)/gfx.mk
26UDEFS += -DLCD_ENABLE 28UDEFS += -DLCD_ENABLE
27ULIBS += -lm 29ULIBS += -lm
30USE_UGFX = yes
28endif 31endif
29SRC += $(GFXSRC) $(VISUALIZER_DIR)/visualizer.c
30UINCDIR += $(GFXINC) $(VISUALIZER_DIR)
31 32
32ifdef LCD_BACKLIGHT_ENABLE 33ifdef LCD_BACKLIGHT_ENABLE
33SRC += $(VISUALIZER_DIR)/lcd_backlight.c 34SRC += $(VISUALIZER_DIR)/lcd_backlight.c
35ifndef EMULATOR
34SRC += lcd_backlight_hal.c 36SRC += lcd_backlight_hal.c
37endif
35UDEFS += -DLCD_BACKLIGHT_ENABLE 38UDEFS += -DLCD_BACKLIGHT_ENABLE
36endif 39endif
37 40
41ifdef LED_ENABLE
42SRC += $(VISUALIZER_DIR)/led_test.c
43UDEFS += -DLED_ENABLE
44USE_UGFX = yes
45endif
46
47ifdef USE_UGFX
48include $(GFXLIB)/gfx.mk
49SRC += $(GFXSRC)
50UDEFS += $(patsubst %,-D%,$(patsubst -D%,%,$(GFXDEFS)))
51ULIBS += $(patsubst %,-l%,$(patsubst -l%,%,$(GFXLIBS)))
52endif
53
38ifndef VISUALIZER_USER 54ifndef VISUALIZER_USER
39VISUALIZER_USER = visualizer_user.c 55VISUALIZER_USER = visualizer_user.c
40endif 56endif
41SRC += $(VISUALIZER_USER) \ No newline at end of file 57SRC += $(VISUALIZER_USER)
58
59ifdef EMULATOR
60UINCDIR += $(TMK_DIR)/common
61endif \ No newline at end of file