aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-05-17 09:35:02 +0300
committerFred Sundvik <fsundvik@gmail.com>2016-05-17 09:35:02 +0300
commitd79e94adb1182ae867df0cc7621ef3d44d213bbc (patch)
tree47edc6387a0b8508d57d2fb613b1ae71df18b5ef
parent15bdef3ee92e6809ec5d0f25901f4a490cd91b58 (diff)
downloadqmk_firmware-d79e94adb1182ae867df0cc7621ef3d44d213bbc.tar.gz
qmk_firmware-d79e94adb1182ae867df0cc7621ef3d44d213bbc.zip
Use ugfx API instead of chibios
m---------ugfx0
-rw-r--r--visualizer.c34
-rw-r--r--visualizer.mk12
3 files changed, 27 insertions, 19 deletions
diff --git a/ugfx b/ugfx
Subproject 314a066d11f09d295d42054a0b53fa1a95c0ba0 Subproject 7d7eeef0ad0f1b28f4fb86ad931cb6774c7b9e8
diff --git a/visualizer.c b/visualizer.c
index 579837edc..ea84546fb 100644
--- a/visualizer.c
+++ b/visualizer.c
@@ -23,7 +23,6 @@ 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>
29 28
@@ -68,7 +67,7 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa
68 status1->suspended == status2->suspended; 67 status1->suspended == status2->suspended;
69} 68}
70 69
71static event_source_t layer_changed_event; 70static GSourceHandle layer_changed_event;
72static bool visualizer_enabled = false; 71static bool visualizer_enabled = false;
73 72
74#define MAX_SIMULTANEOUS_ANIMATIONS 4 73#define MAX_SIMULTANEOUS_ANIMATIONS 4
@@ -132,7 +131,7 @@ void stop_all_keyframe_animations(void) {
132 } 131 }
133} 132}
134 133
135static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systime_t delta, systime_t* sleep_time) { 134static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) {
136 // TODO: Clean up this messy code 135 // TODO: Clean up this messy code
137 dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, 136 dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame,
138 animation->time_left_in_frame, delta); 137 animation->time_left_in_frame, delta);
@@ -331,12 +330,13 @@ bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* s
331} 330}
332 331
333// TODO: Optimize the stack size, this is probably way too big 332// TODO: Optimize the stack size, this is probably way too big
334static THD_WORKING_AREA(visualizerThreadStack, 1024); 333static DECLARE_THREAD_STACK(visualizerThreadStack, 1024);
335static THD_FUNCTION(visualizerThread, arg) { 334static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
336 (void)arg; 335 (void)arg;
337 336
338 event_listener_t event_listener; 337 GListener event_listener;
339 chEvtRegister(&layer_changed_event, &event_listener, 0); 338 geventListenerInit(&event_listener);
339 geventAttachSource(&event_listener, layer_changed_event, 0);
340 340
341 visualizer_keyboard_status_t initial_status = { 341 visualizer_keyboard_status_t initial_status = {
342 .default_layer = 0xFFFFFFFF, 342 .default_layer = 0xFFFFFFFF,
@@ -363,12 +363,12 @@ static THD_FUNCTION(visualizerThread, arg) {
363 LCD_INT(state.current_lcd_color)); 363 LCD_INT(state.current_lcd_color));
364#endif 364#endif
365 365
366 systime_t sleep_time = TIME_INFINITE; 366 systemticks_t sleep_time = TIME_INFINITE;
367 systime_t current_time = chVTGetSystemTimeX(); 367 systemticks_t current_time = gfxSystemTicks();
368 368
369 while(true) { 369 while(true) {
370 systime_t new_time = chVTGetSystemTimeX(); 370 systemticks_t new_time = gfxSystemTicks();
371 systime_t delta = new_time - current_time; 371 systemticks_t delta = new_time - current_time;
372 current_time = new_time; 372 current_time = new_time;
373 bool enabled = visualizer_enabled; 373 bool enabled = visualizer_enabled;
374 if (!same_status(&state.status, &current_status)) { 374 if (!same_status(&state.status, &current_status)) {
@@ -411,7 +411,7 @@ static THD_FUNCTION(visualizerThread, arg) {
411 sleep_time = 0; 411 sleep_time = 0;
412 } 412 }
413 413
414 systime_t after_update = chVTGetSystemTimeX(); 414 systemticks_t after_update = gfxSystemTicks();
415 unsigned update_delta = after_update - current_time; 415 unsigned update_delta = after_update - current_time;
416 if (sleep_time != TIME_INFINITE) { 416 if (sleep_time != TIME_INFINITE) {
417 if (sleep_time > update_delta) { 417 if (sleep_time > update_delta) {
@@ -422,12 +422,14 @@ static THD_FUNCTION(visualizerThread, arg) {
422 } 422 }
423 } 423 }
424 dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time); 424 dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time);
425 chEvtWaitOneTimeout(EVENT_MASK(0), sleep_time); 425 geventEventWait(&event_listener, sleep_time);
426 } 426 }
427#ifdef LCD_ENABLE 427#ifdef LCD_ENABLE
428 gdispCloseFont(state.font_fixed5x8); 428 gdispCloseFont(state.font_fixed5x8);
429 gdispCloseFont(state.font_dejavusansbold12); 429 gdispCloseFont(state.font_dejavusansbold12);
430#endif 430#endif
431
432 return 0;
431} 433}
432 434
433void visualizer_init(void) { 435void visualizer_init(void) {
@@ -449,14 +451,14 @@ void visualizer_init(void) {
449 451
450 // We are using a low priority thread, the idea is to have it run only 452 // We are using a low priority thread, the idea is to have it run only
451 // when the main thread is sleeping during the matrix scanning 453 // when the main thread is sleeping during the matrix scanning
452 chEvtObjectInit(&layer_changed_event); 454 gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
453 (void)chThdCreateStatic(visualizerThreadStack, sizeof(visualizerThreadStack),
454 VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL); 455 VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
455} 456}
456 457
457void update_status(bool changed) { 458void update_status(bool changed) {
458 if (changed) { 459 if (changed) {
459 chEvtBroadcast(&layer_changed_event); 460 GSourceListener* listener = geventGetSourceListener(layer_changed_event, NULL);
461 geventSendEvent(listener);
460 } 462 }
461#ifdef USE_SERIAL_LINK 463#ifdef USE_SERIAL_LINK
462 static systime_t last_update = 0; 464 static systime_t last_update = 0;
diff --git a/visualizer.mk b/visualizer.mk
index c51f8ba5d..678829329 100644
--- a/visualizer.mk
+++ b/visualizer.mk
@@ -21,9 +21,7 @@
21# SOFTWARE. 21# SOFTWARE.
22 22
23GFXLIB = $(VISUALIZER_DIR)/ugfx 23GFXLIB = $(VISUALIZER_DIR)/ugfx
24ifndef EMULATOR
25SRC += $(VISUALIZER_DIR)/visualizer.c 24SRC += $(VISUALIZER_DIR)/visualizer.c
26endif
27UINCDIR += $(GFXINC) $(VISUALIZER_DIR) 25UINCDIR += $(GFXINC) $(VISUALIZER_DIR)
28 26
29ifdef LCD_ENABLE 27ifdef LCD_ENABLE
@@ -33,13 +31,17 @@ USE_UGFX = yes
33endif 31endif
34 32
35ifdef LCD_BACKLIGHT_ENABLE 33ifdef LCD_BACKLIGHT_ENABLE
34ifndef EMULATOR
36SRC += $(VISUALIZER_DIR)/lcd_backlight.c 35SRC += $(VISUALIZER_DIR)/lcd_backlight.c
37SRC += lcd_backlight_hal.c 36SRC += lcd_backlight_hal.c
37endif
38UDEFS += -DLCD_BACKLIGHT_ENABLE 38UDEFS += -DLCD_BACKLIGHT_ENABLE
39endif 39endif
40 40
41ifdef LED_ENABLE 41ifdef LED_ENABLE
42ifndef EMULATOR
42SRC += $(VISUALIZER_DIR)/led_test.c 43SRC += $(VISUALIZER_DIR)/led_test.c
44endif
43UDEFS += -DLED_ENABLE 45UDEFS += -DLED_ENABLE
44USE_UGFX = yes 46USE_UGFX = yes
45endif 47endif
@@ -56,4 +58,8 @@ ifndef EMULATOR
56VISUALIZER_USER = visualizer_user.c 58VISUALIZER_USER = visualizer_user.c
57endif 59endif
58endif 60endif
59SRC += $(VISUALIZER_USER) \ No newline at end of file 61SRC += $(VISUALIZER_USER)
62
63ifdef EMULATOR
64UINCDIR += $(TMK_DIR)/common
65endif \ No newline at end of file