summaryrefslogtreecommitdiff
path: root/quantum/visualizer
diff options
context:
space:
mode:
authorLuiz Ribeiro <luizribeiro@gmail.com>2017-07-04 11:17:28 -0400
committerLuiz Ribeiro <luizribeiro@gmail.com>2017-07-04 11:17:28 -0400
commitd5486265b8afcada68306c815b08c225fce287af (patch)
tree8fb7f8fee4aa3937003bd69d5c77ca867c010d12 /quantum/visualizer
parent738b072bb0f25d0369a998c550c369e4f64cc7a5 (diff)
parent34c8bf47a76c8a2dcd3b1a19dd608f8fb2fafb31 (diff)
downloadqmk_firmware-d5486265b8afcada68306c815b08c225fce287af.tar.gz
qmk_firmware-d5486265b8afcada68306c815b08c225fce287af.zip
Merge branch 'master' into ps2avrGB
Diffstat (limited to 'quantum/visualizer')
-rw-r--r--quantum/visualizer/lcd_backlight.c4
-rw-r--r--quantum/visualizer/lcd_backlight.h3
-rw-r--r--quantum/visualizer/led_keyframes.c20
-rw-r--r--quantum/visualizer/led_keyframes.h3
-rw-r--r--quantum/visualizer/visualizer.c67
-rw-r--r--quantum/visualizer/visualizer.h10
-rw-r--r--quantum/visualizer/visualizer.mk29
7 files changed, 101 insertions, 35 deletions
diff --git a/quantum/visualizer/lcd_backlight.c b/quantum/visualizer/lcd_backlight.c
index 00de3fab52..6cd996f75e 100644
--- a/quantum/visualizer/lcd_backlight.c
+++ b/quantum/visualizer/lcd_backlight.c
@@ -83,3 +83,7 @@ void lcd_backlight_brightness(uint8_t b) {
current_brightness = b;
lcd_backlight_color(current_hue, current_saturation, current_intensity);
}
+
+uint8_t lcd_get_backlight_brightness(void) {
+ return current_brightness;
+}
diff --git a/quantum/visualizer/lcd_backlight.h b/quantum/visualizer/lcd_backlight.h
index 14dde64a1a..95d7a07b46 100644
--- a/quantum/visualizer/lcd_backlight.h
+++ b/quantum/visualizer/lcd_backlight.h
@@ -32,13 +32,14 @@ SOFTWARE.
#define LCD_SAT(color) ((color >> 8) & 0xFF)
#define LCD_INT(color) (color & 0xFF)
-inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) {
+static inline uint32_t change_lcd_color_intensity(uint32_t color, uint8_t new_intensity) {
return (color & 0xFFFFFF00) | new_intensity;
}
void lcd_backlight_init(void);
void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity);
void lcd_backlight_brightness(uint8_t b);
+uint8_t lcd_get_backlight_brightness(void);
void lcd_backlight_hal_init(void);
void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b);
diff --git a/quantum/visualizer/led_keyframes.c b/quantum/visualizer/led_keyframes.c
index 2dacd990d1..7e6e5d1ab9 100644
--- a/quantum/visualizer/led_keyframes.c
+++ b/quantum/visualizer/led_keyframes.c
@@ -41,14 +41,14 @@ static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint
}
// TODO: Should be customizable per keyboard
-#define NUM_ROWS 7
-#define NUM_COLS 7
+#define NUM_ROWS LED_NUM_ROWS
+#define NUM_COLS LED_NUM_COLS
static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS];
static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS];
static uint8_t compute_gradient_color(float t, float index, float num) {
- const float two_pi = M_2_PI;
+ const float two_pi = M_PI * 2.0f;
float normalized_index = (1.0f - index / (num - 1.0f)) * two_pi;
float x = t * two_pi + normalized_index;
float v = 0.5 * (cosf(x) + 1.0f);
@@ -127,3 +127,17 @@ bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer
gdispGSetOrientation(LED_DISPLAY, GDISP_ROTATE_0);
return false;
}
+
+bool led_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
+ (void)state;
+ (void)animation;
+ gdispGSetPowerMode(LED_DISPLAY, powerOff);
+ return false;
+}
+
+bool led_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
+ (void)state;
+ (void)animation;
+ gdispGSetPowerMode(LED_DISPLAY, powerOn);
+ return false;
+}
diff --git a/quantum/visualizer/led_keyframes.h b/quantum/visualizer/led_keyframes.h
index a689430417..a59a4f37d1 100644
--- a/quantum/visualizer/led_keyframes.h
+++ b/quantum/visualizer/led_keyframes.h
@@ -35,6 +35,9 @@ bool led_keyframe_crossfade(keyframe_animation_t* animation, visualizer_state_t*
bool led_keyframe_mirror_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
bool led_keyframe_normal_orientation(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state);
+bool led_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state);
+
extern keyframe_animation_t led_test_animation;
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 6f134097f0..cc99d1e3b6 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -22,8 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
-#include "visualizer.h"
#include "config.h"
+#include "visualizer.h"
#include <string.h>
#ifdef PROTOCOL_CHIBIOS
#include "ch.h"
@@ -58,8 +58,11 @@ SOFTWARE.
static visualizer_keyboard_status_t current_status = {
.layer = 0xFFFFFFFF,
.default_layer = 0xFFFFFFFF,
- .mods = 0xFF,
.leds = 0xFFFFFFFF,
+#ifdef BACKLIGHT_ENABLE
+ .backlight_level = 0,
+#endif
+ .mods = 0xFF,
.suspended = false,
#ifdef VISUALIZER_USER_DATA_SIZE
.user_data = {0}
@@ -72,6 +75,9 @@ static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboa
status1->mods == status2->mods &&
status1->leds == status2->leds &&
status1->suspended == status2->suspended
+#ifdef BACKLIGHT_ENABLE
+ && status1->backlight_level == status2->backlight_level
+#endif
#ifdef VISUALIZER_USER_DATA_SIZE
&& memcmp(status1->user_data, status2->user_data, VISUALIZER_USER_DATA_SIZE) == 0
#endif
@@ -99,15 +105,19 @@ static remote_object_t* remote_objects[] = {
GDisplay* LCD_DISPLAY = 0;
GDisplay* LED_DISPLAY = 0;
+#ifdef LCD_DISPLAY_NUMBER
__attribute__((weak))
GDisplay* get_lcd_display(void) {
- return gdispGetDisplay(0);
+ return gdispGetDisplay(LCD_DISPLAY_NUMBER);
}
+#endif
+#ifdef LED_DISPLAY_NUMBER
__attribute__((weak))
GDisplay* get_led_display(void) {
- return gdispGetDisplay(1);
+ return gdispGetDisplay(LED_DISPLAY_NUMBER);
}
+#endif
void start_keyframe_animation(keyframe_animation_t* animation) {
animation->current_frame = -1;
@@ -245,9 +255,9 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
.mods = 0xFF,
.leds = 0xFFFFFFFF,
.suspended = false,
-#ifdef VISUALIZER_USER_DATA_SIZE
+ #ifdef VISUALIZER_USER_DATA_SIZE
.user_data = {0},
-#endif
+ #endif
};
visualizer_state_t state = {
@@ -279,6 +289,18 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
bool enabled = visualizer_enabled;
if (force_update || !same_status(&state.status, &current_status)) {
force_update = false;
+ #if BACKLIGHT_ENABLE
+ if(current_status.backlight_level != state.status.backlight_level) {
+ if (current_status.backlight_level != 0) {
+ gdispGSetPowerMode(LED_DISPLAY, powerOn);
+ uint16_t percent = (uint16_t)current_status.backlight_level * 100 / BACKLIGHT_LEVELS;
+ gdispGSetBacklight(LED_DISPLAY, percent);
+ }
+ else {
+ gdispGSetPowerMode(LED_DISPLAY, powerOff);
+ }
+ }
+ #endif
if (visualizer_enabled) {
if (current_status.suspended) {
stop_all_keyframe_animations();
@@ -309,7 +331,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
update_keyframe_animation(animations[i], &state, delta, &sleep_time);
}
}
-#ifdef LED_ENABLE
+#ifdef BACKLIGHT_ENABLE
gdispGFlush(LED_DISPLAY);
#endif
@@ -361,25 +383,26 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
void visualizer_init(void) {
gfxInit();
-#ifdef LCD_BACKLIGHT_ENABLE
+ #ifdef LCD_BACKLIGHT_ENABLE
lcd_backlight_init();
-#endif
+ #endif
-#ifdef SERIAL_LINK_ENABLE
+ #ifdef SERIAL_LINK_ENABLE
add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
-#endif
+ #endif
-#ifdef LCD_ENABLE
+ #ifdef LCD_ENABLE
LCD_DISPLAY = get_lcd_display();
-#endif
-#ifdef LED_ENABLE
+ #endif
+
+ #ifdef BACKLIGHT_ENABLE
LED_DISPLAY = get_led_display();
-#endif
+ #endif
// We are using a low priority thread, the idea is to have it run only
// when the main thread is sleeping during the matrix scanning
- gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
- VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
+ gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
+ VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
}
void update_status(bool changed) {
@@ -445,6 +468,9 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uin
.default_layer = default_state,
.mods = mods,
.leds = leds,
+#ifdef BACKLIGHT_ENABLE
+ .backlight_level = current_status.backlight_level,
+#endif
.suspended = current_status.suspended,
};
#ifdef VISUALIZER_USER_DATA_SIZE
@@ -467,3 +493,10 @@ void visualizer_resume(void) {
current_status.suspended = false;
update_status(true);
}
+
+#ifdef BACKLIGHT_ENABLE
+void backlight_set(uint8_t level) {
+ current_status.backlight_level = level;
+ update_status(true);
+}
+#endif
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index d6f279e101..90ecdcbaea 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -28,12 +28,17 @@ SOFTWARE.
#include <stdint.h>
#include <stdbool.h>
+#include "config.h"
#include "gfx.h"
#ifdef LCD_BACKLIGHT_ENABLE
#include "lcd_backlight.h"
#endif
+#ifdef BACKLIGHT_ENABLE
+#include "backlight.h"
+#endif
+
// use this function to merge both real_mods and oneshot_mods in a uint16_t
uint8_t visualizer_get_mods(void);
@@ -65,9 +70,12 @@ struct keyframe_animation_t;
typedef struct {
uint32_t layer;
uint32_t default_layer;
- uint8_t mods;
uint32_t leds; // See led.h for available statuses
+ uint8_t mods;
bool suspended;
+#ifdef BACKLIGHT_ENABLE
+ uint8_t backlight_level;
+#endif
#ifdef VISUALIZER_USER_DATA_SIZE
uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
#endif
diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk
index 5f710124bc..0f7d8636cf 100644
--- a/quantum/visualizer/visualizer.mk
+++ b/quantum/visualizer/visualizer.mk
@@ -42,9 +42,8 @@ SRC += $(VISUALIZER_DIR)/resources/lcd_logo.c
OPT_DEFS += -DLCD_BACKLIGHT_ENABLE
endif
-ifeq ($(strip $(LED_ENABLE)), yes)
+ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
SRC += $(VISUALIZER_DIR)/led_keyframes.c
-OPT_DEFS += -DLED_ENABLE
endif
include $(GFXLIB)/gfx.mk
@@ -52,19 +51,23 @@ GFXSRC := $(patsubst $(TOP_DIR)/%,%,$(GFXSRC))
GFXDEFS := $(patsubst %,-D%,$(patsubst -D%,%,$(GFXDEFS)))
ifneq ("$(wildcard $(KEYMAP_PATH)/visualizer.c)","")
- SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c
+ SRC += keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/visualizer.c
else
- ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","")
- ifeq ("$(wildcard $(SUBPROJECT_PATH)/visualizer.c)","")
-$(error "$(KEYMAP_PATH)/visualizer.c" does not exist)
- else
- SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/visualizer.c
- endif
- else
- SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c
- endif
+ ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/visualizer.c)","")
+ ifeq ("$(wildcard $(SUBPROJECT_PATH)/visualizer.c)","")
+ ifeq ("$(wildcard $(KEYBOARD_PATH)/visualizer.c)","")
+$(error "visualizer.c" not found")
+ else
+ SRC += keyboards/$(KEYBOARD)/visualizer.c
+ endif
+ else
+ SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/visualizer.c
+ endif
+ else
+ SRC += keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/visualizer.c
+ endif
endif
ifdef EMULATOR
UINCDIR += $(TMK_DIR)/common
-endif \ No newline at end of file
+endif