aboutsummaryrefslogtreecommitdiff
path: root/quantum/visualizer
diff options
context:
space:
mode:
authorLuiz Ribeiro <luizribeiro@gmail.com>2017-07-04 11:17:28 -0400
committerLuiz Ribeiro <luizribeiro@gmail.com>2017-07-04 11:17:28 -0400
commitd5486265b8afcada68306c815b08c225fce287af (patch)
tree8fb7f8fee4aa3937003bd69d5c77ca867c010d12 /quantum/visualizer
parent738b072bb0f25d0369a998c550c369e4f64cc7a5 (diff)
parent34c8bf47a76c8a2dcd3b1a19dd608f8fb2fafb31 (diff)
downloadqmk_firmware-d5486265b8afcada68306c815b08c225fce287af.tar.gz
qmk_firmware-d5486265b8afcada68306c815b08c225fce287af.zip
Merge branch 'master' into ps2avrGB
Diffstat (limited to 'quantum/visualizer')
-rw-r--r--quantum/visualizer/lcd_backlight.c4
-rw-r--r--quantum/visualizer/lcd_backlight.h3
-rw-r--r--quantum/visualizer/led_keyframes.c20
-rw-r--r--quantum/visualizer/led_keyframes.h3
-rw-r--r--quantum/visualizer/visualizer.c67
-rw-r--r--quantum/visualizer/visualizer.h10
-rw-r--r--quantum/visualizer/visualizer.mk29
7 files changed, 101 insertions, 35 deletions
diff --git a/quantum/visualizer/lcd_backlight.c b/quantum/visualizer/lcd_backlight.c
index 00de3fab5..6cd996f75 100644
--- a/quantum/visualizer/lcd_backlight.c
+++ b/quantum/visualizer/lcd_backlight.c
@@ -83,3 +83,7 @@ void lcd_backlight_brightness(uint8_t b) {
83 current_brightness = b; 83 current_brightness = b;
84 lcd_backlight_color(current_hue, current_saturation, current_intensity); 84 lcd_backlight_color(current_hue, current_saturation, current_intensity);
85} 85}
86
87uint8_t lcd_get_backlight_brightness(void) {
88 return current_brightness;
89}
diff --git a/quantum/visualizer/lcd_backlight.h b/quantum/visualizer/lcd_backlight.h
index 14dde64a1..95d7a07b4 100644
--- a/quantum/visualizer/lcd_backlight.h
+++ b/quantum/visualizer/lcd_backlight.h
@@ -32,13 +32,14 @@ SOFTWARE.
32#define LCD_SAT(color) ((color >> 8) & 0xFF) 32#define LCD_SAT(color) ((color >> 8) & 0xFF)
33#define LCD_INT(color) (color & 0xFF) 33#define LCD_INT(color) (color & 0xFF)
34 34
35inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) { 35static inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) {
36 return (color & 0xFFFFFF00) | new_intensity; 36 return (color & 0xFFFFFF00) | new_intensity;
37} 37}
38 38
39void lcd_backlight_init(void); 39void lcd_backlight_init(void);
40void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity); 40void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity);
41void lcd_backlight_brightness(uint8_t b); 41void lcd_backlight_brightness(uint8_t b);
42uint8_t lcd_get_backlight_brightness(void);
42 43
43void lcd_backlight_hal_init(void); 44void lcd_backlight_hal_init(void);
44void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b); 45void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b);
diff --git a/quantum/visualizer/led_keyframes.c b/quantum/visualizer/led_keyframes.c
index 2dacd990d..7e6e5d1ab 100644
--- a/quantum/visualizer/led_keyframes.c
+++ b/quantum/visualizer/led_keyframes.c
@@ -41,14 +41,14 @@ static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint
41} 41}
42 42
43// TODO: Should be customizable per keyboard 43// TODO: Should be customizable per keyboard
44#define NUM_ROWS 7 44#define NUM_ROWS LED_NUM_ROWS
45#define NUM_COLS 7 45#define NUM_COLS LED_NUM_COLS
46 46
47static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS]; 47static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS];
48static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS]; 48static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS];
49 49
50static uint8_t compute_gradient_color(float t, float index, float num) { 50static uint8_t compute_gradient_color(float t, float index, float num) {
51 const float two_pi = M_2_PI; 51 const float two_pi = M_PI * 2.0f;
52 float normalized_index = (1.0f - index / (num - 1.0f)) * two_pi; 52 float normalized_index = (1.0f - index / (num - 1.0f)) * two_pi;
53 float x = t * two_pi + normalized_index; 53 float x = t * two_pi + normalized_index;
54 float v = 0.5 * (cosf(x) + 1.0f); 54 float v = 0.5 * (cosf(x) + 1.0f);
@@ -127,3 +127,17 @@ bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer
127 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0); 127 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0);
128 return false; 128 return false;
129} 129}
130
131bool led_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
132 (void)state;
133 (void)animation;
134 gdispGSetPowerMode(LED_DISPLAY, powerOff);
135 return false;
136}
137
138bool led_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
139 (void)state;
140 (void)animation;
141 gdispGSetPowerMode(LED_DISPLAY, powerOn);
142 return false;
143}
diff --git a/quantum/visualizer/led_keyframes.h b/quantum/visualizer/led_keyframes.h
index a68943041..a59a4f37d 100644
--- a/quantum/visualizer/led_keyframes.h
+++ b/quantum/visualizer/led_keyframes.h
@@ -35,6 +35,9 @@ bool led_keyframe_crossfade(keyframe_animation_t* animation, visualizer_state_t*
35bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state); 35bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
36bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state); 36bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
37 37
38bool led_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state);
39bool led_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state);
40
38extern keyframe_animation_t led_test_animation; 41extern keyframe_animation_t led_test_animation;
39 42
40 43
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 6f134097f..cc99d1e3b 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -22,8 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#include "visualizer.h"
26#include "config.h" 25#include "config.h"
26#include "visualizer.h"
27#include <string.h> 27#include <string.h>
28#ifdef PROTOCOL_CHIBIOS 28#ifdef PROTOCOL_CHIBIOS
29#include "ch.h" 29#include "ch.h"
@@ -58,8 +58,11 @@ SOFTWARE.
58static visualizer_keyboard_status_t current_status = { 58static visualizer_keyboard_status_t current_status = {
59 .layer = 0xFFFFFFFF, 59 .layer = 0xFFFFFFFF,
60 .default_layer = 0xFFFFFFFF, 60 .default_layer = 0xFFFFFFFF,
61 .mods = 0xFF,
62 .leds = 0xFFFFFFFF, 61 .leds = 0xFFFFFFFF,
62#ifdef BACKLIGHT_ENABLE
63 .backlight_level = 0,
64#endif
65 .mods = 0xFF,
63 .suspended = false, 66 .suspended = false,
64#ifdef VISUALIZER_USER_DATA_SIZE 67#ifdef VISUALIZER_USER_DATA_SIZE
65 .user_data = {0} 68 .user_data = {0}
@@ -72,6 +75,9 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa
72 status1->mods == status2->mods && 75 status1->mods == status2->mods &&
73 status1->leds == status2->leds && 76 status1->leds == status2->leds &&
74 status1->suspended == status2->suspended 77 status1->suspended == status2->suspended
78#ifdef BACKLIGHT_ENABLE
79 && status1->backlight_level == status2->backlight_level
80#endif
75#ifdef VISUALIZER_USER_DATA_SIZE 81#ifdef VISUALIZER_USER_DATA_SIZE
76 && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0 82 && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0
77#endif 83#endif
@@ -99,15 +105,19 @@ static remote_object_t* remote_objects[] = {
99GDisplay* LCD_DISPLAY = 0; 105GDisplay* LCD_DISPLAY = 0;
100GDisplay* LED_DISPLAY = 0; 106GDisplay* LED_DISPLAY = 0;
101 107
108#ifdef LCD_DISPLAY_NUMBER
102__attribute__((weak)) 109__attribute__((weak))
103GDisplay* get_lcd_display(void) { 110GDisplay* get_lcd_display(void) {
104 return gdispGetDisplay(0); 111 return gdispGetDisplay(LCD_DISPLAY_NUMBER);
105} 112}
113#endif
106 114
115#ifdef LED_DISPLAY_NUMBER
107__attribute__((weak)) 116__attribute__((weak))
108GDisplay* get_led_display(void) { 117GDisplay* get_led_display(void) {
109 return gdispGetDisplay(1); 118 return gdispGetDisplay(LED_DISPLAY_NUMBER);
110} 119}
120#endif
111 121
112void start_keyframe_animation(keyframe_animation_t* animation) { 122void start_keyframe_animation(keyframe_animation_t* animation) {
113 animation->current_frame = -1; 123 animation->current_frame = -1;
@@ -245,9 +255,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
245 .mods = 0xFF, 255 .mods = 0xFF,
246 .leds = 0xFFFFFFFF, 256 .leds = 0xFFFFFFFF,
247 .suspended = false, 257 .suspended = false,
248#ifdef VISUALIZER_USER_DATA_SIZE 258 #ifdef VISUALIZER_USER_DATA_SIZE
249 .user_data = {0}, 259 .user_data = {0},
250#endif 260 #endif
251 }; 261 };
252 262
253 visualizer_state_t state = { 263 visualizer_state_t state = {
@@ -279,6 +289,18 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
279 bool enabled = visualizer_enabled; 289 bool enabled = visualizer_enabled;
280 if (force_update || !same_status(&state.status, &current_status)) { 290 if (force_update || !same_status(&state.status, &current_status)) {
281 force_update = false; 291 force_update = false;
292 #if BACKLIGHT_ENABLE
293 if(current_status.backlight_level != state.status.backlight_level) {
294 if (current_status.backlight_level != 0) {
295 gdispGSetPowerMode(LED_DISPLAY, powerOn);
296 uint16_t percent = (uint16_t)current_status.backlight_level * 100 / BACKLIGHT_LEVELS;
297 gdispGSetBacklight(LED_DISPLAY, percent);
298 }
299 else {
300 gdispGSetPowerMode(LED_DISPLAY, powerOff);
301 }
302 }
303 #endif
282 if (visualizer_enabled) { 304 if (visualizer_enabled) {
283 if (current_status.suspended) { 305 if (current_status.suspended) {
284 stop_all_keyframe_animations(); 306 stop_all_keyframe_animations();
@@ -309,7 +331,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
309 update_keyframe_animation(animations[i], &state, delta, &sleep_time); 331 update_keyframe_animation(animations[i], &state, delta, &sleep_time);
310 } 332 }
311 } 333 }
312#ifdef LED_ENABLE 334#ifdef BACKLIGHT_ENABLE
313 gdispGFlush(LED_DISPLAY); 335 gdispGFlush(LED_DISPLAY);
314#endif 336#endif
315 337
@@ -361,25 +383,26 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
361void visualizer_init(void) { 383void visualizer_init(void) {
362 gfxInit(); 384 gfxInit();
363 385
364#ifdef LCD_BACKLIGHT_ENABLE 386 #ifdef LCD_BACKLIGHT_ENABLE
365 lcd_backlight_init(); 387 lcd_backlight_init();
366#endif 388 #endif
367 389
368#ifdef SERIAL_LINK_ENABLE 390 #ifdef SERIAL_LINK_ENABLE
369 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) ); 391 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
370#endif 392 #endif
371 393
372#ifdef LCD_ENABLE 394 #ifdef LCD_ENABLE
373 LCD_DISPLAY = get_lcd_display(); 395 LCD_DISPLAY = get_lcd_display();
374#endif 396 #endif
375#ifdef LED_ENABLE 397
398 #ifdef BACKLIGHT_ENABLE
376 LED_DISPLAY = get_led_display(); 399 LED_DISPLAY = get_led_display();
377#endif 400 #endif
378 401
379 // We are using a low priority thread, the idea is to have it run only 402 // We are using a low priority thread, the idea is to have it run only
380 // when the main thread is sleeping during the matrix scanning 403 // when the main thread is sleeping during the matrix scanning
381 gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack), 404 gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
382 VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL); 405 VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
383} 406}
384 407
385void update_status(bool changed) { 408void update_status(bool changed) {
@@ -445,6 +468,9 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uin
445 .default_layer = default_state, 468 .default_layer = default_state,
446 .mods = mods, 469 .mods = mods,
447 .leds = leds, 470 .leds = leds,
471#ifdef BACKLIGHT_ENABLE
472 .backlight_level = current_status.backlight_level,
473#endif
448 .suspended = current_status.suspended, 474 .suspended = current_status.suspended,
449 }; 475 };
450#ifdef VISUALIZER_USER_DATA_SIZE 476#ifdef VISUALIZER_USER_DATA_SIZE
@@ -467,3 +493,10 @@ void visualizer_resume(void) {
467 current_status.suspended = false; 493 current_status.suspended = false;
468 update_status(true); 494 update_status(true);
469} 495}
496
497#ifdef BACKLIGHT_ENABLE
498void backlight_set(uint8_t level) {
499 current_status.backlight_level = level;
500 update_status(true);
501}
502#endif
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index d6f279e10..90ecdcbae 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -28,12 +28,17 @@ SOFTWARE.
28#include <stdint.h> 28#include <stdint.h>
29#include <stdbool.h> 29#include <stdbool.h>
30 30
31#include "config.h"
31#include "gfx.h" 32#include "gfx.h"
32 33
33#ifdef LCD_BACKLIGHT_ENABLE 34#ifdef LCD_BACKLIGHT_ENABLE
34#include "lcd_backlight.h" 35#include "lcd_backlight.h"
35#endif 36#endif
36 37
38#ifdef BACKLIGHT_ENABLE
39#include "backlight.h"
40#endif
41
37// use this function to merge both real_mods and oneshot_mods in a uint16_t 42// use this function to merge both real_mods and oneshot_mods in a uint16_t
38uint8_t visualizer_get_mods(void); 43uint8_t visualizer_get_mods(void);
39 44
@@ -65,9 +70,12 @@ struct keyframe_animation_t;
65typedef struct { 70typedef struct {
66 uint32_t layer; 71 uint32_t layer;
67 uint32_t default_layer; 72 uint32_t default_layer;
68 uint8_t mods;
69 uint32_t leds; // See led.h for available statuses 73 uint32_t leds; // See led.h for available statuses
74 uint8_t mods;
70 bool suspended; 75 bool suspended;
76#ifdef BACKLIGHT_ENABLE
77 uint8_t backlight_level;
78#endif
71#ifdef VISUALIZER_USER_DATA_SIZE 79#ifdef VISUALIZER_USER_DATA_SIZE
72 uint8_t user_data[VISUALIZER_USER_DATA_SIZE]; 80 uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
73#endif 81#endif
diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk
index 5f710124b..0f7d8636c 100644
--- a/quantum/visualizer/visualizer.mk
+++ b/quantum/visualizer/visualizer.mk
@@ -42,9 +42,8 @@ SRC += $(VISUALIZER_DIR)/resources/lcd_logo.c
42OPT_DEFS += -DLCD_BACKLIGHT_ENABLE 42OPT_DEFS += -DLCD_BACKLIGHT_ENABLE
43endif 43endif
44 44
45ifeq ($(strip $(LED_ENABLE)), yes) 45ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
46SRC += $(VISUALIZER_DIR)/led_keyframes.c 46SRC += $(VISUALIZER_DIR)/led_keyframes.c
47OPT_DEFS += -DLED_ENABLE
48endif 47endif
49 48
50include $(GFXLIB)/gfx.mk 49include $(GFXLIB)/gfx.mk
@@ -52,19 +51,23 @@ GFXSRC := $(patsubst $(TOP_DIR)/%,%,$(GFXSRC))
52GFXDEFS := $(patsubst %,-D%,$(patsubst -D%,%,$(GFXDEFS))) 51GFXDEFS := $(patsubst %,-D%,$(patsubst -D%,%,$(GFXDEFS)))
53 52
54ifneq ("$(wildcard $(KEYMAP_PATH)/visualizer.c)","") 53ifneq ("$(wildcard $(KEYMAP_PATH)/visualizer.c)","")
55 SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c 54 SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c
56else 55else
57 ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","") 56 ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","")
58 ifeq ("$(wildcard $(SUBPROJECT_PATH)/visualizer.c)","") 57 ifeq ("$(wildcard $(SUBPROJECT_PATH)/visualizer.c)","")
59$(error "$(KEYMAP_PATH)/visualizer.c" does not exist) 58 ifeq ("$(wildcard $(KEYBOARD_PATH)/visualizer.c)","")
60 else 59$(error "visualizer.c" not found")
61 SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/visualizer.c 60 else
62 endif 61 SRC += keyboards/$(KEYBOARD)/visualizer.c
63 else 62 endif
64 SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c 63 else
65 endif 64 SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/visualizer.c
65 endif
66 else
67 SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c
68 endif
66endif 69endif
67 70
68ifdef EMULATOR 71ifdef EMULATOR
69UINCDIR += $(TMK_DIR)/common 72UINCDIR += $(TMK_DIR)/common
70endif \ No newline at end of file 73endif