emulator-template: RGB565 wire-order contract + ready-to-build HW twin
Propagate the lessons from tron-room-demo's hardware bring-up back into the canonical template, so demos are hardware-testable from day one: - Contract change: the sketch renders into emuGfx::fb565 (320x240 uint16_t, RGB565 in PANEL WIRE ORDER - big-endian, the byte sequence the ST7789 receives over SPI, the same convention TFT_eSprite's primitives use). The host expands 565 to 8888 for SDL only. Native little-endian writes look right in the emulator but show byte-swapped on the panel (seen on hardware: BG 0x0002 -> green, fogged floor 0x0882 -> pink) - the new contract makes that bug impossible. - Recommended sketch structure: examples/APP/Core.h holds all rendering/logic device-agnostically (demoInit/demoInput/demoFrame); the .cpp is a thin emulator shell. Bundled sample demonstrates it. - New fw/ scaffold: standalone PlatformIO project (shared boards/lib, T-Deck pin map) with DemoHW.ino driving the same core through a TFT_eSprite frameBuffer() and reporting true fps + render/push split over USB serial every 2 s. -O2 explicitly (pio default -Os skews benchmarks). - shim.h gains rgb565()/wire565() helpers; Makefile deps now include the sketch's headers; --dump now also fires on safety-hatch exit (a long --frames run was silently losing its dump before). Verified: template builds + smoke renders correct 565 colors; DemoHW builds clean for ESP32-S3 (328 KB flash).
This commit is contained in:
@@ -77,6 +77,22 @@ inline uint32_t esp_random()
|
||||
return ((uint32_t)std::rand() << 17) ^ (uint32_t)std::rand() ^ millis();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RGB565 helpers — the panel-facing color format of the T-Deck's ST7789.
|
||||
// The emulator framebuffer contract is RGB565 in PANEL WIRE ORDER
|
||||
// (big-endian): see README "The color contract". Use rgb565() to build
|
||||
// colors and wire565() before storing a pixel into the framebuffer.
|
||||
// ---------------------------------------------------------------------------
|
||||
inline uint16_t rgb565(uint32_t r, uint32_t g, uint32_t b)
|
||||
{
|
||||
return (uint16_t)(((r & 31) << 11) | ((g & 63) << 5) | (b & 31));
|
||||
}
|
||||
|
||||
inline uint16_t wire565(uint16_t c)
|
||||
{
|
||||
return (uint16_t)((c << 8) | (c >> 8));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Minimal String class (Arduino-style)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user