From 81b1f03325698313be0f167318b406d144a3ffc6 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:48:29 +0200 Subject: [PATCH 1/3] Use 2 bits for msp displayport font page --- src/main/io/displayport_msp_bf_compat.c | 2 +- src/main/io/displayport_msp_osd.c | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/io/displayport_msp_bf_compat.c b/src/main/io/displayport_msp_bf_compat.c index 7067ac140f..4219d2b2db 100644 --- a/src/main/io/displayport_msp_bf_compat.c +++ b/src/main/io/displayport_msp_bf_compat.c @@ -27,7 +27,7 @@ uint8_t getBfCharacter(uint8_t ch, uint8_t page) { - uint16_t ech = ch | (page << 8); + uint16_t ech = ch | ((page & 0x3)<< 8) ; if (ech >= 0x20 && ech <= 0x5F) { // ASCII range return ch; diff --git a/src/main/io/displayport_msp_osd.c b/src/main/io/displayport_msp_osd.c index e1e6cb2967..56dbc72343 100644 --- a/src/main/io/displayport_msp_osd.c +++ b/src/main/io/displayport_msp_osd.c @@ -100,7 +100,7 @@ static timeMs_t sendSubFrameMs = 0; static uint8_t currentOsdMode; // HDZero screen mode can change across layouts static uint8_t screen[SCREENSIZE]; -static BITARRAY_DECLARE(fontPage, SCREENSIZE); // font page for each character on the screen +static uint8_t fontPage[SCREENSIZE]; // font page for each character on the screen static BITARRAY_DECLARE(dirty, SCREENSIZE); // change status for each character on the screen static BITARRAY_DECLARE(blinkChar, SCREENSIZE); // Does the character blink? static bool screenCleared; @@ -171,7 +171,7 @@ static int setDisplayMode(displayPort_t *displayPort) static void init(void) { memset(screen, SYM_BLANK, sizeof(screen)); - BITARRAY_CLR_ALL(fontPage); + memset(fontPage, 0, sizeof(fontPage)); BITARRAY_CLR_ALL(dirty); BITARRAY_CLR_ALL(blinkChar); } @@ -204,9 +204,8 @@ static bool readChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint1 } *c = screen[pos]; - if (bitArrayGet(fontPage, pos)) { - *c |= 0x100; - } + uint8_t page = fontPage[pos]; + *c |= (page & 0x3) << 8; if (attr) { *attr = TEXT_ATTRIBUTES_NONE; @@ -219,10 +218,10 @@ static int setChar(const uint16_t pos, const uint16_t c, textAttributes_t attr) { if (pos < SCREENSIZE) { uint8_t ch = c & 0xFF; - bool page = (c >> 8); - if (screen[pos] != ch || bitArrayGet(fontPage, pos) != page) { + uint8_t page = (c >> 8) & 0x3; + if (screen[pos] != ch || fontPage[pos] != page) { screen[pos] = ch; - (page) ? bitArraySet(fontPage, pos) : bitArrayClr(fontPage, pos); + fontPage[pos] = page & 0x3; (TEXT_ATTRIBUTES_HAVE_BLINK(attr)) ? bitArraySet(blinkChar, pos) : bitArrayClr(blinkChar, pos); bitArraySet(dirty, pos); } @@ -287,7 +286,7 @@ static int drawScreen(displayPort_t *displayPort) // 250Hz uint8_t col = pos % COLS; uint8_t attributes = 0; int endOfLine = row * COLS + screenCols; - bool page = bitArrayGet(fontPage, pos); + uint8_t page = fontPage[pos]; bool blink = bitArrayGet(blinkChar, pos); uint8_t len = 4; @@ -299,7 +298,7 @@ static int drawScreen(displayPort_t *displayPort) // 250Hz if (bitArrayGet(dirty, pos)) { next = pos; } - } while (next == pos && next < endOfLine && bitArrayGet(fontPage, next) == page && bitArrayGet(blinkChar, next) == blink); + } while (next == pos && next < endOfLine && fontPage[next] == page && bitArrayGet(blinkChar, next) == blink); if (!isBfCompatibleVideoSystem(osdConfig())) { attributes |= (page << DISPLAYPORT_MSP_ATTR_FONTPAGE); From 9da168d5dcc6339eb8cc105b93ec2c6e46c3c6ea Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sun, 14 Apr 2024 16:12:38 +0200 Subject: [PATCH 2/3] Merge blink bitarry into attr array --- src/main/io/displayport_msp_osd.c | 41 +++++++++++++++++++++---------- src/main/io/displayport_msp_osd.h | 20 ++++++++++++--- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/main/io/displayport_msp_osd.c b/src/main/io/displayport_msp_osd.c index 56dbc72343..ab88ec661f 100644 --- a/src/main/io/displayport_msp_osd.c +++ b/src/main/io/displayport_msp_osd.c @@ -100,9 +100,8 @@ static timeMs_t sendSubFrameMs = 0; static uint8_t currentOsdMode; // HDZero screen mode can change across layouts static uint8_t screen[SCREENSIZE]; -static uint8_t fontPage[SCREENSIZE]; // font page for each character on the screen +static uint8_t attrs[SCREENSIZE]; // font page for each character on the screen static BITARRAY_DECLARE(dirty, SCREENSIZE); // change status for each character on the screen -static BITARRAY_DECLARE(blinkChar, SCREENSIZE); // Does the character blink? static bool screenCleared; static uint8_t screenRows, screenCols; static videoSystem_e osdVideoSystem; @@ -158,6 +157,22 @@ static uint8_t determineHDZeroOsdMode(void) return HD_3016; } + +uint8_t setAttrPage(uint8_t origAttr, uint8_t page) +{ + return (origAttr & ~DISPLAYPORT_MSP_ATTR_FONTPAGE_MASK) | (page & DISPLAYPORT_MSP_ATTR_FONTPAGE_MASK); +} + +uint8_t setAttrBlink(uint8_t origAttr, uint8_t blink) +{ + return (origAttr & ~DISPLAYPORT_MSP_ATTR_BLINK_MASK) | ((blink << DISPLAYPORT_MSP_ATTR_BLINK) & DISPLAYPORT_MSP_ATTR_BLINK_MASK); +} + +uint8_t setAttrVersion(uint8_t origAttr, uint8_t version) +{ + return (origAttr & ~DISPLAYPORT_MSP_ATTR_VERSION_MASK) | ((version << DISPLAYPORT_MSP_ATTR_VERSION) & DISPLAYPORT_MSP_ATTR_VERSION_MASK); +} + static int setDisplayMode(displayPort_t *displayPort) { if (osdVideoSystem == VIDEO_SYSTEM_HDZERO) { @@ -171,9 +186,8 @@ static int setDisplayMode(displayPort_t *displayPort) static void init(void) { memset(screen, SYM_BLANK, sizeof(screen)); - memset(fontPage, 0, sizeof(fontPage)); + memset(attrs, 0, sizeof(attrs)); BITARRAY_CLR_ALL(dirty); - BITARRAY_CLR_ALL(blinkChar); } static int clearScreen(displayPort_t *displayPort) @@ -204,8 +218,8 @@ static bool readChar(displayPort_t *displayPort, uint8_t col, uint8_t row, uint1 } *c = screen[pos]; - uint8_t page = fontPage[pos]; - *c |= (page & 0x3) << 8; + uint8_t page = getAttrPage(attrs[pos]); + *c |= page << 8; if (attr) { *attr = TEXT_ATTRIBUTES_NONE; @@ -218,11 +232,12 @@ static int setChar(const uint16_t pos, const uint16_t c, textAttributes_t attr) { if (pos < SCREENSIZE) { uint8_t ch = c & 0xFF; - uint8_t page = (c >> 8) & 0x3; - if (screen[pos] != ch || fontPage[pos] != page) { + uint8_t page = (c >> 8) & DISPLAYPORT_MSP_ATTR_FONTPAGE_MASK; + if (screen[pos] != ch || getAttrPage(attrs[pos]) != page) { screen[pos] = ch; - fontPage[pos] = page & 0x3; - (TEXT_ATTRIBUTES_HAVE_BLINK(attr)) ? bitArraySet(blinkChar, pos) : bitArrayClr(blinkChar, pos); + attrs[pos] = setAttrPage(attrs[pos], page); + uint8_t blink = (TEXT_ATTRIBUTES_HAVE_BLINK(attr)) ? 1 : 0; + attrs[pos] = setAttrBlink(attrs[pos], blink); bitArraySet(dirty, pos); } } @@ -286,8 +301,8 @@ static int drawScreen(displayPort_t *displayPort) // 250Hz uint8_t col = pos % COLS; uint8_t attributes = 0; int endOfLine = row * COLS + screenCols; - uint8_t page = fontPage[pos]; - bool blink = bitArrayGet(blinkChar, pos); + uint8_t page = getAttrPage(attrs[pos]); + uint8_t blink = getAttrBlink(attrs[pos]); uint8_t len = 4; do { @@ -298,7 +313,7 @@ static int drawScreen(displayPort_t *displayPort) // 250Hz if (bitArrayGet(dirty, pos)) { next = pos; } - } while (next == pos && next < endOfLine && fontPage[next] == page && bitArrayGet(blinkChar, next) == blink); + } while (next == pos && next < endOfLine && getAttrPage(attrs[next]) == page && getAttrBlink(attrs[next]) == blink); if (!isBfCompatibleVideoSystem(osdConfig())) { attributes |= (page << DISPLAYPORT_MSP_ATTR_FONTPAGE); diff --git a/src/main/io/displayport_msp_osd.h b/src/main/io/displayport_msp_osd.h index 0a2f64c48a..affd5b39be 100644 --- a/src/main/io/displayport_msp_osd.h +++ b/src/main/io/displayport_msp_osd.h @@ -27,13 +27,25 @@ #include "drivers/osd.h" #include "msp/msp_serial.h" +// MSP displayport V2 attribute byte bit functions +#define DISPLAYPORT_MSP_ATTR_FONTPAGE 0 // Select bank of 256 characters as per displayPortSeverity_e +#define DISPLAYPORT_MSP_ATTR_BLINK 6 // Device local blink +#define DISPLAYPORT_MSP_ATTR_VERSION 7 // Format indicator; must be zero for V2 (and V1) + +#define DISPLAYPORT_MSP_ATTR_FONTPAGE_MASK 0x3 +#define DISPLAYPORT_MSP_ATTR_BLINK_MASK (1 << DISPLAYPORT_MSP_ATTR_BLINK) +#define DISPLAYPORT_MSP_ATTR_VERSION_MASK (1 << DISPLAYPORT_MSP_ATTR_VERSION) + typedef struct displayPort_s displayPort_t; displayPort_t *mspOsdDisplayPortInit(const videoSystem_e videoSystem); void mspOsdSerialProcess(mspProcessCommandFnPtr mspProcessCommandFn); mspPort_t *getMspOsdPort(void); -// MSP displayport V2 attribute byte bit functions -#define DISPLAYPORT_MSP_ATTR_FONTPAGE 0 // Select bank of 256 characters as per displayPortSeverity_e -#define DISPLAYPORT_MSP_ATTR_BLINK 6 // Device local blink -#define DISPLAYPORT_MSP_ATTR_VERSION 7 // Format indicator; must be zero for V2 (and V1) \ No newline at end of file +#define getAttrPage(attr) (attr & DISPLAYPORT_MSP_ATTR_FONTPAGE_MASK) +#define getAttrBlink(attr) ((attr & DISPLAYPORT_MSP_ATTR_BLINK_MASK) >> DISPLAYPORT_MSP_ATTR_BLINK) +#define getAttrVersion(attr) ((attr & DISPLAYPORT_MSP_ATTR_VERSION_MASK) >> DISPLAYPORT_MSP_ATTR_VERSION) + +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 From 1ee021b5a8cf3dc83afe52347ea6ef8ec71922a6 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Sun, 14 Apr 2024 16:16:58 +0200 Subject: [PATCH 3/3] Formating changes --- src/main/io/displayport_msp_osd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/io/displayport_msp_osd.c b/src/main/io/displayport_msp_osd.c index ab88ec661f..c9372d9fbf 100644 --- a/src/main/io/displayport_msp_osd.c +++ b/src/main/io/displayport_msp_osd.c @@ -59,7 +59,7 @@ typedef enum { // defines are from hdzero code SD_3016, HD_5018, HD_3016, // Special HDZERO mode that just sends the centre 30x16 of the 50x18 canvas to the VRX - HD_6022, // added to support DJI wtfos 60x22 grid + HD_6022, // added to support DJI wtfos 60x22 grid HD_5320 // added to support Avatar and BetaflightHD } resolutionType_e; @@ -97,11 +97,11 @@ static timeMs_t sendSubFrameMs = 0; // set screen size #define SCREENSIZE (ROWS*COLS) -static uint8_t currentOsdMode; // HDZero screen mode can change across layouts +static uint8_t currentOsdMode; // HDZero screen mode can change across layouts static uint8_t screen[SCREENSIZE]; -static uint8_t attrs[SCREENSIZE]; // font page for each character on the screen -static BITARRAY_DECLARE(dirty, SCREENSIZE); // change status for each character on the screen +static uint8_t attrs[SCREENSIZE]; // font page, blink and other attributes +static BITARRAY_DECLARE(dirty, SCREENSIZE); // change status for each character on the screen static bool screenCleared; static uint8_t screenRows, screenCols; static videoSystem_e osdVideoSystem;