aboutsummaryrefslogtreecommitdiff
path: root/quantum/visualizer
diff options
context:
space:
mode:
authorDamien <Dbroqua@users.noreply.github.com>2017-04-13 13:26:02 +0200
committerGitHub <noreply@github.com>2017-04-13 13:26:02 +0200
commita43cb6c0af3ac616903172c4b8932bfc5ee4939b (patch)
treec3ca94b544ab832507b37b6268bb04f7f7eedb4a /quantum/visualizer
parent3e41cde9f99778ca30c03b97470c32780379db43 (diff)
parentd3301c0f8b0005738ab9aa2030d83739ffb5c4b6 (diff)
downloadqmk_firmware-a43cb6c0af3ac616903172c4b8932bfc5ee4939b.tar.gz
qmk_firmware-a43cb6c0af3ac616903172c4b8932bfc5ee4939b.zip
Merge pull request #20 from qmk/master
Merge from QMK
Diffstat (limited to 'quantum/visualizer')
-rw-r--r--quantum/visualizer/example_integration/callbacks.c36
-rw-r--r--quantum/visualizer/example_integration/gfxconf.h325
-rw-r--r--quantum/visualizer/example_integration/lcd_backlight_hal.c91
-rw-r--r--quantum/visualizer/example_integration/visualizer_user.c121
-rw-r--r--quantum/visualizer/lcd_backlight.c8
-rw-r--r--quantum/visualizer/lcd_backlight.h4
-rw-r--r--quantum/visualizer/lcd_backlight_keyframes.c77
-rw-r--r--quantum/visualizer/lcd_backlight_keyframes.h30
-rw-r--r--quantum/visualizer/lcd_keyframes.c188
-rw-r--r--quantum/visualizer/lcd_keyframes.h39
-rw-r--r--quantum/visualizer/led_keyframes.c (renamed from quantum/visualizer/led_test.c)57
-rw-r--r--quantum/visualizer/led_keyframes.h (renamed from quantum/visualizer/led_test.h)20
-rw-r--r--quantum/visualizer/resources/lcd_logo.c61
-rw-r--r--quantum/visualizer/resources/lcd_logo.pngbin0 -> 490 bytes
-rw-r--r--quantum/visualizer/resources/resources.h27
-rw-r--r--quantum/visualizer/visualizer.c226
-rw-r--r--quantum/visualizer/visualizer.h41
-rw-r--r--quantum/visualizer/visualizer.mk21
-rw-r--r--quantum/visualizer/visualizer_keyframes.c23
-rw-r--r--quantum/visualizer/visualizer_keyframes.h26
20 files changed, 576 insertions, 845 deletions
diff --git a/quantum/visualizer/example_integration/callbacks.c b/quantum/visualizer/example_integration/callbacks.c
deleted file mode 100644
index 2539615d6..000000000
--- a/quantum/visualizer/example_integration/callbacks.c
+++ /dev/null
@@ -1,36 +0,0 @@
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#include "keyboard.h"
26#include "action_layer.h"
27#include "visualizer.h"
28#include "host.h"
29
30void post_keyboard_init(void) {
31 visualizer_init();
32}
33
34void post_keyboard_task() {
35 visualizer_set_state(default_layer_state, layer_state, host_keyboard_leds());
36}
diff --git a/quantum/visualizer/example_integration/gfxconf.h b/quantum/visualizer/example_integration/gfxconf.h
deleted file mode 100644
index 304c5d187..000000000
--- a/quantum/visualizer/example_integration/gfxconf.h
+++ /dev/null
@@ -1,325 +0,0 @@
1/**
2 * This file has a different license to the rest of the uGFX system.
3 * You can copy, modify and distribute this file as you see fit.
4 * You do not need to publish your source modifications to this file.
5 * The only thing you are not permitted to do is to relicense it
6 * under a different license.
7 */
8
9/**
10 * Copy this file into your project directory and rename it as gfxconf.h
11 * Edit your copy to turn on the uGFX features you want to use.
12 * The values below are the defaults.
13 *
14 * Only remove the comments from lines where you want to change the
15 * default value. This allows definitions to be included from
16 * driver makefiles when required and provides the best future
17 * compatibility for your project.
18 *
19 * Please use spaces instead of tabs in this file.
20 */
21
22#ifndef _GFXCONF_H
23#define _GFXCONF_H
24
25
26///////////////////////////////////////////////////////////////////////////
27// GOS - One of these must be defined, preferably in your Makefile //
28///////////////////////////////////////////////////////////////////////////
29#define GFX_USE_OS_CHIBIOS TRUE
30//#define GFX_USE_OS_FREERTOS FALSE
31// #define GFX_FREERTOS_USE_TRACE FALSE
32//#define GFX_USE_OS_WIN32 FALSE
33//#define GFX_USE_OS_LINUX FALSE
34//#define GFX_USE_OS_OSX FALSE
35//#define GFX_USE_OS_ECOS FALSE
36//#define GFX_USE_OS_RAWRTOS FALSE
37//#define GFX_USE_OS_ARDUINO FALSE
38//#define GFX_USE_OS_KEIL FALSE
39//#define GFX_USE_OS_CMSIS FALSE
40//#define GFX_USE_OS_RAW32 FALSE
41// #define INTERRUPTS_OFF() optional_code
42// #define INTERRUPTS_ON() optional_code
43// These are not defined by default for some reason
44#define GOS_NEED_X_THREADS FALSE
45#define GOS_NEED_X_HEAP FALSE
46
47// Options that (should where relevant) apply to all operating systems
48 #define GFX_NO_INLINE FALSE
49// #define GFX_COMPILER GFX_COMPILER_UNKNOWN
50// #define GFX_CPU GFX_CPU_UNKNOWN
51// #define GFX_OS_HEAP_SIZE 0
52// #define GFX_OS_NO_INIT FALSE
53// #define GFX_OS_INIT_NO_WARNING FALSE
54// #define GFX_OS_PRE_INIT_FUNCTION myHardwareInitRoutine
55// #define GFX_OS_EXTRA_INIT_FUNCTION myOSInitRoutine
56// #define GFX_OS_EXTRA_DEINIT_FUNCTION myOSDeInitRoutine
57
58
59///////////////////////////////////////////////////////////////////////////
60// GDISP //
61///////////////////////////////////////////////////////////////////////////
62#define GFX_USE_GDISP TRUE
63
64//#define GDISP_NEED_AUTOFLUSH FALSE
65//#define GDISP_NEED_TIMERFLUSH FALSE
66//#define GDISP_NEED_VALIDATION TRUE
67//#define GDISP_NEED_CLIP TRUE
68//#define GDISP_NEED_CIRCLE FALSE
69//#define GDISP_NEED_ELLIPSE FALSE
70//#define GDISP_NEED_ARC FALSE
71//#define GDISP_NEED_ARCSECTORS FALSE
72//#define GDISP_NEED_CONVEX_POLYGON FALSE
73//#define GDISP_NEED_SCROLL FALSE
74//#define GDISP_NEED_PIXELREAD FALSE
75//#define GDISP_NEED_CONTROL FALSE
76//#define GDISP_NEED_QUERY FALSE
77//#define GDISP_NEED_MULTITHREAD FALSE
78//#define GDISP_NEED_STREAMING FALSE
79#define GDISP_NEED_TEXT TRUE
80// #define GDISP_NEED_TEXT_WORDWRAP FALSE
81// #define GDISP_NEED_ANTIALIAS FALSE
82// #define GDISP_NEED_UTF8 FALSE
83 #define GDISP_NEED_TEXT_KERNING TRUE
84// #define GDISP_INCLUDE_FONT_UI1 FALSE
85// #define GDISP_INCLUDE_FONT_UI2 FALSE // The smallest preferred font.
86// #define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
87// #define GDISP_INCLUDE_FONT_DEJAVUSANS10 FALSE
88// #define GDISP_INCLUDE_FONT_DEJAVUSANS12 FALSE
89// #define GDISP_INCLUDE_FONT_DEJAVUSANS16 FALSE
90// #define GDISP_INCLUDE_FONT_DEJAVUSANS20 FALSE
91// #define GDISP_INCLUDE_FONT_DEJAVUSANS24 FALSE
92// #define GDISP_INCLUDE_FONT_DEJAVUSANS32 FALSE
93 #define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12 TRUE
94// #define GDISP_INCLUDE_FONT_FIXED_10X20 FALSE
95// #define GDISP_INCLUDE_FONT_FIXED_7X14 FALSE
96 #define GDISP_INCLUDE_FONT_FIXED_5X8 TRUE
97// #define GDISP_INCLUDE_FONT_DEJAVUSANS12_AA FALSE
98// #define GDISP_INCLUDE_FONT_DEJAVUSANS16_AA FALSE
99// #define GDISP_INCLUDE_FONT_DEJAVUSANS20_AA FALSE
100// #define GDISP_INCLUDE_FONT_DEJAVUSANS24_AA FALSE
101// #define GDISP_INCLUDE_FONT_DEJAVUSANS32_AA FALSE
102// #define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12_AA FALSE
103// #define GDISP_INCLUDE_USER_FONTS FALSE
104
105//#define GDISP_NEED_IMAGE FALSE
106// #define GDISP_NEED_IMAGE_NATIVE FALSE
107// #define GDISP_NEED_IMAGE_GIF FALSE
108// #define GDISP_NEED_IMAGE_BMP FALSE
109// #define GDISP_NEED_IMAGE_BMP_1 FALSE
110// #define GDISP_NEED_IMAGE_BMP_4 FALSE
111// #define GDISP_NEED_IMAGE_BMP_4_RLE FALSE
112// #define GDISP_NEED_IMAGE_BMP_8 FALSE
113// #define GDISP_NEED_IMAGE_BMP_8_RLE FALSE
114// #define GDISP_NEED_IMAGE_BMP_16 FALSE
115// #define GDISP_NEED_IMAGE_BMP_24 FALSE
116// #define GDISP_NEED_IMAGE_BMP_32 FALSE
117// #define GDISP_NEED_IMAGE_JPG FALSE
118// #define GDISP_NEED_IMAGE_PNG FALSE
119// #define GDISP_NEED_IMAGE_ACCOUNTING FALSE
120
121//#define GDISP_NEED_PIXMAP FALSE
122// #define GDISP_NEED_PIXMAP_IMAGE FALSE
123
124//#define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE // If not defined the native hardware orientation is used.
125//#define GDISP_LINEBUF_SIZE 128
126//#define GDISP_STARTUP_COLOR Black
127#define GDISP_NEED_STARTUP_LOGO FALSE
128
129//#define GDISP_TOTAL_DISPLAYS 1
130
131//#define GDISP_DRIVER_LIST GDISPVMT_Win32, GDISPVMT_Win32
132// #ifdef GDISP_DRIVER_LIST
133// // For code and speed optimization define as TRUE or FALSE if all controllers have the same capability
134// #define GDISP_HARDWARE_STREAM_WRITE FALSE
135// #define GDISP_HARDWARE_STREAM_READ FALSE
136// #define GDISP_HARDWARE_STREAM_POS FALSE
137// #define GDISP_HARDWARE_DRAWPIXEL FALSE
138// #define GDISP_HARDWARE_CLEARS FALSE
139// #define GDISP_HARDWARE_FILLS FALSE
140// #define GDISP_HARDWARE_BITFILLS FALSE
141// #define GDISP_HARDWARE_SCROLL FALSE
142// #define GDISP_HARDWARE_PIXELREAD FALSE
143// #define GDISP_HARDWARE_CONTROL FALSE
144// #define GDISP_HARDWARE_QUERY FALSE
145// #define GDISP_HARDWARE_CLIP FALSE
146
147 #define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
148// #endif
149
150// The custom format is not defined for some reason, so define it as error
151// so we don't get compiler warnings
152#define GDISP_PIXELFORMAT_CUSTOM GDISP_PIXELFORMAT_ERROR
153
154#define GDISP_USE_GFXNET FALSE
155// #define GDISP_GFXNET_PORT 13001
156// #define GDISP_GFXNET_CUSTOM_LWIP_STARTUP FALSE
157// #define GDISP_DONT_WAIT_FOR_NET_DISPLAY FALSE
158// #define GDISP_GFXNET_UNSAFE_SOCKETS FALSE
159
160
161///////////////////////////////////////////////////////////////////////////
162// GWIN //
163///////////////////////////////////////////////////////////////////////////
164#define GFX_USE_GWIN FALSE
165
166//#define GWIN_NEED_WINDOWMANAGER FALSE
167// #define GWIN_REDRAW_IMMEDIATE FALSE
168// #define GWIN_REDRAW_SINGLEOP FALSE
169// #define GWIN_NEED_FLASHING FALSE
170// #define GWIN_FLASHING_PERIOD 250
171
172//#define GWIN_NEED_CONSOLE FALSE
173// #define GWIN_CONSOLE_USE_HISTORY FALSE
174// #define GWIN_CONSOLE_HISTORY_AVERAGING FALSE
175// #define GWIN_CONSOLE_HISTORY_ATCREATE FALSE
176// #define GWIN_CONSOLE_ESCSEQ FALSE
177// #define GWIN_CONSOLE_USE_BASESTREAM FALSE
178// #define GWIN_CONSOLE_USE_FLOAT FALSE
179//#define GWIN_NEED_GRAPH FALSE
180//#define GWIN_NEED_GL3D FALSE
181
182//#define GWIN_NEED_WIDGET FALSE
183//#define GWIN_FOCUS_HIGHLIGHT_WIDTH 1
184// #define GWIN_NEED_LABEL FALSE
185// #define GWIN_LABEL_ATTRIBUTE FALSE
186// #define GWIN_NEED_BUTTON FALSE
187// #define GWIN_BUTTON_LAZY_RELEASE FALSE
188// #define GWIN_NEED_SLIDER FALSE
189// #define GWIN_SLIDER_NOSNAP FALSE
190// #define GWIN_SLIDER_DEAD_BAND 5
191// #define GWIN_SLIDER_TOGGLE_INC 20
192// #define GWIN_NEED_CHECKBOX FALSE
193// #define GWIN_NEED_IMAGE FALSE
194// #define GWIN_NEED_IMAGE_ANIMATION FALSE
195// #define GWIN_NEED_RADIO FALSE
196// #define GWIN_NEED_LIST FALSE
197// #define GWIN_NEED_LIST_IMAGES FALSE
198// #define GWIN_NEED_PROGRESSBAR FALSE
199// #define GWIN_PROGRESSBAR_AUTO FALSE
200// #define GWIN_NEED_KEYBOARD FALSE
201// #define GWIN_KEYBOARD_DEFAULT_LAYOUT VirtualKeyboard_English1
202// #define GWIN_NEED_KEYBOARD_ENGLISH1 TRUE
203// #define GWIN_NEED_TEXTEDIT FALSE
204// #define GWIN_FLAT_STYLING FALSE
205// #define GWIN_WIDGET_TAGS FALSE
206
207//#define GWIN_NEED_CONTAINERS FALSE
208// #define GWIN_NEED_CONTAINER FALSE
209// #define GWIN_NEED_FRAME FALSE
210// #define GWIN_NEED_TABSET FALSE
211// #define GWIN_TABSET_TABHEIGHT 18
212
213
214///////////////////////////////////////////////////////////////////////////
215// GEVENT //
216///////////////////////////////////////////////////////////////////////////
217#define GFX_USE_GEVENT FALSE
218
219//#define GEVENT_ASSERT_NO_RESOURCE FALSE
220//#define GEVENT_MAXIMUM_SIZE 32
221//#define GEVENT_MAX_SOURCE_LISTENERS 32
222
223
224///////////////////////////////////////////////////////////////////////////
225// GTIMER //
226///////////////////////////////////////////////////////////////////////////
227#define GFX_USE_GTIMER FALSE
228
229//#define GTIMER_THREAD_PRIORITY HIGH_PRIORITY
230//#define GTIMER_THREAD_WORKAREA_SIZE 2048
231
232
233///////////////////////////////////////////////////////////////////////////
234// GQUEUE //
235///////////////////////////////////////////////////////////////////////////
236#define GFX_USE_GQUEUE FALSE
237
238//#define GQUEUE_NEED_ASYNC FALSE
239//#define GQUEUE_NEED_GSYNC FALSE
240//#define GQUEUE_NEED_FSYNC FALSE
241//#define GQUEUE_NEED_BUFFERS FALSE
242
243///////////////////////////////////////////////////////////////////////////
244// GINPUT //
245///////////////////////////////////////////////////////////////////////////
246#define GFX_USE_GINPUT FALSE
247
248//#define GINPUT_NEED_MOUSE FALSE
249// #define GINPUT_TOUCH_STARTRAW FALSE
250// #define GINPUT_TOUCH_NOTOUCH FALSE
251// #define GINPUT_TOUCH_NOCALIBRATE FALSE
252// #define GINPUT_TOUCH_NOCALIBRATE_GUI FALSE
253// #define GINPUT_MOUSE_POLL_PERIOD 25
254// #define GINPUT_MOUSE_CLICK_TIME 300
255// #define GINPUT_TOUCH_CXTCLICK_TIME 700
256// #define GINPUT_TOUCH_USER_CALIBRATION_LOAD FALSE
257// #define GINPUT_TOUCH_USER_CALIBRATION_SAVE FALSE
258// #define GMOUSE_DRIVER_LIST GMOUSEVMT_Win32, GMOUSEVMT_Win32
259//#define GINPUT_NEED_KEYBOARD FALSE
260// #define GINPUT_KEYBOARD_POLL_PERIOD 200
261// #define GKEYBOARD_DRIVER_LIST GKEYBOARDVMT_Win32, GKEYBOARDVMT_Win32
262// #define GKEYBOARD_LAYOUT_OFF FALSE
263// #define GKEYBOARD_LAYOUT_SCANCODE2_US FALSE
264//#define GINPUT_NEED_TOGGLE FALSE
265//#define GINPUT_NEED_DIAL FALSE
266
267
268///////////////////////////////////////////////////////////////////////////
269// GFILE //
270///////////////////////////////////////////////////////////////////////////
271#define GFX_USE_GFILE FALSE
272
273//#define GFILE_NEED_PRINTG FALSE
274//#define GFILE_NEED_SCANG FALSE
275//#define GFILE_NEED_STRINGS FALSE
276//#define GFILE_NEED_FILELISTS FALSE
277//#define GFILE_NEED_STDIO FALSE
278//#define GFILE_NEED_NOAUTOMOUNT FALSE
279//#define GFILE_NEED_NOAUTOSYNC FALSE
280
281//#define GFILE_NEED_MEMFS FALSE
282//#define GFILE_NEED_ROMFS FALSE
283//#define GFILE_NEED_RAMFS FALSE
284//#define GFILE_NEED_FATFS FALSE
285//#define GFILE_NEED_NATIVEFS FALSE
286//#define GFILE_NEED_CHBIOSFS FALSE
287
288//#define GFILE_ALLOW_FLOATS FALSE
289//#define GFILE_ALLOW_DEVICESPECIFIC FALSE
290//#define GFILE_MAX_GFILES 3
291
292///////////////////////////////////////////////////////////////////////////
293// GADC //
294///////////////////////////////////////////////////////////////////////////
295#define GFX_USE_GADC FALSE
296
297//#define GADC_MAX_LOWSPEED_DEVICES 4
298
299
300///////////////////////////////////////////////////////////////////////////
301// GAUDIO //
302///////////////////////////////////////////////////////////////////////////
303#define GFX_USE_GAUDIO FALSE
304// There seems to be a bug in the ugfx code, the wrong define is used
305// So define it in order to avoid warnings
306#define GFX_USE_GAUDIN GFX_USE_GAUDIO
307// #define GAUDIO_NEED_PLAY FALSE
308// #define GAUDIO_NEED_RECORD FALSE
309
310
311///////////////////////////////////////////////////////////////////////////
312// GMISC //
313///////////////////////////////////////////////////////////////////////////
314#define GFX_USE_GMISC FALSE
315
316//#define GMISC_NEED_ARRAYOPS FALSE
317//#define GMISC_NEED_FASTTRIG FALSE
318//#define GMISC_NEED_FIXEDTRIG FALSE
319//#define GMISC_NEED_INVSQRT FALSE
320// #define GMISC_INVSQRT_MIXED_ENDIAN FALSE
321// #define GMISC_INVSQRT_REAL_SLOW FALSE
322//#define GMISC_NEED_MATRIXFLOAT2D FALSE
323//#define GMISC_NEED_MATRIXFIXED2D FALSE
324
325#endif /* _GFXCONF_H */
diff --git a/quantum/visualizer/example_integration/lcd_backlight_hal.c b/quantum/visualizer/example_integration/lcd_backlight_hal.c
deleted file mode 100644
index 913131b16..000000000
--- a/quantum/visualizer/example_integration/lcd_backlight_hal.c
+++ /dev/null
@@ -1,91 +0,0 @@
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#include "lcd_backlight.h"
26#include "hal.h"
27
28#define RED_PIN 1
29#define GREEN_PIN 2
30#define BLUE_PIN 3
31#define CHANNEL_RED FTM0->CHANNEL[0]
32#define CHANNEL_GREEN FTM0->CHANNEL[1]
33#define CHANNEL_BLUE FTM0->CHANNEL[2]
34
35#define RGB_PORT PORTC
36#define RGB_PORT_GPIO GPIOC
37
38// Base FTM clock selection (72 MHz system clock)
39// @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period
40// Higher pre-scalar will use the most power (also look the best)
41// Pre-scalar calculations
42// 0 - 72 MHz -> 549 Hz
43// 1 - 36 MHz -> 275 Hz
44// 2 - 18 MHz -> 137 Hz
45// 3 - 9 MHz -> 69 Hz (Slightly visible flicker)
46// 4 - 4 500 kHz -> 34 Hz (Visible flickering)
47// 5 - 2 250 kHz -> 17 Hz
48// 6 - 1 125 kHz -> 9 Hz
49// 7 - 562 500 Hz -> 4 Hz
50// Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced
51// Which will reduce the brightness range
52#define PRESCALAR_DEFINE 0
53
54void lcd_backlight_hal_init(void) {
55 // Setup Backlight
56 SIM->SCGC6 |= SIM_SCGC6_FTM0;
57 FTM0->CNT = 0; // Reset counter
58
59 // PWM Period
60 // 16-bit maximum
61 FTM0->MOD = 0xFFFF;
62
63 // Set FTM to PWM output - Edge Aligned, Low-true pulses
64#define CNSC_MODE FTM_SC_CPWMS | FTM_SC_PS(4) | FTM_SC_CLKS(0)
65 CHANNEL_RED.CnSC = CNSC_MODE;
66 CHANNEL_GREEN.CnSC = CNSC_MODE;
67 CHANNEL_BLUE.CnSC = CNSC_MODE;
68
69 // System clock, /w prescalar setting
70 FTM0->SC = FTM_SC_CLKS(1) | FTM_SC_PS(PRESCALAR_DEFINE);
71
72 CHANNEL_RED.CnV = 0;
73 CHANNEL_GREEN.CnV = 0;
74 CHANNEL_BLUE.CnV = 0;
75
76 RGB_PORT_GPIO->PDDR |= (1 << RED_PIN);
77 RGB_PORT_GPIO->PDDR |= (1 << GREEN_PIN);
78 RGB_PORT_GPIO->PDDR |= (1 << BLUE_PIN);
79
80#define RGB_MODE PORTx_PCRn_SRE | PORTx_PCRn_DSE | PORTx_PCRn_MUX(4)
81 RGB_PORT->PCR[RED_PIN] = RGB_MODE;
82 RGB_PORT->PCR[GREEN_PIN] = RGB_MODE;
83 RGB_PORT->PCR[BLUE_PIN] = RGB_MODE;
84}
85
86void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) {
87 CHANNEL_RED.CnV = r;
88 CHANNEL_GREEN.CnV = g;
89 CHANNEL_BLUE.CnV = b;
90}
91
diff --git a/quantum/visualizer/example_integration/visualizer_user.c b/quantum/visualizer/example_integration/visualizer_user.c
deleted file mode 100644
index fc09fe2ea..000000000
--- a/quantum/visualizer/example_integration/visualizer_user.c
+++ /dev/null
@@ -1,121 +0,0 @@
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// Currently we are assuming that both the backlight and LCD are enabled
26// But it's entirely possible to write a custom visualizer that use only
27// one of them
28#ifndef LCD_BACKLIGHT_ENABLE
29#error This visualizer needs that LCD backlight is enabled
30#endif
31
32#ifndef LCD_ENABLE
33#error This visualizer needs that LCD is enabled
34#endif
35
36#include "visualizer.h"
37
38static const char* welcome_text[] = {"TMK", "Infinity Ergodox"};
39
40// Just an example how to write custom keyframe functions, we could have moved
41// all this into the init function
42bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) {
43 (void)animation;
44 // Read the uGFX documentation for information how to use the displays
45 // http://wiki.ugfx.org/index.php/Main_Page
46 gdispClear(White);
47 // You can use static variables for things that can't be found in the animation
48 // or state structs
49 gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black);
50 gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black);
51 // Always remember to flush the display
52 gdispFlush();
53 // you could set the backlight color as well, but we won't do it here, since
54 // it's part of the following animation
55 // lcd_backlight_color(hue, saturation, intensity);
56 // We don't need constant updates, just drawing the screen once is enough
57 return false;
58}
59
60// Feel free to modify the animations below, or even add new ones if needed
61
62// Don't worry, if the startup animation is long, you can use the keyboard like normal
63// during that time
64static keyframe_animation_t startup_animation = {
65 .num_frames = 4,
66 .loop = false,
67 .frame_lengths = {0, MS2ST(1000), MS2ST(5000), 0},
68 .frame_functions = {display_welcome, keyframe_animate_backlight_color, keyframe_no_operation, enable_visualization},
69};
70
71// The color animation animates the LCD color when you change layers
72static keyframe_animation_t color_animation = {
73 .num_frames = 2,
74 .loop = false,
75 // Note that there's a 200 ms no-operation frame,
76 // this prevents the color from changing when activating the layer
77 // momentarily
78 .frame_lengths = {MS2ST(200), MS2ST(500)},
79 .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color},
80};
81
82// The LCD animation alternates between the layer name display and a
83// bitmap that displays all active layers
84static keyframe_animation_t lcd_animation = {
85 .num_frames = 2,
86 .loop = true,
87 .frame_lengths = {MS2ST(2000), MS2ST(2000)},
88 .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap},
89};
90
91void initialize_user_visualizer(visualizer_state_t* state) {
92 // The brightness will be dynamically adjustable in the future
93 // But for now, change it here.
94 lcd_backlight_brightness(0x50);
95 state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF);
96 state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF);
97 start_keyframe_animation(&startup_animation);
98}
99
100void update_user_visualizer_state(visualizer_state_t* state) {
101 // Add more tests, change the colors and layer texts here
102 // Usually you want to check the high bits (higher layers first)
103 // because that's the order layers are processed for keypresses
104 // You can for check for example:
105 // state->status.layer
106 // state->status.default_layer
107 // state->status.leds (see led.h for available statuses)
108 if (state->status.layer & 0x2) {
109 state->target_lcd_color = LCD_COLOR(0xA0, 0xB0, 0xFF);
110 state->layer_text = "Layer 2";
111 }
112 else {
113 state->target_lcd_color = LCD_COLOR(0x50, 0xB0, 0xFF);
114 state->layer_text = "Layer 1";
115 }
116 // You can also stop existing animations, and start your custom ones here
117 // remember that you should normally have only one animation for the LCD
118 // and one for the background. But you can also combine them if you want.
119 start_keyframe_animation(&lcd_animation);
120 start_keyframe_animation(&color_animation);
121}
diff --git a/quantum/visualizer/lcd_backlight.c b/quantum/visualizer/lcd_backlight.c
index 70187d1e0..00de3fab5 100644
--- a/quantum/visualizer/lcd_backlight.c
+++ b/quantum/visualizer/lcd_backlight.c
@@ -25,10 +25,10 @@ SOFTWARE.
25#include "lcd_backlight.h" 25#include "lcd_backlight.h"
26#include <math.h> 26#include <math.h>
27 27
28static uint8_t current_hue = 0x00; 28static uint8_t current_hue = 0;
29static uint8_t current_saturation = 0x00; 29static uint8_t current_saturation = 0;
30static uint8_t current_intensity = 0xFF; 30static uint8_t current_intensity = 0;
31static uint8_t current_brightness = 0x7F; 31static uint8_t current_brightness = 0;
32 32
33void lcd_backlight_init(void) { 33void lcd_backlight_init(void) {
34 lcd_backlight_hal_init(); 34 lcd_backlight_hal_init();
diff --git a/quantum/visualizer/lcd_backlight.h b/quantum/visualizer/lcd_backlight.h
index dd3e37a06..14dde64a1 100644
--- a/quantum/visualizer/lcd_backlight.h
+++ b/quantum/visualizer/lcd_backlight.h
@@ -32,6 +32,10 @@ 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) {
36 return (color & 0xFFFFFF00) | new_intensity;
37}
38
35void lcd_backlight_init(void); 39void lcd_backlight_init(void);
36void 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);
37void lcd_backlight_brightness(uint8_t b); 41void lcd_backlight_brightness(uint8_t b);
diff --git a/quantum/visualizer/lcd_backlight_keyframes.c b/quantum/visualizer/lcd_backlight_keyframes.c
new file mode 100644
index 000000000..8436d4e3d
--- /dev/null
+++ b/quantum/visualizer/lcd_backlight_keyframes.c
@@ -0,0 +1,77 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "lcd_backlight_keyframes.h"
18
19bool backlight_keyframe_animate_color(keyframe_animation_t* animation, visualizer_state_t* state) {
20 int frame_length = animation->frame_lengths[animation->current_frame];
21 int current_pos = frame_length - animation->time_left_in_frame;
22 uint8_t t_h = LCD_HUE(state->target_lcd_color);
23 uint8_t t_s = LCD_SAT(state->target_lcd_color);
24 uint8_t t_i = LCD_INT(state->target_lcd_color);
25 uint8_t p_h = LCD_HUE(state->prev_lcd_color);
26 uint8_t p_s = LCD_SAT(state->prev_lcd_color);
27 uint8_t p_i = LCD_INT(state->prev_lcd_color);
28
29 uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around
30 int d_h2 = t_h - p_h;
31 // Chose the shortest way around
32 int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1;
33 int d_s = t_s - p_s;
34 int d_i = t_i - p_i;
35
36 int hue = (d_h * current_pos) / frame_length;
37 int sat = (d_s * current_pos) / frame_length;
38 int intensity = (d_i * current_pos) / frame_length;
39 //dprintf("%X -> %X = %X\n", p_h, t_h, hue);
40 hue += p_h;
41 sat += p_s;
42 intensity += p_i;
43 state->current_lcd_color = LCD_COLOR(hue, sat, intensity);
44 lcd_backlight_color(
45 LCD_HUE(state->current_lcd_color),
46 LCD_SAT(state->current_lcd_color),
47 LCD_INT(state->current_lcd_color));
48
49 return true;
50}
51
52bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state) {
53 (void)animation;
54 state->prev_lcd_color = state->target_lcd_color;
55 state->current_lcd_color = state->target_lcd_color;
56 lcd_backlight_color(
57 LCD_HUE(state->current_lcd_color),
58 LCD_SAT(state->current_lcd_color),
59 LCD_INT(state->current_lcd_color));
60 return false;
61}
62
63bool backlight_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
64 (void)animation;
65 (void)state;
66 lcd_backlight_hal_color(0, 0, 0);
67 return false;
68}
69
70bool backlight_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
71 (void)animation;
72 (void)state;
73 lcd_backlight_color(LCD_HUE(state->current_lcd_color),
74 LCD_SAT(state->current_lcd_color),
75 LCD_INT(state->current_lcd_color));
76 return false;
77}
diff --git a/quantum/visualizer/lcd_backlight_keyframes.h b/quantum/visualizer/lcd_backlight_keyframes.h
new file mode 100644
index 000000000..e1c125cf9
--- /dev/null
+++ b/quantum/visualizer/lcd_backlight_keyframes.h
@@ -0,0 +1,30 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_
18#define QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_
19
20#include "visualizer.h"
21
22// Animates the LCD backlight color between the current color and the target color (of the state)
23bool backlight_keyframe_animate_color(keyframe_animation_t* animation, visualizer_state_t* state);
24// Sets the backlight color to the target color
25bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state);
26
27bool backlight_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state);
28bool backlight_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state);
29
30#endif /* QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ */
diff --git a/quantum/visualizer/lcd_keyframes.c b/quantum/visualizer/lcd_keyframes.c
new file mode 100644
index 000000000..df11861dd
--- /dev/null
+++ b/quantum/visualizer/lcd_keyframes.c
@@ -0,0 +1,188 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "lcd_keyframes.h"
18#include <string.h>
19#include "action_util.h"
20#include "led.h"
21#include "resources/resources.h"
22
23bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) {
24 (void)animation;
25 gdispClear(White);
26 gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black);
27 return false;
28}
29
30static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, char* buffer) {
31 for (int i=0; i<16;i++)
32 {
33 uint32_t mask = (1u << i);
34 if (default_layer & mask) {
35 if (layer & mask) {
36 *buffer = 'B';
37 } else {
38 *buffer = 'D';
39 }
40 } else if (layer & mask) {
41 *buffer = '1';
42 } else {
43 *buffer = '0';
44 }
45 ++buffer;
46
47 if (i==3 || i==7 || i==11) {
48 *buffer = ' ';
49 ++buffer;
50 }
51 }
52 *buffer = 0;
53}
54
55bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
56 (void)animation;
57 const char* layer_help = "1=On D=Default B=Both";
58 char layer_buffer[16 + 4]; // 3 spaces and one null terminator
59 gdispClear(White);
60 gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black);
61 format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer);
62 gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black);
63 format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer);
64 gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black);
65 return false;
66}
67
68static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
69 *buffer = ' ';
70 ++buffer;
71
72 for (int i = 0; i<8; i++)
73 {
74 uint32_t mask = (1u << i);
75 if (mods & mask) {
76 *buffer = '1';
77 } else {
78 *buffer = '0';
79 }
80 ++buffer;
81
82 if (i==3) {
83 *buffer = ' ';
84 ++buffer;
85 }
86 }
87 *buffer = 0;
88}
89
90bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
91 (void)animation;
92
93 const char* title = "Modifier states";
94 const char* mods_header = " CSAG CSAG ";
95 char status_buffer[12];
96
97 gdispClear(White);
98 gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
99 gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black);
100 format_mods_bitmap_string(state->status.mods, status_buffer);
101 gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black);
102
103 return false;
104}
105
106#define LED_STATE_STRING_SIZE sizeof("NUM CAPS SCRL COMP KANA")
107
108static void get_led_state_string(char* output, visualizer_state_t* state) {
109 uint8_t pos = 0;
110
111 if (state->status.leds & (1u << USB_LED_NUM_LOCK)) {
112 memcpy(output + pos, "NUM ", 4);
113 pos += 4;
114 }
115 if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
116 memcpy(output + pos, "CAPS ", 5);
117 pos += 5;
118 }
119 if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) {
120 memcpy(output + pos, "SCRL ", 5);
121 pos += 5;
122 }
123 if (state->status.leds & (1u << USB_LED_COMPOSE)) {
124 memcpy(output + pos, "COMP ", 5);
125 pos += 5;
126 }
127 if (state->status.leds & (1u << USB_LED_KANA)) {
128 memcpy(output + pos, "KANA ", 5);
129 pos += 5;
130 }
131 output[pos] = 0;
132}
133
134bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state)
135{
136 (void)animation;
137 char output[LED_STATE_STRING_SIZE];
138 get_led_state_string(output, state);
139 gdispClear(White);
140 gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black);
141 return false;
142}
143
144bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) {
145 (void)animation;
146 gdispClear(White);
147 uint8_t y = 10;
148 if (state->status.leds) {
149 char output[LED_STATE_STRING_SIZE];
150 get_led_state_string(output, state);
151 gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black);
152 y = 17;
153 }
154 gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black);
155 return false;
156}
157
158bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t* state) {
159 (void)state;
160 (void)animation;
161 // Read the uGFX documentation for information how to use the displays
162 // http://wiki.ugfx.org/index.php/Main_Page
163 gdispClear(White);
164
165 // You can use static variables for things that can't be found in the animation
166 // or state structs, here we use the image
167
168 //gdispGBlitArea is a tricky function to use since it supports blitting part of the image
169 // if you have full screen image, then just use 128 and 32 for both source and target dimensions
170 gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo);
171
172 return false;
173}
174
175
176bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
177 (void)animation;
178 (void)state;
179 gdispSetPowerMode(powerOff);
180 return false;
181}
182
183bool lcd_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
184 (void)animation;
185 (void)state;
186 gdispSetPowerMode(powerOn);
187 return false;
188}
diff --git a/quantum/visualizer/lcd_keyframes.h b/quantum/visualizer/lcd_keyframes.h
new file mode 100644
index 000000000..2e912b4c7
--- /dev/null
+++ b/quantum/visualizer/lcd_keyframes.h
@@ -0,0 +1,39 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_
18#define QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_
19
20#include "visualizer.h"
21
22// Displays the layer text centered vertically on the screen
23bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state);
24// Displays a bitmap (0/1) of all the currently active layers
25bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
26// Displays a bitmap (0/1) of all the currently active mods
27bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
28// Displays the keyboard led states (CAPS (Caps lock), NUM (Num lock), SCRL (Scroll lock), COMP (Compose), KANA)
29bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state);
30// Displays both the layer text and the led states
31bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state);
32// Displays the QMK logo on the LCD screen
33bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t* state);
34
35bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state);
36bool lcd_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state);
37
38
39#endif /* QUANTUM_VISUALIZER_LCD_KEYFRAMES_H_ */
diff --git a/quantum/visualizer/led_test.c b/quantum/visualizer/led_keyframes.c
index a9abace8d..2dacd990d 100644
--- a/quantum/visualizer/led_test.c
+++ b/quantum/visualizer/led_keyframes.c
@@ -21,50 +21,9 @@ LIABILITY, 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 21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24#include "led_test.h"
25#include "gfx.h" 24#include "gfx.h"
26#include "math.h" 25#include "math.h"
27 26#include "led_keyframes.h"
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 27
69static uint8_t fade_led_color(keyframe_animation_t* animation, int from, int to) { 28static uint8_t fade_led_color(keyframe_animation_t* animation, int from, int to) {
70 int frame_length = animation->frame_lengths[animation->current_frame]; 29 int frame_length = animation->frame_lengths[animation->current_frame];
@@ -96,19 +55,19 @@ static uint8_t compute_gradient_color(float t, float index, float num) {
96 return (uint8_t)(255.0f * v); 55 return (uint8_t)(255.0f * v);
97} 56}
98 57
99bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) { 58bool led_keyframe_fade_in_all(keyframe_animation_t* animation, visualizer_state_t* state) {
100 (void)state; 59 (void)state;
101 keyframe_fade_all_leds_from_to(animation, 0, 255); 60 keyframe_fade_all_leds_from_to(animation, 0, 255);
102 return true; 61 return true;
103} 62}
104 63
105bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) { 64bool led_keyframe_fade_out_all(keyframe_animation_t* animation, visualizer_state_t* state) {
106 (void)state; 65 (void)state;
107 keyframe_fade_all_leds_from_to(animation, 255, 0); 66 keyframe_fade_all_leds_from_to(animation, 255, 0);
108 return true; 67 return true;
109} 68}
110 69
111bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) { 70bool led_keyframe_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
112 (void)state; 71 (void)state;
113 float frame_length = animation->frame_lengths[animation->current_frame]; 72 float frame_length = animation->frame_lengths[animation->current_frame];
114 float current_pos = frame_length - animation->time_left_in_frame; 73 float current_pos = frame_length - animation->time_left_in_frame;
@@ -120,7 +79,7 @@ bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visual
120 return true; 79 return true;
121} 80}
122 81
123bool keyframe_led_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state) { 82bool led_keyframe_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
124 (void)state; 83 (void)state;
125 float frame_length = animation->frame_lengths[animation->current_frame]; 84 float frame_length = animation->frame_lengths[animation->current_frame];
126 float current_pos = frame_length - animation->time_left_in_frame; 85 float current_pos = frame_length - animation->time_left_in_frame;
@@ -139,7 +98,7 @@ static void copy_current_led_state(uint8_t* dest) {
139 } 98 }
140 } 99 }
141} 100}
142bool keyframe_led_crossfade(keyframe_animation_t* animation, visualizer_state_t* state) { 101bool led_keyframe_crossfade(keyframe_animation_t* animation, visualizer_state_t* state) {
143 (void)state; 102 (void)state;
144 if (animation->first_update_of_frame) { 103 if (animation->first_update_of_frame) {
145 copy_current_led_state(&crossfade_start_frame[0][0]); 104 copy_current_led_state(&crossfade_start_frame[0][0]);
@@ -155,14 +114,14 @@ bool keyframe_led_crossfade(keyframe_animation_t* animation, visualizer_state_t*
155 return true; 114 return true;
156} 115}
157 116
158bool keyframe_mirror_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state) { 117bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
159 (void)state; 118 (void)state;
160 (void)animation; 119 (void)animation;
161 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_180); 120 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_180);
162 return false; 121 return false;
163} 122}
164 123
165bool keyframe_normal_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state) { 124bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state) {
166 (void)state; 125 (void)state;
167 (void)animation; 126 (void)animation;
168 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0); 127 gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0);
diff --git a/quantum/visualizer/led_test.h b/quantum/visualizer/led_keyframes.h
index 5e2325753..a68943041 100644
--- a/quantum/visualizer/led_test.h
+++ b/quantum/visualizer/led_keyframes.h
@@ -22,20 +22,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#ifndef TMK_VISUALIZER_LED_TEST_H_ 25#ifndef LED_KEYFRAMES_H
26#define TMK_VISUALIZER_LED_TEST_H_ 26#define LED_KEYFRAMES_H
27 27
28#include "visualizer.h" 28#include "visualizer.h"
29 29
30bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); 30bool led_keyframe_fade_in_all(keyframe_animation_t* animation, visualizer_state_t* state);
31bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); 31bool led_keyframe_fade_out_all(keyframe_animation_t* animation, visualizer_state_t* state);
32bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state); 32bool led_keyframe_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); 33bool led_keyframe_top_to_bottom_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
34bool keyframe_led_crossfade(keyframe_animation_t* animation, visualizer_state_t* state); 34bool led_keyframe_crossfade(keyframe_animation_t* animation, visualizer_state_t* state);
35bool keyframe_mirror_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state); 35bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
36bool keyframe_normal_led_orientation(keyframe_animation_t* animation, visualizer_state_t* state); 36bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
37 37
38extern keyframe_animation_t led_test_animation; 38extern keyframe_animation_t led_test_animation;
39 39
40 40
41#endif /* TMK_VISUALIZER_LED_TEST_H_ */ 41#endif /* LED_KEYFRAMES_H */
diff --git a/quantum/visualizer/resources/lcd_logo.c b/quantum/visualizer/resources/lcd_logo.c
new file mode 100644
index 000000000..d1a0ffa7f
--- /dev/null
+++ b/quantum/visualizer/resources/lcd_logo.c
@@ -0,0 +1,61 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "resources.h"
18
19
20// To generate an image array like this
21// Ensure the image is 128 x 32 or smaller
22// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/
23// Ensure the the conversion process produces a monochrome format array - 1 bit/pixel, left to right, top to bottom
24// Update array in the source code with the C array produced by the conversion program
25
26// The image below is generated from lcd_logo.png
27const uint8_t resource_lcd_logo[512] = {
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00,
46 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00,
47 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00,
48 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00,
49 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00,
50 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00,
51 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
60};
61
diff --git a/quantum/visualizer/resources/lcd_logo.png b/quantum/visualizer/resources/lcd_logo.png
new file mode 100644
index 000000000..6cf26fc67
--- /dev/null
+++ b/quantum/visualizer/resources/lcd_logo.png
Binary files differ
diff --git a/quantum/visualizer/resources/resources.h b/quantum/visualizer/resources/resources.h
new file mode 100644
index 000000000..1ea27a536
--- /dev/null
+++ b/quantum/visualizer/resources/resources.h
@@ -0,0 +1,27 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef QUANTUM_VISUALIZER_RESOURCES_RESOURCES_H_
18#define QUANTUM_VISUALIZER_RESOURCES_RESOURCES_H_
19
20#include <stdint.h>
21
22#ifdef LCD_ENABLE
23extern const uint8_t resource_lcd_logo[];
24#endif
25
26
27#endif /* QUANTUM_VISUALIZER_RESOURCES_RESOURCES_H_ */
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 5826d909e..6f134097f 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -48,20 +48,22 @@ SOFTWARE.
48#include "serial_link/system/serial_link.h" 48#include "serial_link/system/serial_link.h"
49#endif 49#endif
50 50
51#include "action_util.h"
52
51// Define this in config.h 53// Define this in config.h
52#ifndef VISUALIZER_THREAD_PRIORITY 54#ifndef VISUALIZER_THREAD_PRIORITY
53#define "Visualizer thread priority not defined" 55#define "Visualizer thread priority not defined"
54#endif 56#endif
55 57
56// mods status
57#include "action_util.h"
58
59static visualizer_keyboard_status_t current_status = { 58static visualizer_keyboard_status_t current_status = {
60 .layer = 0xFFFFFFFF, 59 .layer = 0xFFFFFFFF,
61 .default_layer = 0xFFFFFFFF, 60 .default_layer = 0xFFFFFFFF,
62 .mods = 0xFF, 61 .mods = 0xFF,
63 .leds = 0xFFFFFFFF, 62 .leds = 0xFFFFFFFF,
64 .suspended = false, 63 .suspended = false,
64#ifdef VISUALIZER_USER_DATA_SIZE
65 .user_data = {0}
66#endif
65}; 67};
66 68
67static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) { 69static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) {
@@ -69,11 +71,19 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa
69 status1->default_layer == status2->default_layer && 71 status1->default_layer == status2->default_layer &&
70 status1->mods == status2->mods && 72 status1->mods == status2->mods &&
71 status1->leds == status2->leds && 73 status1->leds == status2->leds &&
72 status1->suspended == status2->suspended; 74 status1->suspended == status2->suspended
75#ifdef VISUALIZER_USER_DATA_SIZE
76 && memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0
77#endif
78 ;
73} 79}
74 80
75static bool visualizer_enabled = false; 81static bool visualizer_enabled = false;
76 82
83#ifdef VISUALIZER_USER_DATA_SIZE
84static uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
85#endif
86
77#define MAX_SIMULTANEOUS_ANIMATIONS 4 87#define MAX_SIMULTANEOUS_ANIMATIONS 4
78static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {}; 88static keyframe_animation_t* animations[MAX_SIMULTANEOUS_ANIMATIONS] = {};
79 89
@@ -144,6 +154,14 @@ void stop_all_keyframe_animations(void) {
144 } 154 }
145} 155}
146 156
157static uint8_t get_num_running_animations(void) {
158 uint8_t count = 0;
159 for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
160 count += animations[i] ? 1 : 0;
161 }
162 return count;
163}
164
147static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) { 165static bool update_keyframe_animation(keyframe_animation_t* animation, visualizer_state_t* state, systemticks_t delta, systemticks_t* sleep_time) {
148 // TODO: Clean up this messy code 166 // TODO: Clean up this messy code
149 dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame, 167 dprintf("Animation frame%d, left %d, delta %d\n", animation->current_frame,
@@ -212,175 +230,6 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat
212 (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state); 230 (*temp_animation.frame_functions[next_frame])(&temp_animation, &temp_state);
213} 231}
214 232
215bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) {
216 (void)animation;
217 (void)state;
218 return false;
219}
220
221#ifdef LCD_BACKLIGHT_ENABLE
222bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) {
223 int frame_length = animation->frame_lengths[animation->current_frame];
224 int current_pos = frame_length - animation->time_left_in_frame;
225 uint8_t t_h = LCD_HUE(state->target_lcd_color);
226 uint8_t t_s = LCD_SAT(state->target_lcd_color);
227 uint8_t t_i = LCD_INT(state->target_lcd_color);
228 uint8_t p_h = LCD_HUE(state->prev_lcd_color);
229 uint8_t p_s = LCD_SAT(state->prev_lcd_color);
230 uint8_t p_i = LCD_INT(state->prev_lcd_color);
231
232 uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around
233 int d_h2 = t_h - p_h;
234 // Chose the shortest way around
235 int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1;
236 int d_s = t_s - p_s;
237 int d_i = t_i - p_i;
238
239 int hue = (d_h * current_pos) / frame_length;
240 int sat = (d_s * current_pos) / frame_length;
241 int intensity = (d_i * current_pos) / frame_length;
242 //dprintf("%X -> %X = %X\n", p_h, t_h, hue);
243 hue += p_h;
244 sat += p_s;
245 intensity += p_i;
246 state->current_lcd_color = LCD_COLOR(hue, sat, intensity);
247 lcd_backlight_color(
248 LCD_HUE(state->current_lcd_color),
249 LCD_SAT(state->current_lcd_color),
250 LCD_INT(state->current_lcd_color));
251
252 return true;
253}
254
255bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) {
256 (void)animation;
257 state->prev_lcd_color = state->target_lcd_color;
258 state->current_lcd_color = state->target_lcd_color;
259 lcd_backlight_color(
260 LCD_HUE(state->current_lcd_color),
261 LCD_SAT(state->current_lcd_color),
262 LCD_INT(state->current_lcd_color));
263 return false;
264}
265#endif // LCD_BACKLIGHT_ENABLE
266
267#ifdef LCD_ENABLE
268bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) {
269 (void)animation;
270 gdispClear(White);
271 gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black);
272 gdispFlush();
273 return false;
274}
275
276static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, char* buffer) {
277 for (int i=0; i<16;i++)
278 {
279 uint32_t mask = (1u << i);
280 if (default_layer & mask) {
281 if (layer & mask) {
282 *buffer = 'B';
283 } else {
284 *buffer = 'D';
285 }
286 } else if (layer & mask) {
287 *buffer = '1';
288 } else {
289 *buffer = '0';
290 }
291 ++buffer;
292
293 if (i==3 || i==7 || i==11) {
294 *buffer = ' ';
295 ++buffer;
296 }
297 }
298 *buffer = 0;
299}
300
301bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
302 (void)animation;
303 const char* layer_help = "1=On D=Default B=Both";
304 char layer_buffer[16 + 4]; // 3 spaces and one null terminator
305 gdispClear(White);
306 gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black);
307 format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer);
308 gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black);
309 format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer);
310 gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black);
311 gdispFlush();
312 return false;
313}
314
315static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
316 *buffer = ' ';
317 ++buffer;
318
319 for (int i = 0; i<8; i++)
320 {
321 uint32_t mask = (1u << i);
322 if (mods & mask) {
323 *buffer = '1';
324 } else {
325 *buffer = '0';
326 }
327 ++buffer;
328
329 if (i==3) {
330 *buffer = ' ';
331 ++buffer;
332 }
333 }
334 *buffer = 0;
335}
336
337bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
338 (void)animation;
339
340 const char* title = "Modifier states";
341 const char* mods_header = " CSAG CSAG ";
342 char status_buffer[12];
343
344 gdispClear(White);
345 gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
346 gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black);
347 format_mods_bitmap_string(state->status.mods, status_buffer);
348 gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black);
349
350 gdispFlush();
351 return false;
352}
353#endif // LCD_ENABLE
354
355bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) {
356 (void)animation;
357 (void)state;
358#ifdef LCD_ENABLE
359 gdispSetPowerMode(powerOff);
360#endif
361#ifdef LCD_BACKLIGHT_ENABLE
362 lcd_backlight_hal_color(0, 0, 0);
363#endif
364 return false;
365}
366
367bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) {
368 (void)animation;
369 (void)state;
370#ifdef LCD_ENABLE
371 gdispSetPowerMode(powerOn);
372#endif
373 return false;
374}
375
376bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state) {
377 (void)animation;
378 (void)state;
379 dprint("User visualizer inited\n");
380 visualizer_enabled = true;
381 return false;
382}
383
384// TODO: Optimize the stack size, this is probably way too big 233// TODO: Optimize the stack size, this is probably way too big
385static DECLARE_THREAD_STACK(visualizerThreadStack, 1024); 234static DECLARE_THREAD_STACK(visualizerThreadStack, 1024);
386static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { 235static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
@@ -396,6 +245,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
396 .mods = 0xFF, 245 .mods = 0xFF,
397 .leds = 0xFFFFFFFF, 246 .leds = 0xFFFFFFFF,
398 .suspended = false, 247 .suspended = false,
248#ifdef VISUALIZER_USER_DATA_SIZE
249 .user_data = {0},
250#endif
399 }; 251 };
400 252
401 visualizer_state_t state = { 253 visualizer_state_t state = {
@@ -418,13 +270,15 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
418 270
419 systemticks_t sleep_time = TIME_INFINITE; 271 systemticks_t sleep_time = TIME_INFINITE;
420 systemticks_t current_time = gfxSystemTicks(); 272 systemticks_t current_time = gfxSystemTicks();
273 bool force_update = true;
421 274
422 while(true) { 275 while(true) {
423 systemticks_t new_time = gfxSystemTicks(); 276 systemticks_t new_time = gfxSystemTicks();
424 systemticks_t delta = new_time - current_time; 277 systemticks_t delta = new_time - current_time;
425 current_time = new_time; 278 current_time = new_time;
426 bool enabled = visualizer_enabled; 279 bool enabled = visualizer_enabled;
427 if (!same_status(&state.status, &current_status)) { 280 if (force_update || !same_status(&state.status, &current_status)) {
281 force_update = false;
428 if (visualizer_enabled) { 282 if (visualizer_enabled) {
429 if (current_status.suspended) { 283 if (current_status.suspended) {
430 stop_all_keyframe_animations(); 284 stop_all_keyframe_animations();
@@ -433,8 +287,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
433 user_visualizer_suspend(&state); 287 user_visualizer_suspend(&state);
434 } 288 }
435 else { 289 else {
290 visualizer_keyboard_status_t prev_status = state.status;
436 state.status = current_status; 291 state.status = current_status;
437 update_user_visualizer_state(&state); 292 update_user_visualizer_state(&state, &prev_status);
438 } 293 }
439 state.prev_lcd_color = state.current_lcd_color; 294 state.prev_lcd_color = state.current_lcd_color;
440 } 295 }
@@ -458,13 +313,17 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
458 gdispGFlush(LED_DISPLAY); 313 gdispGFlush(LED_DISPLAY);
459#endif 314#endif
460 315
316#ifdef LCD_ENABLE
317 gdispGFlush(LCD_DISPLAY);
318#endif
319
461#ifdef EMULATOR 320#ifdef EMULATOR
462 draw_emulator(); 321 draw_emulator();
463#endif 322#endif
464 // The animation can enable the visualizer 323 // Enable the visualizer when the startup or the suspend animation has finished
465 // And we might need to update the state when that happens 324 if (!visualizer_enabled && state.status.suspended == false && get_num_running_animations() == 0) {
466 // so don't sleep 325 visualizer_enabled = true;
467 if (enabled != visualizer_enabled) { 326 force_update = true;
468 sleep_time = 0; 327 sleep_time = 0;
469 } 328 }
470 329
@@ -554,6 +413,12 @@ uint8_t visualizer_get_mods() {
554 return mods; 413 return mods;
555} 414}
556 415
416#ifdef VISUALIZER_USER_DATA_SIZE
417void visualizer_set_user_data(void* u) {
418 memcpy(user_data, u, VISUALIZER_USER_DATA_SIZE);
419}
420#endif
421
557void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) { 422void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) {
558 // Note that there's a small race condition here, the thread could read 423 // Note that there's a small race condition here, the thread could read
559 // a state where one of these are set but not the other. But this should 424 // a state where one of these are set but not the other. But this should
@@ -582,6 +447,9 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uin
582 .leds = leds, 447 .leds = leds,
583 .suspended = current_status.suspended, 448 .suspended = current_status.suspended,
584 }; 449 };
450#ifdef VISUALIZER_USER_DATA_SIZE
451 memcpy(new_status.user_data, user_data, VISUALIZER_USER_DATA_SIZE);
452#endif
585 if (!same_status(&current_status, &new_status)) { 453 if (!same_status(&current_status, &new_status)) {
586 changed = true; 454 changed = true;
587 current_status = new_status; 455 current_status = new_status;
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index 315af5022..d6f279e10 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -34,7 +34,7 @@ SOFTWARE.
34#include "lcd_backlight.h" 34#include "lcd_backlight.h"
35#endif 35#endif
36 36
37// use this function to merget both real_mods and oneshot_mods in a uint16_t 37// use this function to merge both real_mods and oneshot_mods in a uint16_t
38uint8_t visualizer_get_mods(void); 38uint8_t visualizer_get_mods(void);
39 39
40// This need to be called once at the start 40// This need to be called once at the start
@@ -68,6 +68,9 @@ typedef struct {
68 uint8_t mods; 68 uint8_t mods;
69 uint32_t leds; // See led.h for available statuses 69 uint32_t leds; // See led.h for available statuses
70 bool suspended; 70 bool suspended;
71#ifdef VISUALIZER_USER_DATA_SIZE
72 uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
73#endif
71} visualizer_keyboard_status_t; 74} visualizer_keyboard_status_t;
72 75
73// The state struct is used by the various keyframe functions 76// The state struct is used by the various keyframe functions
@@ -123,32 +126,22 @@ void stop_keyframe_animation(keyframe_animation_t* animation);
123// Useful for crossfades for example 126// Useful for crossfades for example
124void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state); 127void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state);
125 128
126// Some predefined keyframe functions that can be used by the user code 129// The master can set userdata which will be transferred to the slave
127// Does nothing, useful for adding delays 130#ifdef VISUALIZER_USER_DATA_SIZE
128bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); 131void visualizer_set_user_data(void* user_data);
129// Animates the LCD backlight color between the current color and the target color (of the state) 132#endif
130bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
131// Sets the backlight color to the target color
132bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
133// Displays the layer text centered vertically on the screen
134bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state);
135// Displays a bitmap (0/1) of all the currently active layers
136bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
137// Displays a bitmap (0/1) of all the currently active mods
138bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
139
140bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
141bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
142
143// Call this once, when the initial animation has finished, alternatively you can call it
144// directly from the initalize_user_visualizer function (the animation can be null)
145bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state);
146 133
147// These functions have to be implemented by the user 134// These functions have to be implemented by the user
148void initialize_user_visualizer(visualizer_state_t* state); 135// Called regularly each time the state has changed (but not every scan loop)
149void update_user_visualizer_state(visualizer_state_t* state); 136void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status);
137// Called when the computer goes to suspend, will also stop calling update_user_visualizer_state
150void user_visualizer_suspend(visualizer_state_t* state); 138void user_visualizer_suspend(visualizer_state_t* state);
139// You have to start at least one animation as a response to the following two functions
140// When the animation has finished the visualizer will resume normal operation and start calling the
141// update_user_visualizer_state again
142// Called when the keyboard boots up
143void initialize_user_visualizer(visualizer_state_t* state);
144// Called when the computer resumes from a suspend
151void user_visualizer_resume(visualizer_state_t* state); 145void user_visualizer_resume(visualizer_state_t* state);
152 146
153
154#endif /* VISUALIZER_H */ 147#endif /* VISUALIZER_H */
diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk
index 2f4a41d66..5f710124b 100644
--- a/quantum/visualizer/visualizer.mk
+++ b/quantum/visualizer/visualizer.mk
@@ -20,7 +20,8 @@
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE. 21# SOFTWARE.
22 22
23SRC += $(VISUALIZER_DIR)/visualizer.c 23SRC += $(VISUALIZER_DIR)/visualizer.c \
24 $(VISUALIZER_DIR)/visualizer_keyframes.c
24EXTRAINCDIRS += $(GFXINC) $(VISUALIZER_DIR) 25EXTRAINCDIRS += $(GFXINC) $(VISUALIZER_DIR)
25GFXLIB = $(LIB_PATH)/ugfx 26GFXLIB = $(LIB_PATH)/ugfx
26VPATH += $(VISUALIZER_PATH) 27VPATH += $(VISUALIZER_PATH)
@@ -32,25 +33,33 @@ OPT_DEFS += -DLCD_ENABLE
32ULIBS += -lm 33ULIBS += -lm
33endif 34endif
34 35
35ifdef LCD_BACKLIGHT_ENABLE 36ifeq ($(strip $(LCD_ENABLE)), yes)
36SRC += $(VISUALIZER_DIR)/lcd_backlight.c 37SRC += $(VISUALIZER_DIR)/lcd_backlight.c
38SRC += $(VISUALIZER_DIR)/lcd_keyframes.c
39SRC += $(VISUALIZER_DIR)/lcd_backlight_keyframes.c
40# Note, that the linker will strip out any resources that are not actually in use
41SRC += $(VISUALIZER_DIR)/resources/lcd_logo.c
37OPT_DEFS += -DLCD_BACKLIGHT_ENABLE 42OPT_DEFS += -DLCD_BACKLIGHT_ENABLE
38endif 43endif
39 44
40ifdef LED_ENABLE 45ifeq ($(strip $(LED_ENABLE)), yes)
41SRC += $(VISUALIZER_DIR)/led_test.c 46SRC += $(VISUALIZER_DIR)/led_keyframes.c
42OPT_DEFS += -DLED_ENABLE 47OPT_DEFS += -DLED_ENABLE
43endif 48endif
44 49
45include $(GFXLIB)/gfx.mk 50include $(GFXLIB)/gfx.mk
46SRC += $(patsubst $(TOP_DIR)/%,%,$(GFXSRC)) 51GFXSRC := $(patsubst $(TOP_DIR)/%,%,$(GFXSRC))
47OPT_DEFS += $(patsubst %,-D%,$(patsubst -D%,%,$(GFXDEFS))) 52GFXDEFS := $(patsubst %,-D%,$(patsubst -D%,%,$(GFXDEFS)))
48 53
49ifneq ("$(wildcard $(KEYMAP_PATH)/visualizer.c)","") 54ifneq ("$(wildcard $(KEYMAP_PATH)/visualizer.c)","")
50 SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c 55 SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c
51else 56else
52 ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","") 57 ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","")
58 ifeq ("$(wildcard $(SUBPROJECT_PATH)/visualizer.c)","")
53$(error "$(KEYMAP_PATH)/visualizer.c" does not exist) 59$(error "$(KEYMAP_PATH)/visualizer.c" does not exist)
60 else
61 SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/visualizer.c
62 endif
54 else 63 else
55 SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c 64 SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c
56 endif 65 endif
diff --git a/quantum/visualizer/visualizer_keyframes.c b/quantum/visualizer/visualizer_keyframes.c
new file mode 100644
index 000000000..8f6a7e15a
--- /dev/null
+++ b/quantum/visualizer/visualizer_keyframes.c
@@ -0,0 +1,23 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "visualizer_keyframes.h"
18
19bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state) {
20 (void)animation;
21 (void)state;
22 return false;
23}
diff --git a/quantum/visualizer/visualizer_keyframes.h b/quantum/visualizer/visualizer_keyframes.h
new file mode 100644
index 000000000..9ef7653c5
--- /dev/null
+++ b/quantum/visualizer/visualizer_keyframes.h
@@ -0,0 +1,26 @@
1/* Copyright 2017 Fred Sundvik
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef QUANTUM_VISUALIZER_VISUALIZER_KEYFRAMES_H_
18#define QUANTUM_VISUALIZER_VISUALIZER_KEYFRAMES_H_
19
20#include "visualizer.h"
21
22// Some predefined keyframe functions that can be used by the user code
23// Does nothing, useful for adding delays
24bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state);
25
26#endif /* QUANTUM_VISUALIZER_VISUALIZER_KEYFRAMES_H_ */