TFT_ILI9163C test A fork of https://github.com/sumotoy/TFT_ILI9163C

Dependencies:   Adafruit-GFX-Library TFT_ILI9163C mbed

Fork of IL9163C_test by _ peu605

main.cpp

Committer:
peu605
Date:
2015-03-02
Revision:
9:99e7307d5a59
Parent:
8:4fcf5494f425
Child:
11:b838083e66f0

File content as of revision 9:99e7307d5a59:

#include "mbed.h"

#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>

#define __MOSI D11
#define __MISO NC
#define __SCLK D13
#define __CS D10
#define __DC D9
#define __RST D8

// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF
#define TRANSPARENT     -1

#define SPI_BITRATE     50000000L

TFT_ILI9163C tft(__MOSI, __MISO, __SCLK, __CS, __DC, __RST);

Serial pc(SERIAL_TX, SERIAL_RX);
Timer t;

uint32_t results[12];

void delay(uint32_t ms)
{
    wait_ms(ms);
}

uint32_t micros()
{
    return t.read_us();
}

int min(int a, int b)
{
    return a < b ? a : b;
}


unsigned long testFillScreen()
{
    unsigned long start = micros();
    tft.fillScreen();
    tft.fillScreen(RED);
    tft.fillScreen(GREEN);
    tft.fillScreen(BLUE);
    tft.fillScreen();
    return micros() - start;
}

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;
}

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;
}

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;
}

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;
}

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;
}

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;
}

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 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);
        }
        delay(500);
        
        for (int16_t i = _TFTHEIGHT; i >= 0; --i) {
            tft.scroll(i);
            delay(5);
        }
        delay(1000);
    }
}

int main()
{
    t.start();
    
    tft.begin();
    tft.setBitrate(50000000);
    tft.setRotation(0);
//    tft.setRotation(2);
    
    doBenchmark();
    delay(1000);
    
    while (true) {
        loop();
    }
}