PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

345 lines
8.9KB

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