acidportal- 😈 Worlds smallest Evil Portal on a LilyGo T-QT |
git clone git://git.acid.vegas/acidportal.git |
Log | Files | Refs | Archive | README | LICENSE |
TFT_graphicstest_PDQ3.ino (18916B)
1 /* 2 Adapted from the Adafruit and Xark's PDQ graphicstest sketch. 3 4 This sketch uses the GLCD font only. 5 6 Make sure all the display driver and pin connections are correct by 7 editing the User_Setup.h file in the TFT_eSPI library folder. 8 9 Note that yield() or delay(0) must be called in long duration for/while 10 loops to stop the ESP8266 watchdog triggering. 11 12 ######################################################################### 13 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### 14 ######################################################################### 15 */ 16 17 18 #include <TFT_eSPI.h> // Hardware-specific library 19 #include <SPI.h> 20 21 TFT_eSPI tft = TFT_eSPI(); // Invoke custom library 22 23 // These are used to get information about static SRAM and flash memory sizes 24 extern "C" char __data_start[]; // start of SRAM data 25 extern "C" char _end[]; // end of SRAM data (used to check amount of SRAM this program's variables use) 26 extern "C" char __data_load_end[]; // end of FLASH (used to check amount of Flash this program's code and data uses) 27 28 29 void setup() 30 { 31 Serial.begin(115200); 32 33 Serial.println(F("TFT 1.8\" SPI TFT Test! ")); 34 35 tft.init(); // initialize LCD 36 } 37 38 // NOTE: This demo should run, but may look odd on 128x128 LCD (vs 128x160) 39 40 void loop(void) 41 { 42 43 Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x")); 44 // These are not compatible with the ESP8266 core library 45 //Serial.print((uint16_t)__data_load_end, HEX); 46 //Serial.print(F(" RAM=0x")); 47 //Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX); 48 Serial.println(F("Benchmark Time (microseconds)")); 49 50 uint32_t usecHaD = testHaD(); 51 Serial.print(F("HaD pushColor ")); 52 Serial.println(usecHaD); 53 delay(100); 54 55 56 uint32_t usecFillScreen = testFillScreen(); 57 Serial.print(F("Screen fill ")); 58 Serial.println(usecFillScreen); 59 delay(100); 60 61 tft.setRotation(1); 62 uint32_t usecText = testText(); 63 Serial.print(F("Text ")); 64 Serial.println(usecText); 65 delay(100); 66 tft.setRotation(0); 67 68 uint32_t usecPixels = testPixels(); 69 Serial.print(F("Pixels ")); 70 Serial.println(usecPixels); 71 delay(100); 72 73 uint32_t usecLines = testLines(TFT_BLUE); 74 Serial.print(F("Lines ")); 75 Serial.println(usecLines); 76 delay(100); 77 78 uint32_t usecFastLines = testFastLines(TFT_RED, TFT_BLUE); 79 Serial.print(F("Horiz/Vert Lines ")); 80 Serial.println(usecFastLines); 81 delay(100); 82 83 uint32_t usecRects = testRects(TFT_GREEN); 84 Serial.print(F("Rectangles (outline) ")); 85 Serial.println(usecRects); 86 delay(100); 87 88 uint32_t usecFilledRects = testFilledRects(TFT_YELLOW, TFT_MAGENTA); 89 Serial.print(F("Rectangles (filled) ")); 90 Serial.println(usecFilledRects); 91 delay(100); 92 93 uint32_t usecFilledCircles = testFilledCircles(10, TFT_MAGENTA); 94 Serial.print(F("Circles (filled) ")); 95 Serial.println(usecFilledCircles); 96 delay(100); 97 98 uint32_t usecCircles = testCircles(10, TFT_WHITE); 99 Serial.print(F("Circles (outline) ")); 100 Serial.println(usecCircles); 101 delay(100); 102 103 uint32_t usecTriangles = testTriangles(); 104 Serial.print(F("Triangles (outline) ")); 105 Serial.println(usecTriangles); 106 delay(100); 107 108 uint32_t usecFilledTrangles = testFilledTriangles(); 109 Serial.print(F("Triangles (filled) ")); 110 Serial.println(usecFilledTrangles); 111 delay(100); 112 113 uint32_t usecRoundRects = testRoundRects(); 114 Serial.print(F("Rounded rects (outline) ")); 115 Serial.println(usecRoundRects); 116 delay(100); 117 118 uint32_t usedFilledRoundRects = testFilledRoundRects(); 119 Serial.print(F("Rounded rects (filled) ")); 120 Serial.println(usedFilledRoundRects); 121 delay(100); 122 123 Serial.println(F("Done!")); 124 125 uint16_t c = 4; 126 int8_t d = 1; 127 for (int32_t i = 0; i < tft.height(); i++) 128 { 129 tft.drawFastHLine(0, i, tft.width(), c); 130 c += d; 131 if (c <= 4 || c >= 11) 132 d = -d; 133 } 134 135 tft.setCursor(0, 0); 136 tft.setTextColor(TFT_MAGENTA); 137 138 tft.println(F("Bodmer's TFT_eSPI")); 139 140 tft.setTextSize(1); 141 tft.setTextColor(TFT_WHITE); 142 tft.println(F("SPI TFT on ESP8266")); 143 tft.println(F("")); 144 tft.setTextSize(1); 145 tft.setTextColor(tft.color565(0x80, 0x80, 0x80)); 146 147 // These are not compatible with the ESP8266 core library 148 //tft.print(F("Flash=0x")); 149 //tft.print((uint16_t)__data_load_end, HEX); 150 //tft.print(F(" RAM=0x")); 151 //tft.print((uint16_t)_end - (uint16_t)__data_start, HEX); 152 153 tft.setTextColor(TFT_GREEN); 154 tft.print(F("Benchmark usec")); 155 156 tft.setTextColor(TFT_CYAN); 157 tft.print(F("HaD logo ")); 158 tft.setTextColor(TFT_YELLOW); 159 printnice(usecHaD); 160 161 tft.setTextColor(TFT_CYAN); 162 tft.print(F("Clear ")); 163 tft.setTextColor(TFT_YELLOW); 164 printnice(usecFillScreen); 165 166 tft.setTextColor(TFT_CYAN); 167 tft.print(F("Text ")); 168 tft.setTextColor(TFT_YELLOW); 169 printnice(usecText); 170 171 tft.setTextColor(TFT_CYAN); 172 tft.print(F("Pixels ")); 173 tft.setTextColor(TFT_YELLOW); 174 printnice(usecPixels); 175 176 tft.setTextColor(TFT_CYAN); 177 tft.print(F("Lines ")); 178 tft.setTextColor(TFT_YELLOW); 179 printnice(usecLines); 180 181 tft.setTextColor(TFT_CYAN); 182 tft.print(F("H/V Lines ")); 183 tft.setTextColor(TFT_YELLOW); 184 printnice(usecFastLines); 185 186 tft.setTextColor(TFT_CYAN); 187 tft.print(F("Rectangles ")); 188 tft.setTextColor(TFT_YELLOW); 189 printnice(usecRects); 190 191 tft.setTextColor(TFT_CYAN); 192 tft.print(F("Rects-Fill ")); 193 tft.setTextColor(TFT_YELLOW); 194 printnice(usecFilledRects); 195 196 tft.setTextColor(TFT_CYAN); 197 tft.print(F("Circles ")); 198 tft.setTextColor(TFT_YELLOW); 199 printnice(usecCircles); 200 201 tft.setTextColor(TFT_CYAN); 202 tft.print(F("CircleFill ")); 203 tft.setTextColor(TFT_YELLOW); 204 printnice(usecFilledCircles); 205 206 tft.setTextColor(TFT_CYAN); 207 tft.print(F("Triangles ")); 208 tft.setTextColor(TFT_YELLOW); 209 printnice(usecTriangles); 210 211 tft.setTextColor(TFT_CYAN); 212 tft.print(F("Tris-Fill ")); 213 tft.setTextColor(TFT_YELLOW); 214 printnice(usecFilledTrangles); 215 216 tft.setTextColor(TFT_CYAN); 217 tft.print(F("Rnd-Rects ")); 218 tft.setTextColor(TFT_YELLOW); 219 printnice(usecRoundRects); 220 221 tft.setTextColor(TFT_CYAN); 222 tft.print(F("RRects-Fill")); 223 tft.setTextColor(TFT_YELLOW); 224 printnice(usedFilledRoundRects); 225 226 tft.setTextSize(1); 227 tft.println(F("")); 228 tft.setTextColor(TFT_GREEN); 229 tft.print(F("Benchmark Completed!")); 230 231 delay(15 * 1000L); 232 } 233 234 void printnice(int32_t v) 235 { 236 char str[32] = { 0 }; 237 sprintf(str, "%d", v); 238 for (char *p = (str+strlen(str))-3; p > str; p -= 3) 239 { 240 memmove(p+1, p, strlen(p)+1); 241 *p = ','; 242 243 } 244 while (strlen(str) < 10) 245 { 246 memmove(str+1, str, strlen(str)+1); 247 *str = ' '; 248 } 249 tft.print(str); 250 } 251 252 static inline uint32_t micros_start() __attribute__ ((always_inline)); 253 static inline uint32_t micros_start() 254 { 255 uint8_t oms = millis(); 256 while ((uint8_t)millis() == oms) 257 ; 258 return micros(); 259 } 260 261 uint32_t testHaD() 262 { 263 // pseudo-code for cheesy RLE 264 // start with color1 265 // while more input data remaining 266 // count = 0nnnnnnn = 1 byte or 1nnnnnnn nnnnnnnn 2 bytes (0 - 32767) 267 // repeat color count times 268 // toggle color1/color2 269 static const uint8_t HaD_128x160[] PROGMEM = 270 { 271 0x85, 0x91, 0x09, 0x4b, 0x09, 0x24, 0x0a, 0x47, 0x09, 0x27, 0x0a, 0x44, 0x0a, 0x29, 0x0a, 0x42, 272 0x0a, 0x2b, 0x0a, 0x41, 0x0a, 0x2c, 0x0a, 0x3e, 0x0b, 0x2f, 0x09, 0x3d, 0x09, 0x32, 0x08, 0x3c, 273 0x09, 0x33, 0x09, 0x3b, 0x08, 0x33, 0x0a, 0x3a, 0x0a, 0x31, 0x0b, 0x3a, 0x0c, 0x1d, 0x01, 0x10, 274 0x0d, 0x39, 0x0c, 0x1d, 0x01, 0x10, 0x0d, 0x39, 0x0d, 0x0f, 0x01, 0x0c, 0x03, 0x0d, 0x0e, 0x39, 275 0x0e, 0x0c, 0x03, 0x0c, 0x04, 0x0b, 0x0f, 0x39, 0x0f, 0x0a, 0x04, 0x0c, 0x05, 0x09, 0x10, 0x39, 276 0x10, 0x08, 0x05, 0x0c, 0x06, 0x07, 0x11, 0x39, 0x11, 0x06, 0x06, 0x0d, 0x07, 0x04, 0x13, 0x37, 277 0x12, 0x05, 0x07, 0x0d, 0x08, 0x02, 0x15, 0x34, 0x15, 0x03, 0x08, 0x0d, 0x20, 0x32, 0x20, 0x0e, 278 0x21, 0x31, 0x20, 0x0f, 0x21, 0x2e, 0x22, 0x10, 0x22, 0x2b, 0x22, 0x12, 0x22, 0x12, 0x05, 0x12, 279 0x22, 0x14, 0x22, 0x0c, 0x0f, 0x0c, 0x22, 0x16, 0x22, 0x08, 0x15, 0x08, 0x22, 0x18, 0x22, 0x05, 280 0x19, 0x05, 0x21, 0x1c, 0x1f, 0x04, 0x1c, 0x05, 0x1f, 0x1f, 0x1c, 0x04, 0x1e, 0x04, 0x1d, 0x2b, 281 0x11, 0x04, 0x21, 0x03, 0x12, 0x36, 0x0f, 0x03, 0x24, 0x03, 0x10, 0x38, 0x0d, 0x03, 0x26, 0x03, 282 0x0d, 0x3b, 0x0b, 0x03, 0x28, 0x03, 0x0b, 0x3d, 0x0a, 0x03, 0x29, 0x03, 0x09, 0x40, 0x07, 0x03, 283 0x2b, 0x03, 0x07, 0x42, 0x05, 0x03, 0x2c, 0x04, 0x04, 0x45, 0x04, 0x03, 0x2d, 0x03, 0x04, 0x46, 284 0x02, 0x03, 0x2e, 0x03, 0x03, 0x48, 0x01, 0x03, 0x2f, 0x03, 0x01, 0x4c, 0x31, 0x4e, 0x32, 0x4e, 285 0x33, 0x4c, 0x34, 0x4c, 0x34, 0x4c, 0x35, 0x4b, 0x35, 0x4a, 0x0e, 0x03, 0x14, 0x04, 0x0d, 0x4a, 286 0x0b, 0x09, 0x0e, 0x0a, 0x0a, 0x4a, 0x0a, 0x0b, 0x0c, 0x0c, 0x09, 0x4a, 0x09, 0x0d, 0x0a, 0x0e, 287 0x09, 0x49, 0x08, 0x0f, 0x09, 0x0e, 0x09, 0x49, 0x08, 0x0f, 0x09, 0x0f, 0x08, 0x49, 0x08, 0x0f, 288 0x09, 0x0f, 0x08, 0x49, 0x07, 0x0f, 0x0a, 0x0f, 0x08, 0x49, 0x07, 0x0f, 0x0b, 0x0e, 0x08, 0x49, 289 0x07, 0x0d, 0x0e, 0x0d, 0x08, 0x49, 0x07, 0x0b, 0x13, 0x0a, 0x08, 0x49, 0x08, 0x07, 0x18, 0x08, 290 0x08, 0x49, 0x08, 0x06, 0x1b, 0x06, 0x08, 0x49, 0x09, 0x04, 0x1c, 0x05, 0x08, 0x4a, 0x09, 0x04, 291 0x1d, 0x04, 0x08, 0x4a, 0x0a, 0x03, 0x1d, 0x03, 0x09, 0x4b, 0x19, 0x02, 0x1a, 0x4b, 0x19, 0x03, 292 0x19, 0x4b, 0x18, 0x04, 0x18, 0x4d, 0x17, 0x05, 0x17, 0x4a, 0x01, 0x02, 0x17, 0x05, 0x16, 0x4a, 293 0x02, 0x02, 0x17, 0x05, 0x16, 0x02, 0x03, 0x44, 0x03, 0x03, 0x16, 0x02, 0x01, 0x02, 0x16, 0x02, 294 0x03, 0x43, 0x05, 0x03, 0x15, 0x01, 0x03, 0x01, 0x15, 0x03, 0x04, 0x41, 0x06, 0x03, 0x15, 0x01, 295 0x03, 0x01, 0x14, 0x03, 0x07, 0x3d, 0x09, 0x03, 0x2d, 0x03, 0x08, 0x3b, 0x0a, 0x04, 0x2b, 0x03, 296 0x0a, 0x39, 0x0c, 0x03, 0x2a, 0x04, 0x0b, 0x37, 0x0e, 0x03, 0x28, 0x03, 0x0e, 0x2e, 0x04, 0x03, 297 0x10, 0x03, 0x27, 0x03, 0x10, 0x03, 0x03, 0x24, 0x19, 0x03, 0x26, 0x03, 0x1a, 0x1e, 0x1d, 0x03, 298 0x24, 0x03, 0x1e, 0x19, 0x20, 0x04, 0x21, 0x03, 0x20, 0x17, 0x22, 0x04, 0x1f, 0x03, 0x22, 0x15, 299 0x22, 0x04, 0x21, 0x04, 0x21, 0x13, 0x22, 0x05, 0x15, 0x01, 0x0b, 0x05, 0x21, 0x12, 0x21, 0x06, 300 0x15, 0x01, 0x0b, 0x06, 0x21, 0x10, 0x21, 0x07, 0x0a, 0x01, 0x0a, 0x01, 0x0b, 0x07, 0x21, 0x0e, 301 0x20, 0x0a, 0x09, 0x02, 0x09, 0x02, 0x09, 0x09, 0x20, 0x0e, 0x08, 0x02, 0x15, 0x0b, 0x08, 0x03, 302 0x08, 0x03, 0x08, 0x0b, 0x15, 0x03, 0x08, 0x0d, 0x07, 0x04, 0x13, 0x0d, 0x06, 0x05, 0x06, 0x06, 303 0x05, 0x0d, 0x14, 0x04, 0x07, 0x0c, 0x07, 0x06, 0x11, 0x38, 0x12, 0x06, 0x06, 0x0c, 0x06, 0x08, 304 0x10, 0x39, 0x10, 0x08, 0x05, 0x0c, 0x04, 0x0b, 0x0f, 0x39, 0x0f, 0x0a, 0x04, 0x0c, 0x03, 0x0d, 305 0x0e, 0x39, 0x0e, 0x0c, 0x03, 0x0c, 0x02, 0x0e, 0x0e, 0x39, 0x0d, 0x0f, 0x01, 0x0c, 0x01, 0x10, 306 0x0d, 0x39, 0x0d, 0x0f, 0x01, 0x1e, 0x0c, 0x39, 0x0c, 0x30, 0x0a, 0x3a, 0x0a, 0x33, 0x09, 0x3b, 307 0x08, 0x34, 0x09, 0x3b, 0x09, 0x32, 0x09, 0x3c, 0x0a, 0x2f, 0x0a, 0x3e, 0x0a, 0x2d, 0x0b, 0x3f, 308 0x0a, 0x2b, 0x0b, 0x41, 0x0a, 0x29, 0x0b, 0x43, 0x0a, 0x27, 0x0a, 0x46, 0x0a, 0x25, 0x0a, 0x49, 309 0x09, 0x23, 0x08, 0x4e, 0x08, 0x96, 0x12 310 }; 311 312 tft.fillScreen(TFT_BLACK); 313 314 uint32_t start = micros_start(); 315 316 tft.startWrite(); 317 318 for (int i = 0; i < 0x10; i++) 319 { 320 tft.setAddrWindow(0, 0, tft.width(), tft.height()); 321 322 uint16_t cnt = 0; 323 uint16_t color = tft.color565((i << 4) | i, (i << 4) | i, (i << 4) | i); 324 uint16_t curcolor = 0; 325 326 const uint8_t *cmp = &HaD_128x160[0]; 327 tft.startWrite(); 328 while (cmp < &HaD_128x160[sizeof(HaD_128x160)]) 329 { 330 cnt = pgm_read_byte(cmp++); 331 if (cnt & 0x80) 332 cnt = ((cnt & 0x7f) << 8) | pgm_read_byte(cmp++); 333 334 tft.pushColor(curcolor, cnt); // PDQ_GFX has count 335 336 curcolor ^= color; 337 } 338 tft.endWrite(); 339 } 340 341 tft.endWrite(); 342 343 uint32_t t = micros() - start; 344 345 tft.setTextColor(TFT_YELLOW); 346 tft.setCursor(0, 145); 347 tft.print(F(" http://hackaday.io/")); 348 tft.print(F(" Xark")); 349 350 delay(3 * 1000L); 351 352 return t; 353 } 354 355 uint32_t testFillScreen() 356 { 357 uint32_t start = micros_start(); 358 359 for (uint8_t i = 0; i < 12; i++) 360 { 361 tft.fillScreen(TFT_WHITE); 362 tft.fillScreen(TFT_RED); 363 tft.fillScreen(TFT_GREEN); 364 tft.fillScreen(TFT_BLUE); 365 tft.fillScreen(TFT_BLACK); 366 } 367 368 return micros() - start; 369 } 370 371 uint32_t testText() { 372 tft.fillScreen(TFT_BLACK); 373 uint32_t start = micros_start(); 374 tft.setCursor(0, 0); 375 tft.setTextColor(TFT_WHITE); tft.setTextSize(1); 376 tft.println(F("Hello World!")); 377 tft.setTextColor(tft.color565(0xff, 0x00, 0x00)); 378 tft.print(F("RED ")); 379 tft.setTextColor(tft.color565(0x00, 0xff, 0x00)); 380 tft.print(F("GREEN ")); 381 tft.setTextColor(tft.color565(0x00, 0x00, 0xff)); 382 tft.println(F("BLUE")); 383 tft.setTextColor(TFT_YELLOW); 384 tft.println(1234.56); 385 tft.setTextColor(TFT_RED); 386 tft.println(0xDEADBEEF, HEX); 387 tft.setTextColor(TFT_GREEN); 388 tft.setTextSize(2); 389 tft.println(F("Groop")); 390 tft.println(F("I implore thee,")); 391 tft.setTextSize(1); 392 tft.println(F("my foonting turlingdromes.")); 393 tft.println(F("And hooptiously drangle me")); 394 tft.println(F("with crinkly bindlewurdles,")); 395 tft.println(F("Or I will rend thee")); 396 tft.println(F("in the gobberwarts")); 397 tft.println(F("with my blurglecruncheon,")); 398 tft.println(F("see if I don't!")); 399 tft.println(F("")); 400 tft.setTextColor(TFT_MAGENTA); 401 tft.println(F("Woot!")); 402 uint32_t t = micros() - start; 403 delay(1000); 404 return t; 405 } 406 407 uint32_t testPixels() 408 { 409 int32_t w = tft.width(); 410 int32_t h = tft.height(); 411 412 uint32_t start = micros_start(); 413 tft.startWrite(); 414 for (uint16_t y = 0; y < h; y++) 415 { 416 for (uint16_t x = 0; x < w; x++) 417 { 418 tft.drawPixel(x, y, tft.color565(x<<3, y<<3, x*y)); 419 } 420 } 421 tft.endWrite(); 422 return micros() - start; 423 } 424 425 426 uint32_t testLines(uint16_t color) 427 { 428 uint32_t start, t; 429 int32_t x1, y1, x2, y2; 430 int32_t w = tft.width(); 431 int32_t h = tft.height(); 432 433 tft.fillScreen(TFT_BLACK); 434 435 x1 = y1 = 0; 436 y2 = h - 1; 437 438 start = micros_start(); 439 440 for (x2 = 0; x2 < w; x2 += 6) 441 { 442 tft.drawLine(x1, y1, x2, y2, color); 443 } 444 445 x2 = w - 1; 446 447 for (y2 = 0; y2 < h; y2 += 6) 448 { 449 tft.drawLine(x1, y1, x2, y2, color); 450 } 451 452 t = micros() - start; // fillScreen doesn't count against timing 453 454 tft.fillScreen(TFT_BLACK); 455 456 x1 = w - 1; 457 y1 = 0; 458 y2 = h - 1; 459 460 start = micros_start(); 461 462 for (x2 = 0; x2 < w; x2 += 6) 463 { 464 tft.drawLine(x1, y1, x2, y2, color); 465 } 466 467 x2 = 0; 468 for (y2 = 0; y2 < h; y2 += 6) 469 { 470 tft.drawLine(x1, y1, x2, y2, color); 471 } 472 473 t += micros() - start; 474 475 tft.fillScreen(TFT_BLACK); 476 477 x1 = 0; 478 y1 = h - 1; 479 y2 = 0; 480 481 start = micros_start(); 482 483 for (x2 = 0; x2 < w; x2 += 6) 484 { 485 tft.drawLine(x1, y1, x2, y2, color); 486 } 487 x2 = w - 1; 488 for (y2 = 0; y2 < h; y2 += 6) 489 { 490 tft.drawLine(x1, y1, x2, y2, color); 491 } 492 t += micros() - start; 493 494 tft.fillScreen(TFT_BLACK); 495 496 x1 = w - 1; 497 y1 = h - 1; 498 y2 = 0; 499 500 start = micros_start(); 501 502 for (x2 = 0; x2 < w; x2 += 6) 503 { 504 tft.drawLine(x1, y1, x2, y2, color); 505 } 506 507 x2 = 0; 508 for (y2 = 0; y2 < h; y2 += 6) 509 { 510 tft.drawLine(x1, y1, x2, y2, color); 511 } 512 513 t += micros() - start; 514 515 return t; 516 } 517 518 uint32_t testFastLines(uint16_t color1, uint16_t color2) 519 { 520 uint32_t start; 521 int32_t x, y; 522 int32_t w = tft.width(); 523 int32_t h = tft.height(); 524 525 tft.fillScreen(TFT_BLACK); 526 527 start = micros_start(); 528 529 for (y = 0; y < h; y += 5) 530 tft.drawFastHLine(0, y, w, color1); 531 for (x = 0; x < w; x += 5) 532 tft.drawFastVLine(x, 0, h, color2); 533 534 return micros() - start; 535 } 536 537 uint32_t testRects(uint16_t color) 538 { 539 uint32_t start; 540 int32_t n, i, i2; 541 int32_t cx = tft.width() / 2; 542 int32_t cy = tft.height() / 2; 543 544 tft.fillScreen(TFT_BLACK); 545 n = min(tft.width(), tft.height()); 546 start = micros_start(); 547 for (i = 2; i < n; i += 6) 548 { 549 i2 = i / 2; 550 tft.drawRect(cx-i2, cy-i2, i, i, color); 551 } 552 553 return micros() - start; 554 } 555 556 uint32_t testFilledRects(uint16_t color1, uint16_t color2) 557 { 558 uint32_t start, t = 0; 559 int32_t n, i, i2; 560 int32_t cx = tft.width() / 2 - 1; 561 int32_t cy = tft.height() / 2 - 1; 562 563 tft.fillScreen(TFT_BLACK); 564 n = min(tft.width(), tft.height()); 565 for (i = n; i > 0; i -= 6) 566 { 567 i2 = i / 2; 568 569 start = micros_start(); 570 571 tft.fillRect(cx-i2, cy-i2, i, i, color1); 572 573 t += micros() - start; 574 575 // Outlines are not included in timing results 576 tft.drawRect(cx-i2, cy-i2, i, i, color2); 577 } 578 579 return t; 580 } 581 582 uint32_t testFilledCircles(uint8_t radius, uint16_t color) 583 { 584 uint32_t start; 585 int32_t x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 586 587 tft.fillScreen(TFT_BLACK); 588 589 start = micros_start(); 590 591 for (x = radius; x < w; x += r2) 592 { 593 for (y = radius; y < h; y += r2) 594 { 595 tft.fillCircle(x, y, radius, color); 596 } 597 } 598 599 return micros() - start; 600 } 601 602 uint32_t testCircles(uint8_t radius, uint16_t color) 603 { 604 uint32_t start; 605 int32_t x, y, r2 = radius * 2; 606 int32_t w = tft.width() + radius; 607 int32_t h = tft.height() + radius; 608 609 // Screen is not cleared for this one -- this is 610 // intentional and does not affect the reported time. 611 start = micros_start(); 612 613 for (x = 0; x < w; x += r2) 614 { 615 for (y = 0; y < h; y += r2) 616 { 617 tft.drawCircle(x, y, radius, color); 618 } 619 } 620 621 return micros() - start; 622 } 623 624 uint32_t testTriangles() 625 { 626 uint32_t start; 627 int32_t n, i; 628 int32_t cx = tft.width()/ 2 - 1; 629 int32_t cy = tft.height() / 2 - 1; 630 631 tft.fillScreen(TFT_BLACK); 632 n = min(cx, cy); 633 634 start = micros_start(); 635 636 for (i = 0; i < n; i += 5) 637 { 638 tft.drawTriangle( 639 cx , cy - i, // peak 640 cx - i, cy + i, // bottom left 641 cx + i, cy + i, // bottom right 642 tft.color565(0, 0, i)); 643 } 644 645 return micros() - start; 646 } 647 648 uint32_t testFilledTriangles() 649 { 650 uint32_t start, t = 0; 651 int32_t i; 652 int32_t cx = tft.width() / 2 - 1; 653 int32_t cy = tft.height() / 2 - 1; 654 655 tft.fillScreen(TFT_BLACK); 656 657 start = micros_start(); 658 659 for (i = min(cx,cy); i > 10; i -= 5) { 660 start = micros_start(); 661 tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 662 tft.color565(0, i, i)); 663 t += micros() - start; 664 tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 665 tft.color565(i, i, 0)); 666 } 667 668 return t; 669 } 670 671 uint32_t testRoundRects() 672 { 673 uint32_t start; 674 int32_t w, i, i2; 675 int32_t cx = tft.width() / 2 - 1; 676 int32_t cy = tft.height() / 2 - 1; 677 678 tft.fillScreen(TFT_BLACK); 679 680 w = min(tft.width(), tft.height()); 681 682 start = micros_start(); 683 684 for (i = 0; i < w; i += 6) 685 { 686 i2 = i / 2; 687 tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0)); 688 } 689 690 return micros() - start; 691 } 692 693 uint32_t testFilledRoundRects() 694 { 695 uint32_t start; 696 int32_t i, i2; 697 int32_t cx = tft.width() / 2 - 1; 698 int32_t cy = tft.height() / 2 - 1; 699 700 tft.fillScreen(TFT_BLACK); 701 702 start = micros_start(); 703 704 for (i = min(tft.width(), tft.height()); i > 20; i -= 6) 705 { 706 i2 = i / 2; 707 tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); 708 } 709 710 return micros() - start; 711 }