diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2016-05-17 09:35:02 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2016-05-17 09:35:02 +0300 |
| commit | d79e94adb1182ae867df0cc7621ef3d44d213bbc (patch) | |
| tree | 47edc6387a0b8508d57d2fb613b1ae71df18b5ef | |
| parent | 15bdef3ee92e6809ec5d0f25901f4a490cd91b58 (diff) | |
| download | qmk_firmware-d79e94adb1182ae867df0cc7621ef3d44d213bbc.tar.gz qmk_firmware-d79e94adb1182ae867df0cc7621ef3d44d213bbc.zip | |
Use ugfx API instead of chibios
| m--------- | ugfx | 0 | ||||
| -rw-r--r-- | visualizer.c | 34 | ||||
| -rw-r--r-- | visualizer.mk | 12 |
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 | ||
| 71 | static event_source_t layer_changed_event; | 70 | static GSourceHandle layer_changed_event; |
| 72 | static bool visualizer_enabled = false; | 71 | static 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 | ||
| 135 | static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systime_t delta, systime_t* sleep_time) { | 134 | static 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 |
| 334 | static THD_WORKING_AREA(visualizerThreadStack, 1024); | 333 | static DECLARE_THREAD_STACK(visualizerThreadStack, 1024); |
| 335 | static THD_FUNCTION(visualizerThread, arg) { | 334 | static 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, ¤t_status)) { | 374 | if (!same_status(&state.status, ¤t_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 | ||
| 433 | void visualizer_init(void) { | 435 | void 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 | ||
| 457 | void update_status(bool changed) { | 458 | void 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 | ||
| 23 | GFXLIB = $(VISUALIZER_DIR)/ugfx | 23 | GFXLIB = $(VISUALIZER_DIR)/ugfx |
| 24 | ifndef EMULATOR | ||
| 25 | SRC += $(VISUALIZER_DIR)/visualizer.c | 24 | SRC += $(VISUALIZER_DIR)/visualizer.c |
| 26 | endif | ||
| 27 | UINCDIR += $(GFXINC) $(VISUALIZER_DIR) | 25 | UINCDIR += $(GFXINC) $(VISUALIZER_DIR) |
| 28 | 26 | ||
| 29 | ifdef LCD_ENABLE | 27 | ifdef LCD_ENABLE |
| @@ -33,13 +31,17 @@ USE_UGFX = yes | |||
| 33 | endif | 31 | endif |
| 34 | 32 | ||
| 35 | ifdef LCD_BACKLIGHT_ENABLE | 33 | ifdef LCD_BACKLIGHT_ENABLE |
| 34 | ifndef EMULATOR | ||
| 36 | SRC += $(VISUALIZER_DIR)/lcd_backlight.c | 35 | SRC += $(VISUALIZER_DIR)/lcd_backlight.c |
| 37 | SRC += lcd_backlight_hal.c | 36 | SRC += lcd_backlight_hal.c |
| 37 | endif | ||
| 38 | UDEFS += -DLCD_BACKLIGHT_ENABLE | 38 | UDEFS += -DLCD_BACKLIGHT_ENABLE |
| 39 | endif | 39 | endif |
| 40 | 40 | ||
| 41 | ifdef LED_ENABLE | 41 | ifdef LED_ENABLE |
| 42 | ifndef EMULATOR | ||
| 42 | SRC += $(VISUALIZER_DIR)/led_test.c | 43 | SRC += $(VISUALIZER_DIR)/led_test.c |
| 44 | endif | ||
| 43 | UDEFS += -DLED_ENABLE | 45 | UDEFS += -DLED_ENABLE |
| 44 | USE_UGFX = yes | 46 | USE_UGFX = yes |
| 45 | endif | 47 | endif |
| @@ -56,4 +58,8 @@ ifndef EMULATOR | |||
| 56 | VISUALIZER_USER = visualizer_user.c | 58 | VISUALIZER_USER = visualizer_user.c |
| 57 | endif | 59 | endif |
| 58 | endif | 60 | endif |
| 59 | SRC += $(VISUALIZER_USER) \ No newline at end of file | 61 | SRC += $(VISUALIZER_USER) |
| 62 | |||
| 63 | ifdef EMULATOR | ||
| 64 | UINCDIR += $(TMK_DIR)/common | ||
| 65 | endif \ No newline at end of file | ||
