/** * RoomViewHW — RoomView on the real T-Deck (ESP32-S3 + ST7789), with * frame-time instrumentation so you can measure how quickly it runs. * * This is the firmware twin of the emulator sketch * (examples/RoomView/RoomView.cpp): both share the device-agnostic * RoomViewCore.h renderer, which draws the whole scene in RGB565 into a * single 320x240 buffer. Here that buffer IS a TFT_eSprite's * frameBuffer() — the rasterizer writes straight into the sprite, and * the sprite is pushed to the panel with the proven NetDeck M1 * anti-flicker pattern (startWrite / pushSprite / endWrite). * * Build & flash (from the repo root): * pio run -e RoomViewHW -t upload * pio device monitor # 115200 baud * * The loop is deliberately free-running (no pacing): the serial report * every 2 s is the true throughput of the renderer + SPI push on this * hardware: * * RoomViewHW: 120 frames in 2001ms = 60.0 fps | render 12.3 ms, push 14.8 ms * * No input is wired: the camera drifts on its own orbit. Keys (a/d, w/s, * r/f, space) only work in the emulator build. */ #include #include #include #include "utilities.h" #include "RoomViewCore.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("RoomViewHW — NetDeck demo map, orbiting 3D view (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 renderer draws directly into its buffer. fb.setColorDepth(16); if (!fb.createSprite(320, 240)) { Serial.println("RoomViewHW: framebuffer alloc failed (stopping)"); while (true) delay(1000); } uint16_t *buf = (uint16_t *)fb.frameBuffer(0); if (!buf) { Serial.println("RoomViewHW: frameBuffer() unavailable (stopping)"); while (true) delay(1000); } rvcore::rvInit(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; rvcore::rvFrame(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("RoomViewHW: %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; } }