|
| 1 | +/*************************************************** |
| 2 | + This is our GFX example for the Adafruit ILI9341 TFT FeatherWing |
| 3 | + ----> http://www.adafruit.com/products/3315 |
| 4 | +
|
| 5 | + Check out the links above for our tutorials and wiring diagrams |
| 6 | +
|
| 7 | + Adafruit invests time and resources providing this open source code, |
| 8 | + please support Adafruit and open-source hardware by purchasing |
| 9 | + products from Adafruit! |
| 10 | +
|
| 11 | + Written by Limor Fried/Ladyada for Adafruit Industries. |
| 12 | + MIT license, all text above must be included in any redistribution |
| 13 | + ****************************************************/ |
| 14 | + |
| 15 | +#include <SPI.h> |
| 16 | +#include <Adafruit_GFX.h> |
| 17 | +#include <Adafruit_ILI9341.h> |
| 18 | + |
| 19 | +#ifdef ESP8266 |
| 20 | + #define STMPE_CS 16 |
| 21 | + #define TFT_CS 0 |
| 22 | + #define TFT_DC 15 |
| 23 | + #define SD_CS 2 |
| 24 | +#endif |
| 25 | +#ifdef __AVR_ATmega32U4__ |
| 26 | + #define STMPE_CS 6 |
| 27 | + #define TFT_CS 9 |
| 28 | + #define TFT_DC 10 |
| 29 | + #define SD_CS 5 |
| 30 | +#endif |
| 31 | +#ifdef ARDUINO_SAMD_FEATHER_M0 |
| 32 | + #define STMPE_CS 6 |
| 33 | + #define TFT_CS 9 |
| 34 | + #define TFT_DC 10 |
| 35 | + #define SD_CS 5 |
| 36 | +#endif |
| 37 | +#ifdef TEENSYDUINO |
| 38 | + #define TFT_DC 10 |
| 39 | + #define TFT_CS 4 |
| 40 | + #define STMPE_CS 3 |
| 41 | + #define SD_CS 8 |
| 42 | +#endif |
| 43 | +#ifdef ARDUINO_STM32_FEATHER |
| 44 | + #define TFT_DC PB4 |
| 45 | + #define TFT_CS PA15 |
| 46 | + #define STMPE_CS PC7 |
| 47 | + #define SD_CS PC5 |
| 48 | +#endif |
| 49 | + |
| 50 | +Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); |
| 51 | + |
| 52 | +void setup() { |
| 53 | + Serial.begin(115200); |
| 54 | + |
| 55 | + delay(10); |
| 56 | + Serial.println("FeatherWing TFT Test!"); |
| 57 | + |
| 58 | + tft.begin(); |
| 59 | + |
| 60 | + // read diagnostics (optional but can help debug problems) |
| 61 | + uint8_t x = tft.readcommand8(ILI9341_RDMODE); |
| 62 | + Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX); |
| 63 | + x = tft.readcommand8(ILI9341_RDMADCTL); |
| 64 | + Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX); |
| 65 | + x = tft.readcommand8(ILI9341_RDPIXFMT); |
| 66 | + Serial.print("Pixel Format: 0x"); Serial.println(x, HEX); |
| 67 | + x = tft.readcommand8(ILI9341_RDIMGFMT); |
| 68 | + Serial.print("Image Format: 0x"); Serial.println(x, HEX); |
| 69 | + x = tft.readcommand8(ILI9341_RDSELFDIAG); |
| 70 | + Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); |
| 71 | + |
| 72 | + Serial.println(F("Benchmark Time (microseconds)")); |
| 73 | + delay(10); |
| 74 | + Serial.print(F("Screen fill ")); |
| 75 | + Serial.println(testFillScreen()); |
| 76 | + delay(500); |
| 77 | + |
| 78 | + Serial.print(F("Text ")); |
| 79 | + Serial.println(testText()); |
| 80 | + delay(3000); |
| 81 | + |
| 82 | + Serial.print(F("Lines ")); |
| 83 | + Serial.println(testLines(ILI9341_CYAN)); |
| 84 | + delay(500); |
| 85 | + |
| 86 | + Serial.print(F("Horiz/Vert Lines ")); |
| 87 | + Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE)); |
| 88 | + delay(500); |
| 89 | + |
| 90 | + Serial.print(F("Rectangles (outline) ")); |
| 91 | + Serial.println(testRects(ILI9341_GREEN)); |
| 92 | + delay(500); |
| 93 | + |
| 94 | + Serial.print(F("Rectangles (filled) ")); |
| 95 | + Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA)); |
| 96 | + delay(500); |
| 97 | + |
| 98 | + Serial.print(F("Circles (filled) ")); |
| 99 | + Serial.println(testFilledCircles(10, ILI9341_MAGENTA)); |
| 100 | + |
| 101 | + Serial.print(F("Circles (outline) ")); |
| 102 | + Serial.println(testCircles(10, ILI9341_WHITE)); |
| 103 | + delay(500); |
| 104 | + |
| 105 | + Serial.print(F("Triangles (outline) ")); |
| 106 | + Serial.println(testTriangles()); |
| 107 | + delay(500); |
| 108 | + |
| 109 | + Serial.print(F("Triangles (filled) ")); |
| 110 | + Serial.println(testFilledTriangles()); |
| 111 | + delay(500); |
| 112 | + |
| 113 | + Serial.print(F("Rounded rects (outline) ")); |
| 114 | + Serial.println(testRoundRects()); |
| 115 | + delay(500); |
| 116 | + |
| 117 | + Serial.print(F("Rounded rects (filled) ")); |
| 118 | + Serial.println(testFilledRoundRects()); |
| 119 | + delay(500); |
| 120 | + |
| 121 | + Serial.println(F("Done!")); |
| 122 | + |
| 123 | +} |
| 124 | + |
| 125 | + |
| 126 | +void loop(void) { |
| 127 | + for(uint8_t rotation=0; rotation<4; rotation++) { |
| 128 | + tft.setRotation(rotation); |
| 129 | + testText(); |
| 130 | + delay(1000); |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +unsigned long testFillScreen() { |
| 135 | + unsigned long start = micros(); |
| 136 | + tft.fillScreen(ILI9341_BLACK); |
| 137 | + yield(); |
| 138 | + tft.fillScreen(ILI9341_RED); |
| 139 | + yield(); |
| 140 | + tft.fillScreen(ILI9341_GREEN); |
| 141 | + yield(); |
| 142 | + tft.fillScreen(ILI9341_BLUE); |
| 143 | + yield(); |
| 144 | + tft.fillScreen(ILI9341_BLACK); |
| 145 | + yield(); |
| 146 | + return micros() - start; |
| 147 | +} |
| 148 | + |
| 149 | +unsigned long testText() { |
| 150 | + tft.fillScreen(ILI9341_BLACK); |
| 151 | + unsigned long start = micros(); |
| 152 | + tft.setCursor(0, 0); |
| 153 | + tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); |
| 154 | + tft.println("Hello World!"); |
| 155 | + tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2); |
| 156 | + tft.println(1234.56); |
| 157 | + tft.setTextColor(ILI9341_RED); tft.setTextSize(3); |
| 158 | + tft.println(0xDEADBEEF, HEX); |
| 159 | + tft.println(); |
| 160 | + tft.setTextColor(ILI9341_GREEN); |
| 161 | + tft.setTextSize(5); |
| 162 | + tft.println("Groop"); |
| 163 | + tft.setTextSize(2); |
| 164 | + tft.println("I implore thee,"); |
| 165 | + tft.setTextSize(1); |
| 166 | + tft.println("my foonting turlingdromes."); |
| 167 | + tft.println("And hooptiously drangle me"); |
| 168 | + tft.println("with crinkly bindlewurdles,"); |
| 169 | + tft.println("Or I will rend thee"); |
| 170 | + tft.println("in the gobberwarts"); |
| 171 | + tft.println("with my blurglecruncheon,"); |
| 172 | + tft.println("see if I don't!"); |
| 173 | + return micros() - start; |
| 174 | +} |
| 175 | + |
| 176 | +unsigned long testLines(uint16_t color) { |
| 177 | + unsigned long start, t; |
| 178 | + int x1, y1, x2, y2, |
| 179 | + w = tft.width(), |
| 180 | + h = tft.height(); |
| 181 | + |
| 182 | + tft.fillScreen(ILI9341_BLACK); |
| 183 | + yield(); |
| 184 | + |
| 185 | + x1 = y1 = 0; |
| 186 | + y2 = h - 1; |
| 187 | + start = micros(); |
| 188 | + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 189 | + x2 = w - 1; |
| 190 | + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 191 | + t = micros() - start; // fillScreen doesn't count against timing |
| 192 | + |
| 193 | + yield(); |
| 194 | + tft.fillScreen(ILI9341_BLACK); |
| 195 | + yield(); |
| 196 | + |
| 197 | + x1 = w - 1; |
| 198 | + y1 = 0; |
| 199 | + y2 = h - 1; |
| 200 | + start = micros(); |
| 201 | + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 202 | + x2 = 0; |
| 203 | + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 204 | + t += micros() - start; |
| 205 | + |
| 206 | + yield(); |
| 207 | + tft.fillScreen(ILI9341_BLACK); |
| 208 | + yield(); |
| 209 | + |
| 210 | + x1 = 0; |
| 211 | + y1 = h - 1; |
| 212 | + y2 = 0; |
| 213 | + start = micros(); |
| 214 | + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 215 | + x2 = w - 1; |
| 216 | + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 217 | + t += micros() - start; |
| 218 | + |
| 219 | + yield(); |
| 220 | + tft.fillScreen(ILI9341_BLACK); |
| 221 | + yield(); |
| 222 | + |
| 223 | + x1 = w - 1; |
| 224 | + y1 = h - 1; |
| 225 | + y2 = 0; |
| 226 | + start = micros(); |
| 227 | + for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 228 | + x2 = 0; |
| 229 | + for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); |
| 230 | + |
| 231 | + yield(); |
| 232 | + return micros() - start; |
| 233 | +} |
| 234 | + |
| 235 | +unsigned long testFastLines(uint16_t color1, uint16_t color2) { |
| 236 | + unsigned long start; |
| 237 | + int x, y, w = tft.width(), h = tft.height(); |
| 238 | + |
| 239 | + tft.fillScreen(ILI9341_BLACK); |
| 240 | + start = micros(); |
| 241 | + for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1); |
| 242 | + for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2); |
| 243 | + |
| 244 | + return micros() - start; |
| 245 | +} |
| 246 | + |
| 247 | +unsigned long testRects(uint16_t color) { |
| 248 | + unsigned long start; |
| 249 | + int n, i, i2, |
| 250 | + cx = tft.width() / 2, |
| 251 | + cy = tft.height() / 2; |
| 252 | + |
| 253 | + tft.fillScreen(ILI9341_BLACK); |
| 254 | + n = min(tft.width(), tft.height()); |
| 255 | + start = micros(); |
| 256 | + for(i=2; i<n; i+=6) { |
| 257 | + i2 = i / 2; |
| 258 | + tft.drawRect(cx-i2, cy-i2, i, i, color); |
| 259 | + } |
| 260 | + |
| 261 | + return micros() - start; |
| 262 | +} |
| 263 | + |
| 264 | +unsigned long testFilledRects(uint16_t color1, uint16_t color2) { |
| 265 | + unsigned long start, t = 0; |
| 266 | + int n, i, i2, |
| 267 | + cx = tft.width() / 2 - 1, |
| 268 | + cy = tft.height() / 2 - 1; |
| 269 | + |
| 270 | + tft.fillScreen(ILI9341_BLACK); |
| 271 | + n = min(tft.width(), tft.height()); |
| 272 | + for(i=n; i>0; i-=6) { |
| 273 | + i2 = i / 2; |
| 274 | + start = micros(); |
| 275 | + tft.fillRect(cx-i2, cy-i2, i, i, color1); |
| 276 | + t += micros() - start; |
| 277 | + // Outlines are not included in timing results |
| 278 | + tft.drawRect(cx-i2, cy-i2, i, i, color2); |
| 279 | + yield(); |
| 280 | + } |
| 281 | + |
| 282 | + return t; |
| 283 | +} |
| 284 | + |
| 285 | +unsigned long testFilledCircles(uint8_t radius, uint16_t color) { |
| 286 | + unsigned long start; |
| 287 | + int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; |
| 288 | + |
| 289 | + tft.fillScreen(ILI9341_BLACK); |
| 290 | + start = micros(); |
| 291 | + for(x=radius; x<w; x+=r2) { |
| 292 | + for(y=radius; y<h; y+=r2) { |
| 293 | + tft.fillCircle(x, y, radius, color); |
| 294 | + } |
| 295 | + } |
| 296 | + |
| 297 | + return micros() - start; |
| 298 | +} |
| 299 | + |
| 300 | +unsigned long testCircles(uint8_t radius, uint16_t color) { |
| 301 | + unsigned long start; |
| 302 | + int x, y, r2 = radius * 2, |
| 303 | + w = tft.width() + radius, |
| 304 | + h = tft.height() + radius; |
| 305 | + |
| 306 | + // Screen is not cleared for this one -- this is |
| 307 | + // intentional and does not affect the reported time. |
| 308 | + start = micros(); |
| 309 | + for(x=0; x<w; x+=r2) { |
| 310 | + for(y=0; y<h; y+=r2) { |
| 311 | + tft.drawCircle(x, y, radius, color); |
| 312 | + } |
| 313 | + } |
| 314 | + |
| 315 | + return micros() - start; |
| 316 | +} |
| 317 | + |
| 318 | +unsigned long testTriangles() { |
| 319 | + unsigned long start; |
| 320 | + int n, i, cx = tft.width() / 2 - 1, |
| 321 | + cy = tft.height() / 2 - 1; |
| 322 | + |
| 323 | + tft.fillScreen(ILI9341_BLACK); |
| 324 | + n = min(cx, cy); |
| 325 | + start = micros(); |
| 326 | + for(i=0; i<n; i+=5) { |
| 327 | + tft.drawTriangle( |
| 328 | + cx , cy - i, // peak |
| 329 | + cx - i, cy + i, // bottom left |
| 330 | + cx + i, cy + i, // bottom right |
| 331 | + tft.color565(i, i, i)); |
| 332 | + } |
| 333 | + |
| 334 | + return micros() - start; |
| 335 | +} |
| 336 | + |
| 337 | +unsigned long testFilledTriangles() { |
| 338 | + unsigned long start, t = 0; |
| 339 | + int i, cx = tft.width() / 2 - 1, |
| 340 | + cy = tft.height() / 2 - 1; |
| 341 | + |
| 342 | + tft.fillScreen(ILI9341_BLACK); |
| 343 | + start = micros(); |
| 344 | + for(i=min(cx,cy); i>10; i-=5) { |
| 345 | + start = micros(); |
| 346 | + tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, |
| 347 | + tft.color565(0, i*10, i*10)); |
| 348 | + t += micros() - start; |
| 349 | + tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, |
| 350 | + tft.color565(i*10, i*10, 0)); |
| 351 | + yield(); |
| 352 | + } |
| 353 | + |
| 354 | + return t; |
| 355 | +} |
| 356 | + |
| 357 | +unsigned long testRoundRects() { |
| 358 | + unsigned long start; |
| 359 | + int w, i, i2, |
| 360 | + cx = tft.width() / 2 - 1, |
| 361 | + cy = tft.height() / 2 - 1; |
| 362 | + |
| 363 | + tft.fillScreen(ILI9341_BLACK); |
| 364 | + w = min(tft.width(), tft.height()); |
| 365 | + start = micros(); |
| 366 | + for(i=0; i<w; i+=6) { |
| 367 | + i2 = i / 2; |
| 368 | + tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0)); |
| 369 | + } |
| 370 | + |
| 371 | + return micros() - start; |
| 372 | +} |
| 373 | + |
| 374 | +unsigned long testFilledRoundRects() { |
| 375 | + unsigned long start; |
| 376 | + int i, i2, |
| 377 | + cx = tft.width() / 2 - 1, |
| 378 | + cy = tft.height() / 2 - 1; |
| 379 | + |
| 380 | + tft.fillScreen(ILI9341_BLACK); |
| 381 | + start = micros(); |
| 382 | + for(i=min(tft.width(), tft.height()); i>20; i-=6) { |
| 383 | + i2 = i / 2; |
| 384 | + tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); |
| 385 | + yield(); |
| 386 | + } |
| 387 | + |
| 388 | + return micros() - start; |
| 389 | +} |
0 commit comments