mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 05:45:31 +03:00
Adding new (private) MSP commands for configurating serial port
scenarios and baud rates.
This commit is contained in:
parent
98b258e83f
commit
73e82b8446
4 changed files with 54 additions and 39 deletions
|
@ -81,7 +81,7 @@ static serialPortFunction_t serialPortFunctions[SERIAL_PORT_COUNT] = {
|
||||||
#endif
|
#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_USB_VCP, 9600, 115200, SPF_NONE },
|
||||||
{SERIAL_PORT_USART1, 9600, 115200, SPF_NONE | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE},
|
{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},
|
{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}
|
{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_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_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}
|
{SERIAL_PORT_SOFTSERIAL1, 9600, 19200, SPF_SUPPORTS_CALLBACK | SPF_IS_SOFTWARE_INVERTABLE}
|
||||||
|
@ -118,7 +118,7 @@ static serialPortFunction_t serialPortFunctions[SERIAL_PORT_COUNT] = {
|
||||||
#endif
|
#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_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},
|
{SERIAL_PORT_USART2, 9600, 115200, SPF_SUPPORTS_CALLBACK | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE},
|
||||||
#if (SERIAL_PORT_COUNT > 2)
|
#if (SERIAL_PORT_COUNT > 2)
|
||||||
|
@ -544,9 +544,10 @@ serialPort_t *findSharedSerialPort(serialPortFunction_e functionToUse, uint16_t
|
||||||
|
|
||||||
void applySerialConfigToPortFunctions(serialConfig_t *serialConfig)
|
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);
|
uint32_t functionIndex = lookupSerialPortFunctionIndexByIdentifier(serialPortIdentifier);
|
||||||
if (functionIndex == IDENTIFIER_NOT_FOUND) {
|
if (functionIndex == IDENTIFIER_NOT_FOUND) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -73,42 +73,18 @@ typedef enum {
|
||||||
#endif
|
#endif
|
||||||
} serialPortIndex_e;
|
} serialPortIndex_e;
|
||||||
|
|
||||||
|
// serial port identifiers are now fixed, these values are used by MSP commands.
|
||||||
#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
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SERIAL_PORT_USART1 = 0,
|
SERIAL_PORT_USART1 = 0,
|
||||||
SERIAL_PORT_USART2,
|
SERIAL_PORT_USART2,
|
||||||
SERIAL_PORT_USART3,
|
SERIAL_PORT_USART3,
|
||||||
SERIAL_PORT_SOFTSERIAL1,
|
SERIAL_PORT_USART4,
|
||||||
SERIAL_PORT_SOFTSERIAL2
|
SERIAL_PORT_USB_VCP = 20,
|
||||||
|
SERIAL_PORT_SOFTSERIAL1 = 30,
|
||||||
|
SERIAL_PORT_SOFTSERIAL2,
|
||||||
|
SERIAL_PORT_IDENTIFIER_MAX = SERIAL_PORT_SOFTSERIAL2
|
||||||
} serialPortIdentifier_e;
|
} serialPortIdentifier_e;
|
||||||
|
|
||||||
#define SERIAL_PORT_IDENTIFIER_COUNT 5
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// bitmask
|
// bitmask
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -125,6 +101,7 @@ typedef struct serialPortConstraint_s {
|
||||||
uint32_t maxBaudRate;
|
uint32_t maxBaudRate;
|
||||||
serialPortFeature_t feature;
|
serialPortFeature_t feature;
|
||||||
} serialPortConstraint_t;
|
} serialPortConstraint_t;
|
||||||
|
extern const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT];
|
||||||
|
|
||||||
typedef struct serialPortFunction_s {
|
typedef struct serialPortFunction_s {
|
||||||
serialPortIdentifier_e identifier;
|
serialPortIdentifier_e identifier;
|
||||||
|
|
|
@ -196,6 +196,10 @@ const char *boardIdentifier = TARGET_BOARD_IDENTIFIER;
|
||||||
#define MSP_ADJUSTMENT_RANGES 52
|
#define MSP_ADJUSTMENT_RANGES 52
|
||||||
#define MSP_SET_ADJUSTMENT_RANGE 53
|
#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)
|
// 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
|
#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.
|
// 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_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
|
#define MSP_REBOOT 68 //in message reboot settings
|
||||||
|
|
||||||
|
@ -1066,6 +1070,21 @@ static bool processOutCommand(uint8_t cmdMSP)
|
||||||
serialize16(masterConfig.batteryConfig.currentMeterOffset);
|
serialize16(masterConfig.batteryConfig.currentMeterOffset);
|
||||||
break;
|
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
|
#ifdef LED_STRIP
|
||||||
case MSP_LED_COLORS:
|
case MSP_LED_COLORS:
|
||||||
headSerialReply(CONFIGURABLE_COLOR_COUNT * 4);
|
headSerialReply(CONFIGURABLE_COLOR_COUNT * 4);
|
||||||
|
@ -1366,7 +1385,7 @@ static bool processInCommand(void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_BF_SET_CONFIG:
|
case MSP_SET_BF_CONFIG:
|
||||||
|
|
||||||
#ifdef USE_QUAD_MIXER_ONLY
|
#ifdef USE_QUAD_MIXER_ONLY
|
||||||
read8(); // mixerMode ignored
|
read8(); // mixerMode ignored
|
||||||
|
@ -1387,6 +1406,24 @@ static bool processInCommand(void)
|
||||||
masterConfig.batteryConfig.currentMeterOffset = read16();
|
masterConfig.batteryConfig.currentMeterOffset = read16();
|
||||||
break;
|
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
|
#ifdef LED_STRIP
|
||||||
case MSP_SET_LED_COLORS:
|
case MSP_SET_LED_COLORS:
|
||||||
for (i = 0; i < CONFIGURABLE_COLOR_COUNT; i++) {
|
for (i = 0; i < CONFIGURABLE_COLOR_COUNT; i++) {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#pragma once
|
#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_GPIO GPIOB
|
||||||
#define LED0_PIN Pin_3 // PB3 (LED)
|
#define LED0_PIN Pin_3 // PB3 (LED)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue