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.

389 satır
11KB

  1. /***************************************************
  2. This is our GFX example for the Adafruit ILI9341 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 "ILI9341_t3.h"
  15. #include "font_Arial.h"
  16. // For the Adafruit shield, these are the default.
  17. #define TFT_DC 9
  18. #define TFT_CS 10
  19. // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
  20. ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
  21. void setup() {
  22. tft.begin();
  23. // Note: you can now set the SPI speed to any value
  24. // the default value is 30Mhz, but most ILI9341 displays
  25. // can handle at least 60Mhz and as much as 100Mhz
  26. // tft.setClock(60000000);
  27. tft.fillScreen(ILI9341_BLACK);
  28. tft.setTextColor(ILI9341_YELLOW);
  29. tft.setTextSize(2);
  30. tft.println("Waiting for Arduino Serial Monitor...");
  31. Serial.begin(9600);
  32. while (!Serial) ; // wait for Arduino Serial Monitor
  33. Serial.println("ILI9341 Test!");
  34. // read diagnostics (optional but can help debug problems)
  35. uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  36. Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  37. x = tft.readcommand8(ILI9341_RDMADCTL);
  38. Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  39. x = tft.readcommand8(ILI9341_RDPIXFMT);
  40. Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  41. x = tft.readcommand8(ILI9341_RDIMGFMT);
  42. Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  43. x = tft.readcommand8(ILI9341_RDSELFDIAG);
  44. Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
  45. Serial.println(F("Benchmark Time (microseconds)"));
  46. Serial.print(F("Screen fill "));
  47. Serial.println(testFillScreen());
  48. delay(200);
  49. Serial.print(F("Text "));
  50. Serial.println(testText());
  51. delay(600);
  52. Serial.print(F("Proportional Text "));
  53. Serial.println(testProportionalText());
  54. delay(600);
  55. Serial.print(F("Lines "));
  56. Serial.println(testLines(ILI9341_CYAN));
  57. delay(200);
  58. Serial.print(F("Horiz/Vert Lines "));
  59. Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
  60. delay(200);
  61. Serial.print(F("Rectangles (outline) "));
  62. Serial.println(testRects(ILI9341_GREEN));
  63. delay(200);
  64. Serial.print(F("Rectangles (filled) "));
  65. Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
  66. delay(200);
  67. Serial.print(F("Circles (filled) "));
  68. Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
  69. Serial.print(F("Circles (outline) "));
  70. Serial.println(testCircles(10, ILI9341_WHITE));
  71. delay(200);
  72. Serial.print(F("Triangles (outline) "));
  73. Serial.println(testTriangles());
  74. delay(200);
  75. Serial.print(F("Triangles (filled) "));
  76. Serial.println(testFilledTriangles());
  77. delay(200);
  78. Serial.print(F("Rounded rects (outline) "));
  79. Serial.println(testRoundRects());
  80. delay(200);
  81. Serial.print(F("Rounded rects (filled) "));
  82. Serial.println(testFilledRoundRects());
  83. delay(200);
  84. Serial.println(F("Done!"));
  85. }
  86. void loop(void) {
  87. for(uint8_t rotation=0; rotation<4; rotation++) {
  88. tft.setRotation(rotation);
  89. testText();
  90. delay(1000);
  91. }
  92. }
  93. unsigned long testFillScreen() {
  94. unsigned long start = micros();
  95. tft.fillScreen(ILI9341_BLACK);
  96. tft.fillScreen(ILI9341_RED);
  97. tft.fillScreen(ILI9341_GREEN);
  98. tft.fillScreen(ILI9341_BLUE);
  99. tft.fillScreen(ILI9341_BLACK);
  100. return micros() - start;
  101. }
  102. unsigned long testText() {
  103. tft.fillScreen(ILI9341_BLACK);
  104. unsigned long start = micros();
  105. tft.setCursor(0, 0);
  106. tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1);
  107. tft.println("Hello World!");
  108. tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
  109. tft.println(1234.56);
  110. tft.setTextColor(ILI9341_RED); tft.setTextSize(3);
  111. tft.println(0xDEADBEEF, HEX);
  112. tft.println();
  113. tft.setTextColor(ILI9341_GREEN);
  114. tft.setTextSize(5);
  115. tft.println("Groop");
  116. tft.setTextSize(2);
  117. tft.println("I implore thee,");
  118. tft.setTextSize(1);
  119. tft.println("my foonting turlingdromes.");
  120. tft.println("And hooptiously drangle me");
  121. tft.println("with crinkly bindlewurdles,");
  122. tft.println("Or I will rend thee");
  123. tft.println("in the gobberwarts");
  124. tft.println("with my blurglecruncheon,");
  125. tft.println("see if I don't!");
  126. return micros() - start;
  127. }
  128. unsigned long testProportionalText() {
  129. tft.fillScreen(ILI9341_BLACK);
  130. unsigned long start = micros();
  131. tft.setCursor(0, 0);
  132. tft.setTextColor(ILI9341_WHITE); tft.setFont(Arial_10);
  133. tft.println("Hello World!");
  134. tft.setTextColor(ILI9341_YELLOW); tft.setFont(Arial_16);
  135. tft.println(1234.56);
  136. tft.setTextColor(ILI9341_RED); tft.setFont(Arial_24);
  137. tft.println(0xDEADBEEF, HEX);
  138. tft.println();
  139. tft.setTextColor(ILI9341_GREEN);
  140. tft.setFont(Arial_40);
  141. tft.println("Groop");
  142. tft.setFont(Arial_16);
  143. tft.println("I implore thee,");
  144. tft.setFont(Arial_10);
  145. tft.println("my foonting turlingdromes.");
  146. tft.println("And hooptiously drangle me");
  147. tft.println("with crinkly bindlewurdles,");
  148. tft.println("Or I will rend thee");
  149. tft.println("in the gobberwarts");
  150. tft.println("with my blurglecruncheon,");
  151. tft.println("see if I don't!");
  152. tft.setFontAdafruit();
  153. return micros() - start;
  154. }
  155. unsigned long testLines(uint16_t color) {
  156. unsigned long start, t;
  157. int x1, y1, x2, y2,
  158. w = tft.width(),
  159. h = tft.height();
  160. tft.fillScreen(ILI9341_BLACK);
  161. x1 = y1 = 0;
  162. y2 = h - 1;
  163. start = micros();
  164. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  165. x2 = w - 1;
  166. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  167. t = micros() - start; // fillScreen doesn't count against timing
  168. tft.fillScreen(ILI9341_BLACK);
  169. x1 = w - 1;
  170. y1 = 0;
  171. y2 = h - 1;
  172. start = micros();
  173. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  174. x2 = 0;
  175. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  176. t += micros() - start;
  177. tft.fillScreen(ILI9341_BLACK);
  178. x1 = 0;
  179. y1 = h - 1;
  180. y2 = 0;
  181. start = micros();
  182. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  183. x2 = w - 1;
  184. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  185. t += micros() - start;
  186. tft.fillScreen(ILI9341_BLACK);
  187. x1 = w - 1;
  188. y1 = h - 1;
  189. y2 = 0;
  190. start = micros();
  191. for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  192. x2 = 0;
  193. for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  194. return micros() - start;
  195. }
  196. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  197. unsigned long start;
  198. int x, y, w = tft.width(), h = tft.height();
  199. tft.fillScreen(ILI9341_BLACK);
  200. start = micros();
  201. for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  202. for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
  203. return micros() - start;
  204. }
  205. unsigned long testRects(uint16_t color) {
  206. unsigned long start;
  207. int n, i, i2,
  208. cx = tft.width() / 2,
  209. cy = tft.height() / 2;
  210. tft.fillScreen(ILI9341_BLACK);
  211. n = min(tft.width(), tft.height());
  212. start = micros();
  213. for(i=2; i<n; i+=6) {
  214. i2 = i / 2;
  215. tft.drawRect(cx-i2, cy-i2, i, i, color);
  216. }
  217. return micros() - start;
  218. }
  219. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  220. unsigned long start, t = 0;
  221. int n, i, i2,
  222. cx = tft.width() / 2 - 1,
  223. cy = tft.height() / 2 - 1;
  224. tft.fillScreen(ILI9341_BLACK);
  225. n = min(tft.width(), tft.height()) - 1;
  226. for(i=n; i>0; i-=6) {
  227. i2 = i / 2;
  228. start = micros();
  229. tft.fillRect(cx-i2, cy-i2, i, i, color1);
  230. t += micros() - start;
  231. // Outlines are not included in timing results
  232. tft.drawRect(cx-i2, cy-i2, i, i, color2);
  233. }
  234. return t;
  235. }
  236. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  237. unsigned long start;
  238. int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  239. tft.fillScreen(ILI9341_BLACK);
  240. start = micros();
  241. for(x=radius; x<w; x+=r2) {
  242. for(y=radius; y<h; y+=r2) {
  243. tft.fillCircle(x, y, radius, color);
  244. }
  245. }
  246. return micros() - start;
  247. }
  248. unsigned long testCircles(uint8_t radius, uint16_t color) {
  249. unsigned long start;
  250. int x, y, r2 = radius * 2,
  251. w = tft.width() + radius,
  252. h = tft.height() + radius;
  253. // Screen is not cleared for this one -- this is
  254. // intentional and does not affect the reported time.
  255. start = micros();
  256. for(x=0; x<w; x+=r2) {
  257. for(y=0; y<h; y+=r2) {
  258. tft.drawCircle(x, y, radius, color);
  259. }
  260. }
  261. return micros() - start;
  262. }
  263. unsigned long testTriangles() {
  264. unsigned long start;
  265. int n, i, cx = tft.width() / 2 - 1,
  266. cy = tft.height() / 2 - 1;
  267. tft.fillScreen(ILI9341_BLACK);
  268. n = min(cx, cy);
  269. start = micros();
  270. for(i=0; i<n; i+=5) {
  271. tft.drawTriangle(
  272. cx , cy - i, // peak
  273. cx - i, cy + i, // bottom left
  274. cx + i, cy + i, // bottom right
  275. tft.color565(0, 0, i));
  276. }
  277. return micros() - start;
  278. }
  279. unsigned long testFilledTriangles() {
  280. unsigned long start, t = 0;
  281. int i, cx = tft.width() / 2 - 1,
  282. cy = tft.height() / 2 - 1;
  283. tft.fillScreen(ILI9341_BLACK);
  284. start = micros();
  285. for(i=min(cx,cy); i>10; i-=5) {
  286. start = micros();
  287. tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  288. tft.color565(0, i, i));
  289. t += micros() - start;
  290. tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  291. tft.color565(i, i, 0));
  292. }
  293. return t;
  294. }
  295. unsigned long testRoundRects() {
  296. unsigned long start;
  297. int w, i, i2,
  298. cx = tft.width() / 2 - 1,
  299. cy = tft.height() / 2 - 1;
  300. tft.fillScreen(ILI9341_BLACK);
  301. w = min(tft.width(), tft.height()) - 1;
  302. start = micros();
  303. for(i=0; i<w; i+=6) {
  304. i2 = i / 2;
  305. tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  306. }
  307. return micros() - start;
  308. }
  309. unsigned long testFilledRoundRects() {
  310. unsigned long start;
  311. int i, i2,
  312. cx = tft.width() / 2 - 1,
  313. cy = tft.height() / 2 - 1;
  314. tft.fillScreen(ILI9341_BLACK);
  315. start = micros();
  316. for(i=min(tft.width(), tft.height()) - 1; i>20; i-=6) {
  317. i2 = i / 2;
  318. tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  319. }
  320. return micros() - start;
  321. }