Skip to content

Commit

Permalink
Fix incorrect displayport_msp_serial default and add validation
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
etracer65 committed Jan 17, 2021
1 parent 3461423 commit 109e6f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion src/main/pg/displayport_profiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 109e6f7

Please sign in to comment.