aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-04-24 13:46:19 +0300
committerFred Sundvik <fsundvik@gmail.com>2016-04-24 13:46:19 +0300
commitc95b17b536b4437f001d5f5e8a54753969e36bb2 (patch)
treed944e4a2ff6da1d5a06c671dfa1382423f5515d1
parent61f7761c034d46eb0856fb115260de2679abc419 (diff)
downloadqmk_firmware-c95b17b536b4437f001d5f5e8a54753969e36bb2.tar.gz
qmk_firmware-c95b17b536b4437f001d5f5e8a54753969e36bb2.zip
Add simple led support
Also the first version of a led testing animation
-rw-r--r--led_test.c45
-rw-r--r--led_test.h35
-rw-r--r--visualizer.c8
-rw-r--r--visualizer.h3
-rw-r--r--visualizer.mk10
5 files changed, 99 insertions, 2 deletions
diff --git a/led_test.c b/led_test.c
new file mode 100644
index 000000000..1aadd5541
--- /dev/null
+++ b/led_test.c
@@ -0,0 +1,45 @@
1/*
2The MIT License (MIT)
3
4Copyright (c) 2016 Fred Sundvik
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24#include "led_test.h"
25#include "gfx.h"
26
27keyframe_animation_t led_test_animation = {
28 .num_frames = 1,
29 .loop = true,
30 .frame_lengths = {MS2ST(1000)},
31 .frame_functions = {
32 keyframe_fade_in_all_leds,
33 },
34};
35
36bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
37 (void)state;
38 int frame_length = animation->frame_lengths[animation->current_frame];
39 int current_pos = frame_length - animation->time_left_in_frame;
40 uint8_t luma = 0x255 * current_pos / frame_length;
41 color_t color = LUMA2COLOR(luma);
42 gdispGClear(LED_DISPLAY, color);
43 gdispGFlush(LED_DISPLAY);
44 return true;
45}
diff --git a/led_test.h b/led_test.h
new file mode 100644
index 000000000..521e05216
--- /dev/null
+++ b/led_test.h
@@ -0,0 +1,35 @@
1/*
2The MIT License (MIT)
3
4Copyright (c) 2016 Fred Sundvik
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25#ifndef TMK_VISUALIZER_LED_TEST_H_
26#define TMK_VISUALIZER_LED_TEST_H_
27
28#include "visualizer.h"
29
30bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
31
32extern keyframe_animation_t led_test_animation;
33
34
35#endif /* TMK_VISUALIZER_LED_TEST_H_ */
diff --git a/visualizer.c b/visualizer.c
index 867a1d334..ed5c9fa2c 100644
--- a/visualizer.c
+++ b/visualizer.c
@@ -77,6 +77,9 @@ static remote_object_t* remote_objects[] = {
77 77
78#endif 78#endif
79 79
80GDisplay* LCDDisplay;
81GDisplay* LEDDisplay;
82
80 83
81void start_keyframe_animation(keyframe_animation_t* animation) { 84void start_keyframe_animation(keyframe_animation_t* animation) {
82 animation->current_frame = -1; 85 animation->current_frame = -1;
@@ -405,6 +408,11 @@ void visualizer_init(void) {
405#ifdef USE_SERIAL_LINK 408#ifdef USE_SERIAL_LINK
406 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) ); 409 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
407#endif 410#endif
411 // TODO: Make sure these works when either of these are disabled
412 LCDDisplay = gdispGetDisplay(0);
413 LEDDisplay = gdispGetDisplay(1);
414
415
408 // We are using a low priority thread, the idea is to have it run only 416 // We are using a low priority thread, the idea is to have it run only
409 // when the main thread is sleeping during the matrix scanning 417 // when the main thread is sleeping during the matrix scanning
410 chEvtObjectInit(&layer_changed_event); 418 chEvtObjectInit(&layer_changed_event);
diff --git a/visualizer.h b/visualizer.h
index 22798cda6..6a72fde1f 100644
--- a/visualizer.h
+++ b/visualizer.h
@@ -99,6 +99,9 @@ typedef struct keyframe_animation_t {
99 99
100} keyframe_animation_t; 100} keyframe_animation_t;
101 101
102extern GDisplay* LCD_DISPLAY;
103extern GDisplay* LED_DISPLAY;
104
102void start_keyframe_animation(keyframe_animation_t* animation); 105void start_keyframe_animation(keyframe_animation_t* animation);
103void stop_keyframe_animation(keyframe_animation_t* animation); 106void stop_keyframe_animation(keyframe_animation_t* animation);
104 107
diff --git a/visualizer.mk b/visualizer.mk
index 13c5d3158..96ca468e8 100644
--- a/visualizer.mk
+++ b/visualizer.mk
@@ -21,13 +21,14 @@
21# SOFTWARE. 21# SOFTWARE.
22 22
23GFXLIB = $(VISUALIZER_DIR)/ugfx 23GFXLIB = $(VISUALIZER_DIR)/ugfx
24SRC += $(GFXSRC) $(VISUALIZER_DIR)/visualizer.c
25UINCDIR += $(GFXINC) $(VISUALIZER_DIR)
26
24ifdef LCD_ENABLE 27ifdef LCD_ENABLE
25include $(GFXLIB)/gfx.mk 28include $(GFXLIB)/gfx.mk
26UDEFS += -DLCD_ENABLE 29UDEFS += -DLCD_ENABLE
27ULIBS += -lm 30ULIBS += -lm
28endif 31endif
29SRC += $(GFXSRC) $(VISUALIZER_DIR)/visualizer.c
30UINCDIR += $(GFXINC) $(VISUALIZER_DIR)
31 32
32ifdef LCD_BACKLIGHT_ENABLE 33ifdef LCD_BACKLIGHT_ENABLE
33SRC += $(VISUALIZER_DIR)/lcd_backlight.c 34SRC += $(VISUALIZER_DIR)/lcd_backlight.c
@@ -35,6 +36,11 @@ SRC += lcd_backlight_hal.c
35UDEFS += -DLCD_BACKLIGHT_ENABLE 36UDEFS += -DLCD_BACKLIGHT_ENABLE
36endif 37endif
37 38
39ifdef LED_ENABLE
40SRC += $(VISUALIZER_DIR)/led_test.c
41UDEFS += -DLED_ENABLE
42endif
43
38ifndef VISUALIZER_USER 44ifndef VISUALIZER_USER
39VISUALIZER_USER = visualizer_user.c 45VISUALIZER_USER = visualizer_user.c
40endif 46endif