mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 00:05:33 +03:00
Support UART3 and I2C on Paris Air Hero 32 Flex port (aka Naze32_SP).
This change also allows serial ports to be removed at runtime. e.g. UART3 on Naze32 and SoftSerial 1 & 2 when softserial is not enabled.
This commit is contained in:
parent
f2013ab863
commit
a370d60595
5 changed files with 92 additions and 18 deletions
|
@ -53,7 +53,7 @@
|
|||
static serialConfig_t *serialConfig;
|
||||
static serialPortUsage_t serialPortUsageList[SERIAL_PORT_COUNT];
|
||||
|
||||
serialPortIdentifier_e serialPortIdentifiers[SERIAL_PORT_COUNT] = {
|
||||
const serialPortIdentifier_e const serialPortIdentifiers[SERIAL_PORT_COUNT] = {
|
||||
#ifdef USE_VCP
|
||||
SERIAL_PORT_USB_VCP,
|
||||
#endif
|
||||
|
@ -74,7 +74,9 @@ serialPortIdentifier_e serialPortIdentifiers[SERIAL_PORT_COUNT] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
uint32_t baudRates[] = {0, 9600, 19200, 38400, 57600, 115200, 230400, 250000}; // see baudRate_e
|
||||
static uint8_t serialPortCount;
|
||||
|
||||
const uint32_t const baudRates[] = {0, 9600, 19200, 38400, 57600, 115200, 230400, 250000}; // see baudRate_e
|
||||
|
||||
#define BAUD_RATE_COUNT (sizeof(baudRates) / sizeof(baudRates[0]))
|
||||
|
||||
|
@ -226,16 +228,22 @@ bool isSerialConfigValid(serialConfig_t *serialConfigToCheck)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool doesConfigurationUsePort(serialPortIdentifier_e identifier)
|
||||
serialPortConfig_t *serialFindPortConfiguration(serialPortIdentifier_e identifier)
|
||||
{
|
||||
uint8_t index;
|
||||
for (index = 0; index < SERIAL_PORT_COUNT; index++) {
|
||||
serialPortConfig_t *candidate = &serialConfig->portConfigs[index];
|
||||
if (candidate->identifier == identifier && candidate->functionMask) {
|
||||
return true;
|
||||
if (candidate->identifier == identifier) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool doesConfigurationUsePort(serialPortIdentifier_e identifier)
|
||||
{
|
||||
serialPortConfig_t *candidate = serialFindPortConfiguration(identifier);
|
||||
return candidate != NULL && candidate->functionMask;
|
||||
}
|
||||
|
||||
serialPort_t *openSerialPort(
|
||||
|
@ -324,6 +332,7 @@ void serialInit(serialConfig_t *initialSerialConfig, bool softserialEnabled)
|
|||
|
||||
serialConfig = initialSerialConfig;
|
||||
|
||||
serialPortCount = SERIAL_PORT_COUNT;
|
||||
memset(&serialPortUsageList, 0, sizeof(serialPortUsageList));
|
||||
|
||||
for (index = 0; index < SERIAL_PORT_COUNT; index++) {
|
||||
|
@ -339,11 +348,37 @@ void serialInit(serialConfig_t *initialSerialConfig, bool softserialEnabled)
|
|||
#endif
|
||||
) {
|
||||
serialPortUsageList[index].identifier = SERIAL_PORT_NONE;
|
||||
serialPortCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void serialRemovePort(serialPortIdentifier_e identifier)
|
||||
{
|
||||
for (uint8_t index = 0; index < SERIAL_PORT_COUNT; index++) {
|
||||
if (serialPortUsageList[index].identifier == identifier) {
|
||||
serialPortUsageList[index].identifier = SERIAL_PORT_NONE;
|
||||
serialPortCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t serialGetAvailablePortCount(void)
|
||||
{
|
||||
return serialPortCount;
|
||||
}
|
||||
|
||||
bool serialIsPortAvailable(serialPortIdentifier_e identifier)
|
||||
{
|
||||
for (uint8_t index = 0; index < SERIAL_PORT_COUNT; index++) {
|
||||
if (serialPortUsageList[index].identifier == identifier) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void handleSerial(void)
|
||||
{
|
||||
#ifdef USE_CLI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue