Code:
#include <SPI.h>
#include <ILI9341_t3.h>
#define TFT_RS 8
#define TFT_DC 9
#define TFT_CS 10
ILI9341_t3 ili9341 = ILI9341_t3(TFT_CS, TFT_DC, TFT_RS);
void setup() {
delay(2000);
Serial.begin(38400);
// Initialize ILI9341 Display
ili9341.begin();
ili9341.fillScreen(ILI9341_GREEN);
ili9341.fillCircle(50,50,50,ILI9341_RED);
ili9341.fillCircle(50,50,40,ILI9341_BLUE);
ili9341.setCursor(20,20);
ili9341.println("Test Test Test");
// How about some text scrolling.
ili9341.fillRect(0, 205, 110, 110, ILI9341_BLACK);
}
void loop() {
uint16_t x;
uint16_t y;
uint16_t z;
uint16_t col;
#define MAX_ROWS_PER_PASS 8
uint16_t awColors[200*MAX_ROWS_PER_PASS];
uint32_t ulStart, ulDelta;
#if 0
// First lets try speed of read/write one pixel at a time
Serial.print("Time for one pixel at a time: ");
ulStart = millis();
for(z=0; z<200; z++){
for(y=0; y<200; y++) {
for(x=0; x<120; x++) {
col = ili9341.readPixel(x,y);
ili9341.drawPixel(x+120,y+z,col);
}
}
}
Serial.println(ulDelta = millis()-ulStart, DEC);
ScrollTextArea();
ili9341.printf("S %d", ulDelta);
#endif
// Now lets try reading and writing n whole rows at a time;
for (int iRowsPerPass = 1; iRowsPerPass <= MAX_ROWS_PER_PASS; iRowsPerPass++) {
// only for those who divide into 200
int cLoops = 200 / iRowsPerPass;
if ((cLoops * iRowsPerPass) != 200) continue;
Serial.print("Read ");
Serial.print(iRowsPerPass, DEC);
Serial.print(" Rows per Pass push: ");
ulStart = millis();
for(z=0; z<200; z++){
for(y=0; y<200; y+=iRowsPerPass) {
ili9341.readRect(0, y, 120, iRowsPerPass, awColors); // try to read one row at a time...
ili9341.setAddrWindow(120, y+z, 239, y+z+iRowsPerPass-1);
for(x=0; x<120*iRowsPerPass; x++) {
ili9341.pushColor(awColors[x]);
}
}
}
Serial.println(ulDelta = millis()-ulStart, DEC);
ScrollTextArea();
ili9341.printf("%dP %d", iRowsPerPass, ulDelta);
Serial.print("Read ");
Serial.print(iRowsPerPass, DEC);
Serial.print(" Rows per Pass writerect: ");
ulStart = millis();
for(z=0; z<200; z++){
for(y=0; y<200; y+=iRowsPerPass) {
ili9341.readRect(0, y, 120, iRowsPerPass, awColors); // try to read one row at a time...
ili9341.writeRect(120, y+z, 120, iRowsPerPass, awColors); // try to read one row at a time...
}
}
Serial.println(ulDelta = millis()-ulStart, DEC);
ScrollTextArea();
ili9341.printf("%dW %d", iRowsPerPass, ulDelta);
if (iRowsPerPass > 1) {
Serial.print("Read ");
Serial.print(iRowsPerPass, DEC);
Serial.print(" Rows per Pass writerect: ");
ulStart = millis();
for(z=0; z<200; z++){
for(y=0; y<200; y+=iRowsPerPass) {
ili9341.readRect(0, y, 120, iRowsPerPass, awColors); // try to read one row at a time...
for (uint16_t iRow=0; iRow < iRowsPerPass; iRow++) {
ili9341.writeRect(120, y+iRow+z, 120, 1, &awColors[iRow*120]); // try to read one row at a time...
}
}
}
Serial.println(ulDelta = millis()-ulStart, DEC);
ScrollTextArea();
ili9341.printf("%dC %d", iRowsPerPass, ulDelta);
}
}
}
void ScrollTextArea() {
// Assume we are in the area (0, 205) - (110-314)
uint16_t awColors[110];
for (int y=205+16; y < 315; y++) {
ili9341.readRect(0, y, 110, 1, awColors); // try to read one row at a time...
ili9341.writeRect(0, y-16, 110, 1, awColors); // try to read one row at a time...
}
ili9341.setTextSize(2);
ili9341.fillRect(0, 316-16, 110, 16, ILI9341_BLACK);
ili9341.setCursor(0,316-16);
}
FYI - I also tested this on the Adafruit 2.2" TFT display (