TFT_ILI9163C test A fork of https://github.com/sumotoy/TFT_ILI9163C
Dependencies: Adafruit-GFX-Library TFT_ILI9163C mbed
Fork of IL9163C_test by
main.cpp@9:99e7307d5a59, 2015-03-02 (annotated)
- Committer:
- peu605
- Date:
- Mon Mar 02 11:38:58 2015 +0000
- Revision:
- 9:99e7307d5a59
- Parent:
- 8:4fcf5494f425
- Child:
- 11:b838083e66f0
scroll test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peu605 | 0:26cf1056924c | 1 | #include "mbed.h" |
peu605 | 0:26cf1056924c | 2 | |
peu605 | 0:26cf1056924c | 3 | #include <Adafruit_GFX.h> |
peu605 | 0:26cf1056924c | 4 | #include <TFT_ILI9163C.h> |
peu605 | 0:26cf1056924c | 5 | |
peu605 | 0:26cf1056924c | 6 | #define __MOSI D11 |
peu605 | 0:26cf1056924c | 7 | #define __MISO NC |
peu605 | 0:26cf1056924c | 8 | #define __SCLK D13 |
peu605 | 0:26cf1056924c | 9 | #define __CS D10 |
peu605 | 0:26cf1056924c | 10 | #define __DC D9 |
peu605 | 0:26cf1056924c | 11 | #define __RST D8 |
peu605 | 0:26cf1056924c | 12 | |
peu605 | 0:26cf1056924c | 13 | // Color definitions |
peu605 | 0:26cf1056924c | 14 | #define BLACK 0x0000 |
peu605 | 0:26cf1056924c | 15 | #define BLUE 0x001F |
peu605 | 0:26cf1056924c | 16 | #define RED 0xF800 |
peu605 | 0:26cf1056924c | 17 | #define GREEN 0x07E0 |
peu605 | 0:26cf1056924c | 18 | #define CYAN 0x07FF |
peu605 | 0:26cf1056924c | 19 | #define MAGENTA 0xF81F |
peu605 | 8:4fcf5494f425 | 20 | #define YELLOW 0xFFE0 |
peu605 | 0:26cf1056924c | 21 | #define WHITE 0xFFFF |
peu605 | 0:26cf1056924c | 22 | #define TRANSPARENT -1 |
peu605 | 0:26cf1056924c | 23 | |
peu605 | 8:4fcf5494f425 | 24 | #define SPI_BITRATE 50000000L |
peu605 | 8:4fcf5494f425 | 25 | |
peu605 | 9:99e7307d5a59 | 26 | TFT_ILI9163C tft(__MOSI, __MISO, __SCLK, __CS, __DC, __RST); |
peu605 | 0:26cf1056924c | 27 | |
peu605 | 9:99e7307d5a59 | 28 | Serial pc(SERIAL_TX, SERIAL_RX); |
peu605 | 0:26cf1056924c | 29 | Timer t; |
peu605 | 0:26cf1056924c | 30 | |
peu605 | 9:99e7307d5a59 | 31 | uint32_t results[12]; |
peu605 | 0:26cf1056924c | 32 | |
peu605 | 9:99e7307d5a59 | 33 | void delay(uint32_t ms) |
peu605 | 9:99e7307d5a59 | 34 | { |
peu605 | 9:99e7307d5a59 | 35 | wait_ms(ms); |
peu605 | 0:26cf1056924c | 36 | } |
peu605 | 0:26cf1056924c | 37 | |
peu605 | 9:99e7307d5a59 | 38 | uint32_t micros() |
peu605 | 9:99e7307d5a59 | 39 | { |
peu605 | 9:99e7307d5a59 | 40 | return t.read_us(); |
peu605 | 9:99e7307d5a59 | 41 | } |
peu605 | 0:26cf1056924c | 42 | |
peu605 | 9:99e7307d5a59 | 43 | int min(int a, int b) |
peu605 | 9:99e7307d5a59 | 44 | { |
peu605 | 9:99e7307d5a59 | 45 | return a < b ? a : b; |
peu605 | 0:26cf1056924c | 46 | } |
peu605 | 0:26cf1056924c | 47 | |
peu605 | 0:26cf1056924c | 48 | |
peu605 | 9:99e7307d5a59 | 49 | unsigned long testFillScreen() |
peu605 | 9:99e7307d5a59 | 50 | { |
peu605 | 9:99e7307d5a59 | 51 | unsigned long start = micros(); |
peu605 | 9:99e7307d5a59 | 52 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 53 | tft.fillScreen(RED); |
peu605 | 9:99e7307d5a59 | 54 | tft.fillScreen(GREEN); |
peu605 | 9:99e7307d5a59 | 55 | tft.fillScreen(BLUE); |
peu605 | 9:99e7307d5a59 | 56 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 57 | return micros() - start; |
peu605 | 9:99e7307d5a59 | 58 | } |
peu605 | 0:26cf1056924c | 59 | |
peu605 | 9:99e7307d5a59 | 60 | unsigned long testText() |
peu605 | 9:99e7307d5a59 | 61 | { |
peu605 | 9:99e7307d5a59 | 62 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 63 | unsigned long start = micros(); |
peu605 | 9:99e7307d5a59 | 64 | tft.setCursor(0, 0); |
peu605 | 9:99e7307d5a59 | 65 | tft.setTextColor(WHITE); |
peu605 | 9:99e7307d5a59 | 66 | tft.setTextSize(1); |
peu605 | 9:99e7307d5a59 | 67 | tft.printf("Hello World!\n"); |
peu605 | 9:99e7307d5a59 | 68 | tft.setTextColor(YELLOW); |
peu605 | 9:99e7307d5a59 | 69 | tft.setTextSize(2); |
peu605 | 9:99e7307d5a59 | 70 | tft.printf("%.2f\n", 1234.56); |
peu605 | 9:99e7307d5a59 | 71 | tft.setTextColor(RED); |
peu605 | 9:99e7307d5a59 | 72 | tft.setTextSize(3); |
peu605 | 9:99e7307d5a59 | 73 | tft.printf("%x", 0xABCD); |
peu605 | 9:99e7307d5a59 | 74 | tft.printf("\n"); |
peu605 | 9:99e7307d5a59 | 75 | tft.setTextColor(GREEN); |
peu605 | 9:99e7307d5a59 | 76 | tft.setTextSize(4); |
peu605 | 9:99e7307d5a59 | 77 | tft.printf("Hello\n"); |
peu605 | 9:99e7307d5a59 | 78 | tft.setTextSize(2); |
peu605 | 9:99e7307d5a59 | 79 | tft.printf("I implore thee,\n"); |
peu605 | 9:99e7307d5a59 | 80 | tft.setTextSize(1); |
peu605 | 9:99e7307d5a59 | 81 | tft.printf("my foonting turlingdromes.\n"); |
peu605 | 9:99e7307d5a59 | 82 | tft.printf("And hooptiously drangle me\n"); |
peu605 | 9:99e7307d5a59 | 83 | tft.printf("with crinkly bindlewurdles,\n"); |
peu605 | 9:99e7307d5a59 | 84 | tft.printf("Or I will rend thee\n"); |
peu605 | 9:99e7307d5a59 | 85 | tft.printf("in the gobberwarts\n"); |
peu605 | 9:99e7307d5a59 | 86 | tft.printf("with my blurglecruncheon,\n"); |
peu605 | 9:99e7307d5a59 | 87 | tft.printf("see if I don't!\n"); |
peu605 | 9:99e7307d5a59 | 88 | return micros() - start; |
peu605 | 0:26cf1056924c | 89 | } |
peu605 | 0:26cf1056924c | 90 | |
peu605 | 9:99e7307d5a59 | 91 | unsigned long testLines(uint16_t color) |
peu605 | 9:99e7307d5a59 | 92 | { |
peu605 | 9:99e7307d5a59 | 93 | unsigned long start, t; |
peu605 | 9:99e7307d5a59 | 94 | int x1, y1, x2, y2, |
peu605 | 9:99e7307d5a59 | 95 | w = tft.width(), |
peu605 | 9:99e7307d5a59 | 96 | h = tft.height(); |
peu605 | 9:99e7307d5a59 | 97 | |
peu605 | 9:99e7307d5a59 | 98 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 99 | |
peu605 | 9:99e7307d5a59 | 100 | x1 = y1 = 0; |
peu605 | 9:99e7307d5a59 | 101 | y2 = h - 1; |
peu605 | 9:99e7307d5a59 | 102 | start = micros(); |
peu605 | 9:99e7307d5a59 | 103 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 104 | x2 = w - 1; |
peu605 | 9:99e7307d5a59 | 105 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 106 | t = micros() - start; // fillScreen doesn't count against timing |
peu605 | 9:99e7307d5a59 | 107 | |
peu605 | 9:99e7307d5a59 | 108 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 109 | |
peu605 | 9:99e7307d5a59 | 110 | x1 = w - 1; |
peu605 | 9:99e7307d5a59 | 111 | y1 = 0; |
peu605 | 9:99e7307d5a59 | 112 | y2 = h - 1; |
peu605 | 9:99e7307d5a59 | 113 | start = micros(); |
peu605 | 9:99e7307d5a59 | 114 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 115 | x2 = 0; |
peu605 | 9:99e7307d5a59 | 116 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 117 | t += micros() - start; |
peu605 | 9:99e7307d5a59 | 118 | |
peu605 | 9:99e7307d5a59 | 119 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 120 | |
peu605 | 9:99e7307d5a59 | 121 | x1 = 0; |
peu605 | 9:99e7307d5a59 | 122 | y1 = h - 1; |
peu605 | 9:99e7307d5a59 | 123 | y2 = 0; |
peu605 | 9:99e7307d5a59 | 124 | start = micros(); |
peu605 | 9:99e7307d5a59 | 125 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 126 | x2 = w - 1; |
peu605 | 9:99e7307d5a59 | 127 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 128 | t += micros() - start; |
peu605 | 9:99e7307d5a59 | 129 | |
peu605 | 9:99e7307d5a59 | 130 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 131 | |
peu605 | 9:99e7307d5a59 | 132 | x1 = w - 1; |
peu605 | 9:99e7307d5a59 | 133 | y1 = h - 1; |
peu605 | 9:99e7307d5a59 | 134 | y2 = 0; |
peu605 | 9:99e7307d5a59 | 135 | start = micros(); |
peu605 | 9:99e7307d5a59 | 136 | for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 137 | x2 = 0; |
peu605 | 9:99e7307d5a59 | 138 | for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
peu605 | 9:99e7307d5a59 | 139 | |
peu605 | 9:99e7307d5a59 | 140 | return micros() - start; |
peu605 | 0:26cf1056924c | 141 | } |
peu605 | 0:26cf1056924c | 142 | |
peu605 | 9:99e7307d5a59 | 143 | unsigned long testFastLines(uint16_t color1, uint16_t color2) |
peu605 | 9:99e7307d5a59 | 144 | { |
peu605 | 9:99e7307d5a59 | 145 | unsigned long start; |
peu605 | 9:99e7307d5a59 | 146 | int x, y, w = tft.width(), h = tft.height(); |
peu605 | 9:99e7307d5a59 | 147 | |
peu605 | 9:99e7307d5a59 | 148 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 149 | start = micros(); |
peu605 | 9:99e7307d5a59 | 150 | for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1); |
peu605 | 9:99e7307d5a59 | 151 | for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2); |
peu605 | 9:99e7307d5a59 | 152 | |
peu605 | 9:99e7307d5a59 | 153 | return micros() - start; |
peu605 | 9:99e7307d5a59 | 154 | } |
peu605 | 9:99e7307d5a59 | 155 | |
peu605 | 9:99e7307d5a59 | 156 | unsigned long testRects(uint16_t color) |
peu605 | 9:99e7307d5a59 | 157 | { |
peu605 | 9:99e7307d5a59 | 158 | unsigned long start; |
peu605 | 9:99e7307d5a59 | 159 | int n, i, i2, |
peu605 | 9:99e7307d5a59 | 160 | cx = tft.width() / 2, |
peu605 | 9:99e7307d5a59 | 161 | cy = tft.height() / 2; |
peu605 | 9:99e7307d5a59 | 162 | |
peu605 | 9:99e7307d5a59 | 163 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 164 | n = min(tft.width(), tft.height()); |
peu605 | 9:99e7307d5a59 | 165 | start = micros(); |
peu605 | 9:99e7307d5a59 | 166 | for(i=2; i<n; i+=6) { |
peu605 | 9:99e7307d5a59 | 167 | i2 = i / 2; |
peu605 | 9:99e7307d5a59 | 168 | tft.drawRect(cx-i2, cy-i2, i, i, color); |
peu605 | 8:4fcf5494f425 | 169 | } |
peu605 | 9:99e7307d5a59 | 170 | |
peu605 | 9:99e7307d5a59 | 171 | return micros() - start; |
peu605 | 0:26cf1056924c | 172 | } |
peu605 | 0:26cf1056924c | 173 | |
peu605 | 9:99e7307d5a59 | 174 | unsigned long testFilledRects(uint16_t color1, uint16_t color2) |
peu605 | 9:99e7307d5a59 | 175 | { |
peu605 | 9:99e7307d5a59 | 176 | unsigned long start, t = 0; |
peu605 | 9:99e7307d5a59 | 177 | int n, i, i2, |
peu605 | 9:99e7307d5a59 | 178 | cx = (tft.width() / 2) - 1, |
peu605 | 9:99e7307d5a59 | 179 | cy = (tft.height() / 2) - 1; |
peu605 | 9:99e7307d5a59 | 180 | |
peu605 | 9:99e7307d5a59 | 181 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 182 | n = min(tft.width(), tft.height()); |
peu605 | 9:99e7307d5a59 | 183 | for(i=n; i>0; i-=6) { |
peu605 | 9:99e7307d5a59 | 184 | i2 = i / 2; |
peu605 | 9:99e7307d5a59 | 185 | start = micros(); |
peu605 | 9:99e7307d5a59 | 186 | tft.fillRect(cx-i2, cy-i2, i, i, color1); |
peu605 | 9:99e7307d5a59 | 187 | t += micros() - start; |
peu605 | 9:99e7307d5a59 | 188 | // Outlines are not included in timing results |
peu605 | 9:99e7307d5a59 | 189 | tft.drawRect(cx-i2, cy-i2, i, i, color2); |
peu605 | 8:4fcf5494f425 | 190 | } |
peu605 | 9:99e7307d5a59 | 191 | |
peu605 | 9:99e7307d5a59 | 192 | return t; |
peu605 | 0:26cf1056924c | 193 | } |
peu605 | 0:26cf1056924c | 194 | |
peu605 | 9:99e7307d5a59 | 195 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) |
peu605 | 9:99e7307d5a59 | 196 | { |
peu605 | 9:99e7307d5a59 | 197 | unsigned long start; |
peu605 | 9:99e7307d5a59 | 198 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; |
peu605 | 9:99e7307d5a59 | 199 | |
peu605 | 9:99e7307d5a59 | 200 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 201 | start = micros(); |
peu605 | 9:99e7307d5a59 | 202 | for(x=radius; x<w; x+=r2) { |
peu605 | 9:99e7307d5a59 | 203 | for(y=radius; y<h; y+=r2) { |
peu605 | 9:99e7307d5a59 | 204 | tft.fillCircle(x, y, radius, color); |
peu605 | 8:4fcf5494f425 | 205 | } |
peu605 | 0:26cf1056924c | 206 | } |
peu605 | 9:99e7307d5a59 | 207 | |
peu605 | 9:99e7307d5a59 | 208 | return micros() - start; |
peu605 | 9:99e7307d5a59 | 209 | } |
peu605 | 9:99e7307d5a59 | 210 | |
peu605 | 9:99e7307d5a59 | 211 | unsigned long testCircles(uint8_t radius, uint16_t color) |
peu605 | 9:99e7307d5a59 | 212 | { |
peu605 | 9:99e7307d5a59 | 213 | unsigned long start; |
peu605 | 9:99e7307d5a59 | 214 | int x, y, r2 = radius * 2, |
peu605 | 9:99e7307d5a59 | 215 | w = tft.width() + radius, |
peu605 | 9:99e7307d5a59 | 216 | h = tft.height() + radius; |
peu605 | 9:99e7307d5a59 | 217 | |
peu605 | 9:99e7307d5a59 | 218 | // Screen is not cleared for this one -- this is |
peu605 | 9:99e7307d5a59 | 219 | // intentional and does not affect the reported time. |
peu605 | 9:99e7307d5a59 | 220 | start = micros(); |
peu605 | 9:99e7307d5a59 | 221 | for(x=0; x<w; x+=r2) { |
peu605 | 9:99e7307d5a59 | 222 | for(y=0; y<h; y+=r2) { |
peu605 | 9:99e7307d5a59 | 223 | tft.drawCircle(x, y, radius, color); |
peu605 | 9:99e7307d5a59 | 224 | } |
peu605 | 9:99e7307d5a59 | 225 | } |
peu605 | 9:99e7307d5a59 | 226 | |
peu605 | 9:99e7307d5a59 | 227 | return micros() - start; |
peu605 | 0:26cf1056924c | 228 | } |
peu605 | 0:26cf1056924c | 229 | |
peu605 | 9:99e7307d5a59 | 230 | unsigned long testTriangles() |
peu605 | 9:99e7307d5a59 | 231 | { |
peu605 | 9:99e7307d5a59 | 232 | unsigned long start; |
peu605 | 9:99e7307d5a59 | 233 | int n, i, cx = tft.width() / 2 - 1, |
peu605 | 9:99e7307d5a59 | 234 | cy = (tft.height() / 2) - 1; |
peu605 | 9:99e7307d5a59 | 235 | |
peu605 | 9:99e7307d5a59 | 236 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 237 | n = min(cx, cy); |
peu605 | 9:99e7307d5a59 | 238 | start = micros(); |
peu605 | 9:99e7307d5a59 | 239 | for(i=0; i<n; i+=5) { |
peu605 | 9:99e7307d5a59 | 240 | tft.drawTriangle( |
peu605 | 9:99e7307d5a59 | 241 | cx , cy - i, // peak |
peu605 | 9:99e7307d5a59 | 242 | cx - i, cy + i, // bottom left |
peu605 | 9:99e7307d5a59 | 243 | cx + i, cy + i, // bottom right |
peu605 | 9:99e7307d5a59 | 244 | tft.Color565(0, 0, i)); |
peu605 | 0:26cf1056924c | 245 | } |
peu605 | 9:99e7307d5a59 | 246 | |
peu605 | 9:99e7307d5a59 | 247 | return micros() - start; |
peu605 | 9:99e7307d5a59 | 248 | } |
peu605 | 9:99e7307d5a59 | 249 | |
peu605 | 9:99e7307d5a59 | 250 | unsigned long testFilledTriangles() |
peu605 | 9:99e7307d5a59 | 251 | { |
peu605 | 9:99e7307d5a59 | 252 | unsigned long start, t = 0; |
peu605 | 9:99e7307d5a59 | 253 | int i, cx = (tft.width() / 2) - 1, |
peu605 | 9:99e7307d5a59 | 254 | cy = tft.height() / 2 - 1; |
peu605 | 9:99e7307d5a59 | 255 | |
peu605 | 9:99e7307d5a59 | 256 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 257 | start = micros(); |
peu605 | 9:99e7307d5a59 | 258 | for(i=min(cx,cy); i>10; i-=5) { |
peu605 | 9:99e7307d5a59 | 259 | start = micros(); |
peu605 | 9:99e7307d5a59 | 260 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, |
peu605 | 9:99e7307d5a59 | 261 | tft.Color565(0, i, i)); |
peu605 | 9:99e7307d5a59 | 262 | t += micros() - start; |
peu605 | 9:99e7307d5a59 | 263 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, |
peu605 | 9:99e7307d5a59 | 264 | tft.Color565(i, i, 0)); |
peu605 | 9:99e7307d5a59 | 265 | } |
peu605 | 9:99e7307d5a59 | 266 | |
peu605 | 9:99e7307d5a59 | 267 | return t; |
peu605 | 9:99e7307d5a59 | 268 | } |
peu605 | 9:99e7307d5a59 | 269 | |
peu605 | 9:99e7307d5a59 | 270 | unsigned long testRoundRects() |
peu605 | 9:99e7307d5a59 | 271 | { |
peu605 | 9:99e7307d5a59 | 272 | unsigned long start; |
peu605 | 9:99e7307d5a59 | 273 | int w, i, i2, |
peu605 | 9:99e7307d5a59 | 274 | cx = (tft.width() / 2) - 1, |
peu605 | 9:99e7307d5a59 | 275 | cy = (tft.height() / 2) - 1; |
peu605 | 9:99e7307d5a59 | 276 | |
peu605 | 9:99e7307d5a59 | 277 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 278 | w = min(tft.width(), tft.height()); |
peu605 | 9:99e7307d5a59 | 279 | start = micros(); |
peu605 | 9:99e7307d5a59 | 280 | for(i=0; i<w; i+=6) { |
peu605 | 9:99e7307d5a59 | 281 | i2 = i / 2; |
peu605 | 9:99e7307d5a59 | 282 | tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.Color565(i, 0, 0)); |
peu605 | 9:99e7307d5a59 | 283 | } |
peu605 | 9:99e7307d5a59 | 284 | |
peu605 | 9:99e7307d5a59 | 285 | return micros() - start; |
peu605 | 0:26cf1056924c | 286 | } |
peu605 | 0:26cf1056924c | 287 | |
peu605 | 9:99e7307d5a59 | 288 | unsigned long testFilledRoundRects() |
peu605 | 9:99e7307d5a59 | 289 | { |
peu605 | 9:99e7307d5a59 | 290 | unsigned long start; |
peu605 | 9:99e7307d5a59 | 291 | int i, i2, |
peu605 | 9:99e7307d5a59 | 292 | cx = (tft.width() / 2) - 1, |
peu605 | 9:99e7307d5a59 | 293 | cy = (tft.height() / 2) - 1; |
peu605 | 9:99e7307d5a59 | 294 | |
peu605 | 9:99e7307d5a59 | 295 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 296 | start = micros(); |
peu605 | 9:99e7307d5a59 | 297 | for(i=min(tft.width(), tft.height()); i>20; i-=6) { |
peu605 | 9:99e7307d5a59 | 298 | i2 = i / 2; |
peu605 | 9:99e7307d5a59 | 299 | tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.Color565(0, i, 0)); |
peu605 | 8:4fcf5494f425 | 300 | } |
peu605 | 9:99e7307d5a59 | 301 | |
peu605 | 9:99e7307d5a59 | 302 | return micros() - start; |
peu605 | 0:26cf1056924c | 303 | } |
peu605 | 0:26cf1056924c | 304 | |
peu605 | 9:99e7307d5a59 | 305 | |
peu605 | 9:99e7307d5a59 | 306 | void doBenchmark(void) |
peu605 | 9:99e7307d5a59 | 307 | { |
peu605 | 9:99e7307d5a59 | 308 | uint8_t testNumber = 0; |
peu605 | 9:99e7307d5a59 | 309 | pc.printf("Benchmark Time (microseconds)\n"); |
peu605 | 9:99e7307d5a59 | 310 | results[testNumber] = testFillScreen(); |
peu605 | 9:99e7307d5a59 | 311 | pc.printf("Screen fill %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 312 | delay(500); |
peu605 | 9:99e7307d5a59 | 313 | |
peu605 | 9:99e7307d5a59 | 314 | results[testNumber] = testText(); |
peu605 | 9:99e7307d5a59 | 315 | pc.printf("Text %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 316 | delay(500); |
peu605 | 9:99e7307d5a59 | 317 | |
peu605 | 9:99e7307d5a59 | 318 | results[testNumber] = testLines(CYAN); |
peu605 | 9:99e7307d5a59 | 319 | pc.printf("Lines %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 320 | delay(500); |
peu605 | 9:99e7307d5a59 | 321 | |
peu605 | 9:99e7307d5a59 | 322 | results[testNumber] = testFastLines(RED, BLUE); |
peu605 | 9:99e7307d5a59 | 323 | pc.printf("Horiz/Vert Lines %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 324 | delay(500); |
peu605 | 9:99e7307d5a59 | 325 | |
peu605 | 9:99e7307d5a59 | 326 | results[testNumber] = testRects(GREEN); |
peu605 | 9:99e7307d5a59 | 327 | pc.printf("Rectangles (outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 328 | delay(500); |
peu605 | 9:99e7307d5a59 | 329 | |
peu605 | 9:99e7307d5a59 | 330 | results[testNumber] = testFilledRects(YELLOW,MAGENTA); |
peu605 | 9:99e7307d5a59 | 331 | pc.printf("Rectangles (filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 332 | delay(500); |
peu605 | 9:99e7307d5a59 | 333 | |
peu605 | 9:99e7307d5a59 | 334 | results[testNumber] = testFilledCircles(10,MAGENTA); |
peu605 | 9:99e7307d5a59 | 335 | pc.printf("Circles (filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 336 | delay(500); |
peu605 | 9:99e7307d5a59 | 337 | |
peu605 | 9:99e7307d5a59 | 338 | results[testNumber] = testCircles(10,WHITE); |
peu605 | 9:99e7307d5a59 | 339 | pc.printf("Circles (outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 340 | delay(500); |
peu605 | 9:99e7307d5a59 | 341 | |
peu605 | 9:99e7307d5a59 | 342 | results[testNumber] = testTriangles(); |
peu605 | 9:99e7307d5a59 | 343 | pc.printf("Triangles (outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 344 | delay(500); |
peu605 | 9:99e7307d5a59 | 345 | |
peu605 | 9:99e7307d5a59 | 346 | results[testNumber] = testFilledTriangles(); |
peu605 | 9:99e7307d5a59 | 347 | pc.printf("Triangles (filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 348 | delay(500); |
peu605 | 9:99e7307d5a59 | 349 | |
peu605 | 9:99e7307d5a59 | 350 | results[testNumber] = testRoundRects(); |
peu605 | 9:99e7307d5a59 | 351 | pc.printf("Rounded rects (outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 352 | delay(500); |
peu605 | 9:99e7307d5a59 | 353 | |
peu605 | 9:99e7307d5a59 | 354 | results[testNumber] = testFilledRoundRects(); |
peu605 | 9:99e7307d5a59 | 355 | pc.printf("Rounded rects (filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 356 | delay(500); |
peu605 | 9:99e7307d5a59 | 357 | |
peu605 | 9:99e7307d5a59 | 358 | pc.printf("Done!\n"); |
peu605 | 9:99e7307d5a59 | 359 | } |
peu605 | 9:99e7307d5a59 | 360 | |
peu605 | 9:99e7307d5a59 | 361 | void dispResults() { |
peu605 | 9:99e7307d5a59 | 362 | |
peu605 | 9:99e7307d5a59 | 363 | tft.fillScreen(); |
peu605 | 9:99e7307d5a59 | 364 | tft.setCursor(0, 0); |
peu605 | 9:99e7307d5a59 | 365 | tft.setTextColor(WHITE); |
peu605 | 9:99e7307d5a59 | 366 | tft.setTextSize(1); |
peu605 | 9:99e7307d5a59 | 367 | |
peu605 | 9:99e7307d5a59 | 368 | uint8_t testNumber = 0; |
peu605 | 9:99e7307d5a59 | 369 | tft.printf("Benchmark msec\n"); |
peu605 | 9:99e7307d5a59 | 370 | tft.printf("Screen fill %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 371 | tft.printf("Text %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 372 | tft.printf("Lines %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 373 | tft.printf("H/V Lines %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 374 | tft.printf("Rect(outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 375 | tft.printf("Rect(filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 376 | tft.printf("Circ(filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 377 | tft.printf("Circ(outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 378 | tft.printf("Tria(outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 379 | tft.printf("Tria(filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 380 | tft.printf("Round(outline) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 381 | tft.printf("Round(filled) %d\n", results[testNumber++]); |
peu605 | 9:99e7307d5a59 | 382 | |
peu605 | 9:99e7307d5a59 | 383 | } |
peu605 | 9:99e7307d5a59 | 384 | |
peu605 | 9:99e7307d5a59 | 385 | void loop(void) |
peu605 | 9:99e7307d5a59 | 386 | { |
peu605 | 9:99e7307d5a59 | 387 | for(uint8_t rotation=0; rotation<4; rotation++) { |
peu605 | 9:99e7307d5a59 | 388 | tft.setRotation(rotation); |
peu605 | 9:99e7307d5a59 | 389 | dispResults(); |
peu605 | 9:99e7307d5a59 | 390 | for (int16_t i = 0; i <= _TFTHEIGHT; ++i) { |
peu605 | 9:99e7307d5a59 | 391 | tft.scroll(i); |
peu605 | 9:99e7307d5a59 | 392 | delay(5); |
peu605 | 8:4fcf5494f425 | 393 | } |
peu605 | 9:99e7307d5a59 | 394 | delay(500); |
peu605 | 9:99e7307d5a59 | 395 | |
peu605 | 9:99e7307d5a59 | 396 | for (int16_t i = _TFTHEIGHT; i >= 0; --i) { |
peu605 | 9:99e7307d5a59 | 397 | tft.scroll(i); |
peu605 | 9:99e7307d5a59 | 398 | delay(5); |
peu605 | 9:99e7307d5a59 | 399 | } |
peu605 | 9:99e7307d5a59 | 400 | delay(1000); |
peu605 | 0:26cf1056924c | 401 | } |
peu605 | 0:26cf1056924c | 402 | } |
peu605 | 0:26cf1056924c | 403 | |
peu605 | 9:99e7307d5a59 | 404 | int main() |
peu605 | 9:99e7307d5a59 | 405 | { |
peu605 | 8:4fcf5494f425 | 406 | t.start(); |
peu605 | 9:99e7307d5a59 | 407 | |
peu605 | 9:99e7307d5a59 | 408 | tft.begin(); |
peu605 | 9:99e7307d5a59 | 409 | tft.setBitrate(50000000); |
peu605 | 9:99e7307d5a59 | 410 | tft.setRotation(0); |
peu605 | 9:99e7307d5a59 | 411 | // tft.setRotation(2); |
peu605 | 9:99e7307d5a59 | 412 | |
peu605 | 9:99e7307d5a59 | 413 | doBenchmark(); |
peu605 | 9:99e7307d5a59 | 414 | delay(1000); |
peu605 | 9:99e7307d5a59 | 415 | |
peu605 | 0:26cf1056924c | 416 | while (true) { |
peu605 | 0:26cf1056924c | 417 | loop(); |
peu605 | 0:26cf1056924c | 418 | } |
peu605 | 0:26cf1056924c | 419 | } |