From f6cdc121ffa966a8d05bf39f3a3c5331314e7332 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:36:02 +0100 Subject: [PATCH 1/6] Add MSP_OSD_CANVAS for completeness --- src/main/fc/fc_msp.c | 29 +++++++++++++++++++++++++ src/main/io/displayport_msp_osd.c | 36 +++++++------------------------ src/main/io/displayport_msp_osd.h | 24 ++++++++++++++++++++- src/main/msp/msp_protocol.h | 3 +++ 4 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index f490d28128a..1d500867dc0 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -87,6 +87,7 @@ #include "io/adsb.h" #include "io/asyncfatfs/asyncfatfs.h" +#include "io/displayport_msp_osd.h" #include "io/flashfs.h" #include "io/gps.h" #include "io/gps_ublox.h" @@ -1186,6 +1187,18 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF serializeSDCardSummaryReply(dst); break; +#ifdef USE_MSP_DISPLAYPORT + case MSP_OSD_CANVAS: + { + displayPort_t *dp = osdGetDisplayPort(); + if(dp != NULL) { + sbufWriteU8(dst, dp->cols); + sbufWriteU8(dst, dp->rows); + } + } + break; +#endif + #if defined (USE_DJI_HD_OSD) || defined (USE_MSP_DISPLAYPORT) case MSP_BATTERY_STATE: // Battery characteristics @@ -2044,6 +2057,22 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) return MSP_RESULT_ERROR; break; +#ifdef USE_MSP_DISPLAYPORT + case MSP_SET_OSD_CANVAS: + { + displayPort_t *dp = osdGetDisplayPort(); + if(dp != NULL && dataSize == 2) { + dp->cols = constrain(sbuReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); + dp->rows = constrain(sbuReadU8(src), 16, MSP_DISPLAYPORT_MAX_ROWS); + } else { + return MSP_RESULT_ERROR; + } + } + break; +#endif + + + case MSP2_INAV_SET_MISC: if (dataSize == 41) { sbufReadU16(src); // midrc diff --git a/src/main/io/displayport_msp_osd.c b/src/main/io/displayport_msp_osd.c index 0b9be8c6d86..ed17ebfa067 100644 --- a/src/main/io/displayport_msp_osd.c +++ b/src/main/io/displayport_msp_osd.c @@ -74,28 +74,8 @@ static bool vtxSeen, vtxActive, vtxReset; static timeMs_t vtxHeartbeat; static timeMs_t sendSubFrameMs = 0; -// PAL screen size -#define PAL_COLS 30 -#define PAL_ROWS 16 -// NTSC screen size -#define NTSC_COLS 30 -#define NTSC_ROWS 13 -// HDZERO screen size -#define HDZERO_COLS 50 -#define HDZERO_ROWS 18 -// Avatar screen size -#define AVATAR_COLS 53 -#define AVATAR_ROWS 20 -// DJIWTF screen size -#define DJI_COLS 60 -#define DJI_ROWS 22 - -// set COLS and ROWS to largest size available -#define COLS DJI_COLS -#define ROWS DJI_ROWS - // set screen size -#define SCREENSIZE (ROWS*COLS) +#define SCREENSIZE (MSP_DISPLAYPORT_MAX_ROWS * MSP_DISPLAYPORT_MAX_COLS) static uint8_t currentOsdMode; // HDZero screen mode can change across layouts @@ -212,7 +192,7 @@ static bool readChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint1 { UNUSED(displayPort); - uint16_t pos = (row * COLS) + col; + uint16_t pos = (row * MSP_DISPLAYPORT_MAX_COLS) + col; if (pos >= SCREENSIZE) { return false; } @@ -248,14 +228,14 @@ static int writeChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint1 { UNUSED(displayPort); - return setChar((row * COLS) + col, c, attr); + return setChar((row * MSP_DISPLAYPORT_MAX_COLS) + col, c, attr); } static int writeString(displayPort_t *displayPort, uint8_t col, uint8_t row, const char *string, textAttributes_t attr) { UNUSED(displayPort); - uint16_t pos = (row * COLS) + col; + uint16_t pos = (row * MSP_DISPLAYPORT_MAX_COLS) + col; while (*string) { setChar(pos++, *string++, attr); } @@ -289,7 +269,7 @@ static int drawScreen(displayPort_t *displayPort) // 250Hz sendSubFrameMs = (osdConfig()->msp_displayport_fullframe_interval > 0) ? (millis() + DS2MS(osdConfig()->msp_displayport_fullframe_interval)) : 0; } - uint8_t subcmd[COLS + 4]; + uint8_t subcmd[MSP_DISPLAYPORT_MAX_COLS + 4]; uint8_t updateCount = 0; subcmd[0] = MSP_DP_WRITE_STRING; @@ -297,10 +277,10 @@ static int drawScreen(displayPort_t *displayPort) // 250Hz while (next >= 0) { // Look for sequential dirty characters on the same line for the same font page int pos = next; - uint8_t row = pos / COLS; - uint8_t col = pos % COLS; + uint8_t row = pos / MSP_DISPLAYPORT_MAX_COLS; + uint8_t col = pos % MSP_DISPLAYPORT_MAX_COLS; uint8_t attributes = 0; - int endOfLine = row * COLS + screenCols; + int endOfLine = row * MSP_DISPLAYPORT_MAX_COLS + screenCols; uint8_t page = getAttrPage(attrs[pos]); uint8_t blink = getAttrBlink(attrs[pos]); diff --git a/src/main/io/displayport_msp_osd.h b/src/main/io/displayport_msp_osd.h index affd5b39be5..5d8db7bd608 100644 --- a/src/main/io/displayport_msp_osd.h +++ b/src/main/io/displayport_msp_osd.h @@ -36,6 +36,28 @@ #define DISPLAYPORT_MSP_ATTR_BLINK_MASK (1 << DISPLAYPORT_MSP_ATTR_BLINK) #define DISPLAYPORT_MSP_ATTR_VERSION_MASK (1 << DISPLAYPORT_MSP_ATTR_VERSION) +// PAL screen size +#define PAL_COLS 30 +#define PAL_ROWS 16 +// NTSC screen size +#define NTSC_COLS 30 +#define NTSC_ROWS 13 +// HDZERO screen size +#define HDZERO_COLS 50 +#define HDZERO_ROWS 18 +// Avatar screen size +#define AVATAR_COLS 53 +#define AVATAR_ROWS 20 +// DJIWTF screen size +#define DJI_COLS 60 +#define DJI_ROWS 22 + +// set COLS and ROWS to largest size available +#define MSP_DISPLAYPORT_MAX_COLS DJI_COLS +#define MSP_DISPLAYPORT_MAX_ROWS DJI_ROWS + + + typedef struct displayPort_s displayPort_t; displayPort_t *mspOsdDisplayPortInit(const videoSystem_e videoSystem); @@ -48,4 +70,4 @@ mspPort_t *getMspOsdPort(void); uint8_t setAttrPage(uint8_t origAttr, uint8_t page); uint8_t setAttrBlink(uint8_t origAttr, uint8_t page); -uint8_t setAttrVersion(uint8_t origAttr, uint8_t page); \ No newline at end of file +uint8_t setAttrVersion(uint8_t origAttr, uint8_t page); diff --git a/src/main/msp/msp_protocol.h b/src/main/msp/msp_protocol.h index ac847afeaec..7bdd11fcc28 100644 --- a/src/main/msp/msp_protocol.h +++ b/src/main/msp/msp_protocol.h @@ -257,6 +257,9 @@ #define MSP_LED_STRIP_MODECOLOR 127 //out message Get LED strip mode_color settings #define MSP_BATTERY_STATE 130 // DJI googles fc battery info +#define MSP_SET_OSD_CANVAS 188 // Sent from VTX to inform OSD canvas size +#define MSP_OSD_CANVAS 189 // Sent from FC to inform configurator about canvas size + #define MSP_SET_RAW_RC 200 //in message 8 rc chan #define MSP_SET_RAW_GPS 201 //in message fix, numsat, lat, lon, alt, speed #define MSP_SET_BOX 203 //in message BOX setup (number is dependant of your setup) From 09436bc54473e05c8c261facf686ac5e42d3d1d1 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:44:03 +0100 Subject: [PATCH 2/6] Fix typo --- src/main/fc/fc_msp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 1d500867dc0..eacfad40f16 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2062,8 +2062,8 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) { displayPort_t *dp = osdGetDisplayPort(); if(dp != NULL && dataSize == 2) { - dp->cols = constrain(sbuReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); - dp->rows = constrain(sbuReadU8(src), 16, MSP_DISPLAYPORT_MAX_ROWS); + dp->cols = constrain(sbfuReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); + dp->rows = constrain(sbufReadU8(src), 16, MSP_DISPLAYPORT_MAX_ROWS); } else { return MSP_RESULT_ERROR; } From b5242b723bf0e091106bfb723da3dab6fad722e3 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:45:55 +0100 Subject: [PATCH 3/6] another typo --- src/main/fc/fc_msp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index eacfad40f16..22234525e55 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2062,7 +2062,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) { displayPort_t *dp = osdGetDisplayPort(); if(dp != NULL && dataSize == 2) { - dp->cols = constrain(sbfuReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); + dp->cols = constrain(sbufReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); dp->rows = constrain(sbufReadU8(src), 16, MSP_DISPLAYPORT_MAX_ROWS); } else { return MSP_RESULT_ERROR; From f100947975873361eb4eecd4a0a3678ea4ffb513 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:28:16 +0100 Subject: [PATCH 4/6] VIDEO_SYSTEM_AUTO will negotiate canvas size --- src/main/fc/fc_msp.c | 18 ++++++++++-------- src/main/io/displayport_msp_osd.c | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 22234525e55..ec1f2fa004f 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2060,14 +2060,16 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_MSP_DISPLAYPORT case MSP_SET_OSD_CANVAS: { - displayPort_t *dp = osdGetDisplayPort(); - if(dp != NULL && dataSize == 2) { - dp->cols = constrain(sbufReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); - dp->rows = constrain(sbufReadU8(src), 16, MSP_DISPLAYPORT_MAX_ROWS); - } else { - return MSP_RESULT_ERROR; - } - } + if (osdConfig()->video_system == VIDEO_SYSTEM_AUTO) { + displayPort_t *dp = osdGetDisplayPort(); + if (dp != NULL && dataSize == 2) { + dp->cols = constrain(sbufReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); + dp->rows = constrain(sbufReadU8(src), 16, MSP_DISPLAYPORT_MAX_ROWS); + } else { + return MSP_RESULT_ERROR; + } + } + } break; #endif diff --git a/src/main/io/displayport_msp_osd.c b/src/main/io/displayport_msp_osd.c index ed17ebfa067..10c9ccd5c74 100644 --- a/src/main/io/displayport_msp_osd.c +++ b/src/main/io/displayport_msp_osd.c @@ -444,7 +444,6 @@ displayPort_t* mspOsdDisplayPortInit(const videoSystem_e videoSystem) { if (mspOsdSerialInit()) { switch(videoSystem) { - case VIDEO_SYSTEM_AUTO: case VIDEO_SYSTEM_DJICOMPAT: case VIDEO_SYSTEM_PAL: currentOsdMode = SD_3016; @@ -461,6 +460,7 @@ displayPort_t* mspOsdDisplayPortInit(const videoSystem_e videoSystem) screenRows = HDZERO_ROWS; screenCols = HDZERO_COLS; break; + case VIDEO_SYSTEM_AUTO: case VIDEO_SYSTEM_DJIWTF: currentOsdMode = HD_6022; screenRows = DJI_ROWS; From fbc33e00b99e759b34968298996cb1c0fe573b29 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:40:20 +0100 Subject: [PATCH 5/6] Add AUTOHD option --- src/main/drivers/osd.h | 3 ++- src/main/fc/fc_msp.c | 4 +--- src/main/fc/settings.yaml | 2 +- src/main/io/displayport_msp_osd.c | 3 ++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/drivers/osd.h b/src/main/drivers/osd.h index a8b0bbc8e42..e1f2658c200 100644 --- a/src/main/drivers/osd.h +++ b/src/main/drivers/osd.h @@ -50,7 +50,8 @@ typedef enum { VIDEO_SYSTEM_DJIWTF, VIDEO_SYSTEM_AVATAR, VIDEO_SYSTEM_DJICOMPAT, - VIDEO_SYSTEM_DJICOMPAT_HD + VIDEO_SYSTEM_DJICOMPAT_HD, + VIDEO_SYSTEM_AUTOHD } videoSystem_e; typedef enum { diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index ec1f2fa004f..7365789cb0e 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2060,7 +2060,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) #ifdef USE_MSP_DISPLAYPORT case MSP_SET_OSD_CANVAS: { - if (osdConfig()->video_system == VIDEO_SYSTEM_AUTO) { + if (osdConfig()->video_system == VIDEO_SYSTEM_AUTOHD) { displayPort_t *dp = osdGetDisplayPort(); if (dp != NULL && dataSize == 2) { dp->cols = constrain(sbufReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); @@ -2073,8 +2073,6 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) break; #endif - - case MSP2_INAV_SET_MISC: if (dataSize == 41) { sbufReadU16(src); // midrc diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 1960e5dac67..185aef617d5 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -67,7 +67,7 @@ tables: values: ["MAH", "WH"] enum: osd_stats_energy_unit_e - name: osd_video_system - values: ["AUTO", "PAL", "NTSC", "HDZERO", "DJIWTF", "AVATAR", "BF43COMPAT", "BFHDCOMPAT"] + values: ["AUTO", "PAL", "NTSC", "HDZERO", "DJIWTF", "AVATAR", "BF43COMPAT", "BFHDCOMPAT", "AUTOHD"] enum: videoSystem_e - name: osd_telemetry values: ["OFF", "ON","TEST"] diff --git a/src/main/io/displayport_msp_osd.c b/src/main/io/displayport_msp_osd.c index 10c9ccd5c74..abf5e4a2133 100644 --- a/src/main/io/displayport_msp_osd.c +++ b/src/main/io/displayport_msp_osd.c @@ -444,6 +444,7 @@ displayPort_t* mspOsdDisplayPortInit(const videoSystem_e videoSystem) { if (mspOsdSerialInit()) { switch(videoSystem) { + case VIDEO_SYSTEM_AUTO: case VIDEO_SYSTEM_DJICOMPAT: case VIDEO_SYSTEM_PAL: currentOsdMode = SD_3016; @@ -460,7 +461,7 @@ displayPort_t* mspOsdDisplayPortInit(const videoSystem_e videoSystem) screenRows = HDZERO_ROWS; screenCols = HDZERO_COLS; break; - case VIDEO_SYSTEM_AUTO: + case VIDEO_SYSTEM_AUTOHD: case VIDEO_SYSTEM_DJIWTF: currentOsdMode = HD_6022; screenRows = DJI_ROWS; From 7d426b2c269c93020da513783156246fd954dc84 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:04:23 +0100 Subject: [PATCH 6/6] Commiting to continue later --- src/main/fc/fc_msp.c | 2 +- src/main/io/osd.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 7365789cb0e..28e2cc3a2a7 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -2062,7 +2062,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) { if (osdConfig()->video_system == VIDEO_SYSTEM_AUTOHD) { displayPort_t *dp = osdGetDisplayPort(); - if (dp != NULL && dataSize == 2) { + if (dp != NULL) { dp->cols = constrain(sbufReadU8(src), 30, MSP_DISPLAYPORT_MAX_COLS); dp->rows = constrain(sbufReadU8(src), 16, MSP_DISPLAYPORT_MAX_ROWS); } else { diff --git a/src/main/io/osd.h b/src/main/io/osd.h index c57bd62f640..41b673c22b2 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -478,6 +478,10 @@ typedef struct osdConfig_s { uint16_t adsb_ignore_plane_above_me_limit; // in metres #endif uint8_t radar_peers_display_time; // in seconds +#ifdef USE_MSP_DISPLAYPORT + uint8_t osd_autohd_cols; + uint8_t osd_autohd_rows; +#endif } osdConfig_t; PG_DECLARE(osdConfig_t, osdConfig);