MSP DisplayPort support improvement (#9013)

MSP DisplayPort support improvement
This commit is contained in:
Michael Keller 2019-10-20 12:43:03 +13:00 committed by GitHub
commit cb9481b137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 92 additions and 16 deletions

View File

@ -63,6 +63,7 @@
#include "io/gimbal.h"
#include "io/gps.h"
#include "io/ledstrip.h"
#include "io/serial.h"
#include "io/vtx.h"
#include "io/vtx_control.h"
#include "io/vtx_rtc6705.h"
@ -481,6 +482,10 @@ static const char* const lookupTableDshotBitbangedTimer[] = {
"AUTO", "TIM1", "TIM8"
};
static const char * const lookupTableOsdDisplayPortDevice[] = {
"NONE", "AUTO", "MAX7456", "MSP",
};
#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
@ -599,6 +604,7 @@ const lookupTableEntry_t lookupTables[] = {
LOOKUP_TABLE_ENTRY(lookupTableOffOnAuto),
LOOKUP_TABLE_ENTRY(lookupTableInterpolatedSetpoint),
LOOKUP_TABLE_ENTRY(lookupTableDshotBitbangedTimer),
LOOKUP_TABLE_ENTRY(lookupTableOsdDisplayPortDevice),
};
#undef LOOKUP_TABLE_ENTRY
@ -1355,6 +1361,7 @@ const clivalue_t valueTable[] = {
{ "osd_profile_3_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, OSD_PROFILE_NAME_LENGTH, STRING_FLAGS_NONE }, PG_OSD_CONFIG, offsetof(osdConfig_t, profile[2]) },
#endif
{ "osd_gps_sats_show_hdop", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, gps_sats_show_hdop) },
{ "osd_displayport_device", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OSD_DISPLAYPORT_DEVICE }, PG_OSD_CONFIG, offsetof(osdConfig_t, displayPortDevice) },
#endif
{ "osd_rcchannels", VAR_INT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = OSD_RCCHANNELS_COUNT, PG_OSD_CONFIG, offsetof(osdConfig_t, rcChannels) },
@ -1414,6 +1421,7 @@ const clivalue_t valueTable[] = {
#ifdef USE_MSP_DISPLAYPORT
{ "displayport_msp_col_adjust", VAR_INT8 | MASTER_VALUE, .config.minmax = { -6, 0 }, PG_DISPLAY_PORT_MSP_CONFIG, offsetof(displayPortProfile_t, colAdjust) },
{ "displayport_msp_row_adjust", VAR_INT8 | MASTER_VALUE, .config.minmax = { -3, 0 }, PG_DISPLAY_PORT_MSP_CONFIG, offsetof(displayPortProfile_t, rowAdjust) },
{ "displayport_msp_serial", VAR_INT8 | MASTER_VALUE, .config.minmax = { SERIAL_PORT_NONE, SERIAL_PORT_IDENTIFIER_MAX }, PG_DISPLAY_PORT_MSP_CONFIG, offsetof(displayPortProfile_t, displayPortSerial) },
#endif
// PG_DISPLAY_PORT_MSP_CONFIG

View File

@ -138,6 +138,7 @@ typedef enum {
TABLE_OFF_ON_AUTO,
TABLE_INTERPOLATED_SP,
TABLE_DSHOT_BITBANGED_TIMER,
TABLE_OSD_DISPLAYPORT_DEVICE,
LOOKUP_TABLE_COUNT
} lookupTableIndex_e;

View File

@ -60,6 +60,7 @@ typedef struct displayPortProfile_s {
bool invert;
uint8_t blackBrightness;
uint8_t whiteBrightness;
int8_t displayPortSerial; // serialPortIdentifier_e
} displayPortProfile_t;
// Note: displayPortProfile_t used as a parameter group for CMS over CRSF (io/displayport_crsf)

View File

@ -439,12 +439,33 @@ bool max7456Init(const max7456Config_t *max7456Config, const vcdProfile_t *pVcdP
spiBusSetInstance(busdev, spiInstanceByDevice(SPI_CFG_TO_DEV(max7456Config->spiDevice)));
// Detect device type by writing and reading CA[8] bit at CMAL[6].
// Do this at half the speed for safety.
// Detect MAX7456 existence and device type. Do this at half the speed for safety.
// Detect MAX7456 and compatible device by reading OSDM (OSD Insertion MUX) register.
// This register is not modified in this driver, therefore ensured to remain at its default value (0x1B).
spiSetDivisor(busdev->busdev_u.spi.instance, MAX7456_SPI_CLK * 2);
__spiBusTransactionBegin(busdev);
uint8_t osdm = max7456Send(MAX7456ADD_OSDM|MAX7456ADD_READ, 0xff);
if (osdm != 0x1B) {
IOConfigGPIO(busdev->busdev_u.spi.csnPin, IOCFG_IPU);
return false;
}
__spiBusTransactionEnd(busdev);
// At this point, we can claim the ownership of the CS pin
IOInit(busdev->busdev_u.spi.csnPin, OWNER_OSD_CS, 0);
// Detect device type by writing and reading CA[8] bit at CMAL[6].
// This is a bit for accessing second half of character glyph storage, supported only by AT variant.
__spiBusTransactionBegin(busdev);
max7456Send(MAX7456ADD_CMAL, (1 << 6)); // CA[8] bit
if (max7456Send(MAX7456ADD_CMAL|MAX7456ADD_READ, 0xff) & (1 << 6)) {

View File

@ -753,16 +753,43 @@ void init(void)
//The OSD need to be initialised after GYRO to avoid GYRO initialisation failure on some targets
if (featureIsEnabled(FEATURE_OSD)) {
osdDisplayPortDevice_e device = osdConfig()->displayPortDevice;
switch(device) {
case OSD_DISPLAYPORT_DEVICE_AUTO:
FALLTHROUGH;
#if defined(USE_MAX7456)
// If there is a max7456 chip for the OSD then use it
case OSD_DISPLAYPORT_DEVICE_MAX7456:
// If there is a max7456 chip for the OSD configured and detectd then use it.
osdDisplayPort = max7456DisplayPortInit(vcdProfile());
#elif defined(USE_CMS) && defined(USE_MSP_DISPLAYPORT) && defined(USE_OSD_OVER_MSP_DISPLAYPORT) // OSD over MSP; not supported (yet)
osdDisplayPort = displayPortMspInit();
if (osdDisplayPort || device == OSD_DISPLAYPORT_DEVICE_MAX7456) {
break;
}
FALLTHROUGH;
#endif
#if defined(USE_CMS) && defined(USE_MSP_DISPLAYPORT) && defined(USE_OSD_OVER_MSP_DISPLAYPORT)
case OSD_DISPLAYPORT_DEVICE_MSP:
osdDisplayPort = displayPortMspInit();
if (osdDisplayPort || device == OSD_DISPLAYPORT_DEVICE_MSP) {
break;
}
FALLTHROUGH;
#endif
// Other device cases can be added here
case OSD_DISPLAYPORT_DEVICE_NONE:
default:
break;
}
// osdInit will register with CMS by itself.
osdInit(osdDisplayPort);
}
#endif
#endif // USE_OSD
#if defined(USE_CMS) && defined(USE_MSP_DISPLAYPORT)
// If BFOSD is not active, then register MSP_DISPLAYPORT as a CMS device.

View File

@ -88,7 +88,8 @@ typedef enum {
SERIAL_PORT_USART8,
SERIAL_PORT_USB_VCP = 20,
SERIAL_PORT_SOFTSERIAL1 = 30,
SERIAL_PORT_SOFTSERIAL2
SERIAL_PORT_SOFTSERIAL2,
SERIAL_PORT_IDENTIFIER_MAX = SERIAL_PORT_SOFTSERIAL2
} serialPortIdentifier_e;
extern const serialPortIdentifier_e serialPortIdentifiers[SERIAL_PORT_COUNT];

View File

@ -35,6 +35,7 @@
#include "drivers/system.h"
#include "io/serial.h"
#include "io/displayport_msp.h"
#include "msp/msp.h"
@ -57,6 +58,7 @@ void mspSerialAllocatePorts(void)
serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_MSP);
while (portConfig && portIndex < MAX_MSP_PORT_COUNT) {
mspPort_t *mspPort = &mspPorts[portIndex];
if (mspPort->port) {
portIndex++;
continue;
@ -66,6 +68,13 @@ void mspSerialAllocatePorts(void)
if (serialPort) {
bool sharedWithTelemetry = isSerialPortShared(portConfig, FUNCTION_MSP, TELEMETRY_PORT_FUNCTIONS_MASK);
resetMspPort(mspPort, serialPort, sharedWithTelemetry);
#ifdef USE_MSP_DISPLAYPORT
if (serialPort->identifier == displayPortProfileMsp()->displayPortSerial) {
mspPort->isDisplayPort = true;
}
#endif
portIndex++;
}
@ -562,12 +571,8 @@ int mspSerialPush(uint8_t cmd, uint8_t *data, int datalen, mspDirection_e direct
for (int portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
mspPort_t * const mspPort = &mspPorts[portIndex];
if (!mspPort->port) {
continue;
}
// XXX Kludge!!! Avoid zombie VCP port (avoid VCP entirely for now)
if (mspPort->port->identifier == SERIAL_PORT_USB_VCP) {
if (!mspPort->port || !mspPort->isDisplayPort) {
continue;
}

View File

@ -111,6 +111,7 @@ typedef struct mspPort_s {
uint8_t checksum2;
bool sharedWithTelemetry;
mspDescriptor_t descriptor;
bool isDisplayPort;
} mspPort_t;
void mspSerialInit(void);

View File

@ -307,6 +307,8 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
for (int i = 0; i < OSD_RCCHANNELS_COUNT; i++) {
osdConfig->rcChannels[i] = -1;
}
osdConfig->displayPortDevice = OSD_DISPLAYPORT_DEVICE_AUTO;
}
static void osdDrawLogo(int x, int y)

View File

@ -222,6 +222,13 @@ typedef enum {
OSD_WARNING_COUNT // MUST BE LAST
} osdWarningsFlags_e;
typedef enum {
OSD_DISPLAYPORT_DEVICE_NONE = 0,
OSD_DISPLAYPORT_DEVICE_AUTO,
OSD_DISPLAYPORT_DEVICE_MAX7456,
OSD_DISPLAYPORT_DEVICE_MSP,
} osdDisplayPortDevice_e;
// Make sure the number of warnings do not exceed the available 32bit storage
STATIC_ASSERT(OSD_WARNING_COUNT <= 32, osdwarnings_overflow);
@ -262,6 +269,7 @@ typedef struct osdConfig_s {
uint8_t rssi_dbm_alarm;
uint8_t gps_sats_show_hdop;
int8_t rcChannels[OSD_RCCHANNELS_COUNT]; // RC channel values to display, -1 if none
uint8_t displayPortDevice; // osdDisplayPortDevice_e
} osdConfig_t;
PG_DECLARE(osdConfig_t, osdConfig);

View File

@ -222,6 +222,7 @@
#define USE_CMS
#define USE_MSP_DISPLAYPORT
#define USE_MSP_OVER_TELEMETRY
#define USE_OSD_OVER_MSP_DISPLAYPORT
#define USE_LED_STRIP
#endif