Use SERIAL_PORT_NONE identifier to mark ports which are unavailable
This commit is contained in:
parent
86ddf27515
commit
dce873434b
|
@ -241,8 +241,8 @@ serialPort_t *openSerialPort(
|
||||||
portOptions_t options)
|
portOptions_t options)
|
||||||
{
|
{
|
||||||
serialPortUsage_t *serialPortUsage = findSerialPortUsageByIdentifier(identifier);
|
serialPortUsage_t *serialPortUsage = findSerialPortUsageByIdentifier(identifier);
|
||||||
if (!serialPortUsage->enabled || serialPortUsage->function != FUNCTION_NONE) {
|
if (!serialPortUsage || serialPortUsage->function != FUNCTION_NONE) {
|
||||||
// already in use
|
// not available / already in use
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,19 +323,18 @@ void serialInit(serialConfig_t *initialSerialConfig, bool softserialEnabled)
|
||||||
for (index = 0; index < SERIAL_PORT_COUNT; index++) {
|
for (index = 0; index < SERIAL_PORT_COUNT; index++) {
|
||||||
serialPortUsageList[index].identifier = serialPortIdentifiers[index];
|
serialPortUsageList[index].identifier = serialPortIdentifiers[index];
|
||||||
|
|
||||||
serialPortUsageList[index].enabled = true;
|
if (!softserialEnabled) {
|
||||||
|
if (0
|
||||||
#ifdef USE_SOFTSERIAL1
|
#ifdef USE_SOFTSERIAL1
|
||||||
if (serialPortUsageList[index].identifier == SERIAL_PORT_SOFTSERIAL1) {
|
|| serialPortUsageList[index].identifier == SERIAL_PORT_SOFTSERIAL1
|
||||||
serialPortUsageList[index].enabled = softserialEnabled;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SOFTSERIAL2
|
#ifdef USE_SOFTSERIAL2
|
||||||
if (serialPortUsageList[index].identifier == SERIAL_PORT_SOFTSERIAL2) {
|
|| serialPortUsageList[index].identifier == SERIAL_PORT_SOFTSERIAL2
|
||||||
serialPortUsageList[index].enabled = softserialEnabled;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
) {
|
||||||
|
serialPortUsageList[index].identifier = SERIAL_PORT_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ extern uint32_t baudRates[];
|
||||||
|
|
||||||
// serial port identifiers are now fixed, these values are used by MSP commands.
|
// serial port identifiers are now fixed, these values are used by MSP commands.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
SERIAL_PORT_NONE = -1,
|
||||||
SERIAL_PORT_USART1 = 0,
|
SERIAL_PORT_USART1 = 0,
|
||||||
SERIAL_PORT_USART2,
|
SERIAL_PORT_USART2,
|
||||||
SERIAL_PORT_USART3,
|
SERIAL_PORT_USART3,
|
||||||
|
@ -69,7 +70,6 @@ typedef struct serialPortUsage_s {
|
||||||
serialPortIdentifier_e identifier;
|
serialPortIdentifier_e identifier;
|
||||||
serialPort_t *serialPort;
|
serialPort_t *serialPort;
|
||||||
serialPortFunction_e function;
|
serialPortFunction_e function;
|
||||||
bool enabled;
|
|
||||||
} serialPortUsage_t;
|
} serialPortUsage_t;
|
||||||
|
|
||||||
serialPort_t *findSharedSerialPort(uint16_t functionMask, serialPortFunction_e sharedWithFunction);
|
serialPort_t *findSharedSerialPort(uint16_t functionMask, serialPortFunction_e sharedWithFunction);
|
||||||
|
|
Loading…
Reference in New Issue