Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mmosca authored Jul 26, 2024
2 parents aa72b2d + 7e973c2 commit 255572b
Show file tree
Hide file tree
Showing 46 changed files with 2,105 additions and 1,164 deletions.
1 change: 1 addition & 0 deletions make/source.mk
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ COMMON_SRC = \
telemetry/msp_shared.c \
telemetry/ibus.c \
telemetry/ibus_shared.c \
telemetry/sensors.c \
sensors/esc_sensor.c \
io/vtx.c \
io/vtx_rtc6705.c \
Expand Down
55 changes: 24 additions & 31 deletions src/main/cli/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,26 +485,14 @@ const char * const lookupTableSwashType[] = {
"NONE", "PASSTHROUGH", "CP120", "CP135", "CP140", "FP90L", "FP90V",
};

const char * const lookupTableCrsfFmReuse[] = {
"NONE", "GOVERNOR", "HEADSPEED", "THROTTLE", "ESC_TEMP", "MCU_TEMP", "MCU_LOAD", "SYS_LOAD", "RT_LOAD", "BEC_VOLTAGE", "BUS_VOLTAGE", "MCU_VOLTAGE", "ADJFUNC", "GOV_ADJFUNC",
};

const char * const lookupTableCrsfAttReuse[] = {
"NONE", "THROTTLE", "ESC_TEMP", "ESC_PWM", "ESC_BEC_VOLTAGE", "ESC_BEC_CURRENT", "ESC_BEC_TEMP", "ESC_STATUS", "ESC_STATUS2", "MCU_TEMP", "MCU_LOAD", "SYS_LOAD", "RT_LOAD", "BEC_VOLTAGE", "BUS_VOLTAGE", "MCU_VOLTAGE",
};

const char * const lookupTableCrsfGpsReuse[] = {
"NONE", "HEADSPEED", "THROTTLE", "ESC_TEMP", "ESC_PWM", "ESC_THROTTLE", "ESC_BEC_VOLTAGE", "ESC_BEC_CURRENT", "ESC_BEC_TEMP", "ESC_STATUS", "ESC_STATUS2", "MCU_TEMP", "MCU_LOAD", "SYS_LOAD", "RT_LOAD", "BEC_VOLTAGE", "BUS_VOLTAGE", "MCU_VOLTAGE",
};

const char * const lookupTableCrsfGpsSatsReuse[] = {
"NONE", "ESC_TEMP", "MCU_TEMP", "PROFILE", "RATE_PROFILE", "LED_PROFILE", "MODEL_ID",
};

const char * const lookupTableDtermMode[] = {
"GYRO", "ERROR",
};

const char * const lookupTableTelemMode[] = {
"NATIVE", "CUSTOM",
};

#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }

const lookupTableEntry_t lookupTables[] = {
Expand Down Expand Up @@ -614,11 +602,8 @@ const lookupTableEntry_t lookupTables[] = {

LOOKUP_TABLE_ENTRY(lookupTableRescueMode),
LOOKUP_TABLE_ENTRY(lookupTableSwashType),
LOOKUP_TABLE_ENTRY(lookupTableCrsfFmReuse),
LOOKUP_TABLE_ENTRY(lookupTableCrsfAttReuse),
LOOKUP_TABLE_ENTRY(lookupTableCrsfGpsReuse),
LOOKUP_TABLE_ENTRY(lookupTableCrsfGpsSatsReuse),
LOOKUP_TABLE_ENTRY(lookupTableDtermMode),
LOOKUP_TABLE_ENTRY(lookupTableTelemMode),
};

#undef LOOKUP_TABLE_ENTRY
Expand Down Expand Up @@ -716,6 +701,10 @@ const clivalue_t valueTable[] = {
#ifdef USE_SERIAL_RX
{ PARAM_NAME_SERIAL_RX_PROVIDER, VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_SERIAL_RX }, PG_RX_CONFIG, offsetof(rxConfig_t, serialrx_provider) },
{ "serialrx_inverted", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, serialrx_inverted) },
{ "serialrx_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, halfDuplex) },
#ifdef USE_SERIAL_PINSWAP
{ "serialrx_pinswap", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, pinSwap) },
#endif
#endif
#ifdef USE_SPEKTRUM_BIND
{ "spektrum_sat_bind", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { SPEKTRUM_SAT_BIND_DISABLED, SPEKTRUM_SAT_BIND_MAX}, PG_RX_CONFIG, offsetof(rxConfig_t, spektrum_sat_bind) },
Expand All @@ -735,7 +724,6 @@ const clivalue_t valueTable[] = {
{ "crsf_use_negotiated_baud", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, crsf_use_negotiated_baud) },
#endif
#endif
{ "serialrx_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, halfDuplex) },
#ifdef USE_RX_SPI
{ "rx_spi_protocol", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_RX_SPI }, PG_RX_SPI_CONFIG, offsetof(rxSpiConfig_t, rx_spi_protocol) },
{ "rx_spi_bus", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, SPIDEV_COUNT }, PG_RX_SPI_CONFIG, offsetof(rxSpiConfig_t, spibus) },
Expand Down Expand Up @@ -1174,6 +1162,9 @@ const clivalue_t valueTable[] = {
#ifdef USE_TELEMETRY
{ "tlm_inverted", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, telemetry_inverted) },
{ "tlm_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, halfDuplex) },
#ifdef USE_SERIAL_PINSWAP
{ "tlm_pinswap", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, pinSwap) },
#endif
#if defined(USE_TELEMETRY_FRSKY_HUB)
#if defined(USE_GPS)
{ "frsky_default_lat", VAR_INT16 | MASTER_VALUE, .config.minmax = { -9000, 9000 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, gpsNoFixLatitude) },
Expand All @@ -1195,15 +1186,11 @@ const clivalue_t valueTable[] = {
// Set to $size_of_battery to get a percentage of battery used.
{ "mavlink_mah_as_heading_divisor", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 30000 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, mavlink_mah_as_heading_divisor) },
#endif
{ "crsf_flight_mode_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_FM_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_flight_mode_reuse) },
{ "crsf_att_pitch_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_ATT_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_att_pitch_reuse) },
{ "crsf_att_roll_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_ATT_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_att_roll_reuse) },
{ "crsf_att_yaw_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_ATT_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_att_yaw_reuse) },

{ "crsf_gps_heading_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_GPS_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_gps_heading_reuse) },
{ "crsf_gps_ground_speed_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_GPS_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_gps_ground_speed_reuse) },
{ "crsf_gps_altitude_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_GPS_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_gps_altitude_reuse) },
{ "crsf_gps_sats_reuse", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CRSF_GPS_SATS_REUSE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_gps_sats_reuse) },
{ "crsf_telemetry_mode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_TELEM_MODE }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_telemetry_mode) },
{ "crsf_telemetry_link_rate", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 50000 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_telemetry_link_rate) },
{ "crsf_telemetry_link_ratio", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 50000 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_telemetry_link_ratio) },
{ "crsf_telemetry_sensors", VAR_UINT16 | MASTER_VALUE | MODE_ARRAY, .config.array.length = TELEM_SENSOR_SLOT_COUNT, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_telemetry_sensors)},
{ "crsf_telemetry_interval", VAR_UINT16 | MASTER_VALUE | MODE_ARRAY, .config.array.length = TELEM_SENSOR_SLOT_COUNT, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, crsf_telemetry_interval)},

#ifdef USE_TELEMETRY_ENABLE_SENSORS
{ "telemetry_enable_voltage", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = LOG2(SENSOR_VOLTAGE), PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, enableSensors)},
Expand All @@ -1230,7 +1217,7 @@ const clivalue_t valueTable[] = {
{ "telemetry_enable_adjustment", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = LOG2(SENSOR_ADJUSTMENT), PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, enableSensors)},
{ "telemetry_enable_gov_mode", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = LOG2(SENSOR_GOV_MODE), PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, enableSensors)},
#else
{ "telemetry_enable_sensors", VAR_UINT32 | MASTER_VALUE, .config.u32Max = SENSOR_ALL, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, enableSensors)},
{ "telemetry_enable_sensors", VAR_UINT32 | MASTER_VALUE, .config.u32Max = SENSOR_ALL, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, enableSensors)},
#endif
#endif // USE_TELEMETRY

Expand Down Expand Up @@ -1486,6 +1473,9 @@ const clivalue_t valueTable[] = {
// PG_VTX_CONFIG
#if defined(USE_VTX_CONTROL) && defined(USE_VTX_COMMON)
{ "vtx_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_VTX_CONFIG, offsetof(vtxConfig_t, halfDuplex) },
#ifdef USE_SERIAL_PINSWAP
{ "vtx_pinswap", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_VTX_CONFIG, offsetof(vtxConfig_t, pinSwap) },
#endif
#endif

// PG_VTX_IO
Expand Down Expand Up @@ -1530,6 +1520,9 @@ const clivalue_t valueTable[] = {
#ifdef USE_ESC_SENSOR
{ "esc_sensor_protocol", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_ESC_SENSOR_PROTO }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, protocol) },
{ "esc_sensor_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, halfDuplex) },
#ifdef USE_SERIAL_PINSWAP
{ "esc_sensor_pinswap", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, pinSwap) },
#endif
{ "esc_sensor_update_hz", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 10, 500 }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, update_hz) },
{ "esc_sensor_current_offset", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 16000 }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, current_offset) },
{ "esc_sensor_hw4_current_offset", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 1000 }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, hw4_current_offset) },
Expand Down
5 changes: 1 addition & 4 deletions src/main/cli/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ typedef enum {
#endif
TABLE_RESCUE_MODE,
TABLE_SWASH_TYPE,
TABLE_CRSF_FM_REUSE,
TABLE_CRSF_ATT_REUSE,
TABLE_CRSF_GPS_REUSE,
TABLE_CRSF_GPS_SATS_REUSE,
TABLE_DTERM_MODE,
TABLE_TELEM_MODE,

LOOKUP_TABLE_COUNT
} lookupTableIndex_e;
Expand Down
46 changes: 29 additions & 17 deletions src/main/drivers/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,49 @@
#include "pg/serial_pinconfig.h"

typedef enum {
MODE_RX = 1 << 0,
MODE_TX = 1 << 1,
MODE_RXTX = MODE_RX | MODE_TX
MODE_RX = BIT(0),
MODE_TX = BIT(1),
MODE_RXTX = MODE_RX | MODE_TX
} portMode_e;

typedef enum {
SERIAL_NOT_INVERTED = 0 << 0,
SERIAL_INVERTED = 1 << 0,
SERIAL_STOPBITS_1 = 0 << 1,
SERIAL_STOPBITS_2 = 1 << 1,
SERIAL_PARITY_NO = 0 << 2,
SERIAL_PARITY_EVEN = 1 << 2,
SERIAL_UNIDIR = 0 << 3,
SERIAL_BIDIR = 1 << 3,
SERIAL_PINSWAP_BIT = 0,
SERIAL_INVERTED_BIT = 1,
SERIAL_STOPBITS_BIT = 2,
SERIAL_PARITY_BIT = 3,
SERIAL_BIDIR_BIT = 4,
SERIAL_BIDIR_OD_BIT = 5,
SERIAL_BIDIR_NOPULL_BIT = 6,
SERIAL_BIDIR_PULLDOWN_BIT = 7,
} portOptionBits_e;

typedef enum {
SERIAL_NOSWAP = 0,
SERIAL_PINSWAP = BIT(SERIAL_PINSWAP_BIT),
SERIAL_NOT_INVERTED = 0,
SERIAL_INVERTED = BIT(SERIAL_INVERTED_BIT),
SERIAL_STOPBITS_1 = 0,
SERIAL_STOPBITS_2 = BIT(SERIAL_STOPBITS_BIT),
SERIAL_PARITY_NO = 0,
SERIAL_PARITY_EVEN = BIT( SERIAL_PARITY_BIT),
SERIAL_UNIDIR = 0,
SERIAL_BIDIR = BIT(SERIAL_BIDIR_BIT),
/*
* Note on SERIAL_BIDIR_PP
* With SERIAL_BIDIR_PP, the very first start bit of back-to-back bytes
* is lost and the first data byte will be lost by a framing error.
* To ensure the first start bit to be sent, prepend a zero byte (0x00)
* to actual data bytes.
*/
SERIAL_BIDIR_OD = 0 << 4,
SERIAL_BIDIR_PP = 1 << 4,
SERIAL_BIDIR_NOPULL = 1 << 5, // disable pulls in BIDIR RX mode
SERIAL_BIDIR_PP_PD = 1 << 6, // PP mode, normall inverted, but with PullDowns, to fix SA after bidir issue fixed (#10220)
SERIAL_BIDIR_OD = 0,
SERIAL_BIDIR_PP = BIT(SERIAL_BIDIR_OD_BIT),
SERIAL_BIDIR_NOPULL = BIT(SERIAL_BIDIR_NOPULL_BIT), // disable pulls in BIDIR RX mode
SERIAL_BIDIR_PP_PD = BIT(SERIAL_BIDIR_PULLDOWN_BIT), // PP mode, normall inverted, but with PullDowns, to fix SA after bidir issue fixed (#10220)
} portOptions_e;

// Define known line control states which may be passed up by underlying serial driver callback
#define CTRL_LINE_STATE_DTR (1 << 0)
#define CTRL_LINE_STATE_RTS (1 << 1)
#define CTRL_LINE_STATE_DTR BIT(0)
#define CTRL_LINE_STATE_RTS BIT(1)

typedef void (*serialReceiveCallbackPtr)(uint16_t data, void *rxCallbackData); // used by serial drivers to return frames to app
typedef void (*serialIdleCallbackPtr)();
Expand Down
15 changes: 13 additions & 2 deletions src/main/drivers/serial_softserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,19 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb

int pinCfgIndex = portIndex + RESOURCE_SOFT_OFFSET;

ioTag_t tagRx = serialPinConfig()->ioTagRx[pinCfgIndex];
ioTag_t tagTx = serialPinConfig()->ioTagTx[pinCfgIndex];
ioTag_t tagRx, tagTx;
#ifdef USE_SERIAL_PINSWAP
if (options & SERIAL_PINSWAP)
{
tagTx = serialPinConfig()->ioTagRx[pinCfgIndex];
tagRx = serialPinConfig()->ioTagTx[pinCfgIndex];
}
else
#endif
{
tagRx = serialPinConfig()->ioTagRx[pinCfgIndex];
tagTx = serialPinConfig()->ioTagTx[pinCfgIndex];
}

const timerHardware_t *timerTx = timerAllocate(tagTx, OWNER_SERIAL_TX, RESOURCE_INDEX(portIndex + RESOURCE_SOFT_OFFSET));
const timerHardware_t *timerRx = (tagTx == tagRx) ? timerTx : timerAllocate(tagRx, OWNER_SERIAL_RX, RESOURCE_INDEX(portIndex + RESOURCE_SOFT_OFFSET));
Expand Down
2 changes: 2 additions & 0 deletions src/main/drivers/serial_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ LPUART_BUFFERS(1);

serialPort_t *uartOpen(UARTDevice_e device, serialReceiveCallbackPtr rxCallback, void *rxCallbackData, uint32_t baudRate, portMode_e mode, portOptions_e options)
{
uartSelectPins(device, options);

uartPort_t *uartPort = serialUART(device, baudRate, mode, options);

if (!uartPort)
Expand Down
42 changes: 32 additions & 10 deletions src/main/drivers/serial_uart_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void usartConfigurePinInversion(uartPort_t *uartPort) {
}
}

static uartDevice_t *uartFindDevice(uartPort_t *uartPort)
uartDevice_t *uartFindDevice(uartPort_t *uartPort)
{
for (uint32_t i = 0; i < UARTDEV_COUNT_MAX; i++) {
uartDevice_t *candidate = uartDevmap[i];
Expand All @@ -76,17 +76,39 @@ static uartDevice_t *uartFindDevice(uartPort_t *uartPort)
return NULL;
}

#if !(defined(STM32F4))
static void uartConfigurePinSwap(uartPort_t *uartPort)
void uartSelectPins(UARTDevice_e device, portOptions_e options)
{
uartDevice_t *uartDevice = uartFindDevice(uartPort);
if (!uartDevice) {
return;
UNUSED(options);

uartDevice_t *uartDevice = uartDevmap[device];

if (uartDevice) {
#ifdef USE_SERIAL_PINSWAP
bool swapOption = (options & SERIAL_PINSWAP);

if (uartDevice->pinSwap ^ swapOption) {
uartDevice->tx = uartDevice->rxPin;
uartDevice->rx = uartDevice->txPin;
}
else
#endif
{
uartDevice->rx = uartDevice->rxPin;
uartDevice->tx = uartDevice->txPin;
}
}
}

if (uartDevice->pinSwap) {
uartDevice->port.Handle.AdvancedInit.AdvFeatureInit |= UART_ADVFEATURE_SWAP_INIT;
uartDevice->port.Handle.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
#ifdef USE_SERIAL_PINSWAP
static void uartConfigurePinSwap(uartPort_t *uartPort)
{
uartDevice_t *uartDevice = uartFindDevice(uartPort);
if (uartDevice) {
bool swapOption = (uartPort->port.options & SERIAL_PINSWAP);
if (uartDevice->pinSwap ^ swapOption) {
uartDevice->port.Handle.AdvancedInit.AdvFeatureInit |= UART_ADVFEATURE_SWAP_INIT;
uartDevice->port.Handle.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
}
}
}
#endif
Expand Down Expand Up @@ -118,7 +140,7 @@ void uartReconfigure(uartPort_t *uartPort)


usartConfigurePinInversion(uartPort);
#if !(defined(STM32F1) || defined(STM32F4))
#ifdef USE_SERIAL_PINSWAP
uartConfigurePinSwap(uartPort);
#endif

Expand Down
6 changes: 5 additions & 1 deletion src/main/drivers/serial_uart_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ extern const uartHardware_t uartHardware[];
typedef struct uartDevice_s {
uartPort_t port;
const uartHardware_t *hardware;
uartPinDef_t rxPin;
uartPinDef_t txPin;
uartPinDef_t rx;
uartPinDef_t tx;
volatile uint8_t *rxBuffer;
volatile uint8_t *txBuffer;
#if !defined(STM32F4) // Don't support pin swap.
#if defined(USE_SERIAL_PINSWAP)
bool pinSwap;
#endif
} uartDevice_t;
Expand All @@ -219,6 +221,8 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode,

void uartIrqHandler(uartPort_t *s);

void uartSelectPins(UARTDevice_e device, portOptions_e options);

void uartReconfigure(uartPort_t *uartPort);

void uartConfigureDma(uartDevice_t *uartdev);
Expand Down
15 changes: 7 additions & 8 deletions src/main/drivers/serial_uart_pinconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,33 @@ void uartPinConfigure(const serialPinConfig_t *pSerialPinConfig)
const uartHardware_t *hardware = &uartHardware[hindex];
const UARTDevice_e device = hardware->device;

#if !defined(STM32F4) // Don't support pin swap.
#ifdef USE_SERIAL_PINSWAP
uartdev->pinSwap = false;
#endif
for (int pindex = 0 ; pindex < UARTHARDWARE_MAX_PINS ; pindex++) {
if (pSerialPinConfig->ioTagRx[device] && (pSerialPinConfig->ioTagRx[device] == hardware->rxPins[pindex].pin)) {
uartdev->rx = hardware->rxPins[pindex];
uartdev->rxPin = hardware->rxPins[pindex];
}

if (pSerialPinConfig->ioTagTx[device] && (pSerialPinConfig->ioTagTx[device] == hardware->txPins[pindex].pin)) {
uartdev->tx = hardware->txPins[pindex];
uartdev->txPin = hardware->txPins[pindex];
}


#if !defined(STM32F4)
#ifdef USE_SERIAL_PINSWAP
// Check for swapped pins
if (pSerialPinConfig->ioTagTx[device] && (pSerialPinConfig->ioTagTx[device] == hardware->rxPins[pindex].pin)) {
uartdev->tx = hardware->rxPins[pindex];
uartdev->rxPin = hardware->rxPins[pindex];
uartdev->pinSwap = true;
}

if (pSerialPinConfig->ioTagRx[device] && (pSerialPinConfig->ioTagRx[device] == hardware->txPins[pindex].pin)) {
uartdev->rx = hardware->txPins[pindex];
uartdev->txPin = hardware->txPins[pindex];
uartdev->pinSwap = true;
}
#endif
}

if (uartdev->rx.pin || uartdev->tx.pin) {
if (uartdev->rxPin.pin || uartdev->txPin.pin) {
uartdev->hardware = hardware;
uartDevmap[device] = uartdev++;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/drivers/serial_uart_stdperiph.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ static void usartConfigurePinInversion(uartPort_t *uartPort) {
#endif
}

void uartSelectPins(UARTDevice_e device, portOptions_e options)
{
UNUSED(options);

uartDevice_t *uartDevice = uartDevmap[device];

if (uartDevice) {
uartDevice->rx = uartDevice->rxPin;
uartDevice->tx = uartDevice->txPin;
}
}

void uartReconfigure(uartPort_t *uartPort)
{
USART_InitTypeDef USART_InitStructure;
Expand Down
Loading

0 comments on commit 255572b

Please sign in to comment.