From 2fcd9c632c26db5f49ad0d474c04163b12016761 Mon Sep 17 00:00:00 2001 From: Eike Ahmels Date: Fri, 16 May 2025 08:09:04 +0200 Subject: [PATCH 1/3] add font write over msp displayport --- src/main/io/displayport_msp.c | 43 +++++++++++++++++++++++++++++++++++ src/main/io/displayport_msp.h | 5 +++- src/main/msp/msp.c | 7 +++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/main/io/displayport_msp.c b/src/main/io/displayport_msp.c index 08f46491e4..eef351ab6d 100644 --- a/src/main/io/displayport_msp.c +++ b/src/main/io/displayport_msp.c @@ -168,6 +168,45 @@ static uint32_t txBytesFree(const displayPort_t *displayPort) return mspSerialTxBytesFree(); } +#ifdef USE_MSP_DISPLAYPORT_FONT +static bool writeFontCharacter(displayPort_t *displayPort, uint16_t addr, const osdCharacter_t *chr) +{ + uint8_t buf[OSD_CHAR_BYTES + 4]; + + if (!chr) { + return false; + } + + uint8_t *p = buf; + *p++ = MSP_DP_FONTCHAR_WRITE; // command (index 0) + *p++ = addr & 0xff; // address low (index 1) + *p++ = (addr >> 8) & 0xff; // address high (index 2) + *p++ = 0; // padding (index 3) + + memcpy(p, chr->data, OSD_CHAR_BYTES); // write font char data (index >= 4 < len(buf)) + p += OSD_CHAR_BYTES; + int res = output(displayPort, MSP_DISPLAYPORT, buf, p - buf); + + // 80ms delay needed to ensure the MSP display has enough time to process the font data + delay(80); + + return res > 0; +} + +static bool checkReady(displayPort_t *displayPort, bool rescan) +{ + if ( + !displayPort || + displayPort->deviceType != DISPLAYPORT_DEVICE_TYPE_MSP || + !rescan + ) { + return false; + } + + return true; +} +#endif + static const displayPortVTable_t mspDisplayPortVTable = { .grab = grab, .release = release, @@ -182,6 +221,10 @@ static const displayPortVTable_t mspDisplayPortVTable = { .redraw = redraw, .isSynced = isSynced, .txBytesFree = txBytesFree, +#ifdef USE_MSP_DISPLAYPORT_FONT + .writeFontCharacter = writeFontCharacter, + .checkReady = checkReady, +#endif .layerSupported = NULL, .layerSelect = NULL, .layerCopy = NULL, diff --git a/src/main/io/displayport_msp.h b/src/main/io/displayport_msp.h index 25f624bb08..97308cc8ee 100644 --- a/src/main/io/displayport_msp.h +++ b/src/main/io/displayport_msp.h @@ -28,13 +28,16 @@ // MSP Display Port commands typedef enum { - MSP_DP_HEARTBEAT = 0, // Release the display after clearing and updating + MSP_DP_HEARTBEAT = 0, // Release the display after clearing and updating MSP_DP_RELEASE = 1, // Release the display after clearing and updating MSP_DP_CLEAR_SCREEN = 2, // Clear the display MSP_DP_WRITE_STRING = 3, // Write a string at given coordinates MSP_DP_DRAW_SCREEN = 4, // Trigger a screen draw MSP_DP_OPTIONS = 5, // Not used by Betaflight. Reserved by Ardupilot and INAV MSP_DP_SYS = 6, // Display system element displayportSystemElement_e at given coordinates +#ifdef USE_MSP_DISPLAYPORT_FONT + MSP_DP_FONTCHAR_WRITE = 7, // New OSD chip works over MSP, enables font write over MSP +#endif MSP_DP_COUNT, } displayportMspCommand_e; diff --git a/src/main/msp/msp.c b/src/main/msp/msp.c index 3f6aeca7b2..7bdc7b0211 100644 --- a/src/main/msp/msp.c +++ b/src/main/msp/msp.c @@ -943,6 +943,7 @@ static bool mspCommonProcessOutCommand(int16_t cmdMSP, sbuf_t *dst, mspPostProce #define OSD_FLAGS_OSD_HARDWARE_MAX_7456 (1 << 4) #define OSD_FLAGS_OSD_DEVICE_DETECTED (1 << 5) #define OSD_FLAGS_OSD_MSP_DEVICE (1 << 6) +#define OSD_FLAGS_OSD_HARDWARE_AIRBOT_THEIA_OSD (1 << 7) uint8_t osdFlags = 0; @@ -967,7 +968,11 @@ static bool mspCommonProcessOutCommand(int16_t cmdMSP, sbuf_t *dst, mspPostProce break; case OSD_DISPLAYPORT_DEVICE_MSP: - osdFlags |= OSD_FLAGS_OSD_MSP_DEVICE; + osdFlags |= OSD_FLAGS_OSD_MSP_DEVICE +#ifdef USE_MSP_DISPLAYPORT_FONT + | OSD_FLAGS_OSD_HARDWARE_AIRBOT_THEIA_OSD +#endif + ; if (displayIsReady) { osdFlags |= OSD_FLAGS_OSD_DEVICE_DETECTED; } From 369e87a694e7235b957e229b0dfd7f9fab2a384e Mon Sep 17 00:00:00 2001 From: Eike Ahmels Date: Mon, 19 May 2025 07:56:15 +0200 Subject: [PATCH 2/3] refactor to packed struct --- src/main/io/displayport_msp.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/io/displayport_msp.c b/src/main/io/displayport_msp.c index eef351ab6d..4bf7190eb5 100644 --- a/src/main/io/displayport_msp.c +++ b/src/main/io/displayport_msp.c @@ -47,6 +47,14 @@ static displayPort_t mspDisplayPort; static serialPortIdentifier_e displayPortSerial; +typedef struct displayPortMspCommand_s { + uint8_t command; + uint8_t row; + uint8_t col; + uint8_t attribute; + uint8_t data[OSD_CHAR_BYTES]; +} __attribute__((packed)) displayPortMspCommand_t; + static int output(displayPort_t *displayPort, uint8_t cmd, uint8_t *buf, int len) { UNUSED(displayPort); @@ -171,21 +179,20 @@ static uint32_t txBytesFree(const displayPort_t *displayPort) #ifdef USE_MSP_DISPLAYPORT_FONT static bool writeFontCharacter(displayPort_t *displayPort, uint16_t addr, const osdCharacter_t *chr) { - uint8_t buf[OSD_CHAR_BYTES + 4]; + displayPortMspCommand_t displayPortCommand; if (!chr) { return false; } - uint8_t *p = buf; - *p++ = MSP_DP_FONTCHAR_WRITE; // command (index 0) - *p++ = addr & 0xff; // address low (index 1) - *p++ = (addr >> 8) & 0xff; // address high (index 2) - *p++ = 0; // padding (index 3) + displayPortCommand.command = MSP_DP_FONTCHAR_WRITE; + displayPortCommand.row = addr & 0xff; + displayPortCommand.col = (addr >> 8) & 0xff; + displayPortCommand.attribute = 0; - memcpy(p, chr->data, OSD_CHAR_BYTES); // write font char data (index >= 4 < len(buf)) - p += OSD_CHAR_BYTES; - int res = output(displayPort, MSP_DISPLAYPORT, buf, p - buf); + memcpy(displayPortCommand.data, chr->data, OSD_CHAR_BYTES); + + int res = output(displayPort, MSP_DISPLAYPORT, (uint8_t*)&displayPortCommand, OSD_CHAR_BYTES + 4); // 80ms delay needed to ensure the MSP display has enough time to process the font data delay(80); From cd24c216e3bb0086c89952085e66a3f7bc64ed60 Mon Sep 17 00:00:00 2001 From: Eike Ahmels Date: Mon, 19 May 2025 07:57:26 +0200 Subject: [PATCH 3/3] Update src/main/io/displayport_msp.h Co-authored-by: Mark Haslinghuis --- src/main/io/displayport_msp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/io/displayport_msp.h b/src/main/io/displayport_msp.h index 97308cc8ee..24456325f6 100644 --- a/src/main/io/displayport_msp.h +++ b/src/main/io/displayport_msp.h @@ -36,7 +36,7 @@ typedef enum { MSP_DP_OPTIONS = 5, // Not used by Betaflight. Reserved by Ardupilot and INAV MSP_DP_SYS = 6, // Display system element displayportSystemElement_e at given coordinates #ifdef USE_MSP_DISPLAYPORT_FONT - MSP_DP_FONTCHAR_WRITE = 7, // New OSD chip works over MSP, enables font write over MSP + MSP_DP_FONTCHAR_WRITE = 7, // New OSD chip works over MSP, enables font write over MSP #endif MSP_DP_COUNT, } displayportMspCommand_e;