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.

tests.ino 8.5KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. unsigned long testPixel() {
  2. tft.fillWindow();
  3. unsigned long start = micros();
  4. tft.drawPixel(0, 0, RA8875_WHITE);
  5. return micros() - start;
  6. }
  7. unsigned long testPixels() {
  8. int green = 0;
  9. tft.fillWindow();
  10. unsigned long start = micros();
  11. for (uint16_t i = 0; i < tft.width(); i++) {
  12. if (green > 255) green = 0;
  13. tft.drawPixel(i, 0, tft.Color565(0, green, 0));
  14. green++;
  15. }
  16. return micros() - start;
  17. }
  18. unsigned long testFillScreen() {
  19. tft.fillWindow();
  20. unsigned long start = micros();
  21. tft.fillWindow(RA8875_RED);
  22. return micros() - start;
  23. }
  24. unsigned long testText() {
  25. tft.clearScreen();
  26. tft.setTextColor(RA8875_WHITE);
  27. tft.setFontScale(0);
  28. unsigned long start = micros();
  29. tft.println("Hello World!");
  30. tft.setTextColor(RA8875_YELLOW);
  31. tft.setFontScale(1);
  32. tft.println(1234.56);
  33. tft.setTextColor(RA8875_RED);
  34. tft.println(0xFFFF, HEX);
  35. tft.println();
  36. tft.setTextColor(RA8875_GREEN);
  37. tft.setFontScale(3);
  38. tft.println("Hello");
  39. tft.setFontScale(0);
  40. tft.println("I implore thee, my foonting turlingdromes.");
  41. tft.println("And hooptiously drangle me");
  42. tft.println("with crinkly bindlewurdles, Or I will rend thee");
  43. tft.println("in the gobberwartswith my blurglecruncheon,");
  44. tft.println("with my blurglecruncheon,");
  45. tft.println("see if I don't!");
  46. unsigned long result = micros() - start;
  47. return result;
  48. }
  49. unsigned long testLines(uint16_t color) {
  50. unsigned long start = 0;
  51. unsigned long t = 0;
  52. uint16_t i;
  53. tft.fillWindow();
  54. start = micros();
  55. for (i = 0; i < tft.width(); i += 6) tft.drawLine(0, 0, i, tft.height() - 1, color);
  56. for (i = 0; i < tft.height(); i += 6) tft.drawLine(0, 0, tft.width() - 1, i, color);
  57. t = micros() - start;//exclude clear screen from count
  58. tft.fillWindow();
  59. start = micros();
  60. for (i = 0; i < tft.width(); i += 6) tft.drawLine(tft.width() - 1, 0, i, tft.height() - 1, color);
  61. for (i = 0; i < tft.height(); i += 6) tft.drawLine(tft.width() - 1, 0, 0, i, color);
  62. t += micros() - start;
  63. tft.fillWindow();
  64. start = micros();
  65. for (i = 0; i < tft.width(); i += 6) tft.drawLine(0, tft.height() - 1, i, 0, color);
  66. for (i = 0; i < tft.height(); i += 6) tft.drawLine(0, tft.height() - 1, tft.width() - 1, i, color);
  67. t += micros() - start;
  68. tft.fillWindow();
  69. start = micros();
  70. for (i = 0; i < tft.width(); i += 6) tft.drawLine(tft.width() - 1, tft.height() - 1, i, 0, color);
  71. for (i = 0; i < tft.height(); i += 6) tft.drawLine(tft.width() - 1, tft.height() - 1, 0, i, color);
  72. return micros() - start;
  73. }
  74. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  75. unsigned long start;
  76. uint16_t i;
  77. tft.clearScreen();
  78. start = micros();
  79. for (i = 0; i < tft.height(); i += 5) tft.drawFastHLine(0, i, tft.width() - 1, color1);
  80. for (i = 0; i < tft.width(); i += 5) tft.drawFastVLine(i, 0, tft.height() - 1, color2);
  81. return micros() - start;
  82. }
  83. unsigned long testRects(uint16_t color) {
  84. unsigned long start;
  85. uint16_t i;
  86. uint16_t i2;
  87. uint16_t cx = tft.width() / 2;
  88. uint16_t cy = tft.height() / 2;
  89. uint16_t n = min(tft.width(), tft.height());
  90. tft.fillWindow();
  91. start = micros();
  92. for (i = 2; i < n; i += 6) {
  93. i2 = i / 2;
  94. tft.drawRect(cx - i2, cy - i2, i, i, color);
  95. }
  96. return micros() - start;
  97. }
  98. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  99. unsigned long start;
  100. unsigned long t = 0;
  101. int n, i, i2,
  102. cx = tft.width() / 2,
  103. cy = tft.height() / 2;
  104. tft.fillWindow();
  105. n = min(tft.width(), tft.height());
  106. start = micros();
  107. for (i = 2; i < n; i += 6) {
  108. i2 = i / 2;
  109. tft.fillRect(cx - i2, cy - i2, i, i, color1);
  110. }
  111. t = micros() - start;
  112. for (i = 2; i < n; i += 6) {
  113. i2 = i / 2;
  114. tft.drawRect(cx - i2, cy - i2, i, i, color2);
  115. }
  116. return t;
  117. }
  118. unsigned long testFilledCircles(uint8_t radius, uint16_t color1, uint16_t color2) {
  119. unsigned long start;
  120. //unsigned long t = 0;
  121. uint16_t x;
  122. uint16_t y;
  123. uint16_t r2 = radius * 2;
  124. tft.fillWindow();
  125. start = micros();
  126. for (x = radius; x < tft.width(); x += r2) {
  127. for (y = radius; y < tft.height(); y += r2) {
  128. tft.fillCircle(x, y, radius, color1);
  129. //t += micros() - start;
  130. //tft.drawCircle(x, y, radius, color2);
  131. }
  132. }
  133. return micros() - start;
  134. }
  135. unsigned long testCircles(uint8_t radius, uint16_t color) {
  136. unsigned long start;
  137. uint16_t x;
  138. uint16_t y;
  139. uint16_t r2 = radius * 2;
  140. start = micros();
  141. for (x = 0; x < (tft.width() - radius); x += r2) {
  142. for (y = 0; y < (tft.height() - radius); y += r2) {
  143. tft.drawCircle(x, y, radius, color);
  144. }
  145. }
  146. return micros() - start;
  147. }
  148. unsigned long testTriangles(uint16_t color) {
  149. unsigned long start;
  150. uint16_t i;
  151. uint16_t cx = (tft.width() / 2) - 1;
  152. uint16_t cy = (tft.height() / 2) - 1;
  153. uint16_t n = min(cx, cy);
  154. tft.fillWindow();
  155. start = micros();
  156. for (i = 0; i < n; i += 5) {
  157. // peak,bottom left,bottom right
  158. tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, color);
  159. }
  160. return micros() - start;
  161. }
  162. unsigned long testFilledTriangles(uint16_t color1, uint16_t color2) {
  163. unsigned long start;
  164. unsigned long t = 0;
  165. uint16_t i;
  166. uint16_t cx = (tft.width() / 2) - 1;
  167. uint16_t cy = (tft.height() / 2) - 1;
  168. uint16_t n = min(cx, cy);
  169. tft.fillWindow();
  170. start = micros();
  171. for (i = n; i > 10; i -= 5) {
  172. start = micros();
  173. tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, color1);
  174. //tft.Color565(0, i, i));
  175. t += micros() - start;
  176. tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, color2);
  177. //tft.Color565(i, i, 0));
  178. }
  179. return t;
  180. }
  181. unsigned long testFilledRoundRects() {
  182. unsigned long start;
  183. uint16_t i, d;
  184. tft.fillWindow();
  185. if (tft.getRotation() != 1 && tft.getRotation() != 3) {
  186. d = tft.height() - 1;
  187. } else {
  188. d = tft.width() - 1;
  189. }
  190. start = micros();
  191. for (i = d; i >= 10; i--) {
  192. tft.fillRoundRect(tft.width() / 2 - (i / 2), tft.height() / 2 - (i / 2), i, i, i / 4, tft.htmlTo565(0xFF0000 + i));
  193. }
  194. return micros() - start;
  195. }
  196. unsigned long testRoundRects() {
  197. unsigned long start;
  198. uint16_t i, d;
  199. tft.fillWindow();
  200. if (tft.getRotation() != 1 && tft.getRotation() != 3) {
  201. d = tft.height() - 1;
  202. } else {
  203. d = tft.width() - 1;
  204. }
  205. start = micros();
  206. for (i = d; i >= 10; i--) {
  207. tft.drawRoundRect(tft.width() / 2 - (i / 2), tft.height() / 2 - (i / 2), i, i, i / 4, random(0xFFFF));
  208. }
  209. return micros() - start;
  210. }
  211. void test(uint8_t rot) {
  212. tft.clearScreen();
  213. tft.setRotation(rot);
  214. tft.setCursor(CENTER,CENTER);
  215. tft.setTextColor(RA8875_WHITE);
  216. tft.setFontScale(2);
  217. tft.print("Rotation:");
  218. tft.print(rot);
  219. tft.setFontScale(2);
  220. tft.setCursor(0,0);
  221. delay(1000);
  222. Serial.print(F("screen:"));
  223. Serial.print(tft.width());
  224. Serial.print("x");
  225. Serial.print(tft.height());
  226. Serial.print(" - rotation:");
  227. Serial.print(rot);
  228. Serial.println(F("\nBenchmark Time (microseconds)"));
  229. Serial.print(F("Screen fill "));
  230. Serial.println(testFillScreen());
  231. delay(DELAY_BETWEEN);
  232. Serial.print(F("Test Pixel "));
  233. Serial.println(testPixel());
  234. delay(DELAY_BETWEEN);
  235. Serial.print(F("Test Pixels "));
  236. Serial.println(testPixels());
  237. delay(DELAY_BETWEEN);
  238. /*
  239. Serial.print(F("Text "));
  240. Serial.println(testText());
  241. delay(DELAY_BETWEEN);
  242. */
  243. /*
  244. Serial.print(F("Lines "));
  245. Serial.println(testLines(RA8875_CYAN));
  246. delay(DELAY_BETWEEN);
  247. */
  248. /*
  249. Serial.print(F("Horiz/Vert Lines "));
  250. Serial.println(testFastLines(RA8875_RED, RA8875_BLUE));
  251. delay(DELAY_BETWEEN);
  252. */
  253. Serial.print(F("Rectangles (outline) "));
  254. Serial.println(testRects(RA8875_GREEN));
  255. delay(DELAY_BETWEEN);
  256. /*
  257. Serial.print(F("Rectangles (filled) "));
  258. Serial.println(testFilledRects(RA8875_YELLOW, RA8875_MAGENTA));
  259. delay(DELAY_BETWEEN);
  260. */
  261. /*
  262. Serial.print(F("Circles (filled) "));
  263. Serial.println(testFilledCircles(10, RA8875_MAGENTA, RA8875_YELLOW));
  264. delay(DELAY_BETWEEN);
  265. */
  266. /*
  267. Serial.print(F("Circles (outline) "));
  268. Serial.println(testCircles(10, RA8875_WHITE));
  269. delay(DELAY_BETWEEN);
  270. */
  271. Serial.print(F("Triangles (outline) "));
  272. Serial.println(testTriangles(RA8875_CYAN));
  273. delay(DELAY_BETWEEN);
  274. Serial.print(F("Triangles (filled) "));
  275. Serial.println(testFilledTriangles(RA8875_RED, RA8875_CYAN));
  276. delay(DELAY_BETWEEN);
  277. /*
  278. Serial.print(F("Rounded rects (outline) "));
  279. Serial.println(testRoundRects());
  280. delay(DELAY_BETWEEN);
  281. Serial.print(F("Rounded rects (filled) "));
  282. Serial.println(testFilledRoundRects());
  283. delay(DELAY_BETWEEN);
  284. */
  285. Serial.println(F("--------------------------------\n"));
  286. }