Solution to vastly increase the speed of data transfer for ILI9488 and other displays #2770
kawasakizx10rr
started this conversation in
Alerts
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Heya, I love to mod the libraries I use for my projects and I noticed that the time it takes to draw a BMP or XBMP with my ILI9488 display was a bit slow for my liking. I am drawing a 200x200px BMP with a ESP32 and it was taking 360ms. After a bit of optimization i got it down to 136ms and then after some further optimization it down to 75ms.
Currently the tft_Write_16 which is used by practically all the functions sends three SPI transfers which is killing the performance, so i reduced the number of SPI transfers by as much as possible. Here is the code i am using, maybe you can update the lib with these optimizations in mind?
// One less transfer than tft_Write_16
void TFT_eSPI::tftWrite24(const uint16_t color) {
const uint16_t clrs = (((color) & 0xF800)>>8) << 8 | (((color) & 0x07E0)>>3) << 0;
spi.transfer16(clrs);
spi.transfer(((color) & 0x001F)<<3);
}
// Nine less transfers than tft_Write_16, for 4 pixels, (tft_Write_16 uses 3 transfers for each pixel)
void TFT_eSPI::tftWrite96(const uint16_t* colors) {
const uint32_t clrs = (((colors[0]) & 0xF800) >> 8) << 24 | (((colors[0]) & 0x07E0) >> 3) << 16 | (((colors[0]) & 0x001F) << 3) << 8 | (((colors[1]) & 0xF800) >> 8) << 0;
const uint32_t clrs2 = (((colors[1]) & 0x07E0) >> 3) << 24 | (((colors[1]) & 0x001F) << 3) << 16 | (((colors[2]) & 0xF800) >> 8) << 8 | (((colors[2]) & 0x07E0) >> 3) << 0;
const uint32_t clrs3 = (((colors[2]) & 0x001F) << 3) << 24 | (((colors[3]) & 0xF800) >> 8) << 16 | (((colors[3]) & 0x07E0) >> 3) << 8 | (((colors[3]) & 0x001F) << 3) << 0;
spi.transfer32(clrs);
spi.transfer32(clrs2);
spi.transfer32(clrs3);
}
/***************************************************************************************
** Function name: drawXBitmap
** Description: Draw an XBM image with foreground and background colors
***************************************************************************************/
void TFT_eSPI::drawXBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *bitmap, const uint16_t arraySize, uint16_t color, uint16_t bgcolor, const bool flipColors)
{
uint8_t pos = 0;
uint16_t colors[4] {0,0,0,0};
bool swap = _swapBytes;
_swapBytes = flipColors;
begin_tft_write();
inTransaction = true;
setWindow(x, y, x + w - 1, y + h - 1);
// SPI_BUSY_CHECK;
for (int32_t n = 0; n < arraySize; n++) {
const uint8_t data = pgm_read_byte_near(bitmap + n);
for (int16_t b = 7; b >= 0; b--) { // read bits in a byte left to right
if (bitRead(data, b))
colors[pos] = color;
else
colors[pos] = bgcolor;
if (pos < 3) {
pos++;
}
else {
tftWrite96(colors);
pos = 0;
}
}
}
for (uint8_t i = 0; i < pos; i++)
tftWrite24(colors[i]);
_swapBytes = swap; // Restore old value
inTransaction = lockTransaction;
end_tft_write();
}
Beta Was this translation helpful? Give feedback.
All reactions