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/drivers/gdisp') 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/drivers/gdisp') 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 ++++----- 2 files changed, 32 insertions(+), 5 deletions(-) (limited to 'keyboards/ergodox/infinity/drivers/gdisp') 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 */ -- 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/drivers/gdisp') 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 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/drivers/gdisp') 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/drivers/gdisp') 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 + 1 file changed, 1 insertion(+) (limited to 'keyboards/ergodox/infinity/drivers/gdisp') 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 -- 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 --- .../ergodox/infinity/drivers/gdisp/st7565ergodox/gdisp_lld_ST7565.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'keyboards/ergodox/infinity/drivers/gdisp') 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; -- 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/drivers/gdisp') 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