PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

377 líneas
9.3KB

  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <TFT_ILI9163C.h>
  4. #if defined(__SAM3X8E__)
  5. #undef __FlashStringHelper::F(string_literal)
  6. #define F(string_literal) string_literal
  7. #endif
  8. // Color definitions
  9. #define BLACK 0x0000
  10. #define BLUE 0x001F
  11. #define RED 0xF800
  12. #define GREEN 0x07E0
  13. #define CYAN 0x07FF
  14. #define MAGENTA 0xF81F
  15. #define YELLOW 0xFFE0
  16. #define WHITE 0xFFFF
  17. uint8_t errorCode = 0;
  18. /*
  19. Teensy3.x and Arduino's
  20. You are using 4 wire SPI here, so:
  21. MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  22. MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  23. SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  24. the rest of pin below:
  25. */
  26. #define __CS 10
  27. #define __DC 6
  28. /*
  29. Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
  30. Arduino's 8 bit: any
  31. DUE: check arduino site
  32. If you do not use reset, tie it to +3V3
  33. */
  34. TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC, 23);
  35. void setup() {
  36. Serial.begin(38400);
  37. long unsigned debug_start = millis ();
  38. while (!Serial && ((millis () - debug_start) <= 5000)) ;
  39. tft.begin();
  40. //the following it's mainly for Teensy
  41. //it will help you to understand if you have choosed the
  42. //wrong combination of pins!
  43. errorCode = tft.errorCode();
  44. if (errorCode != 0) {
  45. Serial.print("Init error! ");
  46. if (bitRead(errorCode, 0)) Serial.print("MOSI or SCLK pin mismach!\n");
  47. if (bitRead(errorCode, 1)) Serial.print("CS or DC pin mismach!\n");
  48. } else {
  49. Serial.println(F("Benchmark Time (microseconds)"));
  50. }
  51. if (errorCode == 0) {
  52. Serial.print(F("Screen fill "));
  53. Serial.println(testFillScreen());
  54. delay(500);
  55. Serial.print(F("Text "));
  56. Serial.println(testText());
  57. delay(3000);
  58. Serial.print(F("Text2 "));
  59. Serial.println(testText2());
  60. delay(3000);
  61. Serial.print(F("Lines "));
  62. Serial.println(testLines(CYAN));
  63. delay(500);
  64. Serial.print(F("Horiz/Vert Lines "));
  65. Serial.println(testFastLines(RED, BLUE));
  66. delay(500);
  67. Serial.print(F("Rectangles (outline) "));
  68. Serial.println(testRects(GREEN));
  69. delay(500);
  70. Serial.print(F("Rectangles (filled) "));
  71. Serial.println(testFilledRects(YELLOW, MAGENTA));
  72. delay(500);
  73. Serial.print(F("Circles (filled) "));
  74. Serial.println(testFilledCircles(10, MAGENTA));
  75. Serial.print(F("Circles (outline) "));
  76. Serial.println(testCircles(10, WHITE));
  77. delay(500);
  78. Serial.print(F("Triangles (outline) "));
  79. Serial.println(testTriangles());
  80. delay(500);
  81. Serial.print(F("Triangles (filled) "));
  82. Serial.println(testFilledTriangles());
  83. delay(500);
  84. Serial.print(F("Rounded rects (outline) "));
  85. Serial.println(testRoundRects());
  86. delay(500);
  87. Serial.print(F("Rounded rects (filled) "));
  88. Serial.println(testFilledRoundRects());
  89. delay(500);
  90. Serial.println(F("Done!"));
  91. }
  92. }
  93. void loop(void) {
  94. for (uint8_t rotation = 0; rotation < 4; rotation++) {
  95. tft.setRotation(rotation);
  96. testText();
  97. delay(2000);
  98. }
  99. }
  100. unsigned long testFillScreen() {
  101. unsigned long start = micros();
  102. tft.fillScreen();
  103. tft.fillScreen(RED);
  104. tft.fillScreen(GREEN);
  105. tft.fillScreen(BLUE);
  106. tft.fillScreen();
  107. return micros() - start;
  108. }
  109. unsigned long testText() {
  110. tft.fillScreen();
  111. unsigned long start = micros();
  112. tft.setCursor(0, 0);
  113. tft.setTextColor(WHITE);
  114. tft.setTextSize(1);
  115. tft.println("Hello World!");
  116. tft.setTextColor(YELLOW);
  117. tft.setTextSize(2);
  118. tft.println(1234.56);
  119. tft.setTextColor(RED);
  120. tft.setTextSize(3);
  121. tft.println(0xDEAD, HEX);
  122. tft.println();
  123. tft.setTextColor(GREEN);
  124. tft.setTextSize(4);
  125. tft.println("Hello");
  126. return micros() - start;
  127. }
  128. unsigned long testText2() {
  129. tft.fillScreen();
  130. unsigned long start = micros();
  131. tft.setCursor(0, 0);
  132. tft.setTextColor(WHITE);
  133. tft.setTextSize(2);
  134. tft.println("I implore thee,");
  135. tft.setTextSize(1);
  136. tft.println("my foonting turlingdromes.");
  137. tft.println("And hooptiously drangle me");
  138. tft.println("with crinkly bindlewurdles,");
  139. tft.println("Or I will rend thee");
  140. tft.println("in the gobberwarts");
  141. tft.println("with my blurglecruncheon,");
  142. tft.println("see if I don't!");
  143. return micros() - start;
  144. }
  145. unsigned long testLines(uint16_t color) {
  146. unsigned long start, t;
  147. int x1, y1, x2, y2,
  148. w = tft.width(),
  149. h = tft.height();
  150. tft.fillScreen();
  151. x1 = y1 = 0;
  152. y2 = h - 1;
  153. start = micros();
  154. for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  155. x2 = w - 1;
  156. for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  157. t = micros() - start; // fillScreen doesn't count against timing
  158. tft.fillScreen();
  159. x1 = w - 1;
  160. y1 = 0;
  161. y2 = h - 1;
  162. start = micros();
  163. for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  164. x2 = 0;
  165. for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  166. t += micros() - start;
  167. tft.fillScreen();
  168. x1 = 0;
  169. y1 = h - 1;
  170. y2 = 0;
  171. start = micros();
  172. for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  173. x2 = w - 1;
  174. for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  175. t += micros() - start;
  176. tft.fillScreen();
  177. x1 = w - 1;
  178. y1 = h - 1;
  179. y2 = 0;
  180. start = micros();
  181. for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  182. x2 = 0;
  183. for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  184. return micros() - start;
  185. }
  186. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  187. unsigned long start;
  188. int x, y, w = tft.width(), h = tft.height();
  189. tft.fillScreen();
  190. start = micros();
  191. for (y = 0; y < h; y += 5) tft.drawFastHLine(0, y, w, color1);
  192. for (x = 0; x < w; x += 5) tft.drawFastVLine(x, 0, h, color2);
  193. return micros() - start;
  194. }
  195. unsigned long testRects(uint16_t color) {
  196. unsigned long start;
  197. int n, i, i2,
  198. cx = tft.width() / 2,
  199. cy = tft.height() / 2;
  200. tft.fillScreen();
  201. n = min(tft.width(), tft.height());
  202. start = micros();
  203. for (i = 2; i < n; i += 6) {
  204. i2 = i / 2;
  205. tft.drawRect(cx - i2, cy - i2, i, i, color);
  206. }
  207. return micros() - start;
  208. }
  209. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  210. unsigned long start, t = 0;
  211. int n, i, i2,
  212. cx = (tft.width() / 2) - 1,
  213. cy = (tft.height() / 2) - 1;
  214. tft.fillScreen();
  215. n = min(tft.width(), tft.height());
  216. for (i = n; i > 0; i -= 6) {
  217. i2 = i / 2;
  218. start = micros();
  219. tft.fillRect(cx - i2, cy - i2, i, i, color1);
  220. t += micros() - start;
  221. // Outlines are not included in timing results
  222. tft.drawRect(cx - i2, cy - i2, i, i, color2);
  223. }
  224. return t;
  225. }
  226. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  227. unsigned long start;
  228. int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  229. tft.fillScreen();
  230. start = micros();
  231. for (x = radius; x < w; x += r2) {
  232. for (y = radius; y < h; y += r2) {
  233. tft.fillCircle(x, y, radius, color);
  234. }
  235. }
  236. return micros() - start;
  237. }
  238. unsigned long testCircles(uint8_t radius, uint16_t color) {
  239. unsigned long start;
  240. int x, y, r2 = radius * 2,
  241. w = tft.width() + radius,
  242. h = tft.height() + radius;
  243. // Screen is not cleared for this one -- this is
  244. // intentional and does not affect the reported time.
  245. start = micros();
  246. for (x = 0; x < w; x += r2) {
  247. for (y = 0; y < h; y += r2) {
  248. tft.drawCircle(x, y, radius, color);
  249. }
  250. }
  251. return micros() - start;
  252. }
  253. unsigned long testTriangles() {
  254. unsigned long start;
  255. int n, i, cx = tft.width() / 2 - 1,
  256. cy = (tft.height() / 2) - 1;
  257. tft.fillScreen();
  258. n = min(cx, cy);
  259. start = micros();
  260. for (i = 0; i < n; i += 5) {
  261. tft.drawTriangle(
  262. cx , cy - i, // peak
  263. cx - i, cy + i, // bottom left
  264. cx + i, cy + i, // bottom right
  265. tft.Color565(0, 0, i));
  266. }
  267. return micros() - start;
  268. }
  269. unsigned long testFilledTriangles() {
  270. unsigned long start, t = 0;
  271. int i, cx = (tft.width() / 2) - 1,
  272. cy = tft.height() / 2 - 1;
  273. tft.fillScreen();
  274. start = micros();
  275. for (i = min(cx, cy); i > 10; i -= 5) {
  276. start = micros();
  277. tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  278. tft.Color565(0, i, i));
  279. t += micros() - start;
  280. tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  281. tft.Color565(i, i, 0));
  282. }
  283. return t;
  284. }
  285. unsigned long testRoundRects() {
  286. unsigned long start;
  287. int w, i, i2,
  288. cx = (tft.width() / 2) - 1,
  289. cy = (tft.height() / 2) - 1;
  290. tft.fillScreen();
  291. w = min(tft.width(), tft.height());
  292. start = micros();
  293. for (i = 0; i < w; i += 6) {
  294. i2 = i / 2;
  295. tft.drawRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.Color565(i, 0, 0));
  296. }
  297. return micros() - start;
  298. }
  299. unsigned long testFilledRoundRects() {
  300. unsigned long start;
  301. int i, i2,
  302. cx = (tft.width() / 2) - 1,
  303. cy = (tft.height() / 2) - 1;
  304. tft.fillScreen();
  305. start = micros();
  306. for (i = min(tft.width(), tft.height()); i > 20; i -= 6) {
  307. i2 = i / 2;
  308. tft.fillRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.Color565(0, i, 0));
  309. }
  310. return micros() - start;
  311. }