diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2016-04-24 13:46:19 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2016-04-24 13:46:19 +0300 |
| commit | c95b17b536b4437f001d5f5e8a54753969e36bb2 (patch) | |
| tree | d944e4a2ff6da1d5a06c671dfa1382423f5515d1 | |
| parent | 61f7761c034d46eb0856fb115260de2679abc419 (diff) | |
| download | qmk_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.c | 45 | ||||
| -rw-r--r-- | led_test.h | 35 | ||||
| -rw-r--r-- | visualizer.c | 8 | ||||
| -rw-r--r-- | visualizer.h | 3 | ||||
| -rw-r--r-- | visualizer.mk | 10 |
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 | /* | ||
| 2 | The MIT License (MIT) | ||
| 3 | |||
| 4 | Copyright (c) 2016 Fred Sundvik | ||
| 5 | |||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | of this software and associated documentation files (the "Software"), to deal | ||
| 8 | in the Software without restriction, including without limitation the rights | ||
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | copies of the Software, and to permit persons to whom the Software is | ||
| 11 | furnished to do so, subject to the following conditions: | ||
| 12 | |||
| 13 | The above copyright notice and this permission notice shall be included in all | ||
| 14 | copies or substantial portions of the Software. | ||
| 15 | |||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 22 | SOFTWARE. | ||
| 23 | */ | ||
| 24 | #include "led_test.h" | ||
| 25 | #include "gfx.h" | ||
| 26 | |||
| 27 | keyframe_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 | |||
| 36 | bool 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 | /* | ||
| 2 | The MIT License (MIT) | ||
| 3 | |||
| 4 | Copyright (c) 2016 Fred Sundvik | ||
| 5 | |||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | of this software and associated documentation files (the "Software"), to deal | ||
| 8 | in the Software without restriction, including without limitation the rights | ||
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | copies of the Software, and to permit persons to whom the Software is | ||
| 11 | furnished to do so, subject to the following conditions: | ||
| 12 | |||
| 13 | The above copyright notice and this permission notice shall be included in all | ||
| 14 | copies or substantial portions of the Software. | ||
| 15 | |||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 22 | SOFTWARE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #ifndef TMK_VISUALIZER_LED_TEST_H_ | ||
| 26 | #define TMK_VISUALIZER_LED_TEST_H_ | ||
| 27 | |||
| 28 | #include "visualizer.h" | ||
| 29 | |||
| 30 | bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); | ||
| 31 | |||
| 32 | extern 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 | ||
| 80 | GDisplay* LCDDisplay; | ||
| 81 | GDisplay* LEDDisplay; | ||
| 82 | |||
| 80 | 83 | ||
| 81 | void start_keyframe_animation(keyframe_animation_t* animation) { | 84 | void 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 | ||
| 102 | extern GDisplay* LCD_DISPLAY; | ||
| 103 | extern GDisplay* LED_DISPLAY; | ||
| 104 | |||
| 102 | void start_keyframe_animation(keyframe_animation_t* animation); | 105 | void start_keyframe_animation(keyframe_animation_t* animation); |
| 103 | void stop_keyframe_animation(keyframe_animation_t* animation); | 106 | void 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 | ||
| 23 | GFXLIB = $(VISUALIZER_DIR)/ugfx | 23 | GFXLIB = $(VISUALIZER_DIR)/ugfx |
| 24 | SRC += $(GFXSRC) $(VISUALIZER_DIR)/visualizer.c | ||
| 25 | UINCDIR += $(GFXINC) $(VISUALIZER_DIR) | ||
| 26 | |||
| 24 | ifdef LCD_ENABLE | 27 | ifdef LCD_ENABLE |
| 25 | include $(GFXLIB)/gfx.mk | 28 | include $(GFXLIB)/gfx.mk |
| 26 | UDEFS += -DLCD_ENABLE | 29 | UDEFS += -DLCD_ENABLE |
| 27 | ULIBS += -lm | 30 | ULIBS += -lm |
| 28 | endif | 31 | endif |
| 29 | SRC += $(GFXSRC) $(VISUALIZER_DIR)/visualizer.c | ||
| 30 | UINCDIR += $(GFXINC) $(VISUALIZER_DIR) | ||
| 31 | 32 | ||
| 32 | ifdef LCD_BACKLIGHT_ENABLE | 33 | ifdef LCD_BACKLIGHT_ENABLE |
| 33 | SRC += $(VISUALIZER_DIR)/lcd_backlight.c | 34 | SRC += $(VISUALIZER_DIR)/lcd_backlight.c |
| @@ -35,6 +36,11 @@ SRC += lcd_backlight_hal.c | |||
| 35 | UDEFS += -DLCD_BACKLIGHT_ENABLE | 36 | UDEFS += -DLCD_BACKLIGHT_ENABLE |
| 36 | endif | 37 | endif |
| 37 | 38 | ||
| 39 | ifdef LED_ENABLE | ||
| 40 | SRC += $(VISUALIZER_DIR)/led_test.c | ||
| 41 | UDEFS += -DLED_ENABLE | ||
| 42 | endif | ||
| 43 | |||
| 38 | ifndef VISUALIZER_USER | 44 | ifndef VISUALIZER_USER |
| 39 | VISUALIZER_USER = visualizer_user.c | 45 | VISUALIZER_USER = visualizer_user.c |
| 40 | endif | 46 | endif |
