tron-room-demo: free-running hardware benchmark build for the T-Deck
Split the sketch into a device-agnostic renderer core (RoomViewCore.h: RGB565 rasterizer, camera, world sim — no emulator dependencies) plus a thin emulator shell (keyboard pump + the 565-to-8888 presentation blit). Add fw/ as a self-contained PlatformIO project (own platformio.ini pointing at the shared boards/, lib/ and src/netdeck headers — per-env src_dir is not supported by PlatformIO, so NetDeck's top-level config stays untouched). fw/RoomViewHW.ino is the firmware twin: the core rasterizes directly into a TFT_eSprite's frameBuffer() (16-bit, PSRAM) and presents with the proven NetDeck startWrite/pushSprite/endWrite pattern. The loop free-runs and reports true throughput over USB serial every 2 s: fps + average render vs. push split. Verified: emulator render unchanged (smoke frame identical), pio RoomViewHW env builds clean for ESP32-S3 (346 KB flash), make netdeck dual build green.
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* 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 <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
; PlatformIO project for the tron-room-demo hardware benchmark.
|
||||
;
|
||||
; Standalone on purpose (the repo's top-level platformio.ini keeps
|
||||
; src_dir = src/netdeck for NetDeck): this points back at the shared
|
||||
; boards/, lib/ and src/netdeck/ headers, so the firmware twin of the
|
||||
; emulator sketch builds without touching anything NetDeck depends on.
|
||||
;
|
||||
; pio run -d tron-room-demo/fw -t upload # flash the T-Deck
|
||||
; pio device monitor # fps report every 2 s
|
||||
;
|
||||
; Free-running benchmark: no frame pacing. The serial line
|
||||
; RoomViewHW: N frames in M ms = X fps | render Y ms, push Z ms
|
||||
; is the true throughput of the shared RoomViewCore renderer + SPI push.
|
||||
|
||||
[platformio]
|
||||
default_envs = RoomViewHW
|
||||
src_dir = .
|
||||
boards_dir = ../../boards
|
||||
lib_dir = ../../lib
|
||||
|
||||
[env:RoomViewHW]
|
||||
platform = espressif32@6.3.0
|
||||
board = T-Deck
|
||||
framework = arduino
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
build_flags =
|
||||
-DBOARD_HAS_PSRAM=1
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||
-DDISABLE_ALL_LIBRARY_WARNINGS
|
||||
-DSPI_FREQUENCY=80000000
|
||||
-I../../src/netdeck
|
||||
-I..
|
||||
Reference in New Issue
Block a user