Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 2 bits for msp displayport font page #9942

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/io/displayport_msp_bf_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 31 additions & 17 deletions src/main/io/displayport_msp_osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -97,12 +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 BITARRAY_DECLARE(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 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;
Expand Down Expand Up @@ -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) {
Expand All @@ -171,9 +186,8 @@ static int setDisplayMode(displayPort_t *displayPort)
static void init(void)
{
memset(screen, SYM_BLANK, sizeof(screen));
BITARRAY_CLR_ALL(fontPage);
memset(attrs, 0, sizeof(attrs));
BITARRAY_CLR_ALL(dirty);
BITARRAY_CLR_ALL(blinkChar);
}

static int clearScreen(displayPort_t *displayPort)
Expand Down Expand Up @@ -204,9 +218,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 = getAttrPage(attrs[pos]);
*c |= page << 8;

if (attr) {
*attr = TEXT_ATTRIBUTES_NONE;
Expand All @@ -219,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;
bool page = (c >> 8);
if (screen[pos] != ch || bitArrayGet(fontPage, pos) != page) {
uint8_t page = (c >> 8) & DISPLAYPORT_MSP_ATTR_FONTPAGE_MASK;
if (screen[pos] != ch || getAttrPage(attrs[pos]) != page) {
screen[pos] = ch;
(page) ? bitArraySet(fontPage, pos) : bitArrayClr(fontPage, pos);
(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);
}
}
Expand Down Expand Up @@ -287,8 +301,8 @@ 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);
bool blink = bitArrayGet(blinkChar, pos);
uint8_t page = getAttrPage(attrs[pos]);
uint8_t blink = getAttrBlink(attrs[pos]);

uint8_t len = 4;
do {
Expand All @@ -299,7 +313,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 && getAttrPage(attrs[next]) == page && getAttrBlink(attrs[next]) == blink);

if (!isBfCompatibleVideoSystem(osdConfig())) {
attributes |= (page << DISPLAYPORT_MSP_ATTR_FONTPAGE);
Expand Down
20 changes: 16 additions & 4 deletions src/main/io/displayport_msp_osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#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);
Loading