I have this TFT: https://www.waveshare.com/wiki/4inch_TFT_Touch_Shield
It is a shield for the Arduino UNO. I have the sample code successfully working as well.
I was experiencing some remarkable slowness when trying to draw bitmaps, and just generally the display is rather slow. I know I should expect this when trying to use larger displays, but I still can't help but feel like there's some optimization I could make here.
For benchmarking purposes, I made a small loop that draws a 32x32 bitmap in a 4x4 grid and prints the time it takes.
void loop()
{
LCD_SetArealColor(0, 0, 128, 128, WHITE);
unsigned long start_time = millis();
for( uint8_t ii = 0; ii < 4; ii++ )
for ( uint8_t jj = 0; jj < 4; jj++ ) {
GUI_DisColorMap( ii*32, jj*32, testData, 32, 32 );
}
unsigned long end_time = millis();
char str[8];
sprintf( str, "%d\0", end_time - start_time );
LCD_SetArealColor( 40, 120, 140, 150, WHITE );
GUI_DisString_EN(40, 120, str, &Font24, LCD_BACKGROUND, BLUE);
}
This 128x128 draw takes a whopping 4.2 seconds to complete. And this is where I suspect something must be very unoptimized or flat-out wrong. But whatever I tried, I couldn't get my performance to change noticeably. So if anyone can offer advice about what in my setup or library could be so slow, that would be useful!
More details:
Clock: 16MHz
SPI Clock: SPI_CLOCK_DIV2 (library's default. Is there a way to use /1 instead?)
As for optimizations, I tried:
- Changing my compiler settings to -O3 from -Os
- inlining the frequently called functions
- partially unrolling the draw bitmap function
- fixing an apparent bug in LCD_WriteData which writes two bytes out when it should only write one
None of those changes seemed to provide any large-scale improvements, perhaps shaving off 10% at the most. I made some of those improvements before I was using the benchmark, so I don't have real figures for those though, just subjective measures. Anyway, I figure the real culprit is something else. Any thoughts?