diff --git a/edge-e/firmware/sailframes_edge/User_Setup.h b/edge-e/firmware/sailframes_edge/User_Setup.h index 6e410c62..5308f414 100644 --- a/edge-e/firmware/sailframes_edge/User_Setup.h +++ b/edge-e/firmware/sailframes_edge/User_Setup.h @@ -1,31 +1,44 @@ // ============================================================ -// SailFrames E1 — TFT_eSPI User_Setup.h -// Hosyond 3.5" IPS ST7796U, 480x320, SPI +// SailFrames Edge — TFT_eSPI User_Setup.h +// E (LG290P): Hosyond 3.5" IPS ST7796U, 480x320, SPI (default) +// B (LC29HEA): Hosyond 2.8" IPS ILI9341V, 240x320, SPI (-DBUILD_B1) // -// Copy this file to your TFT_eSPI library folder, OR -// #define USER_SETUP_LOADED before including TFT_eSPI.h +// #define USER_SETUP_LOADED is set here so TFT_eSPI uses THIS file +// (it is #included by sailframes_edge.ino before ). // ============================================================ #define USER_SETUP_LOADED -#define ST7796_DRIVER - -#define TFT_WIDTH 320 -#define TFT_HEIGHT 480 - -// ESP32 SPI pin assignments +#ifdef BUILD_B1 + // ---- B1: 2.8" 240x320 ILI9341V, 4-line SPI ---- + // Capacitive touch (FT6336G, I2C) is a SEPARATE chip and is NOT wired on B1 + // (J9 CTP_SCL = NC) — unused. + #define ILI9341_DRIVER + #define TFT_WIDTH 240 + #define TFT_HEIGHT 320 + // ⚠ Do NOT define TFT_BL on B1: GPIO19 is PWR_HOLD (the v0.13 self-power + // latch). TFT_eSPI must never drive GPIO19. The real backlight is GPIO25, + // PWM'd by the firmware (TFT_BL_PIN in the .ino). B1's TFT MISO is not wired + // (J9 SDO_MISO = NC). + #define TFT_MISO -1 +#else + // ---- E: 3.5" 320x480 ST7796U ---- + #define ST7796_DRIVER + #define TFT_WIDTH 320 + #define TFT_HEIGHT 480 + #define TFT_MISO 25 // Swapped with BL to match soldered E1 wiring + #define TFT_BL 19 // Swapped with MISO to match soldered E1 wiring + #define TFT_BACKLIGHT_ON HIGH +#endif + +// ESP32 SPI pin assignments (common to both displays) #define TFT_MOSI 23 -#define TFT_MISO 25 // Swapped with BL to match soldered wiring #define TFT_SCLK 18 #define TFT_CS 5 #define TFT_DC 2 #define TFT_RST 4 -// Backlight pin -#define TFT_BL 19 // Swapped with MISO to match soldered wiring -#define TFT_BACKLIGHT_ON HIGH - -// SPI frequency — 40MHz is safe for ST7796, can try 80MHz if stable +// SPI frequency — 40MHz is safe for both ST7796 and ILI9341 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 20000000 #define SPI_TOUCH_FREQUENCY 2500000 diff --git a/edge-e/firmware/sailframes_edge/sailframes_edge.ino b/edge-e/firmware/sailframes_edge/sailframes_edge.ino index 6ca2870f..9fc190b1 100644 --- a/edge-e/firmware/sailframes_edge/sailframes_edge.ino +++ b/edge-e/firmware/sailframes_edge/sailframes_edge.ino @@ -154,8 +154,13 @@ #define GPS_BAUD 460800 // LG290P configured rate #define SERIAL_BAUD 115200 -#define SCREEN_WIDTH 320 // TFT portrait width -#define SCREEN_HEIGHT 480 // TFT portrait height +#ifdef BUILD_B1 +#define SCREEN_WIDTH 240 // B1: 2.8" ILI9341 portrait width +#define SCREEN_HEIGHT 320 // B1: 2.8" ILI9341 portrait height +#else +#define SCREEN_WIDTH 320 // E: 3.5" ST7796 portrait width +#define SCREEN_HEIGHT 480 // E: 3.5" ST7796 portrait height +#endif #define BNO085_ADDR 0x4B // GY-BNO08X breakout (ADO pin high) #define DPS310_ADDR 0x77 // Pressure/temperature sensor #define GPS_FIX_TIMEOUT_MS 300000 @@ -316,7 +321,11 @@ struct PressureData { // v2.0.0 foundation globals. Types live in v2_types.h (included at top // of file) so Arduino's auto-generated forward declarations can resolve // them. +#ifdef BUILD_B1 +HardwarePlatform g_hw = HW_B1; // B1 build default — a no-SD boot still uses the LC29H path +#else HardwarePlatform g_hw = HW_E1; +#endif UnitRole g_role = ROLE_RACING_BOAT; RadioMode g_radio_mode = MODE_BOOT; @@ -401,7 +410,11 @@ struct Config { int stop_delay_sec = 180; // v2.0.0 foundation (SF_FIRMWARE_V2_SPEC.md Stage 1) +#ifdef BUILD_B1 + char hardware_platform[8] = "b1"; // "e1" or "b1" (B1 build default) +#else char hardware_platform[8] = "e1"; // "e1" or "b1" +#endif char unit_role[24] = "racing_boat"; int config_version = 0; // bumped by cloud config sync (Stage 3) // RTK Phase-2 (docs/RTK_PHASE2_DESIGN.md). SD-config ONLY — deliberately NOT @@ -2229,7 +2242,11 @@ void setup() { } // TFT Display - Initialize AFTER SD +#ifdef BUILD_B1 + Serial.println("[TFT] Initializing ILI9341V (B1 2.8\" 240x320)..."); +#else Serial.println("[TFT] Initializing ST7796U..."); +#endif // Backlight via PWM so we can dim during idle. Init at IDLE level — // updateBacklight() in the loop pushes to RECORDING when logging starts. // Core 3.x ledcAttach: one call attaches a pin with freq + resolution, @@ -2238,10 +2255,18 @@ void setup() { ledcWrite(TFT_BL_PIN, TFT_BL_DUTY_IDLE); tft.init(); tft.setRotation(2); // Portrait orientation (180° from rotation 0) +#ifdef BUILD_B1 + tft.invertDisplay(true); // ILI9341 IPS on B1 — bench-confirmed colors need inversion +#else tft.invertDisplay(true); // Required for correct colors on this ST7796 panel +#endif tft.fillScreen(COLOR_BG); oledOK = true; +#ifdef BUILD_B1 + Serial.println("[TFT] ILI9341V initialized (240x320 portrait)"); +#else Serial.println("[TFT] ST7796U initialized (320x480 portrait)"); +#endif // SD-card fault gate. If the card never came up, loadConfig() never ran // and config.boat_id is still its compile-time default ("E1"). Booting on @@ -2254,6 +2279,16 @@ void setup() { // in the loop below still yields to the IDF idle task, keeping its // watchdog fed. Recovery is operator action: reseat the card + power-cycle. if (!sdOK) { +#ifdef BUILD_B1 + // B1.0 hardware has a dead microSD (J5 net→pad bug, fixed in v0.13). For + // bring-up, continue in DEGRADED mode instead of halting: no logging, the + // sentinel boat_id "UNCFG" (non-colliding), but TFT + GNSS + power latch all + // come up. The identity-impersonation risk the E gate below guards against + // does NOT apply — UNCFG never collides with a real boat. E build keeps the + // halt (this whole branch is compiled out without -DBUILD_B1). + Serial.println("[SD] B1 build: SD unavailable — continuing in DEGRADED mode " + "(no logging, boat_id=UNCFG). v0.13 hardware fixes the SD."); +#else tft.fillScreen(COLOR_BG); tft.setTextDatum(MC_DATUM); tft.setTextColor(COLOR_ERROR, COLOR_BG); @@ -2273,6 +2308,7 @@ void setup() { Serial.println("[SD] HALTED: SD card failure — see TFT for contact info."); delay(5000); // yields to idle task so the IDF idle WDT stays fed } +#endif } // Splash screen - show device ID, domain, and firmware version @@ -2281,7 +2317,11 @@ void setup() { // Draw device ID in HUGE font (fill most of the screen) tft.setTextColor(COLOR_TEXT, COLOR_BG); +#ifdef BUILD_B1 + tft.setTextSize(3); // 2.8" 240px wide: a 5-char id ("UNCFG") must fit +#else tft.setTextSize(8); +#endif tft.drawString(config.boat_id, SCREEN_WIDTH/2, SCREEN_HEIGHT/2 - 60, 4); // "Sailframes.com" - black, medium size @@ -2291,7 +2331,11 @@ void setup() { // Firmware version at bottom - large enough to read across the cabin tft.setTextColor(COLOR_LABEL, COLOR_BG); +#ifdef BUILD_B1 + tft.setTextSize(1); // "2026.06.08.03" at size 2 font 4 overflows 240px +#else tft.setTextSize(2); +#endif tft.drawString(FW_VERSION, SCREEN_WIDTH/2, SCREEN_HEIGHT - 40, 4); tft.setTextSize(1); @@ -2624,7 +2668,18 @@ void lc29hConfigBase() { // Single entry point used at boot + on the `gps` reconfig command. With RTK // off this is EXACTLY configureLG290P() (byte-identical legacy path). void gnssConfigure() { - if (!config.rtk_enabled) { configureLG290P(); return; } + if (!config.rtk_enabled) { + configureLG290P(); +#ifdef BUILD_B1 + // B1/LC29HEA: enable EPE (estimated position error) so gps.hacc_m gives a + // live horizontal-accuracy readout on the TFT even with RTK off. Sent after + // configureLG290P()'s save+restart → RAM-only, re-applied every boot. Kept + // out of configureLG290P() so the E (LG290P) build stays byte-identical. + sendPQTM("PQTMCFGMSGRATE,W,PQTMEPE,1,2"); + delay(150); +#endif + return; + } bool base = roleIsBase(); if (g_hw == HW_B1) { if (base) lc29hConfigBase(); else lc29hConfigRover(); } else { if (base) lg290pConfigBase(); else lg290pConfigRover(); } @@ -3779,6 +3834,66 @@ static int prevDispSats = -1; static int prevRecState = -1; // d2LayoutDrawn declared globally near other display flags +// ---- D2 layout geometry ---------------------------------------------------- +// E (3.5" 320x480): the original constants — the #else values below are byte- +// identical to the literals this layout shipped with, so the E build is +// unchanged. B1 (2.8" 240x320): the big fonts shrink to Font 8 x1 (75px) and +// everything repacks into 320 px tall / 240 px wide; the HDOP cell is dropped +// from the top bar (no room at 240 px). +#ifdef BUILD_B1 + #define D2_TOPBAR_H 22 + #define D2_TB_TXT_Y 4 + #define D2_TB_REC_X 3 + #define D2_TB_FIX_X 66 + #define D2_TB_SAT_X 108 + #define D2_TB_SATN_X 150 + #define D2_LBL_X 3 + #define D2_LBL_FONT 2 + #define D2_COG_LBL_Y 24 + #define D2_COG_CLR_Y 42 + #define D2_COG_CLR_H 80 + #define D2_COG_VAL_Y 84 + #define D2_DIV_Y 145 + #define D2_SOG_LBL_Y 148 + #define D2_SOG_CLR_Y 166 + #define D2_SOG_CLR_H 80 + #define D2_SOG_VAL_Y 210 + #define D2_BIG_SZ 1 + #define D2_BAR_CLR_Y 270 + #define D2_BAR_CLR_H 50 + #define D2_BAR_FILL_Y 272 + #define D2_BAR_FILL_H 48 + #define D2_ROW1_Y 278 + #define D2_ROW2_Y 300 +#else + #define D2_TOPBAR_H 30 + #define D2_TB_TXT_Y 7 + #define D2_TB_REC_X 5 + #define D2_TB_FIX_X 100 + #define D2_TB_SAT_X 145 + #define D2_TB_SATN_X 180 + #define D2_TB_HDOP_X 210 + #define D2_TB_HDOPV_X 250 + #define D2_LBL_X 5 + #define D2_LBL_FONT 4 + #define D2_COG_LBL_Y 35 + #define D2_COG_CLR_Y 60 + #define D2_COG_CLR_H 155 + #define D2_COG_VAL_Y 130 + #define D2_DIV_Y 220 + #define D2_SOG_LBL_Y 225 + #define D2_SOG_CLR_Y 250 + #define D2_SOG_CLR_H 155 + #define D2_SOG_VAL_Y 320 + #define D2_BIG_SZ 2 + #define D2_BAR_CLR_Y 430 + #define D2_BAR_CLR_H 50 + #define D2_BAR_FILL_Y 440 + #define D2_BAR_FILL_H 40 + #define D2_ROW1_Y 440 + #define D2_ROW2_Y 456 +#endif + // Compact firmware tag for the status bar — YY.MM.DD.N from // FW_VERSION "YYYY.MM.DD.NN" (e.g. "26.05.20.2" from "2026.05.20.02"). // Lazy-cached. @@ -3841,19 +3956,19 @@ void updateDisplayD2() { // [BLACK: H P AWS AWA / BAT% W | WiFi N R ] (50px, two rows) // BLACK bars for top and bottom - tft.fillRect(0, 0, SCREEN_WIDTH, 30, TFT_BLACK); - tft.fillRect(0, 440, SCREEN_WIDTH, 40, TFT_BLACK); + tft.fillRect(0, 0, SCREEN_WIDTH, D2_TOPBAR_H, TFT_BLACK); + tft.fillRect(0, D2_BAR_FILL_Y, SCREEN_WIDTH, D2_BAR_FILL_H, TFT_BLACK); // Divider between COG and SOG uint16_t lineColor = tft.color565(180, 180, 180); - tft.drawFastHLine(0, 220, SCREEN_WIDTH, lineColor); + tft.drawFastHLine(0, D2_DIV_Y, SCREEN_WIDTH, lineColor); - // Labels for COG and SOG - LARGE (Font 4 = 26px) + // Labels for COG and SOG - LARGE (Font 4 = 26px on E, Font 2 on B1) uint16_t labelColor = tft.color565(100, 100, 100); tft.setTextColor(labelColor, COLOR_BG); tft.setTextDatum(TL_DATUM); - tft.drawString("COG", 5, 35, 4); - tft.drawString("SOG", 5, 225, 4); + tft.drawString("COG", D2_LBL_X, D2_COG_LBL_Y, D2_LBL_FONT); + tft.drawString("SOG", D2_LBL_X, D2_SOG_LBL_Y, D2_LBL_FONT); // Reset prev values prevSOG = prevCOG = prevHeel = prevPitch = -999; @@ -3874,7 +3989,7 @@ void updateDisplayD2() { // TOP BAR: WHITE text on BLACK background // Clear entire top bar first to prevent any ghosting - tft.fillRect(0, 0, SCREEN_WIDTH, 30, TFT_BLACK); + tft.fillRect(0, 0, SCREEN_WIDTH, D2_TOPBAR_H, TFT_BLACK); // Recording state (left side) const char* recStr; @@ -3887,7 +4002,7 @@ void updateDisplayD2() { } tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextDatum(TL_DATUM); - tft.drawString(recStr, 5, 7, 2); + tft.drawString(recStr, D2_TB_REC_X, D2_TB_TXT_Y, 2); // Fix type (0=none, 1=GPS, 2=DGPS/SBAS, 4=RTK fix, 5=RTK float) const char* fixStr; @@ -3898,17 +4013,19 @@ void updateDisplayD2() { case 5: fixStr = "FLT"; break; default: fixStr = "---"; break; } - tft.drawString(fixStr, 100, 7, 2); + tft.drawString(fixStr, D2_TB_FIX_X, D2_TB_TXT_Y, 2); // SAT count - tft.drawString("SAT", 145, 7, 2); + tft.drawString("SAT", D2_TB_SAT_X, D2_TB_TXT_Y, 2); snprintf(buf, sizeof(buf), "%2d", dispSats); - tft.drawString(buf, 180, 7, 2); + tft.drawString(buf, D2_TB_SATN_X, D2_TB_TXT_Y, 2); - // HDOP - tft.drawString("HDOP", 210, 7, 2); +#ifndef BUILD_B1 + // HDOP (dropped on B1 — no room at 240 px wide) + tft.drawString("HDOP", D2_TB_HDOP_X, D2_TB_TXT_Y, 2); snprintf(buf, sizeof(buf), "%.1f", gps.hdop); - tft.drawString(buf, 250, 7, 2); + tft.drawString(buf, D2_TB_HDOPV_X, D2_TB_TXT_Y, 2); +#endif // WiFi status removed from top bar - shown on bottom bar instead } @@ -3916,12 +4033,12 @@ void updateDisplayD2() { // COG area: 30-220 (190px), center at 130 (moved down to not overlap label) if (abs(gps.course - prevCOG) > 0.5) { prevCOG = gps.course; - tft.fillRect(0, 60, SCREEN_WIDTH, 155, COLOR_BG); + tft.fillRect(0, D2_COG_CLR_Y, SCREEN_WIDTH, D2_COG_CLR_H, COLOR_BG); tft.setTextColor(TFT_BLACK, COLOR_BG); tft.setTextDatum(MC_DATUM); - tft.setTextSize(2); + tft.setTextSize(D2_BIG_SZ); snprintf(buf, sizeof(buf), "%03d", (int)gps.course); - tft.drawString(buf, SCREEN_WIDTH/2, 130, 8); + tft.drawString(buf, SCREEN_WIDTH/2, D2_COG_VAL_Y, 8); tft.setTextSize(1); } @@ -3941,14 +4058,43 @@ void updateDisplayD2() { if (strcmp(newSogBuf, prevSogBuf) != 0) { strcpy(prevSogBuf, newSogBuf); prevSOG = gps.speed_kts; - tft.fillRect(0, 250, SCREEN_WIDTH, 155, COLOR_BG); + tft.fillRect(0, D2_SOG_CLR_Y, SCREEN_WIDTH, D2_SOG_CLR_H, COLOR_BG); tft.setTextColor(TFT_BLACK, COLOR_BG); tft.setTextDatum(MC_DATUM); - tft.setTextSize(2); - tft.drawString(newSogBuf, SCREEN_WIDTH/2, 320, 8); + tft.setTextSize(D2_BIG_SZ); + tft.drawString(newSogBuf, SCREEN_WIDTH/2, D2_SOG_VAL_Y, 8); tft.setTextSize(1); } +#ifdef BUILD_B1 + // B1: live GNSS quality in the COG/SOG label rows (top-right). HDOP next to + // COG; horizontal 1-sigma accuracy (gps.hacc_m from $PQTMEPE) next to SOG. + // These rows sit above the big-number clear regions, so value redraws don't + // wipe them. Updated only on change. + static float prevHDOP2 = -999, prevHacc = -999; + if (fabsf(gps.hdop - prevHDOP2) > 0.1f) { + prevHDOP2 = gps.hdop; + tft.fillRect(80, D2_COG_LBL_Y, SCREEN_WIDTH - 80, 18, COLOR_BG); + tft.setTextColor(tft.color565(100, 100, 100), COLOR_BG); + tft.setTextDatum(TR_DATUM); + char hb[16]; snprintf(hb, sizeof(hb), "HDOP %.1f", gps.hdop); + tft.drawString(hb, SCREEN_WIDTH - 3, D2_COG_LBL_Y, 2); + tft.setTextDatum(TL_DATUM); + } + if (fabsf(gps.hacc_m - prevHacc) > 0.005f) { + prevHacc = gps.hacc_m; + tft.fillRect(80, D2_SOG_LBL_Y, SCREEN_WIDTH - 80, 18, COLOR_BG); + tft.setTextColor(tft.color565(100, 100, 100), COLOR_BG); + tft.setTextDatum(TR_DATUM); + char ab[16]; + if (gps.hacc_m <= 0.0f) snprintf(ab, sizeof(ab), "ACC --"); + else if (gps.hacc_m < 1.0f) snprintf(ab, sizeof(ab), "ACC %dcm", (int)lroundf(gps.hacc_m * 100)); + else snprintf(ab, sizeof(ab), "ACC %.1fm", gps.hacc_m); + tft.drawString(ab, SCREEN_WIDTH - 3, D2_SOG_LBL_Y, 2); + tft.setTextDatum(TL_DATUM); + } +#endif + // Bottom status bar - two rows on BLACK background static bool prevWindConnected = true; static bool prevWifiConnected = false; @@ -3983,8 +4129,8 @@ void updateDisplayD2() { prevArmed = g_ocs.armed; // BOTTOM BAR: Two rows - WHITE on BLACK - // Clear entire bottom bar first (50px tall) - tft.fillRect(0, 430, SCREEN_WIDTH, 50, TFT_BLACK); + // Clear entire bottom bar first + tft.fillRect(0, D2_BAR_CLR_Y, SCREEN_WIDTH, D2_BAR_CLR_H, TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK); // Row 1 (y=440): Heel + Pitch always; AWS + AWA appended when wind connected. @@ -4001,7 +4147,7 @@ void updateDisplayD2() { snprintf(row1, sizeof(row1), "H %+.0f P %+.0f%s", imu.heel, imu.pitch, lineTag); } tft.setTextDatum(MC_DATUM); - tft.drawString(row1, SCREEN_WIDTH/2, 440, 2); + tft.drawString(row1, SCREEN_WIDTH/2, D2_ROW1_Y, 2); // Row 2 (y=458): // Left: "BAT N% W" (W appears immediately after BAT% when wind connected) @@ -4018,7 +4164,7 @@ void updateDisplayD2() { } else { snprintf(left, sizeof(left), "BAT %d%% FW%s", battery.percent, fwShortTag()); } - tft.drawString(left, 5, 456, 2); + tft.drawString(left, D2_LBL_X, D2_ROW2_Y, 2); // Right side: WiFi + IP when idle, falls back to counts during traffic. // IP next to the SSID indicator gives a debug surface for telnet/curl @@ -4036,7 +4182,7 @@ void updateDisplayD2() { snprintf(right, sizeof(right), "%s", wifiInd); } tft.setTextDatum(TR_DATUM); - tft.drawString(right, SCREEN_WIDTH - 5, 456, 2); + tft.drawString(right, SCREEN_WIDTH - 5, D2_ROW2_Y, 2); tft.setTextDatum(TL_DATUM); } }