TFT_ILI9163C test A fork of https://github.com/sumotoy/TFT_ILI9163C
Dependencies: Adafruit-GFX-Library TFT_ILI9163C mbed
Fork of IL9163C_test by
Diff: main.cpp
- Revision:
- 9:99e7307d5a59
- Parent:
- 8:4fcf5494f425
- Child:
- 11:b838083e66f0
--- a/main.cpp Wed Feb 04 10:59:10 2015 +0000 +++ b/main.cpp Mon Mar 02 11:38:58 2015 +0000 @@ -23,348 +23,396 @@ #define SPI_BITRATE 50000000L -TFT_ILI9163C display(__MOSI, __MISO, __SCLK, __CS, __DC, __RST); -//TFT_ILI9163C display(__MOSI, __MISO, __SCLK, __CS, __DC); +TFT_ILI9163C tft(__MOSI, __MISO, __SCLK, __CS, __DC, __RST); +Serial pc(SERIAL_TX, SERIAL_RX); Timer t; -const float p = 3.1415926; +uint32_t results[12]; -int32_t random(int32_t howbig) { - if (howbig == 0) { - return 0; - } - return rand() % howbig; -} - -int32_t random(int32_t howsmall, int32_t howbig) { - if (howsmall >= howbig) { - return howsmall; - } - int32_t diff = howbig - howsmall +1; - return random(diff) + howsmall; +void delay(uint32_t ms) +{ + wait_ms(ms); } -void testlines(uint16_t color) { - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(0, 0, x, display.height()-1, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(0, 0, display.width()-1, y, color); - } - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(display.width()-1, 0, x, display.height()-1, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(display.width()-1, 0, 0, y, color); - } +uint32_t micros() +{ + return t.read_us(); +} - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(0, display.height()-1, x, 0, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(0, display.height()-1, display.width()-1, y, color); - } - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(display.width()-1, display.height()-1, x, 0, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(display.width()-1, display.height()-1, 0, y, color); - } - wait_ms(500); +int min(int a, int b) +{ + return a < b ? a : b; } -void testdrawtext(char *text, uint16_t color) { - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); +unsigned long testFillScreen() +{ + unsigned long start = micros(); + tft.fillScreen(); + tft.fillScreen(RED); + tft.fillScreen(GREEN); + tft.fillScreen(BLUE); + tft.fillScreen(); + return micros() - start; +} - for (uint8_t i=0; i < 168; i++) { - if (i == '\n') continue; - display.writeChar(i); - if ((i > 0) && (i % 21 == 0)) - display.printf("\n"); - } +unsigned long testText() +{ + tft.fillScreen(); + unsigned long start = micros(); + tft.setCursor(0, 0); + tft.setTextColor(WHITE); + tft.setTextSize(1); + tft.printf("Hello World!\n"); + tft.setTextColor(YELLOW); + tft.setTextSize(2); + tft.printf("%.2f\n", 1234.56); + tft.setTextColor(RED); + tft.setTextSize(3); + tft.printf("%x", 0xABCD); + tft.printf("\n"); + tft.setTextColor(GREEN); + tft.setTextSize(4); + tft.printf("Hello\n"); + tft.setTextSize(2); + tft.printf("I implore thee,\n"); + tft.setTextSize(1); + tft.printf("my foonting turlingdromes.\n"); + tft.printf("And hooptiously drangle me\n"); + tft.printf("with crinkly bindlewurdles,\n"); + tft.printf("Or I will rend thee\n"); + tft.printf("in the gobberwarts\n"); + tft.printf("with my blurglecruncheon,\n"); + tft.printf("see if I don't!\n"); + return micros() - start; } -void testfastlines(uint16_t color1, uint16_t color2) { - display.clearScreen(); - for (int16_t y=0; y < display.height()-1; y+=5) { - display.drawFastHLine(0, y, display.width()-1, color1); - } - for (int16_t x=0; x < display.width()-1; x+=5) { - display.drawFastVLine(x, 0, display.height()-1, color2); - } +unsigned long testLines(uint16_t color) +{ + unsigned long start, t; + int x1, y1, x2, y2, + w = tft.width(), + h = tft.height(); + + tft.fillScreen(); + + x1 = y1 = 0; + y2 = h - 1; + start = micros(); + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); + x2 = w - 1; + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); + t = micros() - start; // fillScreen doesn't count against timing + + tft.fillScreen(); + + x1 = w - 1; + y1 = 0; + y2 = h - 1; + start = micros(); + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); + x2 = 0; + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); + t += micros() - start; + + tft.fillScreen(); + + x1 = 0; + y1 = h - 1; + y2 = 0; + start = micros(); + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); + x2 = w - 1; + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); + t += micros() - start; + + tft.fillScreen(); + + x1 = w - 1; + y1 = h - 1; + y2 = 0; + start = micros(); + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); + x2 = 0; + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); + + return micros() - start; } -void testdrawrects(uint16_t color) { - display.clearScreen(); - for (int16_t x=0; x < display.height()-1; x+=6) { - display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color); +unsigned long testFastLines(uint16_t color1, uint16_t color2) +{ + unsigned long start; + int x, y, w = tft.width(), h = tft.height(); + + tft.fillScreen(); + start = micros(); + for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1); + for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2); + + return micros() - start; +} + +unsigned long testRects(uint16_t color) +{ + unsigned long start; + int n, i, i2, + cx = tft.width() / 2, + cy = tft.height() / 2; + + tft.fillScreen(); + n = min(tft.width(), tft.height()); + start = micros(); + for(i=2; i<n; i+=6) { + i2 = i / 2; + tft.drawRect(cx-i2, cy-i2, i, i, color); } + + return micros() - start; } -void testfillrects(uint16_t color1, uint16_t color2) { - display.clearScreen(); - for (int16_t x=display.height()-1; x > 6; x-=6) { - display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1); - display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2); +unsigned long testFilledRects(uint16_t color1, uint16_t color2) +{ + unsigned long start, t = 0; + int n, i, i2, + cx = (tft.width() / 2) - 1, + cy = (tft.height() / 2) - 1; + + tft.fillScreen(); + n = min(tft.width(), tft.height()); + for(i=n; i>0; i-=6) { + i2 = i / 2; + start = micros(); + tft.fillRect(cx-i2, cy-i2, i, i, color1); + t += micros() - start; + // Outlines are not included in timing results + tft.drawRect(cx-i2, cy-i2, i, i, color2); } + + return t; } -void testfillcircles(uint8_t radius, uint16_t color) { - for (uint8_t x=radius; x < display.width()-1; x+=radius*2) { - for (uint8_t y=radius; y < display.height()-1; y+=radius*2) { - display.fillCircle(x, y, radius, color); +unsigned long testFilledCircles(uint8_t radius, uint16_t color) +{ + unsigned long start; + int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; + + tft.fillScreen(); + start = micros(); + for(x=radius; x<w; x+=r2) { + for(y=radius; y<h; y+=r2) { + tft.fillCircle(x, y, radius, color); } } + + return micros() - start; +} + +unsigned long testCircles(uint8_t radius, uint16_t color) +{ + unsigned long start; + int x, y, r2 = radius * 2, + w = tft.width() + radius, + h = tft.height() + radius; + + // Screen is not cleared for this one -- this is + // intentional and does not affect the reported time. + start = micros(); + for(x=0; x<w; x+=r2) { + for(y=0; y<h; y+=r2) { + tft.drawCircle(x, y, radius, color); + } + } + + return micros() - start; } -void testdrawcircles(uint8_t radius, uint16_t color) { - for (int16_t x=0; x < (display.width()-1)+radius; x+=radius*2) { - for (int16_t y=0; y < (display.height())-1+radius; y+=radius*2) { - display.drawCircle(x, y, radius, color); - } +unsigned long testTriangles() +{ + unsigned long start; + int n, i, cx = tft.width() / 2 - 1, + cy = (tft.height() / 2) - 1; + + tft.fillScreen(); + n = min(cx, cy); + start = micros(); + for(i=0; i<n; i+=5) { + tft.drawTriangle( + cx , cy - i, // peak + cx - i, cy + i, // bottom left + cx + i, cy + i, // bottom right + tft.Color565(0, 0, i)); } + + return micros() - start; +} + +unsigned long testFilledTriangles() +{ + unsigned long start, t = 0; + int i, cx = (tft.width() / 2) - 1, + cy = tft.height() / 2 - 1; + + tft.fillScreen(); + start = micros(); + for(i=min(cx,cy); i>10; i-=5) { + start = micros(); + tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, + tft.Color565(0, i, i)); + t += micros() - start; + tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, + tft.Color565(i, i, 0)); + } + + return t; +} + +unsigned long testRoundRects() +{ + unsigned long start; + int w, i, i2, + cx = (tft.width() / 2) - 1, + cy = (tft.height() / 2) - 1; + + tft.fillScreen(); + w = min(tft.width(), tft.height()); + start = micros(); + for(i=0; i<w; i+=6) { + i2 = i / 2; + tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.Color565(i, 0, 0)); + } + + return micros() - start; } -void testtriangles() { - display.clearScreen(); - int color = 0xF800; - int t; - int w = display.width()/2; - int x = display.height(); - int y = 0; - int z = display.width(); - for(t = 0 ; t <= 15; t+=1) { - display.drawTriangle(w, y, y, x, z, x, color); - x-=4; - y+=4; - z-=4; - color+=100; +unsigned long testFilledRoundRects() +{ + unsigned long start; + int i, i2, + cx = (tft.width() / 2) - 1, + cy = (tft.height() / 2) - 1; + + tft.fillScreen(); + start = micros(); + for(i=min(tft.width(), tft.height()); i>20; i-=6) { + i2 = i / 2; + tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.Color565(0, i, 0)); } + + return micros() - start; } -void testroundrects() { - display.clearScreen(); - int color = 100; - int i; - int t; - for(t = 0 ; t <= 4; t+=1) { - int x = 0; - int y = 0; - int w = display.width(); - int h = display.height(); - for(i = 0 ; i <= 24; i+=1) { - display.drawRoundRect(x, y, w, h, 5, color); - x+=2; - y+=3; - w-=4; - h-=6; - color+=1100; + +void doBenchmark(void) +{ + uint8_t testNumber = 0; + pc.printf("Benchmark Time (microseconds)\n"); + results[testNumber] = testFillScreen(); + pc.printf("Screen fill %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testText(); + pc.printf("Text %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testLines(CYAN); + pc.printf("Lines %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testFastLines(RED, BLUE); + pc.printf("Horiz/Vert Lines %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testRects(GREEN); + pc.printf("Rectangles (outline) %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testFilledRects(YELLOW,MAGENTA); + pc.printf("Rectangles (filled) %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testFilledCircles(10,MAGENTA); + pc.printf("Circles (filled) %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testCircles(10,WHITE); + pc.printf("Circles (outline) %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testTriangles(); + pc.printf("Triangles (outline) %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testFilledTriangles(); + pc.printf("Triangles (filled) %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testRoundRects(); + pc.printf("Rounded rects (outline) %d\n", results[testNumber++]); + delay(500); + + results[testNumber] = testFilledRoundRects(); + pc.printf("Rounded rects (filled) %d\n", results[testNumber++]); + delay(500); + + pc.printf("Done!\n"); +} + +void dispResults() { + + tft.fillScreen(); + tft.setCursor(0, 0); + tft.setTextColor(WHITE); + tft.setTextSize(1); + + uint8_t testNumber = 0; + tft.printf("Benchmark msec\n"); + tft.printf("Screen fill %d\n", results[testNumber++]); + tft.printf("Text %d\n", results[testNumber++]); + tft.printf("Lines %d\n", results[testNumber++]); + tft.printf("H/V Lines %d\n", results[testNumber++]); + tft.printf("Rect(outline) %d\n", results[testNumber++]); + tft.printf("Rect(filled) %d\n", results[testNumber++]); + tft.printf("Circ(filled) %d\n", results[testNumber++]); + tft.printf("Circ(outline) %d\n", results[testNumber++]); + tft.printf("Tria(outline) %d\n", results[testNumber++]); + tft.printf("Tria(filled) %d\n", results[testNumber++]); + tft.printf("Round(outline) %d\n", results[testNumber++]); + tft.printf("Round(filled) %d\n", results[testNumber++]); + +} + +void loop(void) +{ + for(uint8_t rotation=0; rotation<4; rotation++) { + tft.setRotation(rotation); + dispResults(); + for (int16_t i = 0; i <= _TFTHEIGHT; ++i) { + tft.scroll(i); + delay(5); } - color+=100; + delay(500); + + for (int16_t i = _TFTHEIGHT; i >= 0; --i) { + tft.scroll(i); + delay(5); + } + delay(1000); } } -void tftPrintTest() { - display.clearScreen(); - display.setCursor(0, 5); - display.setTextColor(RED); - display.setTextSize(1); - display.printf("Hello World!\n"); - display.setTextColor(YELLOW, GREEN); - display.setTextSize(2); - display.printf("Hello Wo"); - display.setTextColor(BLUE); - display.setTextSize(3); - display.printf("%.2f", 12.57); - wait_ms(1500); - display.setCursor(0, 5); - display.clearScreen(); - display.setTextColor(WHITE); - display.setTextSize(0); - display.printf("Hello World!\n"); - display.setTextSize(1); - display.setTextColor(GREEN); - display.printf("%5f", p); - display.printf(" Want pi?\n"); - display.printf("%x", 8675309); - display.printf(" Print HEX\n"); - display.setTextColor(WHITE); - display.printf("Sketch has been\n"); - display.printf("running for: \n"); - display.setTextColor(MAGENTA); - display.printf("%d", t.read_ms() / 1000); - display.setTextColor(WHITE); - display.printf(" sec."); -} - - -void randomRect(bool fill) { - display.clearScreen(); - uint8_t k,c; - for (k = 0; k < 16; k++) { - for (c = 0; c < 32; c++) { - uint8_t cx, cy, x, y, w, h; - // center - cx = random(0,display.width()); - cy = random(0,display.height()); - // size - w = random(0,30 + 6); - h = random(0,20 + 4); - // upper-left - x = cx - w / 2; - y = cy - h / 2; -// if (x < 0) x = 0; -// if (y < 0) y = 0; - // adjust size - if (x + w > display.width()) w = display.width() - x; - if (y + h > display.height()) h = display.height() - y; - if (fill) { - display.fillRect(x, y, w, h,random(0x0010,0xFFFF)); - } else { - display.drawRect(x, y, w, h,random(0x0010,0xFFFF)); - } - - } - display.clearScreen(); - } -} - -void randomCircles(bool fill) { - display.clearScreen(); - uint8_t k,c; - for (k = 0; k < display.height(); k++) { - for (c = 0; c < display.height()/2; c++) { - // coordinates - uint8_t x = random(0,120 + 3), y = random(0,90 + 2), r = random(0,40 + 1); - if (x - r < 0) r = x; - if (x + r > (display.width()-1)) r = (display.width() - 1) - x; - if (y - r < 0) r = y; - if (y + r > (display.height()-1)) r = (display.height() - 1) - y; - if (fill) { - display.fillCircle(x, y, r,random(0x0010,0xFFFF)); - } else { - display.drawCircle(x, y, r,random(0x0010,0xFFFF)); - } - } - if (!fill)display.clearScreen(); - } -} - - -void randomLines() { - display.clearScreen(); - uint8_t k,c; - for (k = 0; k < display.height(); k++) { - for (c = 0; c < display.height()/2; c++) { - uint8_t x1 = random(0,display.width()), y1 = random(0,display.height()), x2 = random(0,display.width()), y2 = random(0,display.height()); - display.drawLine(x1, y1, x2, y2,random(0x0010,0xFFFF)); - } - display.clearScreen(); - } -} - - -void randomPoints() { - display.clearScreen(); - for (uint8_t k = 0; k < 128; k++) { - for (uint16_t c = 0; c < 1000; c++) { - uint8_t x = random(0,display.width()), y = random(0,display.height()); - display.drawPixel(x, y, random(0x0010,0xFFFF)); - } - display.clearScreen(); - } -} - -void loop() { - - testlines(random(0x0010,0xFFFF)); - randomLines(); - //randomCircles(1); - randomCircles(0); - randomRect(1); - randomRect(1); - randomRect(1); - randomRect(1); - randomRect(1); - randomRect(0); - randomRect(0); - randomRect(0); - randomRect(0); - randomRect(0); - randomRect(0); - randomPoints(); -} - -void setup(void) { - +int main() +{ t.start(); - - display.begin(); - display.setBitrate(SPI_BITRATE); - display.setRotation(2); - -// lcdTestPattern(); -// delay(1000); - - display.clearScreen(); - display.setCursor(0,0); - display.printf("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa"); - wait_ms(1000); - - tftPrintTest(); - wait_ms(2000); - - //a single pixel - display.drawPixel(display.width()/2, display.height()/2, GREEN); - wait_ms(500); - - // line draw test - testlines(YELLOW); - wait_ms(500); - - // optimized lines - testfastlines(RED, BLUE); - wait_ms(500); - - testdrawrects(GREEN); - wait_ms(1000); - - testfillrects(BLUE, YELLOW); - wait_ms(1000); - - randomRect(0); - wait_ms(100); - randomCircles(0); - wait_ms(100); - randomLines(); - wait_ms(100); - randomPoints(); - wait_ms(500); - - display.clearScreen(); - testfillcircles(10, BLUE); - testdrawcircles(10, WHITE); - wait_ms(1000); - - testroundrects(); - wait_ms(500); - - testtriangles(); - wait_ms(500); -} - -int main() { - - setup(); - + + tft.begin(); + tft.setBitrate(50000000); + tft.setRotation(0); +// tft.setRotation(2); + + doBenchmark(); + delay(1000); + while (true) { loop(); }