From 109e6f721c0fa5cfbfe076256679e09af99bf017 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Sun, 17 Jan 2021 11:33:19 -0500 Subject: [PATCH] Fix incorrect displayport_msp_serial default and add validation Was incorrectly defaulting to 0 which is UART1. Should be -1 (`SERIAL_PORT_NONE`). Add validation to ensure the selected UART exists, has MSP enabled, and is appropriate (not VCP). --- src/main/config/config.c | 13 +++++++++++++ src/main/pg/displayport_profiles.c | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/config/config.c b/src/main/config/config.c index 25d6128d27..31744673f8 100644 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -68,6 +68,7 @@ #include "pg/adc.h" #include "pg/beeper.h" #include "pg/beeper_dev.h" +#include "pg/displayport_profiles.h" #include "pg/gyrodev.h" #include "pg/motor.h" #include "pg/pg.h" @@ -598,6 +599,18 @@ static void validateAndFixConfig(void) batteryConfigMutable()->vbatmaxcellvoltage = VBAT_CELL_VOLTAGE_DEFAULT_MAX; } + // validate that displayport_msp_serial is referencing a valid UART that actually has MSP enabled + if (displayPortProfileMsp()->displayPortSerial != SERIAL_PORT_NONE) { + const serialPortConfig_t *portConfig = serialFindPortConfiguration(displayPortProfileMsp()->displayPortSerial); + if (!portConfig || !(portConfig->functionMask & FUNCTION_MSP) +#ifndef USE_MSP_PUSH_OVER_VCP + || (portConfig->identifier == SERIAL_PORT_USB_VCP) +#endif + ) { + displayPortProfileMspMutable()->displayPortSerial = SERIAL_PORT_NONE; + } + } + #if defined(TARGET_VALIDATECONFIG) // This should be done at the end of the validation targetValidateConfiguration(); diff --git a/src/main/pg/displayport_profiles.c b/src/main/pg/displayport_profiles.c index 537c77c9e6..2e702b6b54 100644 --- a/src/main/pg/displayport_profiles.c +++ b/src/main/pg/displayport_profiles.c @@ -22,13 +22,20 @@ #include "platform.h" +#include "io/serial.h" + #include "pg/displayport_profiles.h" #include "pg/pg.h" #include "pg/pg_ids.h" #if defined(USE_MSP_DISPLAYPORT) -PG_REGISTER(displayPortProfile_t, displayPortProfileMsp, PG_DISPLAY_PORT_MSP_CONFIG, 0); +PG_REGISTER_WITH_RESET_FN(displayPortProfile_t, displayPortProfileMsp, PG_DISPLAY_PORT_MSP_CONFIG, 0); + +void pgResetFn_displayPortProfileMsp(displayPortProfile_t *displayPortProfile) +{ + displayPortProfile->displayPortSerial = SERIAL_PORT_NONE; +} #endif