From ac8845d5894d09bc6a50d2428eeda6e73fda0b67 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Sat, 7 Mar 2020 16:26:44 +0000 Subject: [PATCH] Fix #566 plus others Fix image rendering issue. Deprecate use of pushColors. Improve ES8266 image rendering performance for ESP8266 and ILI9488. Add getTextPadding(). --- Processors/TFT_eSPI_ESP32.c | 26 ++++++++++--------- Processors/TFT_eSPI_ESP8266.c | 48 +++++++++++++++++++++++++++++++++-- TFT_eSPI.cpp | 24 ++++++++++++------ TFT_eSPI.h | 3 ++- library.json | 2 +- library.properties | 2 +- 6 files changed, 80 insertions(+), 25 deletions(-) diff --git a/Processors/TFT_eSPI_ESP32.c b/Processors/TFT_eSPI_ESP32.c index 595e5fb..8e0fdc7 100644 --- a/Processors/TFT_eSPI_ESP32.c +++ b/Processors/TFT_eSPI_ESP32.c @@ -411,16 +411,6 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) } } -/*************************************************************************************** -** Function name: pushSwapBytePixels - for ESP32 and 3 byte RGB display -** Description: Write a sequence of pixels with swapped bytes -***************************************************************************************/ -void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ - - uint16_t *data = (uint16_t*)data_in; - while ( len-- ) {tft_Write_16(*data); data++;} -} - /*************************************************************************************** ** Function name: pushPixels - for ESP32 and 3 byte RGB display ** Description: Write a sequence of pixels @@ -428,8 +418,20 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ uint16_t *data = (uint16_t*)data_in; - if(_swapBytes) { while ( len-- ) {tft_Write_16(*data); data++;} } - else { while ( len-- ) {tft_Write_16S(*data); data++;} } + // ILI9488 write macro is not endianess dependant, hence !_swapBytes + if(!_swapBytes) { while ( len-- ) {tft_Write_16S(*data); data++;} } + else { while ( len-- ) {tft_Write_16(*data); data++;} } +} + +/*************************************************************************************** +** Function name: pushSwapBytePixels - for ESP32 and 3 byte RGB display +** Description: Write a sequence of pixels with swapped bytes +***************************************************************************************/ +void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ + + uint16_t *data = (uint16_t*)data_in; + // ILI9488 write macro is not endianess dependant, so swap byte macro not used here + while ( len-- ) {tft_Write_16(*data); data++;} } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/Processors/TFT_eSPI_ESP8266.c b/Processors/TFT_eSPI_ESP8266.c index 9dd834f..7a7287c 100644 --- a/Processors/TFT_eSPI_ESP8266.c +++ b/Processors/TFT_eSPI_ESP8266.c @@ -183,7 +183,50 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ uint16_t *data = (uint16_t*)data_in; - if (_swapBytes) while ( len-- ) { tft_Write_16S(*data); data++;} + + // Send groups of 4 concatenated pixels + if (len > 3) { + SPI1U1 = ((4 * 24 - 1) << SPILMOSI); + while (len > 3) { + + uint8_t r[4]; + uint8_t g[4]; + uint8_t b[4]; + + if (!_swapBytes) { + // Split out the colours + for (uint16_t i = 0; i < 4; i++) { + uint16_t col = *data++; + r[i] = (col & 0xF8); + g[i] = (col & 0xE000)>>11 | (col & 0x07)<<5; + b[i] = (col & 0x1F00)>>5; + } + } + else { + for (uint16_t i = 0; i < 4; i++) { + uint16_t col = *data++; + r[i] = (col & 0xF800)>>8; + g[i] = (col & 0x07E0)>>3; + b[i] = (col & 0x001F)<<3; + } + } + uint32_t r0 = r[1]<<24 | b[0]<<16 | g[0]<<8 | r[0]; + uint32_t r1 = g[2]<<24 | r[2]<<16 | b[1]<<8 | g[1]; + uint32_t r2 = b[3]<<24 | g[3]<<16 | r[3]<<8 | b[2]; + + while(SPI1CMD & SPIBUSY) {} + SPI1W0 = r0; + SPI1W1 = r1; + SPI1W2 = r2; + + SPI1CMD |= SPIBUSY; + len -= 4; + } + while(SPI1CMD & SPIBUSY) {} + } + + // ILI9488 write macro is not endianess dependant, hence !_swapBytes + if (!_swapBytes) while ( len-- ) { tft_Write_16S(*data); data++;} else while ( len-- ) {tft_Write_16(*data); data++;} } @@ -194,7 +237,8 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ uint16_t *data = (uint16_t*)data_in; - while ( len-- ) {tft_Write_16S(*data); data++;} + // ILI9488 write macro is not endianess dependant, so swap byte macro not used here + while ( len-- ) {tft_Write_16(*data); data++;} } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index cd44a46..f4b65f8 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -899,12 +899,12 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d data += dx + dy * w; // Check if whole image can be pushed - if (dw == w) pushColors(data, dw * dh, _swapBytes); + if (dw == w) pushPixels(data, dw * dh); else { // Push line segments to crop image while (dh--) { - pushColors(data, dw, _swapBytes); + pushPixels(data, dw); data += w; } } @@ -967,14 +967,14 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d move = true; if (np) { - pushColors((uint16_t*)lineBuf, np, _swapBytes); + pushPixels((uint16_t*)lineBuf, np); np = 0; } } px++; ptr++; } - if (np) pushColors((uint16_t*)lineBuf, np, _swapBytes); + if (np) pushPixels((uint16_t*)lineBuf, np); y++; data += w; @@ -1026,7 +1026,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1 for (int32_t j = 0; j < PI_BUF_SIZE; j++) { pix_buffer[j] = pgm_read_word(&data[i * PI_BUF_SIZE + j]); } - pushColors(pix_buffer, PI_BUF_SIZE, _swapBytes); + pushPixels(pix_buffer, PI_BUF_SIZE); } // Work out number of pixels not yet sent @@ -1038,7 +1038,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1 { pix_buffer[i] = pgm_read_word(&data[nb * PI_BUF_SIZE + i]); } - pushColors(pix_buffer, np, _swapBytes); + pushPixels(pix_buffer, np); } inTransaction = false; @@ -1097,14 +1097,14 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1 else { move = true; if (np) { - pushColors(lineBuf, np, _swapBytes); + pushPixels(lineBuf, np); np = 0; } } px++; ptr++; } - if (np) pushColors(lineBuf, np, _swapBytes); + if (np) pushPixels(lineBuf, np); y++; data += w; @@ -2275,6 +2275,14 @@ void TFT_eSPI::setTextPadding(uint16_t x_width) padX = x_width; } +/*************************************************************************************** +** Function name: setTextPadding +** Description: Define padding width (aids erasing old text and numbers) +***************************************************************************************/ +uint16_t TFT_eSPI::getTextPadding(void) +{ + return padX; +} /*************************************************************************************** ** Function name: getRotation diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 3d54ddc..17de206 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -16,7 +16,7 @@ #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "2.1.5" +#define TFT_ESPI_VERSION "2.1.6" /*************************************************************************************** ** Section 1: Load required header files @@ -510,6 +510,7 @@ class TFT_eSPI : public Print { uint8_t getTextDatum(void); void setTextPadding(uint16_t x_width); // Set text padding (background blanking/over-write) width in pixels + uint16_t getTextPadding(void); // Get text padding #ifdef LOAD_GFXFF void setFreeFont(const GFXfont *f = NULL), // Select the GFX Free Font diff --git a/library.json b/library.json index a866c9e..8fe3418 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.1.5", + "version": "2.1.6", "keywords": "Arduino, tft, ePaper, display, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140", "description": "A TFT and ePaper SPI graphics library with optimisation for ESP8266, ESP32 and STM32", "repository": diff --git a/library.properties b/library.properties index 4bbe860..b1b2ff7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.1.5 +version=2.1.6 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32