Commit ac8845d5 authored by Bodmer's avatar Bodmer

Fix #566 plus others

Fix image rendering issue.
Deprecate use of pushColors.
Improve ES8266 image rendering performance for ESP8266 and ILI9488.
Add getTextPadding().
parent 65ccbf01
......@@ -412,24 +412,26 @@ 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
** Function name: pushPixels - for ESP32 and 3 byte RGB display
** Description: Write a sequence of pixels
***************************************************************************************/
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;
while ( len-- ) {tft_Write_16(*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: pushPixels - for ESP32 and 3 byte RGB display
** Description: Write a sequence of pixels
** Function name: pushSwapBytePixels - for ESP32 and 3 byte RGB display
** Description: Write a sequence of pixels with swapped bytes
***************************************************************************************/
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;
if(_swapBytes) { while ( len-- ) {tft_Write_16(*data); data++;} }
else { 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++;}
}
////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -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++;}
}
////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -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
......
......@@ -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
......
{
"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":
......
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment