/** * DemoHW — the template's bundled demo on the real T-Deck * (ESP32-S3 + ST7789), with frame-time instrumentation. * * Firmware twin of the emulator sketch (../examples/Demo/Demo.cpp). * Both drive the same device-agnostic DemoCore.h, which renders the * whole scene in RGB565 (panel wire order) into a single 320x240 * buffer. Here that buffer IS a TFT_eSprite's frameBuffer() — the core * writes straight into the sprite, and the sprite is pushed with the * proven NetDeck M1 anti-flicker pattern. * * Build & flash (from the repo root): * pio run -d emulator-template/fw -t upload * pio device monitor # 115200 baud * * The loop is deliberately free-running: the serial report every 2 s is * the true throughput of the core + SPI push on this hardware. */ #include #include #include #include "utilities.h" #include "DemoCore.h" TFT_eSPI tft; static TFT_eSprite fb(&tft); // full-frame 320x240x16 buffer (PSRAM) // --- frame-time accounting --------------------------------------------------- static uint32_t accRenderUs = 0; static uint32_t accPushUs = 0; static uint32_t accFrames = 0; static uint32_t reportT0 = 0; void setup() { Serial.begin(115200); Serial.println(); Serial.println("DemoHW — emulator-template demo on real T-Deck (RGB565)"); Serial.println("Free-running benchmark: report every 2 s over USB serial."); // Proven T-Deck bring-up (same sequence as NetDeck.ino hardwareInit) pinMode(BOARD_POWERON, OUTPUT); digitalWrite(BOARD_POWERON, HIGH); pinMode(BOARD_SDCARD_CS, OUTPUT); pinMode(RADIO_CS_PIN, OUTPUT); pinMode(BOARD_TFT_CS, OUTPUT); digitalWrite(BOARD_SDCARD_CS, HIGH); digitalWrite(RADIO_CS_PIN, HIGH); digitalWrite(BOARD_TFT_CS, HIGH); pinMode(BOARD_SPI_MISO, INPUT_PULLUP); SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); tft.begin(); tft.setRotation(1); // 320x240 landscape tft.fillScreen(TFT_BLACK); pinMode(BOARD_BL_PIN, OUTPUT); digitalWrite(BOARD_BL_PIN, HIGH); // Full-frame 16-bit sprite; the core draws directly into its buffer. fb.setColorDepth(16); if (!fb.createSprite(320, 240)) { Serial.println("DemoHW: framebuffer alloc failed (stopping)"); while (true) delay(1000); } uint16_t *buf = (uint16_t *)fb.frameBuffer(0); if (!buf) { Serial.println("DemoHW: frameBuffer() unavailable (stopping)"); while (true) delay(1000); } demo::demoInit(buf); reportT0 = millis(); } void loop() { static uint32_t lastUs = 0; uint32_t t0 = micros(); // Delta time from real elapsed time — motion speed stays correct no // matter the achieved fps. float dt = lastUs ? (t0 - lastUs) / 1e6f : 1.0f / 60.0f; lastUs = t0; if (dt > 0.1f) dt = 0.1f; demo::demoFrame(dt, millis()); uint32_t renderUs = micros() - t0; // Panel push: the M1 anti-flicker pattern (NetDeck.ino present()). uint32_t p0 = micros(); tft.startWrite(); fb.pushSprite(0, 0); tft.endWrite(); uint32_t pushUs = micros() - p0; // --- accounting --- accRenderUs += renderUs; accPushUs += pushUs; accFrames++; uint32_t elapsed = millis() - reportT0; if (elapsed >= 2000) { float fps = accFrames * 1000.0f / elapsed; float avgRender = accFrames ? accRenderUs / (float)accFrames / 1000.0f : 0.0f; float avgPush = accFrames ? accPushUs / (float)accFrames / 1000.0f : 0.0f; Serial.printf("DemoHW: %lu frames in %lu ms = %.1f fps | " "render %.1f ms, push %.1f ms\n", (unsigned long)accFrames, (unsigned long)elapsed, fps, avgRender, avgPush); reportT0 = millis(); accRenderUs = accPushUs = accFrames = 0; } }