From a916f4e8b897b6b8925d7113d84f9eac7e7b67be Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 3 Jun 2017 14:34:50 +0300 Subject: [PATCH 1/9] Let BACKLIGHT_ENABLE control the Infinity LEDs --- build_keyboard.mk | 6 ++++-- keyboards/ergodox/infinity/animations.c | 4 ++-- keyboards/ergodox/infinity/rules.mk | 9 ++------- keyboards/ergodox/keymaps/333fred/Makefile | 2 +- quantum/visualizer/visualizer.c | 4 ++-- quantum/visualizer/visualizer.mk | 3 +-- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/build_keyboard.mk b/build_keyboard.mk index 9fa8c312..36eab3a9 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -233,8 +233,10 @@ ifeq ($(strip $(LCD_ENABLE)), yes) CIE1931_CURVE = yes endif -ifeq ($(strip $(LED_ENABLE)), yes) - CIE1931_CURVE = yes +ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) + ifeq ($(strip $(VISUALIZER_ENABLE)), yes) + CIE1931_CURVE = yes + endif endif ifeq ($(strip $(CIE1931_CURVE)), yes) diff --git a/keyboards/ergodox/infinity/animations.c b/keyboards/ergodox/infinity/animations.c index 4c9f6d9c..0e732b74 100644 --- a/keyboards/ergodox/infinity/animations.c +++ b/keyboards/ergodox/infinity/animations.c @@ -25,7 +25,7 @@ #include "lcd_backlight_keyframes.h" #endif -#ifdef LED_ENABLE +#ifdef BACKLIGHT_ENABLE #include "led_keyframes.h" #endif @@ -61,7 +61,7 @@ keyframe_animation_t default_suspend_animation = { }; #endif -#if defined(LED_ENABLE) +#if defined(BACKLIGHT_ENABLE) #define CROSSFADE_TIME 1000 #define GRADIENT_TIME 3000 diff --git a/keyboards/ergodox/infinity/rules.mk b/keyboards/ergodox/infinity/rules.mk index 9e6170d8..af29ebce 100644 --- a/keyboards/ergodox/infinity/rules.mk +++ b/keyboards/ergodox/infinity/rules.mk @@ -62,15 +62,10 @@ CUSTOM_MATRIX ?= yes # Custom matrix file SERIAL_LINK_ENABLE = yes VISUALIZER_ENABLE ?= yes LCD_ENABLE ?= yes -LED_ENABLE ?= no +BACKLIGHT_ENABLE ?= yes LCD_BACKLIGHT_ENABLE ?= yes MIDI_ENABLE = no RGBLIGHT_ENABLE = no -ifdef LCD_ENABLE include $(SUBPROJECT_PATH)/drivers/gdisp/st7565ergodox/driver.mk -endif - -ifdef LED_ENABLE -include $(SUBPROJECT_PATH)/drivers/gdisp/IS31FL3731C/driver.mk -endif \ No newline at end of file +include $(SUBPROJECT_PATH)/drivers/gdisp/IS31FL3731C/driver.mk \ No newline at end of file diff --git a/keyboards/ergodox/keymaps/333fred/Makefile b/keyboards/ergodox/keymaps/333fred/Makefile index 87985bda..b977722a 100644 --- a/keyboards/ergodox/keymaps/333fred/Makefile +++ b/keyboards/ergodox/keymaps/333fred/Makefile @@ -1,7 +1,7 @@ SUBPROJECT_DEFAULT = infinity LCD_BACKLIGHT_ENABLE = yes LCD_ENABLE = yes -LED_ENABLE = yes +BACKLIGHT_ENABLE = yes BACKLIGHT_ENABLE = yes NKRO_ENABLE = yes TAP_DANCE_ENABLE = yes diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 6f134097..cd2dff6a 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -309,7 +309,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 @@ -372,7 +372,7 @@ void visualizer_init(void) { #ifdef LCD_ENABLE LCD_DISPLAY = get_lcd_display(); #endif -#ifdef LED_ENABLE +#ifdef BACKLIGHT_ENABLE LED_DISPLAY = get_led_display(); #endif diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk index 5f710124..6f97603b 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 From 0f9bfafb9e1fea118a0a61ff2baaff73b05ec157 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 3 Jun 2017 15:31:02 +0300 Subject: [PATCH 2/9] Turn off LED matrix by default --- .../infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c index ea09c4bb..24726944 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c @@ -173,7 +173,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { } // software shutdown disable (i.e. turn stuff on) - write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON); + write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); gfxSleepMilliseconds(10); // Finish Init @@ -183,7 +183,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; g->g.Orientation = GDISP_ROTATE_0; - g->g.Powermode = powerOn; + g->g.Powermode = powerOff; g->g.Backlight = GDISP_INITIAL_BACKLIGHT; g->g.Contrast = GDISP_INITIAL_CONTRAST; return TRUE; From effffa33a503a093be4fa00b570df7a4e2996edc Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 3 Jun 2017 21:14:26 +0300 Subject: [PATCH 3/9] Backlight level handling for the visualizer --- quantum/visualizer/visualizer.c | 30 +++++++++++++++++++++++++++++- quantum/visualizer/visualizer.h | 9 ++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index cd2dff6a..29db7005 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -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 @@ -279,6 +285,18 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { bool enabled = visualizer_enabled; if (force_update || !same_status(&state.status, ¤t_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 / 255; + gdispGSetBacklight(LED_DISPLAY, percent); + } + else { + gdispGSetPowerMode(LED_DISPLAY, powerOff); + } + } + #endif if (visualizer_enabled) { if (current_status.suspended) { stop_all_keyframe_animations(); @@ -445,6 +463,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 +488,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 d6f279e1..1c567440 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h @@ -34,6 +34,10 @@ SOFTWARE. #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 +69,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 From 2a7f9a7e46e1f4350be249c267fa7c35fd6562b5 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 3 Jun 2017 21:30:52 +0300 Subject: [PATCH 4/9] Add backlight control to the IS31FL3731 driver --- .../drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c index 24726944..0b48783d 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c @@ -43,7 +43,7 @@ extern const uint8_t CIE1931_CURVE[]; #define GDISP_INITIAL_CONTRAST 0 #endif #ifndef GDISP_INITIAL_BACKLIGHT - #define GDISP_INITIAL_BACKLIGHT 100 + #define GDISP_INITIAL_BACKLIGHT 0 #endif #define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0) @@ -204,7 +204,8 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { uint8_t* src = PRIV(g)->frame_buffer; for (int y=0;ywrite_buffer[get_led_address(g, x, y)]=CIE1931_CURVE[*src]; + uint8_t val = (uint16_t)*src * g->g.Backlight / 100; + PRIV(g)->write_buffer[get_led_address(g, x, y)]=CIE1931_CURVE[val]; ++src; } } @@ -297,8 +298,13 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->g.Orientation = (orientation_t)g->p.ptr; return; - case GDISP_CONTROL_CONTRAST: - return; + case GDISP_CONTROL_BACKLIGHT: + if (g->g.Backlight == (unsigned)g->p.ptr) + return; + unsigned val = (unsigned)g->p.ptr; + g->g.Backlight = val > 255 ? 255 : val; + g->flags |= GDISP_FLG_NEEDFLUSH; + return; } } #endif // GDISP_NEED_CONTROL From b51a0db6ed03d939baad7cb9d87ed13c3653c7d2 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 3 Jun 2017 22:04:10 +0300 Subject: [PATCH 5/9] Add backlight support to the default Ergodox Infinity animations --- keyboards/ergodox/infinity/animations.c | 69 +++++++++++++++++++++---- quantum/visualizer/led_keyframes.c | 14 +++++ quantum/visualizer/led_keyframes.h | 3 ++ 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/keyboards/ergodox/infinity/animations.c b/keyboards/ergodox/infinity/animations.c index 0e732b74..675519e3 100644 --- a/keyboards/ergodox/infinity/animations.c +++ b/keyboards/ergodox/infinity/animations.c @@ -32,31 +32,78 @@ #include "visualizer_keyframes.h" -#if defined(LCD_ENABLE) && defined(LCD_BACKLIGHT_ENABLE) +#if defined(LCD_ENABLE) || defined(LCD_BACKLIGHT_ENABLE) || defined(BACKLIGHT_ENABLE) + +static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) { +#ifdef LCD_ENABLE + lcd_keyframe_enable(animation, state); +#endif +#ifdef LCD_BACKLIGHT_ENABLE + backlight_keyframe_enable(animation, state); +#endif +#ifdef BACKLIGHT_ENABLE + led_keyframe_enable(animation, state); +#endif + return false; +} + +static bool keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) { +#ifdef LCD_ENABLE + lcd_keyframe_disable(animation, state); +#endif +#ifdef LCD_BACKLIGHT_ENABLE + backlight_keyframe_disable(animation, state); +#endif +#ifdef BACKLIGHT_ENABLE + led_keyframe_disable(animation, state); +#endif + return false; +} + +static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state) { + bool ret = false; +#ifdef LCD_BACKLIGHT_ENABLE + ret |= backlight_keyframe_animate_color(animation, state); +#endif +#ifdef BACLIGHT_ENABLE + ret |= led_keyframe_fade_in_all(animation, state); +#endif + return ret; +} + +static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_t* state) { + bool ret = false; +#ifdef LCD_BACKLIGHT_ENABLE + ret |= backlight_keyframe_animate_color(animation, state); +#endif +#ifdef BACLIGHT_ENABLE + ret |= led_keyframe_fade_out_all(animation, state); +#endif + return ret; +} + // Don't worry, if the startup animation is long, you can use the keyboard like normal // during that time keyframe_animation_t default_startup_animation = { - .num_frames = 4, + .num_frames = 3, .loop = false, - .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(5000), 0}, + .frame_lengths = {0, 0, gfxMillisecondsToTicks(5000)}, .frame_functions = { - lcd_keyframe_enable, - backlight_keyframe_enable, + keyframe_enable, lcd_keyframe_draw_logo, - backlight_keyframe_animate_color, + keyframe_fade_in, }, }; keyframe_animation_t default_suspend_animation = { - .num_frames = 4, + .num_frames = 3, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, .frame_functions = { lcd_keyframe_display_layer_text, - backlight_keyframe_animate_color, - lcd_keyframe_disable, - backlight_keyframe_disable, + keyframe_fade_out, + keyframe_disable, }, }; #endif diff --git a/quantum/visualizer/led_keyframes.c b/quantum/visualizer/led_keyframes.c index 2dacd990..c14491e5 100644 --- a/quantum/visualizer/led_keyframes.c +++ b/quantum/visualizer/led_keyframes.c @@ -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 a6894304..a59a4f37 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; From 19f0285a766e412db14e6cbe24532fdbff610af0 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Thu, 15 Jun 2017 23:21:01 +0300 Subject: [PATCH 6/9] Fix typo in BACKLIGHT_ENABLE --- keyboards/ergodox/infinity/animations.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/ergodox/infinity/animations.c b/keyboards/ergodox/infinity/animations.c index 675519e3..ebc08fde 100644 --- a/keyboards/ergodox/infinity/animations.c +++ b/keyboards/ergodox/infinity/animations.c @@ -65,7 +65,7 @@ static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t #ifdef LCD_BACKLIGHT_ENABLE ret |= backlight_keyframe_animate_color(animation, state); #endif -#ifdef BACLIGHT_ENABLE +#ifdef BACKLIGHT_ENABLE ret |= led_keyframe_fade_in_all(animation, state); #endif return ret; @@ -76,7 +76,7 @@ static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_ #ifdef LCD_BACKLIGHT_ENABLE ret |= backlight_keyframe_animate_color(animation, state); #endif -#ifdef BACLIGHT_ENABLE +#ifdef BACKLIGHT_ENABLE ret |= led_keyframe_fade_out_all(animation, state); #endif return ret; From 7d5606085fbd775019fc514f3ffca84edfc11aa6 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 02:01:02 +0300 Subject: [PATCH 7/9] Correctly calculate backlight level --- quantum/visualizer/visualizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 29db7005..486ff25b 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c @@ -289,7 +289,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) { 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 / 255; + uint16_t percent = (uint16_t)current_status.backlight_level * 100 / BACKLIGHT_LEVELS; gdispGSetBacklight(LED_DISPLAY, percent); } else { From ec88a0b3ccfdd22373a707e084202f1f1cf481b2 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 02:02:38 +0300 Subject: [PATCH 8/9] Make sure that the backlight level is within the right range --- tmk_core/common/backlight.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c index 0e0ad2d1..d03bfe93 100644 --- a/tmk_core/common/backlight.c +++ b/tmk_core/common/backlight.c @@ -28,6 +28,9 @@ void backlight_init(void) eeconfig_init(); } backlight_config.raw = eeconfig_read_backlight(); + if (backlight_config.level > BACKLIGHT_LEVELS) { + backlight_config.level = BACKLIGHT_LEVELS; + } backlight_set(backlight_config.enable ? backlight_config.level : 0); } From 086aad0d7e5770e0be36498e5f569af5a23b111c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 02:06:30 +0300 Subject: [PATCH 9/9] Make sure backlight is in the range 0-100 --- .../infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c index 0b48783d..b4a5c84b 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c @@ -302,7 +302,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { if (g->g.Backlight == (unsigned)g->p.ptr) return; unsigned val = (unsigned)g->p.ptr; - g->g.Backlight = val > 255 ? 255 : val; + g->g.Backlight = val > 100 ? 100 : val; g->flags |= GDISP_FLG_NEEDFLUSH; return; }