Improved OSD & displayPort initialisation. Allowed nested screen grabbing
This commit is contained in:
parent
9a62b04699
commit
7c8d1967d0
|
@ -45,19 +45,25 @@ void displayGrab(displayPort_t *instance)
|
|||
{
|
||||
instance->vTable->grab(instance);
|
||||
instance->vTable->clearScreen(instance);
|
||||
instance->isGrabbed = true;
|
||||
++instance->grabCount;
|
||||
}
|
||||
|
||||
void displayRelease(displayPort_t *instance)
|
||||
{
|
||||
instance->vTable->release(instance);
|
||||
instance->isGrabbed = false;
|
||||
--instance->grabCount;
|
||||
}
|
||||
|
||||
void displayReleaseAll(displayPort_t *instance)
|
||||
{
|
||||
instance->vTable->release(instance);
|
||||
instance->grabCount = 0;
|
||||
}
|
||||
|
||||
bool displayIsGrabbed(const displayPort_t *instance)
|
||||
{
|
||||
// can be called before initialised
|
||||
return (instance && instance->isGrabbed);
|
||||
return (instance && instance->grabCount > 0);
|
||||
}
|
||||
|
||||
int displayWrite(displayPort_t *instance, uint8_t x, uint8_t y, const char *s)
|
||||
|
@ -90,3 +96,12 @@ uint16_t displayTxBytesFree(const displayPort_t *instance)
|
|||
return instance->vTable->txBytesFree(instance);
|
||||
}
|
||||
|
||||
void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable)
|
||||
{
|
||||
instance->vTable = vTable;
|
||||
instance->vTable->clearScreen(instance);
|
||||
instance->cleared = true;
|
||||
instance->grabCount = 0;
|
||||
instance->cursorRow = -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ typedef struct displayPort_s {
|
|||
// CMS state
|
||||
bool cleared;
|
||||
int8_t cursorRow;
|
||||
bool isGrabbed;
|
||||
int8_t grabCount;
|
||||
} displayPort_t;
|
||||
|
||||
typedef struct displayPortVTable_s {
|
||||
|
@ -45,6 +45,7 @@ typedef struct displayPortVTable_s {
|
|||
|
||||
void displayGrab(displayPort_t *instance);
|
||||
void displayRelease(displayPort_t *instance);
|
||||
void displayReleaseAll(displayPort_t *instance);
|
||||
bool displayIsGrabbed(const displayPort_t *instance);
|
||||
void displayClearScreen(displayPort_t *instance);
|
||||
void displayDrawScreen(displayPort_t *instance);
|
||||
|
@ -55,3 +56,4 @@ bool displayIsTransferInProgress(const displayPort_t *instance);
|
|||
void displayHeartbeat(displayPort_t *instance);
|
||||
void displayResync(displayPort_t *instance);
|
||||
uint16_t displayTxBytesFree(const displayPort_t *instance);
|
||||
void displayInit(displayPort_t *instance, const displayPortVTable_t *vTable);
|
||||
|
|
|
@ -37,6 +37,122 @@
|
|||
#include "max7456.h"
|
||||
#include "max7456_symbols.h"
|
||||
|
||||
|
||||
|
||||
//MAX7456 opcodes
|
||||
#define DMM_REG 0x04
|
||||
#define DMAH_REG 0x05
|
||||
#define DMAL_REG 0x06
|
||||
#define DMDI_REG 0x07
|
||||
#define VM0_REG 0x00
|
||||
#define VM1_REG 0x01
|
||||
|
||||
// video mode register 0 bits
|
||||
#define VIDEO_BUFFER_DISABLE 0x01
|
||||
#define MAX7456_RESET 0x02
|
||||
#define VERTICAL_SYNC_NEXT_VSYNC 0x04
|
||||
#define OSD_ENABLE 0x08
|
||||
#define SYNC_MODE_AUTO 0x00
|
||||
#define SYNC_MODE_INTERNAL 0x30
|
||||
#define SYNC_MODE_EXTERNAL 0x20
|
||||
#define VIDEO_MODE_PAL 0x40
|
||||
#define VIDEO_MODE_NTSC 0x00
|
||||
|
||||
// video mode register 1 bits
|
||||
|
||||
|
||||
// duty cycle is on_off
|
||||
#define BLINK_DUTY_CYCLE_50_50 0x00
|
||||
#define BLINK_DUTY_CYCLE_33_66 0x01
|
||||
#define BLINK_DUTY_CYCLE_25_75 0x02
|
||||
#define BLINK_DUTY_CYCLE_75_25 0x03
|
||||
|
||||
// blinking time
|
||||
#define BLINK_TIME_0 0x00
|
||||
#define BLINK_TIME_1 0x04
|
||||
#define BLINK_TIME_2 0x08
|
||||
#define BLINK_TIME_3 0x0C
|
||||
|
||||
// background mode brightness (percent)
|
||||
#define BACKGROUND_BRIGHTNESS_0 0x00
|
||||
#define BACKGROUND_BRIGHTNESS_7 0x01
|
||||
#define BACKGROUND_BRIGHTNESS_14 0x02
|
||||
#define BACKGROUND_BRIGHTNESS_21 0x03
|
||||
#define BACKGROUND_BRIGHTNESS_28 0x04
|
||||
#define BACKGROUND_BRIGHTNESS_35 0x05
|
||||
#define BACKGROUND_BRIGHTNESS_42 0x06
|
||||
#define BACKGROUND_BRIGHTNESS_49 0x07
|
||||
|
||||
#define BACKGROUND_MODE_GRAY 0x40
|
||||
|
||||
//MAX7456 commands
|
||||
#define CLEAR_DISPLAY 0x04
|
||||
#define CLEAR_DISPLAY_VERT 0x06
|
||||
#define END_STRING 0xff
|
||||
|
||||
|
||||
#define MAX7456ADD_VM0 0x00 //0b0011100// 00 // 00 ,0011100
|
||||
#define MAX7456ADD_VM1 0x01
|
||||
#define MAX7456ADD_HOS 0x02
|
||||
#define MAX7456ADD_VOS 0x03
|
||||
#define MAX7456ADD_DMM 0x04
|
||||
#define MAX7456ADD_DMAH 0x05
|
||||
#define MAX7456ADD_DMAL 0x06
|
||||
#define MAX7456ADD_DMDI 0x07
|
||||
#define MAX7456ADD_CMM 0x08
|
||||
#define MAX7456ADD_CMAH 0x09
|
||||
#define MAX7456ADD_CMAL 0x0a
|
||||
#define MAX7456ADD_CMDI 0x0b
|
||||
#define MAX7456ADD_OSDM 0x0c
|
||||
#define MAX7456ADD_RB0 0x10
|
||||
#define MAX7456ADD_RB1 0x11
|
||||
#define MAX7456ADD_RB2 0x12
|
||||
#define MAX7456ADD_RB3 0x13
|
||||
#define MAX7456ADD_RB4 0x14
|
||||
#define MAX7456ADD_RB5 0x15
|
||||
#define MAX7456ADD_RB6 0x16
|
||||
#define MAX7456ADD_RB7 0x17
|
||||
#define MAX7456ADD_RB8 0x18
|
||||
#define MAX7456ADD_RB9 0x19
|
||||
#define MAX7456ADD_RB10 0x1a
|
||||
#define MAX7456ADD_RB11 0x1b
|
||||
#define MAX7456ADD_RB12 0x1c
|
||||
#define MAX7456ADD_RB13 0x1d
|
||||
#define MAX7456ADD_RB14 0x1e
|
||||
#define MAX7456ADD_RB15 0x1f
|
||||
#define MAX7456ADD_OSDBL 0x6c
|
||||
#define MAX7456ADD_STAT 0xA0
|
||||
|
||||
#define NVM_RAM_SIZE 54
|
||||
#define WRITE_NVR 0xA0
|
||||
#define STATUS_REG_NVR_BUSY 0x20
|
||||
|
||||
/** Line multiples, for convenience & one less op at runtime **/
|
||||
#define LINE 30
|
||||
#define LINE01 0
|
||||
#define LINE02 30
|
||||
#define LINE03 60
|
||||
#define LINE04 90
|
||||
#define LINE05 120
|
||||
#define LINE06 150
|
||||
#define LINE07 180
|
||||
#define LINE08 210
|
||||
#define LINE09 240
|
||||
#define LINE10 270
|
||||
#define LINE11 300
|
||||
#define LINE12 330
|
||||
#define LINE13 360
|
||||
#define LINE14 390
|
||||
#define LINE15 420
|
||||
#define LINE16 450
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//on shared SPI buss we want to change clock for OSD chip and restore for other devices
|
||||
#ifdef MAX7456_SPI_CLK
|
||||
#define ENABLE_MAX7456 {spiSetDivisor(MAX7456_SPI_INSTANCE, MAX7456_SPI_CLK);IOLo(max7456CsPin);}
|
||||
|
|
|
@ -26,114 +26,6 @@
|
|||
|
||||
#define BWBRIGHTNESS ((BLACKBRIGHTNESS << 2) | WHITEBRIGHTNESS)
|
||||
|
||||
//MAX7456 opcodes
|
||||
#define DMM_REG 0x04
|
||||
#define DMAH_REG 0x05
|
||||
#define DMAL_REG 0x06
|
||||
#define DMDI_REG 0x07
|
||||
#define VM0_REG 0x00
|
||||
#define VM1_REG 0x01
|
||||
|
||||
// video mode register 0 bits
|
||||
#define VIDEO_BUFFER_DISABLE 0x01
|
||||
#define MAX7456_RESET 0x02
|
||||
#define VERTICAL_SYNC_NEXT_VSYNC 0x04
|
||||
#define OSD_ENABLE 0x08
|
||||
#define SYNC_MODE_AUTO 0x00
|
||||
#define SYNC_MODE_INTERNAL 0x30
|
||||
#define SYNC_MODE_EXTERNAL 0x20
|
||||
#define VIDEO_MODE_PAL 0x40
|
||||
#define VIDEO_MODE_NTSC 0x00
|
||||
|
||||
// video mode register 1 bits
|
||||
|
||||
|
||||
// duty cycle is on_off
|
||||
#define BLINK_DUTY_CYCLE_50_50 0x00
|
||||
#define BLINK_DUTY_CYCLE_33_66 0x01
|
||||
#define BLINK_DUTY_CYCLE_25_75 0x02
|
||||
#define BLINK_DUTY_CYCLE_75_25 0x03
|
||||
|
||||
// blinking time
|
||||
#define BLINK_TIME_0 0x00
|
||||
#define BLINK_TIME_1 0x04
|
||||
#define BLINK_TIME_2 0x08
|
||||
#define BLINK_TIME_3 0x0C
|
||||
|
||||
// background mode brightness (percent)
|
||||
#define BACKGROUND_BRIGHTNESS_0 0x00
|
||||
#define BACKGROUND_BRIGHTNESS_7 0x01
|
||||
#define BACKGROUND_BRIGHTNESS_14 0x02
|
||||
#define BACKGROUND_BRIGHTNESS_21 0x03
|
||||
#define BACKGROUND_BRIGHTNESS_28 0x04
|
||||
#define BACKGROUND_BRIGHTNESS_35 0x05
|
||||
#define BACKGROUND_BRIGHTNESS_42 0x06
|
||||
#define BACKGROUND_BRIGHTNESS_49 0x07
|
||||
|
||||
#define BACKGROUND_MODE_GRAY 0x40
|
||||
|
||||
//MAX7456 commands
|
||||
#define CLEAR_DISPLAY 0x04
|
||||
#define CLEAR_DISPLAY_VERT 0x06
|
||||
#define END_STRING 0xff
|
||||
|
||||
|
||||
#define MAX7456ADD_VM0 0x00 //0b0011100// 00 // 00 ,0011100
|
||||
#define MAX7456ADD_VM1 0x01
|
||||
#define MAX7456ADD_HOS 0x02
|
||||
#define MAX7456ADD_VOS 0x03
|
||||
#define MAX7456ADD_DMM 0x04
|
||||
#define MAX7456ADD_DMAH 0x05
|
||||
#define MAX7456ADD_DMAL 0x06
|
||||
#define MAX7456ADD_DMDI 0x07
|
||||
#define MAX7456ADD_CMM 0x08
|
||||
#define MAX7456ADD_CMAH 0x09
|
||||
#define MAX7456ADD_CMAL 0x0a
|
||||
#define MAX7456ADD_CMDI 0x0b
|
||||
#define MAX7456ADD_OSDM 0x0c
|
||||
#define MAX7456ADD_RB0 0x10
|
||||
#define MAX7456ADD_RB1 0x11
|
||||
#define MAX7456ADD_RB2 0x12
|
||||
#define MAX7456ADD_RB3 0x13
|
||||
#define MAX7456ADD_RB4 0x14
|
||||
#define MAX7456ADD_RB5 0x15
|
||||
#define MAX7456ADD_RB6 0x16
|
||||
#define MAX7456ADD_RB7 0x17
|
||||
#define MAX7456ADD_RB8 0x18
|
||||
#define MAX7456ADD_RB9 0x19
|
||||
#define MAX7456ADD_RB10 0x1a
|
||||
#define MAX7456ADD_RB11 0x1b
|
||||
#define MAX7456ADD_RB12 0x1c
|
||||
#define MAX7456ADD_RB13 0x1d
|
||||
#define MAX7456ADD_RB14 0x1e
|
||||
#define MAX7456ADD_RB15 0x1f
|
||||
#define MAX7456ADD_OSDBL 0x6c
|
||||
#define MAX7456ADD_STAT 0xA0
|
||||
|
||||
#define NVM_RAM_SIZE 54
|
||||
#define WRITE_NVR 0xA0
|
||||
#define STATUS_REG_NVR_BUSY 0x20
|
||||
|
||||
/** Line multiples, for convenience & one less op at runtime **/
|
||||
#define LINE 30
|
||||
#define LINE01 0
|
||||
#define LINE02 30
|
||||
#define LINE03 60
|
||||
#define LINE04 90
|
||||
#define LINE05 120
|
||||
#define LINE06 150
|
||||
#define LINE07 180
|
||||
#define LINE08 210
|
||||
#define LINE09 240
|
||||
#define LINE10 270
|
||||
#define LINE11 300
|
||||
#define LINE12 330
|
||||
#define LINE13 360
|
||||
#define LINE14 390
|
||||
#define LINE15 420
|
||||
#define LINE16 450
|
||||
|
||||
|
||||
/** PAL or NTSC, value is number of chars total */
|
||||
#define VIDEO_BUFFER_CHARS_NTSC 390
|
||||
#define VIDEO_BUFFER_CHARS_PAL 480
|
||||
|
|
|
@ -1552,7 +1552,10 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
|||
for (int i = 0; i < 54; i++) {
|
||||
font_data[i] = sbufReadU8(src);
|
||||
}
|
||||
#ifdef USE_MAX7456
|
||||
// !!TODO - replace this with a device independent implementation
|
||||
max7456WriteNvm(addr, font_data);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ static int grab(displayPort_t *displayPort)
|
|||
{
|
||||
UNUSED(displayPort);
|
||||
osdResetAlarms();
|
||||
displayPort->isGrabbed = true;
|
||||
refreshTimeout = 0;
|
||||
|
||||
return 0;
|
||||
|
@ -46,7 +45,6 @@ static int grab(displayPort_t *displayPort)
|
|||
static int release(displayPort_t *displayPort)
|
||||
{
|
||||
UNUSED(displayPort);
|
||||
displayPort->isGrabbed = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -119,7 +117,7 @@ static uint32_t txBytesFree(const displayPort_t *displayPort)
|
|||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
static displayPortVTable_t max7456VTable = {
|
||||
static const displayPortVTable_t max7456VTable = {
|
||||
.grab = grab,
|
||||
.release = release,
|
||||
.clearScreen = clearScreen,
|
||||
|
@ -135,9 +133,8 @@ static displayPortVTable_t max7456VTable = {
|
|||
|
||||
displayPort_t *max7456DisplayPortInit(uint8_t system)
|
||||
{
|
||||
max7456DisplayPort.vTable = &max7456VTable;
|
||||
displayInit(&max7456DisplayPort, &max7456VTable);
|
||||
max7456Init(system);
|
||||
max7456DisplayPort.isGrabbed = false;
|
||||
resync(&max7456DisplayPort);
|
||||
return &max7456DisplayPort;
|
||||
}
|
||||
|
|
|
@ -42,16 +42,17 @@ static int output(displayPort_t *displayPort, uint8_t cmd, const uint8_t *buf, i
|
|||
return mspSerialPush(cmd, buf, len);
|
||||
}
|
||||
|
||||
static int grab(displayPort_t *displayPort)
|
||||
static int heartbeat(displayPort_t *displayPort)
|
||||
{
|
||||
const uint8_t subcmd[] = { 0 };
|
||||
|
||||
// ensure display is not released by MW OSD software
|
||||
return output(displayPort, MSP_DISPLAYPORT, subcmd, sizeof(subcmd));
|
||||
}
|
||||
|
||||
static int heartbeat(displayPort_t *displayPort)
|
||||
static int grab(displayPort_t *displayPort)
|
||||
{
|
||||
return grab(displayPort); // ensure display is not released by MW OSD software
|
||||
return heartbeat(displayPort);
|
||||
}
|
||||
|
||||
static int release(displayPort_t *displayPort)
|
||||
|
@ -141,8 +142,7 @@ static const displayPortVTable_t mspDisplayPortVTable = {
|
|||
|
||||
displayPort_t *displayPortMspInit(void)
|
||||
{
|
||||
mspDisplayPort.vTable = &mspDisplayPortVTable;
|
||||
mspDisplayPort.isGrabbed = false;
|
||||
displayInit(&mspDisplayPort, &mspDisplayPortVTable);
|
||||
resync(&mspDisplayPort);
|
||||
return &mspDisplayPort;
|
||||
}
|
||||
|
|
|
@ -112,9 +112,8 @@ static const displayPortVTable_t oledVTable = {
|
|||
|
||||
displayPort_t *displayPortOledInit(void)
|
||||
{
|
||||
oledDisplayPort.vTable = &oledVTable;
|
||||
displayInit(&oledDisplayPort, &oledVTable);
|
||||
oledDisplayPort.rows = SCREEN_CHARACTER_ROW_COUNT;
|
||||
oledDisplayPort.cols = SCREEN_CHARACTER_COLUMN_COUNT;
|
||||
oledDisplayPort.isGrabbed = false;
|
||||
return &oledDisplayPort;
|
||||
}
|
||||
|
|
|
@ -407,7 +407,12 @@ void init(void)
|
|||
|
||||
#ifdef OSD
|
||||
if (feature(FEATURE_OSD)) {
|
||||
#ifdef USE_MAX7456
|
||||
// if there is a max7456 chip for the OSD then use it, otherwise use MSP
|
||||
displayPort_t *osdDisplayPort = max7456DisplayPortInit(masterConfig.osdProfile.video_system);
|
||||
#else
|
||||
displayPort_t *osdDisplayPort = displayPortMspInit();
|
||||
#endif
|
||||
osdInit(osdDisplayPort);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue