From aee9b10e92a597984ba9693b2dfcf597ca380a70 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 10 Jul 2016 23:45:39 +0300 Subject: Add a keyboard specific visualizer --- keyboards/ergodox/infinity/Makefile | 2 +- keyboards/ergodox/infinity/rules.mk | 2 +- keyboards/ergodox/infinity/visualizer.c | 168 ++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 keyboards/ergodox/infinity/visualizer.c (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/Makefile b/keyboards/ergodox/infinity/Makefile index 191c6bb66..bd09e5885 100644 --- a/keyboards/ergodox/infinity/Makefile +++ b/keyboards/ergodox/infinity/Makefile @@ -1,3 +1,3 @@ ifndef MAKEFILE_INCLUDED include ../../../Makefile -endif \ No newline at end of file +endif diff --git a/keyboards/ergodox/infinity/rules.mk b/keyboards/ergodox/infinity/rules.mk index 473a6dfec..1b011cd58 100644 --- a/keyboards/ergodox/infinity/rules.mk +++ b/keyboards/ergodox/infinity/rules.mk @@ -59,7 +59,7 @@ OPT_DEFS += -DCORTEX_VTOR_INIT=0x00002000 # CUSTOM_MATRIX ?= yes # Custom matrix file SERIAL_LINK_ENABLE = yes -VISUALIZER_ENABLE ?= no #temporarily disabled to make everything compile +VISUALIZER_ENABLE ?= yes LCD_ENABLE ?= yes LED_ENABLE ?= yes LCD_BACKLIGHT_ENABLE ?= yes diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c new file mode 100644 index 000000000..c0d335ce6 --- /dev/null +++ b/keyboards/ergodox/infinity/visualizer.c @@ -0,0 +1,168 @@ +/* +Copyright 2016 Fred Sundvik + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +// Currently we are assuming that both the backlight and LCD are enabled +// But it's entirely possible to write a custom visualizer that use only +// one of them +#ifndef LCD_BACKLIGHT_ENABLE +#error This visualizer needs that LCD backlight is enabled +#endif + +#ifndef LCD_ENABLE +#error This visualizer needs that LCD is enabled +#endif + +#include "visualizer.h" +#include "led_test.h" + +static const char* welcome_text[] = {"TMK", "Infinity Ergodox"}; + +// Just an example how to write custom keyframe functions, we could have moved +// all this into the init function +bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)animation; + // Read the uGFX documentation for information how to use the displays + // http://wiki.ugfx.org/index.php/Main_Page + gdispClear(White); + // You can use static variables for things that can't be found in the animation + // or state structs + gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black); + gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black); + // Always remember to flush the display + gdispFlush(); + // you could set the backlight color as well, but we won't do it here, since + // it's part of the following animation + // lcd_backlight_color(hue, saturation, intensity); + // We don't need constant updates, just drawing the screen once is enough + return false; +} + +// Feel free to modify the animations below, or even add new ones if needed + +// Don't worry, if the startup animation is long, you can use the keyboard like normal +// during that time +static keyframe_animation_t startup_animation = { + .num_frames = 4, + .loop = false, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_functions = { + display_welcome, + keyframe_animate_backlight_color, + keyframe_no_operation, + enable_visualization + }, +}; + +// The color animation animates the LCD color when you change layers +static keyframe_animation_t color_animation = { + .num_frames = 2, + .loop = false, + // Note that there's a 200 ms no-operation frame, + // this prevents the color from changing when activating the layer + // momentarily + .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, + .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color}, +}; + +// The LCD animation alternates between the layer name display and a +// bitmap that displays all active layers +static keyframe_animation_t lcd_animation = { + .num_frames = 2, + .loop = true, + .frame_lengths = {gfxMillisecondsToTicks(2000), gfxMillisecondsToTicks(2000)}, + .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap}, +}; + +static keyframe_animation_t suspend_animation = { + .num_frames = 3, + .loop = false, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, + .frame_functions = { + keyframe_display_layer_text, + keyframe_animate_backlight_color, + keyframe_disable_lcd_and_backlight, + }, +}; + +static keyframe_animation_t resume_animation = { + .num_frames = 5, + .loop = false, + .frame_lengths = {0, 0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_functions = { + keyframe_enable_lcd_and_backlight, + display_welcome, + keyframe_animate_backlight_color, + keyframe_no_operation, + enable_visualization, + }, +}; + +void initialize_user_visualizer(visualizer_state_t* state) { + // The brightness will be dynamically adjustable in the future + // But for now, change it here. + lcd_backlight_brightness(0x50); + state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF); + state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + start_keyframe_animation(&startup_animation); + start_keyframe_animation(&led_test_animation); +} + +void update_user_visualizer_state(visualizer_state_t* state) { + // Add more tests, change the colors and layer texts here + // Usually you want to check the high bits (higher layers first) + // because that's the order layers are processed for keypresses + // You can for check for example: + // state->status.layer + // state->status.default_layer + // state->status.leds (see led.h for available statuses) + if (state->status.layer & 0x8) { + state->target_lcd_color = LCD_COLOR(0xC0, 0xB0, 0xFF); + state->layer_text = "Numpad"; + } + else if (state->status.layer & 0x4) { + state->target_lcd_color = LCD_COLOR(0, 0xB0, 0xFF); + state->layer_text = "KBD functions"; + } + else if (state->status.layer & 0x2) { + state->target_lcd_color = LCD_COLOR(0x80, 0xB0, 0xFF); + state->layer_text = "Function keys"; + } + else { + state->target_lcd_color = LCD_COLOR(0x40, 0xB0, 0xFF); + state->layer_text = "Default"; + } + // You can also stop existing animations, and start your custom ones here + // remember that you should normally have only one animation for the LCD + // and one for the background. But you can also combine them if you want. + start_keyframe_animation(&lcd_animation); + start_keyframe_animation(&color_animation); +} + +void user_visualizer_suspend(visualizer_state_t* state) { + state->layer_text = "Suspending..."; + uint8_t hue = LCD_HUE(state->current_lcd_color); + uint8_t sat = LCD_SAT(state->current_lcd_color); + state->target_lcd_color = LCD_COLOR(hue, sat, 0); + start_keyframe_animation(&suspend_animation); +} + +void user_visualizer_resume(visualizer_state_t* state) { + state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0x00); + state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + start_keyframe_animation(&resume_animation); + start_keyframe_animation(&led_test_animation); +} -- cgit v1.2.3-24-g4f1b From bb86be1f1f3927a7ce339cb9439c97914af24754 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 28 Aug 2016 23:08:34 +0300 Subject: Remove unneeded makefile include --- keyboards/ergodox/infinity/rules.mk | 4 ---- 1 file changed, 4 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/rules.mk b/keyboards/ergodox/infinity/rules.mk index 1b011cd58..d51574aca 100644 --- a/keyboards/ergodox/infinity/rules.mk +++ b/keyboards/ergodox/infinity/rules.mk @@ -66,10 +66,6 @@ LCD_BACKLIGHT_ENABLE ?= yes MIDI_ENABLE = no RGBLIGHT_ENABLE = no -ifndef QUANTUM_DIR - include ../../../Makefile -endif - ifdef LCD_ENABLE include $(SUBPROJECT_PATH)/drivers/gdisp/st7565ergodox/driver.mk endif -- cgit v1.2.3-24-g4f1b From f5c89416527a3ec435ed49137fd2bf4af216024c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 28 Aug 2016 23:25:39 +0300 Subject: UGFX is compiled once per keyboard instead of keymap --- keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h index 290571ce5..abda0bd85 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h @@ -8,8 +8,6 @@ #ifndef _GDISP_LLD_BOARD_H #define _GDISP_LLD_BOARD_H -#include "print.h" - #define ST7565_LCD_BIAS ST7565_LCD_BIAS_9 // actually 6 #define ST7565_ADC ST7565_ADC_NORMAL #define ST7565_COM_SCAN ST7565_COM_SCAN_DEC -- cgit v1.2.3-24-g4f1b From 2b24d35846693a3365a35b6ee9bc31b70659cfcf Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 31 Mar 2017 23:58:10 +0300 Subject: Hopefully finally fix the corrupt LCD The SPI bus is now selected and deselected before each set of commands. Also speed up things by buffering many commands into a single batch. --- .../drivers/gdisp/st7565ergodox/board_ST7565.h | 46 +-- .../drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 393 +++++++++++---------- 2 files changed, 228 insertions(+), 211 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h index abda0bd85..c2092b5e8 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h @@ -37,10 +37,14 @@ // MSB First // CLK Low by default static const SPIConfig spi1config = { - NULL, - /* HW dependent part.*/ - ST7565_GPIOPORT, - ST7565_SS_PIN, + // Operation complete callback or @p NULL. + .end_cb = NULL, + //The chip select line port - when not using pcs. + .ssport = ST7565_GPIOPORT, + // brief The chip select line pad number - when not using pcs. + .sspad=ST7565_SS_PIN, + // SPI initialization data. + .tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(7) | SPIx_CTARn_DT(7) @@ -50,13 +54,10 @@ static const SPIConfig spi1config = { //SPI_CR1_BR_0 }; -static bool_t st7565_is_data_mode = 1; - static GFXINLINE void init_board(GDisplay *g) { (void) g; palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); - st7565_is_data_mode = 1; palSetPadModeNamed(RST, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN); palSetPadModeRaw(MOSI, ST7565_SPI_MODE); @@ -65,7 +66,6 @@ static GFXINLINE void init_board(GDisplay *g) { spiInit(); spiStart(&SPID1, &spi1config); - spiSelect(&SPID1); } static GFXINLINE void post_init_board(GDisplay *g) { @@ -86,39 +86,27 @@ static GFXINLINE void acquire_bus(GDisplay *g) { (void) g; // Only the LCD is using the SPI bus, so no need to acquire // spiAcquireBus(&SPID1); + spiSelect(&SPID1); } static GFXINLINE void release_bus(GDisplay *g) { (void) g; // Only the LCD is using the SPI bus, so no need to release //spiReleaseBus(&SPID1); + spiUnselect(&SPID1); } -static GFXINLINE void write_cmd(GDisplay *g, uint8_t cmd) { - (void) g; - if (st7565_is_data_mode) { - // The sleeps need to be at lest 10 vs 25 ns respectively - // So let's sleep two ticks, one tick might not be enough - // if we are at the end of the tick - chThdSleep(2); - palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN); - chThdSleep(2); - st7565_is_data_mode = 0; - } - spiSend(&SPID1, 1, &cmd); +static GFXINLINE void enter_data_mode(GDisplay *g) { + palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); +} + +static GFXINLINE void enter_cmd_mode(GDisplay *g) { + palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN); } + static GFXINLINE void write_data(GDisplay *g, uint8_t* data, uint16_t length) { (void) g; - if (!st7565_is_data_mode) { - // The sleeps need to be at lest 10 vs 25 ns respectively - // So let's sleep two ticks, one tick might not be enough - // if we are at the end of the tick - chThdSleep(2); - palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); - chThdSleep(2); - st7565_is_data_mode = 1; - } spiSend(&SPID1, length, data); } diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c index c33aea81a..4547f1419 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c @@ -20,16 +20,16 @@ /*===========================================================================*/ #ifndef GDISP_SCREEN_HEIGHT - #define GDISP_SCREEN_HEIGHT 32 +#define GDISP_SCREEN_HEIGHT 32 #endif #ifndef GDISP_SCREEN_WIDTH - #define GDISP_SCREEN_WIDTH 128 +#define GDISP_SCREEN_WIDTH 128 #endif #ifndef GDISP_INITIAL_CONTRAST - #define GDISP_INITIAL_CONTRAST 0 +#define GDISP_INITIAL_CONTRAST 0 #endif #ifndef GDISP_INITIAL_BACKLIGHT - #define GDISP_INITIAL_BACKLIGHT 100 +#define GDISP_INITIAL_BACKLIGHT 100 #endif #define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0) @@ -40,16 +40,16 @@ /* Driver config defaults for backward compatibility. */ /*===========================================================================*/ #ifndef ST7565_LCD_BIAS - #define ST7565_LCD_BIAS ST7565_LCD_BIAS_7 +#define ST7565_LCD_BIAS ST7565_LCD_BIAS_7 #endif #ifndef ST7565_ADC - #define ST7565_ADC ST7565_ADC_NORMAL +#define ST7565_ADC ST7565_ADC_NORMAL #endif #ifndef ST7565_COM_SCAN - #define ST7565_COM_SCAN ST7565_COM_SCAN_INC +#define ST7565_COM_SCAN ST7565_COM_SCAN_INC #endif #ifndef ST7565_PAGE_ORDER - #define ST7565_PAGE_ORDER 0,1,2,3 +#define ST7565_PAGE_ORDER 0,1,2,3 #endif /*===========================================================================*/ @@ -58,12 +58,24 @@ typedef struct{ bool_t buffer2; + uint8_t data_pos; + uint8_t data[16]; uint8_t ram[GDISP_SCREEN_HEIGHT * GDISP_SCREEN_WIDTH / 8]; }PrivData; // Some common routines and macros #define PRIV(g) ((PrivData*)g->priv) #define RAM(g) (PRIV(g)->ram) + +static GFXINLINE void write_cmd(GDisplay* g, uint8_t cmd) { + PRIV(g)->data[PRIV(g)->data_pos++] = cmd; +} + +static GFXINLINE void flush_cmd(GDisplay* g) { + write_data(g, PRIV(g)->data, PRIV(g)->data_pos); + PRIV(g)->data_pos = 0; +} + #define write_cmd2(g, cmd1, cmd2) { write_cmd(g, cmd1); write_cmd(g, cmd2); } #define write_cmd3(g, cmd1, cmd2, cmd3) { write_cmd(g, cmd1); write_cmd(g, cmd2); write_cmd(g, cmd3); } @@ -86,207 +98,224 @@ typedef struct{ */ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { - // The private area is the display surface. - g->priv = gfxAlloc(sizeof(PrivData)); - PRIV(g)->buffer2 = false; - - // Initialise the board interface - init_board(g); - - // Hardware reset - setpin_reset(g, TRUE); - gfxSleepMilliseconds(20); - setpin_reset(g, FALSE); - gfxSleepMilliseconds(20); - - acquire_bus(g); + // The private area is the display surface. + g->priv = gfxAlloc(sizeof(PrivData)); + PRIV(g)->buffer2 = false; + PRIV(g)->data_pos = 0; + + // Initialise the board interface + init_board(g); + + // Hardware reset + setpin_reset(g, TRUE); + gfxSleepMilliseconds(20); + setpin_reset(g, FALSE); + gfxSleepMilliseconds(20); + + acquire_bus(g); + enter_cmd_mode(g); write_cmd(g, ST7565_DISPLAY_OFF); - write_cmd(g, ST7565_LCD_BIAS); + write_cmd(g, ST7565_LCD_BIAS); write_cmd(g, ST7565_ADC); write_cmd(g, ST7565_COM_SCAN); - + write_cmd(g, ST7565_START_LINE | 0); - write_cmd(g, ST7565_RESISTOR_RATIO | 0x6); + write_cmd(g, ST7565_RESISTOR_RATIO | 0x6); - // turn on voltage converter (VC=1, VR=0, VF=0) - write_cmd(g, ST7565_POWER_CONTROL | 0x04); - delay_ms(50); + // turn on voltage converter (VC=1, VR=0, VF=0) + write_cmd(g, ST7565_POWER_CONTROL | 0x04); + flush_cmd(g); + delay_ms(50); - // turn on voltage regulator (VC=1, VR=1, VF=0) - write_cmd(g, ST7565_POWER_CONTROL | 0x06); - delay_ms(50); + // turn on voltage regulator (VC=1, VR=1, VF=0) + write_cmd(g, ST7565_POWER_CONTROL | 0x06); + flush_cmd(g); + delay_ms(50); - // turn on voltage follower (VC=1, VR=1, VF=1) - write_cmd(g, ST7565_POWER_CONTROL | 0x07); - delay_ms(50); + // turn on voltage follower (VC=1, VR=1, VF=1) + write_cmd(g, ST7565_POWER_CONTROL | 0x07); + flush_cmd(g); + delay_ms(50); - write_cmd(g, 0xE2); + write_cmd(g, 0xE2); write_cmd(g, ST7565_COM_SCAN); - write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST*64/101); - //write_cmd2(g, ST7565_CONTRAST, 0); - write_cmd(g, ST7565_DISPLAY_ON); - write_cmd(g, ST7565_ALLON_NORMAL); - write_cmd(g, ST7565_INVERT_DISPLAY); + write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST*64/101); + //write_cmd2(g, ST7565_CONTRAST, 0); + write_cmd(g, ST7565_DISPLAY_ON); + write_cmd(g, ST7565_ALLON_NORMAL); + write_cmd(g, ST7565_INVERT_DISPLAY); - write_cmd(g, ST7565_RMW); + write_cmd(g, ST7565_RMW); + flush_cmd(g); // Finish Init post_init_board(g); - // Release the bus - release_bus(g); - - /* Initialise the GDISP structure */ - g->g.Width = GDISP_SCREEN_WIDTH; - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Orientation = GDISP_ROTATE_0; - g->g.Powermode = powerOn; - g->g.Backlight = GDISP_INITIAL_BACKLIGHT; - g->g.Contrast = GDISP_INITIAL_CONTRAST; - return TRUE; + // Release the bus + release_bus(g); + + /* Initialise the GDISP structure */ + g->g.Width = GDISP_SCREEN_WIDTH; + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Orientation = GDISP_ROTATE_0; + g->g.Powermode = powerOn; + g->g.Backlight = GDISP_INITIAL_BACKLIGHT; + g->g.Contrast = GDISP_INITIAL_CONTRAST; + return TRUE; } #if GDISP_HARDWARE_FLUSH - LLDSPEC void gdisp_lld_flush(GDisplay *g) { - unsigned p; - - // Don't flush if we don't need it. - if (!(g->flags & GDISP_FLG_NEEDFLUSH)) - return; - - acquire_bus(g); - unsigned dstOffset = (PRIV(g)->buffer2 ? 4 : 0); - for (p = 0; p < 4; p++) { - write_cmd(g, ST7565_PAGE | (p + dstOffset)); - write_cmd(g, ST7565_COLUMN_MSB | 0); - write_cmd(g, ST7565_COLUMN_LSB | 0); - write_cmd(g, ST7565_RMW); - write_data(g, RAM(g) + (p*GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH); - } - unsigned line = (PRIV(g)->buffer2 ? 32 : 0); - write_cmd(g, ST7565_START_LINE | line); - PRIV(g)->buffer2 = !PRIV(g)->buffer2; - release_bus(g); - - g->flags &= ~GDISP_FLG_NEEDFLUSH; - } +LLDSPEC void gdisp_lld_flush(GDisplay *g) { + unsigned p; + + // Don't flush if we don't need it. + if (!(g->flags & GDISP_FLG_NEEDFLUSH)) + return; + + acquire_bus(g); + enter_cmd_mode(g); + unsigned dstOffset = (PRIV(g)->buffer2 ? 4 : 0); + for (p = 0; p < 4; p++) { + write_cmd(g, ST7565_PAGE | (p + dstOffset)); + write_cmd(g, ST7565_COLUMN_MSB | 0); + write_cmd(g, ST7565_COLUMN_LSB | 0); + write_cmd(g, ST7565_RMW); + flush_cmd(g); + enter_data_mode(g); + write_data(g, RAM(g) + (p*GDISP_SCREEN_WIDTH), GDISP_SCREEN_WIDTH); + enter_cmd_mode(g); + } + unsigned line = (PRIV(g)->buffer2 ? 32 : 0); + write_cmd(g, ST7565_START_LINE | line); + flush_cmd(g); + PRIV(g)->buffer2 = !PRIV(g)->buffer2; + release_bus(g); + + g->flags &= ~GDISP_FLG_NEEDFLUSH; +} #endif #if GDISP_HARDWARE_DRAWPIXEL - LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { - coord_t x, y; - - switch(g->g.Orientation) { - default: - case GDISP_ROTATE_0: - x = g->p.x; - y = g->p.y; - break; - case GDISP_ROTATE_90: - x = g->p.y; - y = GDISP_SCREEN_HEIGHT-1 - g->p.x; - break; - case GDISP_ROTATE_180: - x = GDISP_SCREEN_WIDTH-1 - g->p.x; - y = GDISP_SCREEN_HEIGHT-1 - g->p.y; - break; - case GDISP_ROTATE_270: - x = GDISP_SCREEN_HEIGHT-1 - g->p.y; - y = g->p.x; - break; - } - if (gdispColor2Native(g->p.color) != Black) - RAM(g)[xyaddr(x, y)] |= xybit(y); - else - RAM(g)[xyaddr(x, y)] &= ~xybit(y); - g->flags |= GDISP_FLG_NEEDFLUSH; - } +LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { + coord_t x, y; + + switch(g->g.Orientation) { + default: + case GDISP_ROTATE_0: + x = g->p.x; + y = g->p.y; + break; + case GDISP_ROTATE_90: + x = g->p.y; + y = GDISP_SCREEN_HEIGHT-1 - g->p.x; + break; + case GDISP_ROTATE_180: + x = GDISP_SCREEN_WIDTH-1 - g->p.x; + y = GDISP_SCREEN_HEIGHT-1 - g->p.y; + break; + case GDISP_ROTATE_270: + x = GDISP_SCREEN_HEIGHT-1 - g->p.y; + y = g->p.x; + break; + } + if (gdispColor2Native(g->p.color) != Black) + RAM(g)[xyaddr(x, y)] |= xybit(y); + else + RAM(g)[xyaddr(x, y)] &= ~xybit(y); + g->flags |= GDISP_FLG_NEEDFLUSH; +} #endif #if GDISP_HARDWARE_PIXELREAD - LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { - coord_t x, y; - - switch(g->g.Orientation) { - default: - case GDISP_ROTATE_0: - x = g->p.x; - y = g->p.y; - break; - case GDISP_ROTATE_90: - x = g->p.y; - y = GDISP_SCREEN_HEIGHT-1 - g->p.x; - break; - case GDISP_ROTATE_180: - x = GDISP_SCREEN_WIDTH-1 - g->p.x; - y = GDISP_SCREEN_HEIGHT-1 - g->p.y; - break; - case GDISP_ROTATE_270: - x = GDISP_SCREEN_HEIGHT-1 - g->p.y; - y = g->p.x; - break; - } - return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? White : Black; - } +LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { + coord_t x, y; + + switch(g->g.Orientation) { + default: + case GDISP_ROTATE_0: + x = g->p.x; + y = g->p.y; + break; + case GDISP_ROTATE_90: + x = g->p.y; + y = GDISP_SCREEN_HEIGHT-1 - g->p.x; + break; + case GDISP_ROTATE_180: + x = GDISP_SCREEN_WIDTH-1 - g->p.x; + y = GDISP_SCREEN_HEIGHT-1 - g->p.y; + break; + case GDISP_ROTATE_270: + x = GDISP_SCREEN_HEIGHT-1 - g->p.y; + y = g->p.x; + break; + } + return (RAM(g)[xyaddr(x, y)] & xybit(y)) ? White : Black; +} #endif #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL - LLDSPEC void gdisp_lld_control(GDisplay *g) { - switch(g->p.x) { - case GDISP_CONTROL_POWER: - if (g->g.Powermode == (powermode_t)g->p.ptr) - return; - switch((powermode_t)g->p.ptr) { - case powerOff: - case powerSleep: - case powerDeepSleep: - acquire_bus(g); - write_cmd(g, ST7565_DISPLAY_OFF); - release_bus(g); - break; - case powerOn: - acquire_bus(g); - write_cmd(g, ST7565_DISPLAY_ON); - release_bus(g); - break; - default: - return; - } - g->g.Powermode = (powermode_t)g->p.ptr; - return; - - case GDISP_CONTROL_ORIENTATION: - if (g->g.Orientation == (orientation_t)g->p.ptr) - return; - switch((orientation_t)g->p.ptr) { - /* Rotation is handled by the drawing routines */ - case GDISP_ROTATE_0: - case GDISP_ROTATE_180: - g->g.Height = GDISP_SCREEN_HEIGHT; - g->g.Width = GDISP_SCREEN_WIDTH; - break; - case GDISP_ROTATE_90: - case GDISP_ROTATE_270: - g->g.Height = GDISP_SCREEN_WIDTH; - g->g.Width = GDISP_SCREEN_HEIGHT; - break; - default: - return; - } - g->g.Orientation = (orientation_t)g->p.ptr; - return; - - case GDISP_CONTROL_CONTRAST: - if ((unsigned)g->p.ptr > 100) - g->p.ptr = (void *)100; - acquire_bus(g); - write_cmd2(g, ST7565_CONTRAST, ((((unsigned)g->p.ptr)<<6)/101) & 0x3F); - release_bus(g); - g->g.Contrast = (unsigned)g->p.ptr; - return; - } - } +LLDSPEC void gdisp_lld_control(GDisplay *g) { + switch(g->p.x) { + case GDISP_CONTROL_POWER: + if (g->g.Powermode == (powermode_t)g->p.ptr) + return; + switch((powermode_t)g->p.ptr) { + case powerOff: + case powerSleep: + case powerDeepSleep: + acquire_bus(g); + enter_cmd_mode(g); + write_cmd(g, ST7565_DISPLAY_OFF); + flush_cmd(g); + release_bus(g); + break; + case powerOn: + acquire_bus(g); + enter_cmd_mode(g); + write_cmd(g, ST7565_DISPLAY_ON); + flush_cmd(g); + release_bus(g); + break; + default: + return; + } + g->g.Powermode = (powermode_t)g->p.ptr; + return; + + case GDISP_CONTROL_ORIENTATION: + if (g->g.Orientation == (orientation_t)g->p.ptr) + return; + switch((orientation_t)g->p.ptr) { + /* Rotation is handled by the drawing routines */ + case GDISP_ROTATE_0: + case GDISP_ROTATE_180: + g->g.Height = GDISP_SCREEN_HEIGHT; + g->g.Width = GDISP_SCREEN_WIDTH; + break; + case GDISP_ROTATE_90: + case GDISP_ROTATE_270: + g->g.Height = GDISP_SCREEN_WIDTH; + g->g.Width = GDISP_SCREEN_HEIGHT; + break; + default: + return; + } + g->g.Orientation = (orientation_t)g->p.ptr; + return; + + case GDISP_CONTROL_CONTRAST: + if ((unsigned)g->p.ptr > 100) + g->p.ptr = (void *)100; + acquire_bus(g); + enter_cmd_mode(g); + write_cmd2(g, ST7565_CONTRAST, ((((unsigned)g->p.ptr)<<6)/101) & 0x3F); + flush_cmd(g); + release_bus(g); + g->g.Contrast = (unsigned)g->p.ptr; + return; + } +} #endif // GDISP_NEED_CONTROL #endif // GFX_USE_GDISP -- cgit v1.2.3-24-g4f1b From a8f5897b976ee9f16b1798db38fb0ee4b8981c9e Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 16:36:34 +0300 Subject: Add support for blitting to the Infinity LCD --- .../drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 26 ++++++++++++++++++++++ .../drivers/gdisp/st7565ergodox/gdisp_lld_config.h | 11 ++++----- keyboards/ergodox/infinity/gfxconf.h | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c index 4547f1419..2c8a168e7 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c @@ -254,6 +254,32 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { } #endif +LLDSPEC void gdisp_lld_blit_area(GDisplay *g) { + uint8_t* buffer = (uint8_t*)g->p.ptr; + int linelength = g->p.cx; + for (int i = 0; i < g->p.cy; i++) { + unsigned dstx = g->p.x; + unsigned dsty = g->p.y + i; + unsigned srcx = g->p.x1; + unsigned srcy = g->p.y1 + i; + unsigned srcbit = srcy * g->p.x2 + srcx; + for(int j=0; j < linelength; j++) { + uint8_t src = buffer[srcbit / 8]; + uint8_t bit = 7-(srcbit % 8); + uint8_t bitset = (src >> bit) & 1; + uint8_t* dst = &(RAM(g)[xyaddr(dstx, dsty)]); + if (bitset) { + *dst |= xybit(dsty); + } + else { + *dst &= ~xybit(dsty); + } + dstx++; + srcbit++; + } + } +} + #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL LLDSPEC void gdisp_lld_control(GDisplay *g) { switch(g->p.x) { diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_config.h b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_config.h index 48587b9e1..2b66a877c 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_config.h +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_config.h @@ -14,12 +14,13 @@ /* Driver hardware support. */ /*===========================================================================*/ -#define GDISP_HARDWARE_FLUSH TRUE // This controller requires flushing -#define GDISP_HARDWARE_DRAWPIXEL TRUE -#define GDISP_HARDWARE_PIXELREAD TRUE -#define GDISP_HARDWARE_CONTROL TRUE +#define GDISP_HARDWARE_FLUSH TRUE // This controller requires flushing +#define GDISP_HARDWARE_DRAWPIXEL TRUE +#define GDISP_HARDWARE_PIXELREAD TRUE +#define GDISP_HARDWARE_CONTROL TRUE +#define GDISP_HARDWARE_BITFILLS TRUE -#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO +#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_MONO #endif /* GFX_USE_GDISP */ diff --git a/keyboards/ergodox/infinity/gfxconf.h b/keyboards/ergodox/infinity/gfxconf.h index 8caa577b7..45b9f5858 100644 --- a/keyboards/ergodox/infinity/gfxconf.h +++ b/keyboards/ergodox/infinity/gfxconf.h @@ -143,7 +143,7 @@ #define GDISP_HARDWARE_DRAWPIXEL TRUE #define GDISP_HARDWARE_CLEARS FALSE #define GDISP_HARDWARE_FILLS FALSE - #define GDISP_HARDWARE_BITFILLS FALSE + //#define GDISP_HARDWARE_BITFILLS FALSE #define GDISP_HARDWARE_SCROLL FALSE #define GDISP_HARDWARE_PIXELREAD TRUE #define GDISP_HARDWARE_CONTROL TRUE -- cgit v1.2.3-24-g4f1b From e6f7a8a47a82258725683980b83e215c8323aef2 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 16:37:31 +0300 Subject: Display QMK logo at startup of Infinity Ergodox --- keyboards/ergodox/infinity/lcd_logo.png | Bin 0 -> 490 bytes keyboards/ergodox/infinity/visualizer.c | 89 +++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 24 deletions(-) create mode 100644 keyboards/ergodox/infinity/lcd_logo.png (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/lcd_logo.png b/keyboards/ergodox/infinity/lcd_logo.png new file mode 100644 index 000000000..6cf26fc67 Binary files /dev/null and b/keyboards/ergodox/infinity/lcd_logo.png differ diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index c0d335ce6..0ce1d4ae4 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -29,25 +29,68 @@ along with this program. If not, see . #include "visualizer.h" #include "led_test.h" -static const char* welcome_text[] = {"TMK", "Infinity Ergodox"}; +// To generate an image array like this +// Ensure the image is 128 x 32 or smaller +// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/ +// Ensure the the conversion process produces a monochrome format array - 1 bit/pixel, left to right, top to bottom +// Update array in the source code with the C array produced by the conversion program + +// The image below is generated from lcd_logo.png +static const uint8_t image_data_lcd_logo[512] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0x80); +static const uint32_t initial_color = LCD_COLOR(0, 0, 0xFF); -// Just an example how to write custom keyframe functions, we could have moved -// all this into the init function -bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) { +bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { + (void)state; (void)animation; + (void)state; // Read the uGFX documentation for information how to use the displays // http://wiki.ugfx.org/index.php/Main_Page gdispClear(White); + // You can use static variables for things that can't be found in the animation - // or state structs - gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black); - gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black); + // or state structs, here we use the image + + //gdispGBlitArea is a tricky function to use since it supports blitting part of the image + // if you have full screen image, then just use 128 and 32 for both source and target dimensions + gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); + // Always remember to flush the display gdispFlush(); - // you could set the backlight color as well, but we won't do it here, since - // it's part of the following animation - // lcd_backlight_color(hue, saturation, intensity); - // We don't need constant updates, just drawing the screen once is enough return false; } @@ -56,13 +99,12 @@ bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) // Don't worry, if the startup animation is long, you can use the keyboard like normal // during that time static keyframe_animation_t startup_animation = { - .num_frames = 4, + .num_frames = 3, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - display_welcome, + display_logo, keyframe_animate_backlight_color, - keyframe_no_operation, enable_visualization }, }; @@ -78,6 +120,7 @@ static keyframe_animation_t color_animation = { .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color}, }; + // The LCD animation alternates between the layer name display and a // bitmap that displays all active layers static keyframe_animation_t lcd_animation = { @@ -99,14 +142,13 @@ static keyframe_animation_t suspend_animation = { }; static keyframe_animation_t resume_animation = { - .num_frames = 5, + .num_frames = 4, .loop = false, - .frame_lengths = {0, 0, gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(5000), 0}, + .frame_lengths = {0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { keyframe_enable_lcd_and_backlight, - display_welcome, + display_logo, keyframe_animate_backlight_color, - keyframe_no_operation, enable_visualization, }, }; @@ -115,10 +157,9 @@ void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. lcd_backlight_brightness(0x50); - state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF); - state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + state->current_lcd_color = initial_color; + state->target_lcd_color = logo_background_color; start_keyframe_animation(&startup_animation); - start_keyframe_animation(&led_test_animation); } void update_user_visualizer_state(visualizer_state_t* state) { @@ -161,8 +202,8 @@ void user_visualizer_suspend(visualizer_state_t* state) { } void user_visualizer_resume(visualizer_state_t* state) { - state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0x00); - state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); + state->current_lcd_color = initial_color; + state->target_lcd_color = logo_background_color; start_keyframe_animation(&resume_animation); start_keyframe_animation(&led_test_animation); } -- cgit v1.2.3-24-g4f1b From bc97413bf70b1906b387dea35bb22575ec57eff8 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 16:38:12 +0300 Subject: Disable LEDs on Infinity Ergodox --- keyboards/ergodox/infinity/rules.mk | 2 +- keyboards/ergodox/infinity/visualizer.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/rules.mk b/keyboards/ergodox/infinity/rules.mk index d51574aca..aaadfe34b 100644 --- a/keyboards/ergodox/infinity/rules.mk +++ b/keyboards/ergodox/infinity/rules.mk @@ -61,7 +61,7 @@ CUSTOM_MATRIX ?= yes # Custom matrix file SERIAL_LINK_ENABLE = yes VISUALIZER_ENABLE ?= yes LCD_ENABLE ?= yes -LED_ENABLE ?= yes +LED_ENABLE ?= no LCD_BACKLIGHT_ENABLE ?= yes MIDI_ENABLE = no RGBLIGHT_ENABLE = no diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 0ce1d4ae4..c8fc3d78e 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,7 +27,6 @@ along with this program. If not, see . #endif #include "visualizer.h" -#include "led_test.h" // To generate an image array like this // Ensure the image is 128 x 32 or smaller @@ -205,5 +204,4 @@ void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; start_keyframe_animation(&resume_animation); - start_keyframe_animation(&led_test_animation); } -- cgit v1.2.3-24-g4f1b From f113f95440f8cd7377930868656caf515dbd609c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 17:43:38 +0300 Subject: Move CIE1931 and breathing tables to its own file --- .../drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c | 37 +++------------------- 1 file changed, 5 insertions(+), 32 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c index 1d21f0c49..ea09c4bb0 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/IS31FL3731C/gdisp_IS31FL3731C.c @@ -25,6 +25,10 @@ along with this program. If not, see . #include "board_IS31FL3731C.h" + +// Can't include led_tables from here +extern const uint8_t CIE1931_CURVE[]; + /*===========================================================================*/ /* Driver local definitions. */ /*===========================================================================*/ @@ -100,37 +104,6 @@ along with this program. If not, see . #define IS31 -//Generated by http://jared.geek.nz/2013/feb/linear-led-pwm -const unsigned char cie[256] = { - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, - 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, - 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, - 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, - 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, - 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, - 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, - 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, - 28, 28, 29, 29, 30, 31, 31, 32, 32, 33, - 34, 34, 35, 36, 37, 37, 38, 39, 39, 40, - 41, 42, 43, 43, 44, 45, 46, 47, 47, 48, - 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 68, 70, 71, 72, 73, 74, 75, 76, 77, 79, - 80, 81, 82, 83, 85, 86, 87, 88, 90, 91, - 92, 94, 95, 96, 98, 99, 100, 102, 103, 105, - 106, 108, 109, 110, 112, 113, 115, 116, 118, 120, - 121, 123, 124, 126, 128, 129, 131, 132, 134, 136, - 138, 139, 141, 143, 145, 146, 148, 150, 152, 154, - 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, - 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, - 196, 198, 200, 202, 204, 207, 209, 211, 214, 216, - 218, 220, 223, 225, 228, 230, 232, 235, 237, 240, - 242, 245, 247, 250, 252, 255, -}; - - /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ @@ -231,7 +204,7 @@ 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)]=cie[*src]; + PRIV(g)->write_buffer[get_led_address(g, x, y)]=CIE1931_CURVE[*src]; ++src; } } -- cgit v1.2.3-24-g4f1b From 951b6f33a0dc479d29831aaa5c73fc526faf0471 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 21:28:27 +0300 Subject: CIE 1931 for the LCD backlight --- keyboards/ergodox/infinity/infinity.c | 29 ++++++++++++++++++++++++++--- keyboards/ergodox/infinity/visualizer.c | 6 +++--- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/infinity.c b/keyboards/ergodox/infinity/infinity.c index 02db67eaf..ecc072abb 100644 --- a/keyboards/ergodox/infinity/infinity.c +++ b/keyboards/ergodox/infinity/infinity.c @@ -70,10 +70,33 @@ void lcd_backlight_hal_init(void) { RGB_PORT->PCR[BLUE_PIN] = RGB_MODE; } +static uint16_t cie_lightness(uint16_t v) { + // The CIE 1931 formula for lightness + // Y = luminance (output) 0-1 + // L = lightness input 0 - 100 + + // Y = (L* / 902.3) if L* <= 8 + // Y = ((L* + 16) / 116)^3 if L* > 8 + + float l = 100.0f * (v / 65535.0f); + float y = 0.0f; + if (l <= 8.0f) { + y = l / 902.3; + } + else { + y = ((l + 16.0f) / 116.0f); + y = y * y * y; + if (y > 1.0f) { + y = 1.0f; + } + } + return y * 65535.0f; +} + void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) { - CHANNEL_RED.CnV = r; - CHANNEL_GREEN.CnV = g; - CHANNEL_BLUE.CnV = b; + CHANNEL_RED.CnV = cie_lightness(r); + CHANNEL_GREEN.CnV = cie_lightness(g); + CHANNEL_BLUE.CnV = cie_lightness(b); } __attribute__ ((weak)) diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index c8fc3d78e..12336fdc5 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -70,8 +70,8 @@ static const uint8_t image_data_lcd_logo[512] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0x80); -static const uint32_t initial_color = LCD_COLOR(0, 0, 0xFF); +static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); +static const uint32_t initial_color = LCD_COLOR(0, 0, 0); bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { (void)state; @@ -155,7 +155,7 @@ static keyframe_animation_t resume_animation = { void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. - lcd_backlight_brightness(0x50); + lcd_backlight_brightness(130); state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; start_keyframe_animation(&startup_animation); -- cgit v1.2.3-24-g4f1b From 9a4ce28683b667ab67d48d92196bab7e277d4800 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Apr 2017 22:52:58 +0300 Subject: Display layer bitmap and keyboard led states on the LCD --- keyboards/ergodox/infinity/visualizer.c | 86 ++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 29 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 12336fdc5..6af3a72ee 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -73,6 +73,14 @@ static const uint8_t image_data_lcd_logo[512] = { static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); +typedef enum { + LCD_STATE_INITIAL, + LCD_STATE_LAYER_BITMAP, + LCD_STATE_BITMAP_AND_LEDS, +} lcd_state_t; + +static lcd_state_t lcd_state = LCD_STATE_INITIAL; + bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { (void)state; (void)animation; @@ -122,11 +130,18 @@ static keyframe_animation_t color_animation = { // The LCD animation alternates between the layer name display and a // bitmap that displays all active layers -static keyframe_animation_t lcd_animation = { +static keyframe_animation_t lcd_bitmap_animation = { + .num_frames = 1, + .loop = false, + .frame_lengths = {gfxMillisecondsToTicks(0)}, + .frame_functions = {keyframe_display_layer_bitmap}, +}; + +static keyframe_animation_t lcd_bitmap_leds_animation = { .num_frames = 2, .loop = true, .frame_lengths = {gfxMillisecondsToTicks(2000), gfxMillisecondsToTicks(2000)}, - .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap}, + .frame_functions = {keyframe_display_layer_bitmap, keyframe_display_led_states}, }; static keyframe_animation_t suspend_animation = { @@ -158,38 +173,50 @@ void initialize_user_visualizer(visualizer_state_t* state) { lcd_backlight_brightness(130); state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; + lcd_state = LCD_STATE_INITIAL; start_keyframe_animation(&startup_animation); } -void update_user_visualizer_state(visualizer_state_t* state) { - // Add more tests, change the colors and layer texts here - // Usually you want to check the high bits (higher layers first) - // because that's the order layers are processed for keypresses - // You can for check for example: - // state->status.layer - // state->status.default_layer - // state->status.leds (see led.h for available statuses) - if (state->status.layer & 0x8) { - state->target_lcd_color = LCD_COLOR(0xC0, 0xB0, 0xFF); - state->layer_text = "Numpad"; - } - else if (state->status.layer & 0x4) { - state->target_lcd_color = LCD_COLOR(0, 0xB0, 0xFF); - state->layer_text = "KBD functions"; - } - else if (state->status.layer & 0x2) { - state->target_lcd_color = LCD_COLOR(0x80, 0xB0, 0xFF); - state->layer_text = "Function keys"; - } - else { +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { + // Check the status here to start and stop animations + // You might have to save some state, like the current animation here so that you can start the right + // This function is called every time the status changes + + // NOTE that this is called from the visualizer thread, so don't access anything else outside the status + // This is also important because the slave won't have access to the active layer for example outside the + // status. + + if (lcd_state == LCD_STATE_INITIAL) { state->target_lcd_color = LCD_COLOR(0x40, 0xB0, 0xFF); - state->layer_text = "Default"; + start_keyframe_animation(&color_animation); + } + + if (state->status.leds) { + if (lcd_state != LCD_STATE_BITMAP_AND_LEDS || + state->status.leds != prev_status.leds || + state->status.layer != prev_status.layer || + state->status.default_layer != prev_status.default_layer) { + + // NOTE: that it doesn't matter if the animation isn't playing, stop will do nothing in that case + stop_keyframe_animation(&lcd_bitmap_animation); + + lcd_state = LCD_STATE_BITMAP_AND_LEDS; + // For information: + // The logic in this function makes sure that this doesn't happen, but if you call start on an + // animation that is already playing it will be restarted. + start_keyframe_animation(&lcd_bitmap_leds_animation); + } + } else { + if (lcd_state != LCD_STATE_LAYER_BITMAP || + state->status.layer != prev_status.layer || + state->status.default_layer != prev_status.default_layer) { + + stop_keyframe_animation(&lcd_bitmap_leds_animation); + + lcd_state = LCD_STATE_LAYER_BITMAP; + start_keyframe_animation(&lcd_bitmap_animation); + } } - // You can also stop existing animations, and start your custom ones here - // remember that you should normally have only one animation for the LCD - // and one for the background. But you can also combine them if you want. - start_keyframe_animation(&lcd_animation); - start_keyframe_animation(&color_animation); } void user_visualizer_suspend(visualizer_state_t* state) { @@ -203,5 +230,6 @@ void user_visualizer_suspend(visualizer_state_t* state) { void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; + lcd_state = LCD_STATE_INITIAL; start_keyframe_animation(&resume_animation); } -- cgit v1.2.3-24-g4f1b From 39385144e7dc3337e623cdc8147b4a441f22fd62 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 2 Apr 2017 01:31:04 +0300 Subject: Emulate Ergodox EZ leds by LCD colors --- keyboards/ergodox/infinity/config.h | 2 + keyboards/ergodox/infinity/infinity.c | 22 +++- keyboards/ergodox/infinity/infinity.h | 71 +++++++------ keyboards/ergodox/infinity/visualizer.c | 175 ++++++++++++++++++++++++++++++-- 4 files changed, 226 insertions(+), 44 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/config.h b/keyboards/ergodox/infinity/config.h index 9e264083b..6cde193e1 100644 --- a/keyboards/ergodox/infinity/config.h +++ b/keyboards/ergodox/infinity/config.h @@ -54,6 +54,8 @@ along with this program. If not, see . // The visualizer needs gfx thread priorities #define VISUALIZER_THREAD_PRIORITY (NORMAL_PRIORITY - 2) +#define VISUALIZER_USER_DATA_SIZE 16 + /* * Feature disable options * These options are also useful to firmware size reduction. diff --git a/keyboards/ergodox/infinity/infinity.c b/keyboards/ergodox/infinity/infinity.c index ecc072abb..62259ed3f 100644 --- a/keyboards/ergodox/infinity/infinity.c +++ b/keyboards/ergodox/infinity/infinity.c @@ -126,34 +126,48 @@ void matrix_scan_kb(void) { matrix_scan_user(); } +__attribute__ ((weak)) void ergodox_board_led_on(void){ } +__attribute__ ((weak)) void ergodox_right_led_1_on(void){ } +__attribute__ ((weak)) void ergodox_right_led_2_on(void){ } +__attribute__ ((weak)) void ergodox_right_led_3_on(void){ } -void ergodox_right_led_on(uint8_t led){ -} - +__attribute__ ((weak)) void ergodox_board_led_off(void){ } +__attribute__ ((weak)) void ergodox_right_led_1_off(void){ } +__attribute__ ((weak)) void ergodox_right_led_2_off(void){ } +__attribute__ ((weak)) void ergodox_right_led_3_off(void){ } -void ergodox_right_led_off(uint8_t led){ +__attribute__ ((weak)) +void ergodox_right_led_1_set(uint8_t n) { +} + +__attribute__ ((weak)) +void ergodox_right_led_2_set(uint8_t n) { +} + +__attribute__ ((weak)) +void ergodox_right_led_3_set(uint8_t n) { } #ifdef ONEHAND_ENABLE diff --git a/keyboards/ergodox/infinity/infinity.h b/keyboards/ergodox/infinity/infinity.h index fec9e565c..73a0f4bf7 100644 --- a/keyboards/ergodox/infinity/infinity.h +++ b/keyboards/ergodox/infinity/infinity.h @@ -7,13 +7,38 @@ void ergodox_board_led_on(void); void ergodox_right_led_1_on(void); void ergodox_right_led_2_on(void); void ergodox_right_led_3_on(void); -void ergodox_right_led_on(uint8_t led); + +inline void ergodox_right_led_on(uint8_t led) { + switch (led) { + case 0: + ergodox_right_led_1_on(); + break; + case 1: + ergodox_right_led_2_on(); + break; + case 2: + ergodox_right_led_3_on(); + break; + } +} void ergodox_board_led_off(void); void ergodox_right_led_1_off(void); void ergodox_right_led_2_off(void); void ergodox_right_led_3_off(void); -void ergodox_right_led_off(uint8_t led); +inline void ergodox_right_led_off(uint8_t led) { + switch (led) { + case 0: + ergodox_right_led_1_off(); + break; + case 1: + ergodox_right_led_2_off(); + break; + case 2: + ergodox_right_led_3_off(); + break; + } +} inline void ergodox_led_all_on(void) { @@ -31,36 +56,22 @@ inline void ergodox_led_all_off(void) ergodox_right_led_3_off(); } -inline void ergodox_right_led_1_set(uint8_t n){ - if (n) { - ergodox_right_led_1_on(); - } else { - ergodox_right_led_1_off(); - } -} - -inline void ergodox_right_led_2_set(uint8_t n){ - if (n) { - ergodox_right_led_2_on(); - } else { - ergodox_right_led_2_off(); - } -} - -inline void ergodox_right_led_3_set(uint8_t n){ - if (n) { - ergodox_right_led_3_on(); - } else { - ergodox_right_led_3_off(); - } -} +void ergodox_right_led_1_set(uint8_t n); +void ergodox_right_led_2_set(uint8_t n); +void ergodox_right_led_3_set(uint8_t n); inline void ergodox_right_led_set(uint8_t led, uint8_t n){ - if (n) { - ergodox_right_led_on(led); - } else { - ergodox_right_led_off(led); - } + switch (led) { + case 0: + ergodox_right_led_1_set(n); + break; + case 1: + ergodox_right_led_2_set(n); + break; + case 2: + ergodox_right_led_3_set(n); + break; + } } inline void ergodox_led_all_set(uint8_t n) { diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 6af3a72ee..7bc42fbc7 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,6 +27,7 @@ along with this program. If not, see . #endif #include "visualizer.h" +#include "system/serial_link.h" // To generate an image array like this // Ensure the image is 128 x 32 or smaller @@ -73,6 +74,15 @@ static const uint8_t image_data_lcd_logo[512] = { static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); +static const uint32_t led_emulation_colors[4] = { + LCD_COLOR(0, 0, 0), + LCD_COLOR(255, 255, 255), + LCD_COLOR(84, 255, 255), + LCD_COLOR(168, 255, 255), +}; + +static uint32_t next_led_target_color = 0; + typedef enum { LCD_STATE_INITIAL, LCD_STATE_LAYER_BITMAP, @@ -81,6 +91,19 @@ typedef enum { static lcd_state_t lcd_state = LCD_STATE_INITIAL; +typedef struct { + uint8_t led_on; + uint8_t led1; + uint8_t led2; + uint8_t led3; +} visualizer_user_data_t; + +// Don't access from visualization function, use the visualizer state instead +static visualizer_user_data_t user_data_keyboard = {}; + +_Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, + "Please increase the VISUALIZER_USER_DATA_SIZE"); + bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { (void)state; (void)animation; @@ -117,16 +140,27 @@ static keyframe_animation_t startup_animation = { }; // The color animation animates the LCD color when you change layers -static keyframe_animation_t color_animation = { - .num_frames = 2, +static keyframe_animation_t one_led_color = { + .num_frames = 1, .loop = false, - // Note that there's a 200 ms no-operation frame, - // this prevents the color from changing when activating the layer - // momentarily - .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, - .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color}, + .frame_lengths = {gfxMillisecondsToTicks(0)}, + .frame_functions = {keyframe_set_backlight_color}, }; +bool swap_led_target_color(keyframe_animation_t* animation, visualizer_state_t* state) { + uint32_t temp = next_led_target_color; + next_led_target_color = state->target_lcd_color; + state->target_lcd_color = temp; + return false; +} + +// The color animation animates the LCD color when you change layers +static keyframe_animation_t two_led_colors = { + .num_frames = 2, + .loop = true, + .frame_lengths = {gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(0)}, + .frame_functions = {keyframe_set_backlight_color, swap_led_target_color}, +}; // The LCD animation alternates between the layer name display and a // bitmap that displays all active layers @@ -177,6 +211,45 @@ void initialize_user_visualizer(visualizer_state_t* state) { start_keyframe_animation(&startup_animation); } +static const uint32_t red; +static const uint32_t green; +static const uint32_t blue; + +inline bool is_led_on(visualizer_user_data_t* user_data, uint8_t num) { + return user_data->led_on & (1u << num); +} + +static uint8_t get_led_index_master(visualizer_user_data_t* user_data) { + for (int i=0; i < 3; i++) { + if (is_led_on(user_data, i)) { + return i + 1; + } + } + return 0; +} + +static uint8_t get_led_index_slave(visualizer_user_data_t* user_data) { + uint8_t master_index = get_led_index_master(user_data); + if (master_index!=0) { + for (int i=master_index; i < 3; i++) { + if (is_led_on(user_data, i)) { + return i + 1; + } + } + } + + return 0; +} + +static uint8_t get_secondary_led_index(visualizer_user_data_t* user_data) { + if (is_led_on(user_data, 0) && + is_led_on(user_data, 1) && + is_led_on(user_data, 2)) { + return 3; + } + return 0; +} + void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { // Check the status here to start and stop animations // You might have to save some state, like the current animation here so that you can start the right @@ -186,9 +259,38 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard // This is also important because the slave won't have access to the active layer for example outside the // status. - if (lcd_state == LCD_STATE_INITIAL) { - state->target_lcd_color = LCD_COLOR(0x40, 0xB0, 0xFF); - start_keyframe_animation(&color_animation); + + visualizer_user_data_t* user_data_new = (visualizer_user_data_t*)state->status.user_data; + visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status.user_data; + + uint8_t new_index; + uint8_t old_index; + + if (is_serial_link_master()) { + new_index = get_led_index_master(user_data_new); + old_index = get_led_index_master(user_data_old); + } + else { + new_index = get_led_index_slave(user_data_new); + old_index = get_led_index_slave(user_data_old); + } + uint8_t new_secondary_index = get_secondary_led_index(user_data_new); + uint8_t old_secondary_index = get_secondary_led_index(user_data_old); + + if (lcd_state == LCD_STATE_INITIAL || + new_index != old_index || + new_secondary_index != old_secondary_index) { + + if (new_secondary_index != 0) { + state->target_lcd_color = led_emulation_colors[new_index]; + next_led_target_color = led_emulation_colors[new_secondary_index]; + stop_keyframe_animation(&one_led_color); + start_keyframe_animation(&two_led_colors); + } else { + state->target_lcd_color = led_emulation_colors[new_index]; + stop_keyframe_animation(&two_led_colors); + start_keyframe_animation(&one_led_color); + } } if (state->status.leds) { @@ -233,3 +335,56 @@ void user_visualizer_resume(visualizer_state_t* state) { lcd_state = LCD_STATE_INITIAL; start_keyframe_animation(&resume_animation); } + +void ergodox_board_led_on(void){ + // No board led support +} + +void ergodox_right_led_1_on(void){ + user_data_keyboard.led_on |= (1u << 0); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_2_on(void){ + user_data_keyboard.led_on |= (1u << 1); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_3_on(void){ + user_data_keyboard.led_on |= (1u << 2); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_board_led_off(void){ + // No board led support +} + +void ergodox_right_led_1_off(void){ + user_data_keyboard.led_on &= ~(1u << 0); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_2_off(void){ + user_data_keyboard.led_on &= ~(1u << 1); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_3_off(void){ + user_data_keyboard.led_on &= ~(1u << 2); + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_1_set(uint8_t n) { + user_data_keyboard.led1 = n; + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_2_set(uint8_t n) { + user_data_keyboard.led2 = n; + visualizer_set_user_data(&user_data_keyboard); +} + +void ergodox_right_led_3_set(uint8_t n) { + user_data_keyboard.led3 = n; + visualizer_set_user_data(&user_data_keyboard); +} -- cgit v1.2.3-24-g4f1b From 5fbaf31dc26a7bb27eb276ec419255e92b293d60 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 2 Apr 2017 02:29:50 +0300 Subject: Brightness for Ergodox Infinity emulated LEDs --- keyboards/ergodox/infinity/config.h | 2 +- keyboards/ergodox/infinity/visualizer.c | 76 ++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 21 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/config.h b/keyboards/ergodox/infinity/config.h index 6cde193e1..95f713819 100644 --- a/keyboards/ergodox/infinity/config.h +++ b/keyboards/ergodox/infinity/config.h @@ -40,7 +40,7 @@ along with this program. If not, see . /* number of backlight levels */ #define BACKLIGHT_LEVELS 3 -#define LED_BRIGHTNESS_LO 15 +#define LED_BRIGHTNESS_LO 100 #define LED_BRIGHTNESS_HI 255 /* define if matrix has ghost */ diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 7bc42fbc7..c7afd9384 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -99,7 +99,12 @@ typedef struct { } visualizer_user_data_t; // Don't access from visualization function, use the visualizer state instead -static visualizer_user_data_t user_data_keyboard = {}; +static visualizer_user_data_t user_data_keyboard = { + .led_on = 0, + .led1 = LED_BRIGHTNESS_HI, + .led2 = LED_BRIGHTNESS_HI, + .led3 = LED_BRIGHTNESS_HI, +}; _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, "Please increase the VISUALIZER_USER_DATA_SIZE"); @@ -250,18 +255,21 @@ static uint8_t get_secondary_led_index(visualizer_user_data_t* user_data) { return 0; } -void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t prev_status) { - // Check the status here to start and stop animations - // You might have to save some state, like the current animation here so that you can start the right - // This function is called every time the status changes - - // NOTE that this is called from the visualizer thread, so don't access anything else outside the status - // This is also important because the slave won't have access to the active layer for example outside the - // status. - +static uint8_t get_brightness(visualizer_user_data_t* user_data, uint8_t index) { + switch (index) { + case 1: + return user_data->led1; + case 2: + return user_data->led2; + case 3: + return user_data->led3; + } + return 0; +} +static void update_emulated_leds(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { visualizer_user_data_t* user_data_new = (visualizer_user_data_t*)state->status.user_data; - visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status.user_data; + visualizer_user_data_t* user_data_old = (visualizer_user_data_t*)prev_status->user_data; uint8_t new_index; uint8_t old_index; @@ -277,27 +285,41 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard uint8_t new_secondary_index = get_secondary_led_index(user_data_new); uint8_t old_secondary_index = get_secondary_led_index(user_data_old); + uint8_t old_brightness = get_brightness(user_data_old, old_index); + uint8_t new_brightness = get_brightness(user_data_new, new_index); + + uint8_t old_secondary_brightness = get_brightness(user_data_old, old_secondary_index); + uint8_t new_secondary_brightness = get_brightness(user_data_new, new_secondary_index); + if (lcd_state == LCD_STATE_INITIAL || new_index != old_index || - new_secondary_index != old_secondary_index) { + new_secondary_index != old_secondary_index || + new_brightness != old_brightness || + new_secondary_brightness != old_secondary_brightness) { if (new_secondary_index != 0) { - state->target_lcd_color = led_emulation_colors[new_index]; - next_led_target_color = led_emulation_colors[new_secondary_index]; + state->target_lcd_color = change_lcd_color_intensity( + led_emulation_colors[new_index], new_brightness); + next_led_target_color = change_lcd_color_intensity( + led_emulation_colors[new_secondary_index], new_secondary_brightness); + stop_keyframe_animation(&one_led_color); start_keyframe_animation(&two_led_colors); } else { - state->target_lcd_color = led_emulation_colors[new_index]; + state->target_lcd_color = change_lcd_color_intensity( + led_emulation_colors[new_index], new_brightness); stop_keyframe_animation(&two_led_colors); start_keyframe_animation(&one_led_color); } } +} +static void update_lcd_text(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { if (state->status.leds) { if (lcd_state != LCD_STATE_BITMAP_AND_LEDS || - state->status.leds != prev_status.leds || - state->status.layer != prev_status.layer || - state->status.default_layer != prev_status.default_layer) { + state->status.leds != prev_status->leds || + state->status.layer != prev_status->layer || + state->status.default_layer != prev_status->default_layer) { // NOTE: that it doesn't matter if the animation isn't playing, stop will do nothing in that case stop_keyframe_animation(&lcd_bitmap_animation); @@ -310,8 +332,8 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard } } else { if (lcd_state != LCD_STATE_LAYER_BITMAP || - state->status.layer != prev_status.layer || - state->status.default_layer != prev_status.default_layer) { + state->status.layer != prev_status->layer || + state->status.default_layer != prev_status->default_layer) { stop_keyframe_animation(&lcd_bitmap_leds_animation); @@ -321,6 +343,20 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard } } +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { + // Check the status here to start and stop animations + // You might have to save some state, like the current animation here so that you can start the right + // This function is called every time the status changes + + // NOTE that this is called from the visualizer thread, so don't access anything else outside the status + // This is also important because the slave won't have access to the active layer for example outside the + // status. + + update_emulated_leds(state, prev_status); + update_lcd_text(state, prev_status); + +} + void user_visualizer_suspend(visualizer_state_t* state) { state->layer_text = "Suspending..."; uint8_t hue = LCD_HUE(state->current_lcd_color); -- cgit v1.2.3-24-g4f1b From 5815c5d317b02d688990980fdf01848e81247c21 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 08:40:39 +0300 Subject: Move LCD keyframes to its own file --- keyboards/ergodox/infinity/visualizer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index c7afd9384..3abed08db 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,6 +27,7 @@ along with this program. If not, see . #endif #include "visualizer.h" +#include "lcd_keyframes.h" #include "system/serial_link.h" // To generate an image array like this @@ -173,14 +174,14 @@ static keyframe_animation_t lcd_bitmap_animation = { .num_frames = 1, .loop = false, .frame_lengths = {gfxMillisecondsToTicks(0)}, - .frame_functions = {keyframe_display_layer_bitmap}, + .frame_functions = {lcd_keyframe_display_layer_bitmap}, }; static keyframe_animation_t lcd_bitmap_leds_animation = { .num_frames = 2, .loop = true, .frame_lengths = {gfxMillisecondsToTicks(2000), gfxMillisecondsToTicks(2000)}, - .frame_functions = {keyframe_display_layer_bitmap, keyframe_display_led_states}, + .frame_functions = {lcd_keyframe_display_layer_bitmap, lcd_keyframe_display_led_states}, }; static keyframe_animation_t suspend_animation = { @@ -188,7 +189,7 @@ static keyframe_animation_t suspend_animation = { .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, .frame_functions = { - keyframe_display_layer_text, + lcd_keyframe_display_layer_text, keyframe_animate_backlight_color, keyframe_disable_lcd_and_backlight, }, -- cgit v1.2.3-24-g4f1b From 5ba228b684a32c1099efc6207842a56ff102961a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 08:48:30 +0300 Subject: Move LCD backlight keyframes to its own file --- keyboards/ergodox/infinity/visualizer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 3abed08db..bbed4e989 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -28,6 +28,7 @@ along with this program. If not, see . #include "visualizer.h" #include "lcd_keyframes.h" +#include "lcd_backlight_keyframes.h" #include "system/serial_link.h" // To generate an image array like this @@ -140,7 +141,7 @@ static keyframe_animation_t startup_animation = { .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { display_logo, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, enable_visualization }, }; @@ -150,7 +151,7 @@ static keyframe_animation_t one_led_color = { .num_frames = 1, .loop = false, .frame_lengths = {gfxMillisecondsToTicks(0)}, - .frame_functions = {keyframe_set_backlight_color}, + .frame_functions = {backlight_keyframe_set_color}, }; bool swap_led_target_color(keyframe_animation_t* animation, visualizer_state_t* state) { @@ -165,7 +166,7 @@ static keyframe_animation_t two_led_colors = { .num_frames = 2, .loop = true, .frame_lengths = {gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(0)}, - .frame_functions = {keyframe_set_backlight_color, swap_led_target_color}, + .frame_functions = {backlight_keyframe_set_color, swap_led_target_color}, }; // The LCD animation alternates between the layer name display and a @@ -190,7 +191,7 @@ static keyframe_animation_t suspend_animation = { .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, .frame_functions = { lcd_keyframe_display_layer_text, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, keyframe_disable_lcd_and_backlight, }, }; @@ -202,7 +203,7 @@ static keyframe_animation_t resume_animation = { .frame_functions = { keyframe_enable_lcd_and_backlight, display_logo, - keyframe_animate_backlight_color, + backlight_keyframe_animate_color, enable_visualization, }, }; -- cgit v1.2.3-24-g4f1b From 1e7585e76771e1a2d8ca733fc09c19f9fa0e903c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 09:21:18 +0300 Subject: Separated backlight and LCD disable/enable Also moved them to correct places --- keyboards/ergodox/infinity/visualizer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index bbed4e989..8e684d991 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -186,22 +186,24 @@ static keyframe_animation_t lcd_bitmap_leds_animation = { }; static keyframe_animation_t suspend_animation = { - .num_frames = 3, + .num_frames = 4, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, .frame_functions = { lcd_keyframe_display_layer_text, backlight_keyframe_animate_color, - keyframe_disable_lcd_and_backlight, + lcd_keyframe_disable, + lcd_keyframe_disable, }, }; static keyframe_animation_t resume_animation = { - .num_frames = 4, + .num_frames = 5, .loop = false, - .frame_lengths = {0, 0, gfxMillisecondsToTicks(10000), 0}, + .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - keyframe_enable_lcd_and_backlight, + lcd_keyframe_enable, + backlight_keyframe_enable, display_logo, backlight_keyframe_animate_color, enable_visualization, -- cgit v1.2.3-24-g4f1b From 64d63ab42281318d891434fbc00277043298dd70 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 10:08:25 +0300 Subject: Remove the need to manually enable the visualizer --- keyboards/ergodox/infinity/visualizer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 8e684d991..0897ea348 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -136,13 +136,12 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { // Don't worry, if the startup animation is long, you can use the keyboard like normal // during that time static keyframe_animation_t startup_animation = { - .num_frames = 3, + .num_frames = 2, .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { display_logo, backlight_keyframe_animate_color, - enable_visualization }, }; @@ -198,7 +197,7 @@ static keyframe_animation_t suspend_animation = { }; static keyframe_animation_t resume_animation = { - .num_frames = 5, + .num_frames = 4, .loop = false, .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { @@ -206,7 +205,6 @@ static keyframe_animation_t resume_animation = { backlight_keyframe_enable, display_logo, backlight_keyframe_animate_color, - enable_visualization, }, }; -- cgit v1.2.3-24-g4f1b From b7041d06aef4dcf2f2a47504a699e538cfb1d9ac Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 5 Apr 2017 10:14:24 +0300 Subject: Move common visualizer keyframes into visualizer_keyframes.h --- keyboards/ergodox/infinity/visualizer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 0897ea348..2e10fdd70 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -27,6 +27,7 @@ along with this program. If not, see . #endif #include "visualizer.h" +#include "visualizer_keyframes.h" #include "lcd_keyframes.h" #include "lcd_backlight_keyframes.h" #include "system/serial_link.h" -- cgit v1.2.3-24-g4f1b From 3994fb1e79615af849aa03378293831f59c9b259 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 7 Apr 2017 10:51:53 +0300 Subject: Yet another try to fix the LCD corruption It turns out that the ChibiOS K20 SPI driver doesn't handle the chip select, so it needs to be done manually. Acquiring the bus is not enough since the pin was in the wrong mode. This is now fixed. Also increase the frequency of the SPI from around 200kHz to nearly 20 Mhz. --- .../drivers/gdisp/st7565ergodox/board_ST7565.h | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h index c2092b5e8..e8c17e6e3 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h @@ -45,15 +45,28 @@ static const SPIConfig spi1config = { .sspad=ST7565_SS_PIN, // SPI initialization data. .tar0 = - SPIx_CTARn_FMSZ(7) - | SPIx_CTARn_ASC(7) - | SPIx_CTARn_DT(7) - | SPIx_CTARn_CSSCK(7) - | SPIx_CTARn_PBR(0) - | SPIx_CTARn_BR(7) - //SPI_CR1_BR_0 + SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes + | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns + | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns + | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns + | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2 + | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns }; +static GFXINLINE void acquire_bus(GDisplay *g) { + (void) g; + // Only the LCD is using the SPI bus, so no need to acquire + // spiAcquireBus(&SPID1); + spiSelect(&SPID1); +} + +static GFXINLINE void release_bus(GDisplay *g) { + (void) g; + // Only the LCD is using the SPI bus, so no need to release + //spiReleaseBus(&SPID1); + spiUnselect(&SPID1); +} + static GFXINLINE void init_board(GDisplay *g) { (void) g; palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL); @@ -62,10 +75,11 @@ static GFXINLINE void init_board(GDisplay *g) { palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN); palSetPadModeRaw(MOSI, ST7565_SPI_MODE); palSetPadModeRaw(SLCK, ST7565_SPI_MODE); - palSetPadModeRaw(SS, ST7565_SPI_MODE); + palSetPadModeRaw(SS, PAL_MODE_OUTPUT_PUSHPULL); spiInit(); spiStart(&SPID1, &spi1config); + release_bus(g); } static GFXINLINE void post_init_board(GDisplay *g) { @@ -82,20 +96,6 @@ static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) { } } -static GFXINLINE void acquire_bus(GDisplay *g) { - (void) g; - // Only the LCD is using the SPI bus, so no need to acquire - // spiAcquireBus(&SPID1); - spiSelect(&SPID1); -} - -static GFXINLINE void release_bus(GDisplay *g) { - (void) g; - // Only the LCD is using the SPI bus, so no need to release - //spiReleaseBus(&SPID1); - spiUnselect(&SPID1); -} - static GFXINLINE void enter_data_mode(GDisplay *g) { palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN); } -- cgit v1.2.3-24-g4f1b From 995002fa912545128625ec2d8c53cff5de560b97 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 7 Apr 2017 10:55:29 +0300 Subject: LCD initialization sequence according to the docs The LCD initialization show now be much better and faster with no flickering at the startup. Also fix the contrast control. --- .../drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 40 ++++++---------------- .../infinity/drivers/gdisp/st7565ergodox/st7565.h | 2 ++ 2 files changed, 13 insertions(+), 29 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c index 2c8a168e7..0de457a7a 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c @@ -26,7 +26,7 @@ #define GDISP_SCREEN_WIDTH 128 #endif #ifndef GDISP_INITIAL_CONTRAST -#define GDISP_INITIAL_CONTRAST 0 +#define GDISP_INITIAL_CONTRAST 35 #endif #ifndef GDISP_INITIAL_BACKLIGHT #define GDISP_INITIAL_BACKLIGHT 100 @@ -111,41 +111,25 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { gfxSleepMilliseconds(20); setpin_reset(g, FALSE); gfxSleepMilliseconds(20); - acquire_bus(g); enter_cmd_mode(g); - write_cmd(g, ST7565_DISPLAY_OFF); + + write_cmd(g, ST7565_RESET); write_cmd(g, ST7565_LCD_BIAS); write_cmd(g, ST7565_ADC); write_cmd(g, ST7565_COM_SCAN); - write_cmd(g, ST7565_START_LINE | 0); - - write_cmd(g, ST7565_RESISTOR_RATIO | 0x6); - - // turn on voltage converter (VC=1, VR=0, VF=0) - write_cmd(g, ST7565_POWER_CONTROL | 0x04); - flush_cmd(g); - delay_ms(50); - - // turn on voltage regulator (VC=1, VR=1, VF=0) - write_cmd(g, ST7565_POWER_CONTROL | 0x06); - flush_cmd(g); - delay_ms(50); + write_cmd(g, ST7565_RESISTOR_RATIO | 0x1); + write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST); - // turn on voltage follower (VC=1, VR=1, VF=1) + // turn on internal power supply (VC=1, VR=1, VF=1) write_cmd(g, ST7565_POWER_CONTROL | 0x07); - flush_cmd(g); - delay_ms(50); - write_cmd(g, 0xE2); - write_cmd(g, ST7565_COM_SCAN); - write_cmd2(g, ST7565_CONTRAST, GDISP_INITIAL_CONTRAST*64/101); - //write_cmd2(g, ST7565_CONTRAST, 0); - write_cmd(g, ST7565_DISPLAY_ON); - write_cmd(g, ST7565_ALLON_NORMAL); write_cmd(g, ST7565_INVERT_DISPLAY); + write_cmd(g, ST7565_ALLON_NORMAL); + write_cmd(g, ST7565_DISPLAY_ON); + write_cmd(g, ST7565_START_LINE | 0); write_cmd(g, ST7565_RMW); flush_cmd(g); @@ -331,14 +315,12 @@ LLDSPEC void gdisp_lld_control(GDisplay *g) { return; case GDISP_CONTROL_CONTRAST: - if ((unsigned)g->p.ptr > 100) - g->p.ptr = (void *)100; + g->g.Contrast = (unsigned)g->p.ptr & 63; acquire_bus(g); enter_cmd_mode(g); - write_cmd2(g, ST7565_CONTRAST, ((((unsigned)g->p.ptr)<<6)/101) & 0x3F); + write_cmd2(g, ST7565_CONTRAST, g->g.Contrast); flush_cmd(g); release_bus(g); - g->g.Contrast = (unsigned)g->p.ptr; return; } } diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/st7565.h b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/st7565.h index 48636b33d..24924ff05 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/st7565.h +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/st7565.h @@ -34,4 +34,6 @@ #define ST7565_RESISTOR_RATIO 0x20 #define ST7565_POWER_CONTROL 0x28 +#define ST7565_RESET 0xE2 + #endif /* _ST7565_H */ -- cgit v1.2.3-24-g4f1b From 3eb8785e8770c07e6a4280c50240d5d951461911 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 20:10:20 +0300 Subject: Add automatic flush for the LCD screen --- .../ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 1 + keyboards/ergodox/infinity/visualizer.c | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c index 0de457a7a..5b7b6d44c 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c @@ -262,6 +262,7 @@ LLDSPEC void gdisp_lld_blit_area(GDisplay *g) { srcbit++; } } + g->flags |= GDISP_FLG_NEEDFLUSH; } #if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 2e10fdd70..6f9b0210a 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -127,8 +127,6 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { // if you have full screen image, then just use 128 and 32 for both source and target dimensions gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); - // Always remember to flush the display - gdispFlush(); return false; } -- cgit v1.2.3-24-g4f1b From df67169d4260881443d88b142855d4aa2def6dc3 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 21:19:44 +0300 Subject: Move LCD logo to visualizer resources --- keyboards/ergodox/infinity/lcd_logo.png | Bin 490 -> 0 bytes keyboards/ergodox/infinity/visualizer.c | 44 ++------------------------------ 2 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 keyboards/ergodox/infinity/lcd_logo.png (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/lcd_logo.png b/keyboards/ergodox/infinity/lcd_logo.png deleted file mode 100644 index 6cf26fc67..000000000 Binary files a/keyboards/ergodox/infinity/lcd_logo.png and /dev/null differ diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 6f9b0210a..90933b00a 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -32,47 +32,7 @@ along with this program. If not, see . #include "lcd_backlight_keyframes.h" #include "system/serial_link.h" -// To generate an image array like this -// Ensure the image is 128 x 32 or smaller -// Convert the bitmap to a C array using a program like http://www.riuson.com/lcd-image-converter/ -// Ensure the the conversion process produces a monochrome format array - 1 bit/pixel, left to right, top to bottom -// Update array in the source code with the C array produced by the conversion program - -// The image below is generated from lcd_logo.png -static const uint8_t image_data_lcd_logo[512] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xf8, 0xfe, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x06, 0x29, 0x41, 0x24, 0x52, 0x24, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x42, 0xaa, 0xaa, 0xaa, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x82, 0x28, 0xaa, 0xae, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x09, 0x55, 0x43, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x0a, 0x55, 0x42, 0x28, 0xaa, 0xaa, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x38, 0x38, 0x38, 0x05, 0x45, 0x42, 0x28, 0x89, 0x4a, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x38, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1c, 0x38, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0e, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x03, 0xff, 0x80, 0x04, 0x45, 0x14, 0xa4, 0x92, 0x83, 0x52, 0x22, 0x22, 0x36, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0xba, 0x84, 0x55, 0x55, 0x57, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0xb2, 0x55, 0x55, 0x42, 0x65, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x08, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x56, 0x65, 0x42, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x0a, 0xaa, 0xaa, 0xaa, 0x92, 0x81, 0x54, 0x45, 0x42, 0x45, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x04, 0x48, 0xa2, 0x4a, 0x89, 0x06, 0x24, 0x42, 0x41, 0x36, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; +#include "resources/resources.h" static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); @@ -125,7 +85,7 @@ bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { //gdispGBlitArea is a tricky function to use since it supports blitting part of the image // if you have full screen image, then just use 128 and 32 for both source and target dimensions - gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)image_data_lcd_logo); + gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo); return false; } -- cgit v1.2.3-24-g4f1b From 3074269c4a07ff7f1ab2a76ebdb8904cd642e283 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 21:30:11 +0300 Subject: Move the logo drawing keyframe to lcd_keyframes --- keyboards/ergodox/infinity/visualizer.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 90933b00a..bac85c593 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -72,24 +72,6 @@ static visualizer_user_data_t user_data_keyboard = { _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, "Please increase the VISUALIZER_USER_DATA_SIZE"); -bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) { - (void)state; - (void)animation; - (void)state; - // Read the uGFX documentation for information how to use the displays - // http://wiki.ugfx.org/index.php/Main_Page - gdispClear(White); - - // You can use static variables for things that can't be found in the animation - // or state structs, here we use the image - - //gdispGBlitArea is a tricky function to use since it supports blitting part of the image - // if you have full screen image, then just use 128 and 32 for both source and target dimensions - gdispGBlitArea(GDISP, 0, 0, 128, 32, 0, 0, 128, (pixel_t*)resource_lcd_logo); - - return false; -} - // Feel free to modify the animations below, or even add new ones if needed // Don't worry, if the startup animation is long, you can use the keyboard like normal @@ -99,7 +81,7 @@ static keyframe_animation_t startup_animation = { .loop = false, .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { - display_logo, + lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, }; @@ -162,7 +144,7 @@ static keyframe_animation_t resume_animation = { .frame_functions = { lcd_keyframe_enable, backlight_keyframe_enable, - display_logo, + lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, }; -- cgit v1.2.3-24-g4f1b From ed1710589f2f63e485c8780c7c8c03e0f65136a0 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 21:34:30 +0300 Subject: Fix suspend not disabling backlight --- keyboards/ergodox/infinity/visualizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index bac85c593..8c3f3f29f 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -133,7 +133,7 @@ static keyframe_animation_t suspend_animation = { lcd_keyframe_display_layer_text, backlight_keyframe_animate_color, lcd_keyframe_disable, - lcd_keyframe_disable, + backlight_keyframe_disable, }, }; -- cgit v1.2.3-24-g4f1b From c6ca996f4eaa4cce90e02c123230e1e655c9465a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 22:30:37 +0300 Subject: Combine startup and resume animations --- .../drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 3 +-- keyboards/ergodox/infinity/visualizer.c | 20 +++++--------------- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c index 5b7b6d44c..b04ad0293 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c @@ -127,7 +127,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { write_cmd(g, ST7565_INVERT_DISPLAY); write_cmd(g, ST7565_ALLON_NORMAL); - write_cmd(g, ST7565_DISPLAY_ON); write_cmd(g, ST7565_START_LINE | 0); write_cmd(g, ST7565_RMW); @@ -143,7 +142,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; diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 8c3f3f29f..7ae371c5f 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -77,10 +77,12 @@ _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, // Don't worry, if the startup animation is long, you can use the keyboard like normal // during that time static keyframe_animation_t startup_animation = { - .num_frames = 2, + .num_frames = 4, .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, + .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, .frame_functions = { + lcd_keyframe_enable, + backlight_keyframe_enable, lcd_keyframe_draw_logo, backlight_keyframe_animate_color, }, @@ -137,18 +139,6 @@ static keyframe_animation_t suspend_animation = { }, }; -static keyframe_animation_t resume_animation = { - .num_frames = 4, - .loop = false, - .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, - .frame_functions = { - lcd_keyframe_enable, - backlight_keyframe_enable, - lcd_keyframe_draw_logo, - backlight_keyframe_animate_color, - }, -}; - void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. @@ -312,7 +302,7 @@ void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&resume_animation); + start_keyframe_animation(&startup_animation); } void ergodox_board_led_on(void){ -- cgit v1.2.3-24-g4f1b From 306353bf06e5e5a76890ffb0c48a4dcca76c4399 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 22:48:18 +0300 Subject: Create a file for shared Ergodox Infinity animations --- keyboards/ergodox/infinity/animations.c | 54 +++++++++++++++++++++++++++++++++ keyboards/ergodox/infinity/animations.h | 25 +++++++++++++++ keyboards/ergodox/infinity/rules.mk | 5 +-- keyboards/ergodox/infinity/visualizer.c | 38 +++-------------------- 4 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 keyboards/ergodox/infinity/animations.c create mode 100644 keyboards/ergodox/infinity/animations.h (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/animations.c b/keyboards/ergodox/infinity/animations.c new file mode 100644 index 000000000..54ab99460 --- /dev/null +++ b/keyboards/ergodox/infinity/animations.c @@ -0,0 +1,54 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "animations.h" +#include "visualizer.h" +#ifdef LCD_ENABLE +#include "lcd_keyframes.h" +#endif +#ifdef LCD_BACKLIGHT_ENABLE +#include "lcd_backlight_keyframes.h" +#endif + +#if defined(VISUALIZER_ENABLE) && defined(LCD_ENABLE) && defined(LCD_BACKLIGHT_ENABLE) + +// 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, + .loop = false, + .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(5000), 0}, + .frame_functions = { + lcd_keyframe_enable, + backlight_keyframe_enable, + lcd_keyframe_draw_logo, + backlight_keyframe_animate_color, + }, +}; + +keyframe_animation_t default_suspend_animation = { + .num_frames = 4, + .loop = false, + .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, + .frame_functions = { + lcd_keyframe_display_layer_text, + backlight_keyframe_animate_color, + lcd_keyframe_disable, + backlight_keyframe_disable, + }, +}; + +#endif diff --git a/keyboards/ergodox/infinity/animations.h b/keyboards/ergodox/infinity/animations.h new file mode 100644 index 000000000..0c441ff7e --- /dev/null +++ b/keyboards/ergodox/infinity/animations.h @@ -0,0 +1,25 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ +#define KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ + +#include "visualizer.h" + +extern keyframe_animation_t default_startup_animation; +extern keyframe_animation_t default_suspend_animation; + +#endif /* KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ */ diff --git a/keyboards/ergodox/infinity/rules.mk b/keyboards/ergodox/infinity/rules.mk index aaadfe34b..9e6170d89 100644 --- a/keyboards/ergodox/infinity/rules.mk +++ b/keyboards/ergodox/infinity/rules.mk @@ -1,6 +1,7 @@ # project specific files SRC = matrix.c \ - led.c + led.c \ + animations.c ## chip/board settings # - the next two should match the directories in @@ -72,4 +73,4 @@ endif ifdef LED_ENABLE include $(SUBPROJECT_PATH)/drivers/gdisp/IS31FL3731C/driver.mk -endif +endif \ No newline at end of file diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 7ae371c5f..a4b09a34d 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c @@ -31,8 +31,7 @@ along with this program. If not, see . #include "lcd_keyframes.h" #include "lcd_backlight_keyframes.h" #include "system/serial_link.h" - -#include "resources/resources.h" +#include "animations.h" static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); static const uint32_t initial_color = LCD_COLOR(0, 0, 0); @@ -74,19 +73,6 @@ _Static_assert(sizeof(visualizer_user_data_t) <= VISUALIZER_USER_DATA_SIZE, // Feel free to modify the animations below, or even add new ones if needed -// Don't worry, if the startup animation is long, you can use the keyboard like normal -// during that time -static keyframe_animation_t startup_animation = { - .num_frames = 4, - .loop = false, - .frame_lengths = {0, 0, 0, gfxMillisecondsToTicks(10000), 0}, - .frame_functions = { - lcd_keyframe_enable, - backlight_keyframe_enable, - lcd_keyframe_draw_logo, - backlight_keyframe_animate_color, - }, -}; // The color animation animates the LCD color when you change layers static keyframe_animation_t one_led_color = { @@ -127,18 +113,6 @@ static keyframe_animation_t lcd_bitmap_leds_animation = { .frame_functions = {lcd_keyframe_display_layer_bitmap, lcd_keyframe_display_led_states}, }; -static keyframe_animation_t suspend_animation = { - .num_frames = 4, - .loop = false, - .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0, 0}, - .frame_functions = { - lcd_keyframe_display_layer_text, - backlight_keyframe_animate_color, - lcd_keyframe_disable, - backlight_keyframe_disable, - }, -}; - void initialize_user_visualizer(visualizer_state_t* state) { // The brightness will be dynamically adjustable in the future // But for now, change it here. @@ -146,13 +120,9 @@ void initialize_user_visualizer(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&startup_animation); + start_keyframe_animation(&default_startup_animation); } -static const uint32_t red; -static const uint32_t green; -static const uint32_t blue; - inline bool is_led_on(visualizer_user_data_t* user_data, uint8_t num) { return user_data->led_on & (1u << num); } @@ -295,14 +265,14 @@ void user_visualizer_suspend(visualizer_state_t* state) { uint8_t hue = LCD_HUE(state->current_lcd_color); uint8_t sat = LCD_SAT(state->current_lcd_color); state->target_lcd_color = LCD_COLOR(hue, sat, 0); - start_keyframe_animation(&suspend_animation); + start_keyframe_animation(&default_suspend_animation); } void user_visualizer_resume(visualizer_state_t* state) { state->current_lcd_color = initial_color; state->target_lcd_color = logo_background_color; lcd_state = LCD_STATE_INITIAL; - start_keyframe_animation(&startup_animation); + start_keyframe_animation(&default_startup_animation); } void ergodox_board_led_on(void){ -- cgit v1.2.3-24-g4f1b From c5d2b7ff16f81a8061127e0ec636cf9b914725c5 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Apr 2017 23:04:27 +0300 Subject: Rename led test to led_keyframes and move animation to Ergodox --- keyboards/ergodox/infinity/animations.c | 55 ++++++++++++++++++++++++++++++++- keyboards/ergodox/infinity/animations.h | 5 +++ 2 files changed, 59 insertions(+), 1 deletion(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/animations.c b/keyboards/ergodox/infinity/animations.c index 54ab99460..4c9f6d9c8 100644 --- a/keyboards/ergodox/infinity/animations.c +++ b/keyboards/ergodox/infinity/animations.c @@ -14,6 +14,8 @@ * along with this program. If not, see . */ +#if defined(VISUALIZER_ENABLE) + #include "animations.h" #include "visualizer.h" #ifdef LCD_ENABLE @@ -23,7 +25,14 @@ #include "lcd_backlight_keyframes.h" #endif -#if defined(VISUALIZER_ENABLE) && defined(LCD_ENABLE) && defined(LCD_BACKLIGHT_ENABLE) +#ifdef LED_ENABLE +#include "led_keyframes.h" +#endif + +#include "visualizer_keyframes.h" + + +#if defined(LCD_ENABLE) && defined(LCD_BACKLIGHT_ENABLE) // Don't worry, if the startup animation is long, you can use the keyboard like normal // during that time @@ -50,5 +59,49 @@ keyframe_animation_t default_suspend_animation = { backlight_keyframe_disable, }, }; +#endif + +#if defined(LED_ENABLE) +#define CROSSFADE_TIME 1000 +#define GRADIENT_TIME 3000 + +keyframe_animation_t led_test_animation = { + .num_frames = 14, + .loop = true, + .frame_lengths = { + gfxMillisecondsToTicks(1000), // fade in + gfxMillisecondsToTicks(1000), // no op (leds on) + gfxMillisecondsToTicks(1000), // fade out + gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade + gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in) + gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade + gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom + 0, // mirror leds + gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade + gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out) + gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade + gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom + 0, // normal leds + gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade + + }, + .frame_functions = { + led_keyframe_fade_in_all, + keyframe_no_operation, + led_keyframe_fade_out_all, + led_keyframe_crossfade, + led_keyframe_left_to_right_gradient, + led_keyframe_crossfade, + led_keyframe_top_to_bottom_gradient, + led_keyframe_mirror_orientation, + led_keyframe_crossfade, + led_keyframe_left_to_right_gradient, + led_keyframe_crossfade, + led_keyframe_top_to_bottom_gradient, + led_keyframe_normal_orientation, + led_keyframe_crossfade, + }, +}; +#endif #endif diff --git a/keyboards/ergodox/infinity/animations.h b/keyboards/ergodox/infinity/animations.h index 0c441ff7e..6d8b9830d 100644 --- a/keyboards/ergodox/infinity/animations.h +++ b/keyboards/ergodox/infinity/animations.h @@ -19,7 +19,12 @@ #include "visualizer.h" +// You can use these default animations, but of course you can also write your own custom ones instead extern keyframe_animation_t default_startup_animation; extern keyframe_animation_t default_suspend_animation; +// An animation for testing and demonstrating the led support, should probably not be used for real world +// cases +extern keyframe_animation_t led_test_animation; + #endif /* KEYBOARDS_ERGODOX_INFINITY_ANIMATIONS_H_ */ -- cgit v1.2.3-24-g4f1b From 65b7bf68785b5b1d4257ba4fd95c3f53df230985 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 9 Apr 2017 18:32:10 +0300 Subject: Extract Ergodox default visualizer into simple_visualizer It's good enough if you only want to change the lcd text and color. --- keyboards/ergodox/infinity/simple_visualizer.h | 123 +++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 keyboards/ergodox/infinity/simple_visualizer.h (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/simple_visualizer.h b/keyboards/ergodox/infinity/simple_visualizer.h new file mode 100644 index 000000000..ded8a3222 --- /dev/null +++ b/keyboards/ergodox/infinity/simple_visualizer.h @@ -0,0 +1,123 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEYBOARDS_ERGODOX_INFINITY_SIMPLE_VISUALIZER_H_ +#define KEYBOARDS_ERGODOX_INFINITY_SIMPLE_VISUALIZER_H_ + +// Currently we are assuming that both the backlight and LCD are enabled +// But it's entirely possible to write a custom visualizer that use only +// one of them +#ifndef LCD_BACKLIGHT_ENABLE +#error This visualizer needs that LCD backlight is enabled +#endif + +#ifndef LCD_ENABLE +#error This visualizer needs that LCD is enabled +#endif + +#include "visualizer.h" +#include "visualizer_keyframes.h" +#include "lcd_keyframes.h" +#include "lcd_backlight_keyframes.h" +#include "system/serial_link.h" +#include "led.h" +#include "animations.h" + +static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); +static const uint32_t initial_color = LCD_COLOR(0, 0, 0); + +static bool initial_update = true; + +// Feel free to modify the animations below, or even add new ones if needed + +static keyframe_animation_t lcd_layer_display = { + .num_frames = 1, + .loop = false, + .frame_lengths = {gfxMillisecondsToTicks(0)}, + .frame_functions = {lcd_keyframe_display_layer_and_led_states} +}; + +// The color animation animates the LCD color when you change layers +static keyframe_animation_t color_animation = { + .num_frames = 2, + .loop = false, + // Note that there's a 200 ms no-operation frame, + // this prevents the color from changing when activating the layer + // momentarily + .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, + .frame_functions = {keyframe_no_operation, backlight_keyframe_animate_color}, +}; + +void initialize_user_visualizer(visualizer_state_t* state) { + // The brightness will be dynamically adjustable in the future + // But for now, change it here. + lcd_backlight_brightness(130); + state->current_lcd_color = initial_color; + state->target_lcd_color = logo_background_color; + initial_update = true; + start_keyframe_animation(&default_startup_animation); +} + + +// This function should be implemented by the keymap visualizer +// Don't change anything else than state->target_lcd_color and state->layer_text as that's the only thing +// that the simple_visualizer assumes that you are updating +// Also make sure that the buffer passed to state->layer_text remains valid until the previous animation is +// stopped. This can be done by either double buffering it or by using constant strings +static void get_visualizer_layer_and_color(visualizer_state_t* state); + +void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { + // Add more tests, change the colors and layer texts here + // Usually you want to check the high bits (higher layers first) + // because that's the order layers are processed for keypresses + // You can for check for example: + // state->status.layer + // state->status.default_layer + // state->status.leds (see led.h for available statuses) + + uint32_t prev_color = state->target_lcd_color; + const char* prev_layer_text = state->layer_text; + + get_visualizer_layer_and_color(state); + + if (initial_update || prev_color != state->target_lcd_color) { + start_keyframe_animation(&color_animation); + } + + if (initial_update || prev_layer_text != state->layer_text) { + start_keyframe_animation(&lcd_layer_display); + } + // You can also stop existing animations, and start your custom ones here + // remember that you should normally have only one animation for the LCD + // and one for the background. But you can also combine them if you want. +} + +void user_visualizer_suspend(visualizer_state_t* state) { + state->layer_text = "Suspending..."; + uint8_t hue = LCD_HUE(state->current_lcd_color); + uint8_t sat = LCD_SAT(state->current_lcd_color); + state->target_lcd_color = LCD_COLOR(hue, sat, 0); + start_keyframe_animation(&default_suspend_animation); +} + +void user_visualizer_resume(visualizer_state_t* state) { + state->current_lcd_color = initial_color; + state->target_lcd_color = logo_background_color; + initial_update = true; + start_keyframe_animation(&default_startup_animation); +} + +#endif /* KEYBOARDS_ERGODOX_INFINITY_SIMPLE_VISUALIZER_H_ */ -- cgit v1.2.3-24-g4f1b From 94b14bdd6ac09467686d330571ab05ff0f9bf380 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Thu, 13 Apr 2017 23:00:27 +0300 Subject: Add missing serial_link.h include Which fixes a warning when building Ergodox Infinity as a righthand master. --- keyboards/ergodox/infinity/matrix.c | 1 + 1 file changed, 1 insertion(+) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/matrix.c b/keyboards/ergodox/infinity/matrix.c index 1fda90484..3364f8c90 100644 --- a/keyboards/ergodox/infinity/matrix.c +++ b/keyboards/ergodox/infinity/matrix.c @@ -24,6 +24,7 @@ along with this program. If not, see . #include "print.h" #include "debug.h" #include "matrix.h" +#include "serial_link/system/serial_link.h" /* -- cgit v1.2.3-24-g4f1b From 430a8e17508926718759b860977cb59831720fca Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Wed, 19 Apr 2017 07:59:39 +0300 Subject: Fix LCD SS pin configuration There was a typo, so the attempted configuration proably didn't do what it should have done. I think it left the pin floating, and could cause the LCD problems issue-1230. --- keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'keyboards/ergodox/infinity') diff --git a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h index e8c17e6e3..9650ffb44 100644 --- a/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h +++ b/keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h @@ -75,7 +75,7 @@ static GFXINLINE void init_board(GDisplay *g) { palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN); palSetPadModeRaw(MOSI, ST7565_SPI_MODE); palSetPadModeRaw(SLCK, ST7565_SPI_MODE); - palSetPadModeRaw(SS, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadModeNamed(SS, PAL_MODE_OUTPUT_PUSHPULL); spiInit(); spiStart(&SPID1, &spi1config); -- cgit v1.2.3-24-g4f1b