diff --git a/src/main/io/serial.c b/src/main/io/serial.c index 4f569b8aa..a05894189 100644 --- a/src/main/io/serial.c +++ b/src/main/io/serial.c @@ -81,7 +81,7 @@ static serialPortFunction_t serialPortFunctions[SERIAL_PORT_COUNT] = { #endif }; -static const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { +const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { {SERIAL_PORT_USB_VCP, 9600, 115200, SPF_NONE }, {SERIAL_PORT_USART1, 9600, 115200, SPF_NONE | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, {SERIAL_PORT_USART2, 9600, 115200, SPF_SUPPORTS_CALLBACK | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, @@ -102,7 +102,7 @@ static serialPortFunction_t serialPortFunctions[SERIAL_PORT_COUNT] = { {SERIAL_PORT_SOFTSERIAL1, NULL, SCENARIO_UNUSED, FUNCTION_NONE} }; -static const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { +const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { {SERIAL_PORT_USART1, 9600, 115200, SPF_NONE | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, {SERIAL_PORT_USART3, 9600, 115200, SPF_SUPPORTS_CALLBACK | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, {SERIAL_PORT_SOFTSERIAL1, 9600, 19200, SPF_SUPPORTS_CALLBACK | SPF_IS_SOFTWARE_INVERTABLE} @@ -118,7 +118,7 @@ static serialPortFunction_t serialPortFunctions[SERIAL_PORT_COUNT] = { #endif }; -static const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { +const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { {SERIAL_PORT_USART1, 9600, 115200, SPF_NONE | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, {SERIAL_PORT_USART2, 9600, 115200, SPF_SUPPORTS_CALLBACK | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, #if (SERIAL_PORT_COUNT > 2) @@ -544,9 +544,10 @@ serialPort_t *findSharedSerialPort(serialPortFunction_e functionToUse, uint16_t void applySerialConfigToPortFunctions(serialConfig_t *serialConfig) { - uint32_t portIndex = 0, serialPortIdentifier; + uint32_t portIndex = 0, serialPortIdentifier, constraintIndex; - for (serialPortIdentifier = 0; serialPortIdentifier < SERIAL_PORT_IDENTIFIER_COUNT && portIndex < SERIAL_PORT_COUNT; serialPortIdentifier++) { + for (constraintIndex = 0; constraintIndex < SERIAL_PORT_COUNT && portIndex < SERIAL_PORT_COUNT; constraintIndex++) { + serialPortIdentifier = serialPortConstraints[constraintIndex].identifier; uint32_t functionIndex = lookupSerialPortFunctionIndexByIdentifier(serialPortIdentifier); if (functionIndex == IDENTIFIER_NOT_FOUND) { continue; diff --git a/src/main/io/serial.h b/src/main/io/serial.h index 043d2c486..854044421 100644 --- a/src/main/io/serial.h +++ b/src/main/io/serial.h @@ -73,42 +73,18 @@ typedef enum { #endif } serialPortIndex_e; - -#ifdef STM32F303xC - -typedef enum { - SERIAL_PORT_USB_VCP = 0, - SERIAL_PORT_USART1, - SERIAL_PORT_USART2, - SERIAL_PORT_USART3, - SERIAL_PORT_USART4 -} serialPortIdentifier_e; - -#define SERIAL_PORT_IDENTIFIER_COUNT 5 -#else - -#ifdef CC3D - -typedef enum { - SERIAL_PORT_USART1 = 0, - SERIAL_PORT_USART3, - SERIAL_PORT_SOFTSERIAL1, -} serialPortIdentifier_e; - -#define SERIAL_PORT_IDENTIFIER_COUNT 3 -#else - +// serial port identifiers are now fixed, these values are used by MSP commands. typedef enum { SERIAL_PORT_USART1 = 0, SERIAL_PORT_USART2, SERIAL_PORT_USART3, - SERIAL_PORT_SOFTSERIAL1, - SERIAL_PORT_SOFTSERIAL2 + SERIAL_PORT_USART4, + SERIAL_PORT_USB_VCP = 20, + SERIAL_PORT_SOFTSERIAL1 = 30, + SERIAL_PORT_SOFTSERIAL2, + SERIAL_PORT_IDENTIFIER_MAX = SERIAL_PORT_SOFTSERIAL2 } serialPortIdentifier_e; -#define SERIAL_PORT_IDENTIFIER_COUNT 5 -#endif -#endif // bitmask typedef enum { @@ -125,6 +101,7 @@ typedef struct serialPortConstraint_s { uint32_t maxBaudRate; serialPortFeature_t feature; } serialPortConstraint_t; +extern const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT]; typedef struct serialPortFunction_s { serialPortIdentifier_e identifier; diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c index 42eb50853..b43409bf5 100644 --- a/src/main/io/serial_msp.c +++ b/src/main/io/serial_msp.c @@ -196,6 +196,10 @@ const char *boardIdentifier = TARGET_BOARD_IDENTIFIER; #define MSP_ADJUSTMENT_RANGES 52 #define MSP_SET_ADJUSTMENT_RANGE 53 +// private - only to be used by the configurator, the commands are likely to change +#define MSP_CF_SERIAL_CONFIG 54 +#define MSP_SET_CF_SERIAL_CONFIG 55 + // // Baseflight MSP commands (if enabled they exist in Cleanflight) // @@ -203,9 +207,9 @@ const char *boardIdentifier = TARGET_BOARD_IDENTIFIER; #define MSP_SET_RX_MAP 65 //in message set rx map, numchannels to set comes from MSP_RX_MAP // FIXME - Provided for backwards compatibility with configurator code until configurator is updated. -// DEPRECATED - DO NOT USE "MSP_CONFIG" and MSP_SET_CONFIG. In Cleanflight, isolated commands already exist and should be used instead. +// DEPRECATED - DO NOT USE "MSP_BF_CONFIG" and MSP_SET_BF_CONFIG. In Cleanflight, isolated commands already exist and should be used instead. #define MSP_BF_CONFIG 66 //out message baseflight-specific settings that aren't covered elsewhere -#define MSP_BF_SET_CONFIG 67 //in message baseflight-specific settings save +#define MSP_SET_BF_CONFIG 67 //in message baseflight-specific settings save #define MSP_REBOOT 68 //in message reboot settings @@ -1066,6 +1070,21 @@ static bool processOutCommand(uint8_t cmdMSP) serialize16(masterConfig.batteryConfig.currentMeterOffset); break; + case MSP_CF_SERIAL_CONFIG: + headSerialReply( + ((sizeof(uint8_t) * 2) * SERIAL_PORT_COUNT) + + (sizeof(uint32_t) * 4) + ); + for (i = 0; i < SERIAL_PORT_COUNT; i++) { + serialize8(serialPortConstraints[i].identifier); + serialize8(masterConfig.serialConfig.serial_port_scenario[i]); + } + serialize32(masterConfig.serialConfig.msp_baudrate); + serialize32(masterConfig.serialConfig.cli_baudrate); + serialize32(masterConfig.serialConfig.gps_baudrate); + serialize32(masterConfig.serialConfig.gps_passthrough_baudrate); + break; + #ifdef LED_STRIP case MSP_LED_COLORS: headSerialReply(CONFIGURABLE_COLOR_COUNT * 4); @@ -1366,7 +1385,7 @@ static bool processInCommand(void) } break; - case MSP_BF_SET_CONFIG: + case MSP_SET_BF_CONFIG: #ifdef USE_QUAD_MIXER_ONLY read8(); // mixerMode ignored @@ -1387,6 +1406,24 @@ static bool processInCommand(void) masterConfig.batteryConfig.currentMeterOffset = read16(); break; + case MSP_SET_CF_SERIAL_CONFIG: + { + uint8_t baudRateSize = (sizeof(uint32_t) * 4); + uint8_t serialPortCount = currentPort->dataSize - baudRateSize; + if (serialPortCount != SERIAL_PORT_COUNT) { + headSerialError(0); + break; + } + for (i = 0; i < SERIAL_PORT_COUNT; i++) { + masterConfig.serialConfig.serial_port_scenario[i] = read8(); + } + masterConfig.serialConfig.msp_baudrate = read32(); + masterConfig.serialConfig.cli_baudrate = read32(); + masterConfig.serialConfig.gps_baudrate = read32(); + masterConfig.serialConfig.gps_passthrough_baudrate = read32(); + } + break; + #ifdef LED_STRIP case MSP_SET_LED_COLORS: for (i = 0; i < CONFIGURABLE_COLOR_COUNT; i++) { diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index dce2448db..453cb18e9 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -17,7 +17,7 @@ #pragma once -#define TARGET_BOARD_IDENTIFIER "AFNA" // AFroNAze - NAZE might be considerd misleading on Naze clones like the flip32. +#define TARGET_BOARD_IDENTIFIER "AFNA" // AFroNAze - NAZE might be considered misleading on Naze clones like the flip32. #define LED0_GPIO GPIOB #define LED0_PIN Pin_3 // PB3 (LED)