PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

172 lines
5.1KB

  1. #include <extRAM_t4.h>
  2. extRAM_t4 ext_mem;
  3. #include <ili9488_t3_font_ArialBold.h>
  4. #include <ILI9488_t3.h>
  5. #define TRY_EXTMEM
  6. #define UPDATE_HALF_FRAME
  7. #define ROTATION 3
  8. #include "SPI.h"
  9. //#define USE_SPI1
  10. #if defined(USE_SPI1)
  11. #if defined(__IMXRT1062__) // Teensy 4.x
  12. #define TFT_DC 2
  13. #define TFT_CS 0
  14. #define TFT_RST 3
  15. #define TFT_SCK 27
  16. #define TFT_MISO 1
  17. #define TFT_MOSI 26
  18. #else
  19. #define TFT_DC 31
  20. #define TFT_CS 10 // any pin will work not hardware
  21. #define TFT_RST 8
  22. #define TFT_SCK 32
  23. #define TFT_MISO 5
  24. #define TFT_MOSI 21
  25. //#define DEBUG_PIN 13
  26. #endif
  27. ILI9488_t3 tft = ILI9488_t3(&SPI1, TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);
  28. //------------------------------------
  29. #else // default pins
  30. #define TFT_DC 9 // only CS pin
  31. #define TFT_CS 10 // using standard pin
  32. #define TFT_RST 8
  33. ILI9488_t3 tft = ILI9488_t3(&SPI, TFT_CS, TFT_DC, TFT_RST);
  34. //--------------------------------------
  35. #endif
  36. uint16_t our_pallet[] = {
  37. ILI9488_BLACK, ILI9488_RED, ILI9488_GREEN, ILI9488_BLUE,
  38. ILI9488_YELLOW, ILI9488_ORANGE, ILI9488_CYAN, ILI9488_PINK
  39. };
  40. #define COUNT_SHUTDOWN_FRAMES 16
  41. volatile uint8_t shutdown_cont_update_count = 0xff;
  42. EXTMEM RAFB extmem_frame_buffer[ILI9488_TFTWIDTH * ILI9488_TFTHEIGHT];
  43. void setup() {
  44. while (!Serial && (millis() < 4000)) ;
  45. Serial.begin(115200);
  46. Serial.printf("Begin: CS:%d, DC:%dRST: %d\n", TFT_CS, TFT_DC, TFT_RST);
  47. Serial.printf(" Size of RAFB: %d\n", sizeof(RAFB));
  48. tft.begin(26000000);
  49. tft.setFrameBuffer(extmem_frame_buffer);
  50. tft.setRotation(ROTATION);
  51. ext_mem.begin();
  52. tft.useFrameBuffer(true);
  53. tft.fillScreen(ILI9488_BLACK);
  54. tft.setCursor(ILI9488_t3::CENTER, ILI9488_t3::CENTER);
  55. tft.setTextColor(ILI9488_RED);
  56. tft.setFont(Arial_20_Bold);
  57. tft.println("*** Press key to start ***");
  58. tft.updateScreen();
  59. tft.setFrameCompleteCB(&frame_callback, true);
  60. }
  61. void frame_callback() {
  62. //Serial.printf("FCB: %d %d\n", tft.frameCount(), tft.subFrameCount());
  63. uint32_t frameCount = tft.frameCount();
  64. // See if end of test signalled.
  65. if (shutdown_cont_update_count == COUNT_SHUTDOWN_FRAMES) {
  66. uint8_t color_index = (frameCount >> 4) & 0x7;
  67. tft.setCursor(ILI9488_t3::CENTER, ILI9488_t3::CENTER);
  68. tft.setTextColor(our_pallet[(color_index + 3) & 7]);
  69. tft.setFont(Arial_20_Bold);
  70. tft.println("Stop Signalled");
  71. shutdown_cont_update_count--;
  72. arm_dcache_flush(extmem_frame_buffer, sizeof(extmem_frame_buffer));
  73. } else if (shutdown_cont_update_count == 0) {
  74. tft.setCursor(ILI9488_t3::CENTER, tft.getCursorY());
  75. tft.println("endUpdateAsync");
  76. tft.endUpdateAsync();
  77. Serial.println("after endUpdateAsync");
  78. arm_dcache_flush(extmem_frame_buffer, sizeof(extmem_frame_buffer));
  79. } else if (shutdown_cont_update_count < COUNT_SHUTDOWN_FRAMES) {
  80. shutdown_cont_update_count--;
  81. } else {
  82. #ifdef UPDATE_HALF_FRAME
  83. bool draw_frame = false;
  84. if (((frameCount & 0xf) == 0) && tft.subFrameCount()) {
  85. draw_frame = true;
  86. tft.setClipRect(0, 0, tft.width(), tft.height() / 2);
  87. } else if (((frameCount & 0xf) == 1) && !tft.subFrameCount()) {
  88. draw_frame = true;
  89. tft.setClipRect(0, tft.height() / 2, tft.width(), tft.height() / 2);
  90. }
  91. if (draw_frame)
  92. #else
  93. if (tft.subFrameCount()) {
  94. // lets ignore these right now
  95. return;
  96. }
  97. if ((frameCount & 0xf) == 0)
  98. #endif
  99. {
  100. // First pass ignore subframe...
  101. uint8_t color_index = (frameCount >> 4) & 0x7;
  102. tft.fillScreen(our_pallet[color_index]);
  103. tft.drawRect(5, 5, tft.width() - 10, tft.height() - 10, our_pallet[(color_index + 1) & 7]);
  104. tft.drawRect(25, 25, tft.width() - 50, tft.height() - 50, our_pallet[(color_index + 2) & 7]);
  105. static uint8_t display_other = 0;
  106. switch (display_other) {
  107. case 0:
  108. tft.fillRect(50, 50, tft.width() - 100, tft.height() - 100, our_pallet[(color_index + 1) & 7]);
  109. break;
  110. case 1:
  111. tft.fillCircle(tft.width() / 2, tft.height() / 2, 100, our_pallet[(color_index + 1) & 7]);
  112. break;
  113. case 2:
  114. tft.fillTriangle(50, 50, tft.width() - 50, 50, tft.width() / 2, tft.height() - 50, our_pallet[(color_index + 1) & 7]);
  115. break;
  116. }
  117. if (!tft.subFrameCount()) {
  118. display_other++;
  119. if (display_other > 2) display_other = 0 ;
  120. }
  121. arm_dcache_flush(extmem_frame_buffer, sizeof(extmem_frame_buffer));
  122. tft.setClipRect();
  123. }
  124. }
  125. }
  126. void loop(void) {
  127. // See if any text entered
  128. int ich;
  129. if ((ich = Serial.read()) != -1) {
  130. while (Serial.read() != -1) ;
  131. if (!tft.asyncUpdateActive()) {
  132. // We are not running DMA currently so start it up.
  133. Serial.println("Starting up DMA Updates");
  134. shutdown_cont_update_count = 0xff;
  135. tft.updateScreenAsync(true);
  136. } else {
  137. shutdown_cont_update_count = COUNT_SHUTDOWN_FRAMES;
  138. while (shutdown_cont_update_count) ;
  139. tft.waitUpdateAsyncComplete();
  140. tft.setCursor(ILI9488_t3::CENTER, tft.getCursorY());
  141. tft.print("Finished Test\n");
  142. Serial.println("after waitUpdateAsyncComplete");
  143. Serial.println("Finished test");
  144. delay(2000);
  145. Serial.println("Do normal update to see if data is there");
  146. tft.updateScreen();
  147. }
  148. }
  149. }