PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

350 lines
9.3KB

  1. /***************************************************
  2. This is our GFX example for the Adafruit ILI9488 Breakout and Shield
  3. ----> http://www.adafruit.com/products/1651
  4. Check out the links above for our tutorials and wiring diagrams
  5. These displays use SPI to communicate, 4 or 5 pins are required to
  6. interface (RST is optional)
  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. Written by Limor Fried/Ladyada for Adafruit Industries.
  11. MIT license, all text above must be included in any redistribution
  12. ****************************************************/
  13. #include "SPI.h"
  14. #include "ILI9488_t3.h"
  15. #define TFT_RST 8
  16. #define TFT_DC 9
  17. #define TFT_CS 10
  18. ILI9488_t3 tft = ILI9488_t3(&SPI, TFT_CS, TFT_DC, TFT_RST);
  19. void setup() {
  20. tft.begin();
  21. tft.fillScreen(ILI9488_BLACK);
  22. tft.setTextColor(ILI9488_YELLOW);
  23. tft.setTextSize(2);
  24. tft.println("Waiting for Arduino Serial Monitor...");
  25. tft.setOrigin(0,0);
  26. Serial.begin(9600);
  27. while (!Serial) ; // wait for Arduino Serial Monitor
  28. Serial.println("ILI9488 Test!");
  29. // read diagnostics (optional but can help debug problems)
  30. uint8_t x = tft.readcommand8(ILI9488_RDMODE);
  31. Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  32. x = tft.readcommand8(ILI9488_RDMADCTL);
  33. Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  34. x = tft.readcommand8(ILI9488_RDPIXFMT);
  35. Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  36. x = tft.readcommand8(ILI9488_RDIMGFMT);
  37. Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  38. x = tft.readcommand8(ILI9488_RDSELFDIAG);
  39. Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
  40. Serial.println(F("Benchmark Time (microseconds)"));
  41. Serial.print(F("Screen fill "));
  42. Serial.println(testFillScreen());
  43. delay(200);
  44. Serial.print(F("Text "));
  45. Serial.println(testText());
  46. delay(600);
  47. Serial.print(F("Lines "));
  48. Serial.println(testLines(ILI9488_CYAN));
  49. delay(500);
  50. Serial.print(F("Horiz/Vert Lines "));
  51. Serial.println(testFastLines(ILI9488_RED, ILI9488_BLUE));
  52. delay(500);
  53. Serial.print(F("Rectangles (outline) "));
  54. Serial.println(testRects(ILI9488_GREEN));
  55. delay(500);
  56. Serial.print(F("Rectangles (filled) "));
  57. Serial.println(testFilledRects(ILI9488_YELLOW, ILI9488_MAGENTA));
  58. delay(500);
  59. Serial.print(F("Circles (filled) "));
  60. Serial.println(testFilledCircles(10, ILI9488_MAGENTA));
  61. Serial.print(F("Circles (outline) "));
  62. Serial.println(testCircles(10, ILI9488_WHITE));
  63. delay(200);
  64. Serial.print(F("Triangles (outline) "));
  65. Serial.println(testTriangles());
  66. delay(200);
  67. Serial.print(F("Triangles (filled) "));
  68. Serial.println(testFilledTriangles());
  69. delay(200);
  70. Serial.print(F("Rounded rects (outline) "));
  71. Serial.println(testRoundRects());
  72. delay(200);
  73. Serial.print(F("Rounded rects (filled) "));
  74. Serial.println(testFilledRoundRects());
  75. delay(200);
  76. Serial.println(F("Done!"));
  77. }
  78. void loop(void) {
  79. for(uint8_t rotation=0; rotation<4; rotation++) {
  80. tft.setRotation(rotation);
  81. testText();
  82. delay(1000);
  83. }
  84. }
  85. unsigned long testFillScreen() {
  86. unsigned long start = micros();
  87. tft.fillScreen(ILI9488_BLACK);
  88. tft.fillScreen(ILI9488_RED);
  89. tft.fillScreen(ILI9488_GREEN);
  90. tft.fillScreen(ILI9488_BLUE);
  91. tft.fillScreen(ILI9488_BLACK);
  92. return micros() - start;
  93. }
  94. unsigned long testText() {
  95. tft.fillScreen(ILI9488_BLACK);
  96. unsigned long start = micros();
  97. tft.setCursor(0, 0);
  98. tft.setTextColor(ILI9488_WHITE); tft.setTextSize(1);
  99. tft.println("Hello World!");
  100. tft.setTextColor(ILI9488_YELLOW); tft.setTextSize(2);
  101. tft.println(1234.56);
  102. tft.setTextColor(ILI9488_RED); tft.setTextSize(3);
  103. tft.println(0xDEADBEEF, HEX);
  104. tft.println();
  105. tft.setTextColor(ILI9488_GREEN);
  106. tft.setTextSize(5);
  107. tft.println("Groop");
  108. tft.setTextSize(2);
  109. tft.println("I implore thee,");
  110. tft.setTextSize(1);
  111. tft.println("my foonting turlingdromes.");
  112. tft.println("And hooptiously drangle me");
  113. tft.println("with crinkly bindlewurdles,");
  114. tft.println("Or I will rend thee");
  115. tft.println("in the gobberwarts");
  116. tft.println("with my blurglecruncheon,");
  117. tft.println("see if I don't!");
  118. return micros() - start;
  119. }
  120. unsigned long testLines(uint16_t color) {
  121. unsigned long start, t;
  122. int x1, y1, x2, y2,
  123. w = tft.width(),
  124. h = tft.height();
  125. tft.fillScreen(ILI9488_BLACK);
  126. x1 = y1 = 0;
  127. y2 = h - 1;
  128. start = micros();
  129. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  130. x2 = w - 1;
  131. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  132. t = micros() - start; // fillScreen doesn't count against timing
  133. tft.fillScreen(ILI9488_BLACK);
  134. x1 = w - 1;
  135. y1 = 0;
  136. y2 = h - 1;
  137. start = micros();
  138. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  139. x2 = 0;
  140. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  141. t += micros() - start;
  142. tft.fillScreen(ILI9488_BLACK);
  143. x1 = 0;
  144. y1 = h - 1;
  145. y2 = 0;
  146. start = micros();
  147. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  148. x2 = w - 1;
  149. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  150. t += micros() - start;
  151. tft.fillScreen(ILI9488_BLACK);
  152. x1 = w - 1;
  153. y1 = h - 1;
  154. y2 = 0;
  155. start = micros();
  156. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  157. x2 = 0;
  158. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  159. return micros() - start;
  160. }
  161. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  162. unsigned long start;
  163. int x, y, w = tft.width(), h = tft.height();
  164. tft.fillScreen(ILI9488_BLACK);
  165. start = micros();
  166. for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  167. for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
  168. return micros() - start;
  169. }
  170. unsigned long testRects(uint16_t color) {
  171. unsigned long start;
  172. int n, i, i2,
  173. cx = tft.width() / 2,
  174. cy = tft.height() / 2;
  175. tft.fillScreen(ILI9488_BLACK);
  176. n = min(tft.width(), tft.height());
  177. start = micros();
  178. for(i=2; i<n; i+=6) {
  179. i2 = i / 2;
  180. tft.drawRect(cx-i2, cy-i2, i, i, color);
  181. }
  182. return micros() - start;
  183. }
  184. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  185. unsigned long start, t = 0;
  186. int n, i, i2,
  187. cx = tft.width() / 2 - 1,
  188. cy = tft.height() / 2 - 1;
  189. tft.fillScreen(ILI9488_BLACK);
  190. n = min(tft.width(), tft.height()) - 1;
  191. for(i=n; i>0; i-=6) {
  192. i2 = i / 2;
  193. start = micros();
  194. tft.fillRect(cx-i2, cy-i2, i, i, color1);
  195. t += micros() - start;
  196. // Outlines are not included in timing results
  197. tft.drawRect(cx-i2, cy-i2, i, i, color2);
  198. }
  199. return t;
  200. }
  201. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  202. unsigned long start;
  203. int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  204. tft.fillScreen(ILI9488_BLACK);
  205. start = micros();
  206. for(x=radius; x<w; x+=r2) {
  207. for(y=radius; y<h; y+=r2) {
  208. tft.fillCircle(x, y, radius, color);
  209. }
  210. }
  211. return micros() - start;
  212. }
  213. unsigned long testCircles(uint8_t radius, uint16_t color) {
  214. unsigned long start;
  215. int x, y, r2 = radius * 2,
  216. w = tft.width() + radius,
  217. h = tft.height() + radius;
  218. // Screen is not cleared for this one -- this is
  219. // intentional and does not affect the reported time.
  220. start = micros();
  221. for(x=0; x<w; x+=r2) {
  222. for(y=0; y<h; y+=r2) {
  223. tft.drawCircle(x, y, radius, color);
  224. }
  225. }
  226. return micros() - start;
  227. }
  228. unsigned long testTriangles() {
  229. unsigned long start;
  230. int n, i, cx = tft.width() / 2 - 1,
  231. cy = tft.height() / 2 - 1;
  232. tft.fillScreen(ILI9488_BLACK);
  233. n = min(cx, cy);
  234. start = micros();
  235. for(i=0; i<n; i+=5) {
  236. tft.drawTriangle(
  237. cx , cy - i, // peak
  238. cx - i, cy + i, // bottom left
  239. cx + i, cy + i, // bottom right
  240. tft.color565(0, 0, i));
  241. }
  242. return micros() - start;
  243. }
  244. unsigned long testFilledTriangles() {
  245. unsigned long start, t = 0;
  246. int i, cx = tft.width() / 2 - 1,
  247. cy = tft.height() / 2 - 1;
  248. tft.fillScreen(ILI9488_BLACK);
  249. start = micros();
  250. for(i=min(cx,cy); i>10; i-=5) {
  251. start = micros();
  252. tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  253. tft.color565(0, i, i));
  254. t += micros() - start;
  255. tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  256. tft.color565(i, i, 0));
  257. }
  258. return t;
  259. }
  260. unsigned long testRoundRects() {
  261. unsigned long start;
  262. int w, i, i2,
  263. cx = tft.width() / 2 - 1,
  264. cy = tft.height() / 2 - 1;
  265. tft.fillScreen(ILI9488_BLACK);
  266. w = min(tft.width(), tft.height()) - 1;
  267. start = micros();
  268. for(i=0; i<w; i+=6) {
  269. i2 = i / 2;
  270. tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  271. }
  272. return micros() - start;
  273. }
  274. unsigned long testFilledRoundRects() {
  275. unsigned long start;
  276. int i, i2,
  277. cx = tft.width() / 2 - 1,
  278. cy = tft.height() / 2 - 1;
  279. tft.fillScreen(ILI9488_BLACK);
  280. start = micros();
  281. for(i=min(tft.width(), tft.height()) - 1; i>20; i-=6) {
  282. i2 = i / 2;
  283. tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  284. }
  285. return micros() - start;
  286. }