diff --git a/src/main/common/log.h b/src/main/common/log.h index bc6795e5dd9..ac45e48e89c 100644 --- a/src/main/common/log.h +++ b/src/main/common/log.h @@ -30,6 +30,7 @@ typedef enum { LOG_TOPIC_POS_ESTIMATOR, // 8, mask = 256 LOG_TOPIC_VTX, // 9, mask = 512 LOG_TOPIC_OSD, // 10, mask = 1024 + LOG_TOPIC_SERIAL, // 11, mask = 2048 LOG_TOPIC_COUNT, } logTopic_e; diff --git a/src/main/config/parameter_group_ids.h b/src/main/config/parameter_group_ids.h index 2acb9c8172e..2797cbe200f 100644 --- a/src/main/config/parameter_group_ids.h +++ b/src/main/config/parameter_group_ids.h @@ -132,7 +132,8 @@ #define PG_GEOZONE_CONFIG 1042 #define PG_GEOZONES 1043 #define PG_GEOZONE_VERTICES 1044 -#define PG_INAV_END PG_GEOZONE_VERTICES +#define PG_CRSFRXPORT_CONFIG 1045 +#define PG_INAV_END PG_CRSFRXPORT_CONFIG // OSD configuration (subject to change) //#define PG_OSD_FONT_CONFIG 2047 diff --git a/src/main/drivers/serial.h b/src/main/drivers/serial.h index 6ca0a7d1ec2..8ae96dc97bf 100644 --- a/src/main/drivers/serial.h +++ b/src/main/drivers/serial.h @@ -53,6 +53,8 @@ typedef enum portOptions_t { SERIAL_LONGSTOP = 0 << 6, SERIAL_SHORTSTOP = 1 << 6, + + SERIAL_RXTX_SWAP = 1 << 7 } portOptions_t; typedef void (*serialReceiveCallbackPtr)(uint16_t data, void *rxCallbackData); // used by serial drivers to return frames to app diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index cce38422848..e473db85ce0 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -27,6 +27,7 @@ #include "platform.h" #include "build/build_config.h" +#include "build/debug.h" #include "common/utils.h" #include "drivers/io.h" @@ -86,6 +87,11 @@ static void uartReconfigure(uartPort_t *uartPort) usartConfigurePinInversion(uartPort); + if (uartPort->port.options & SERIAL_RXTX_SWAP) + { + SET_BIT(uartPort->USARTx->CR2, USART_CR2_SWAP); + } + if (uartPort->port.options & SERIAL_BIDIR) { HAL_HalfDuplex_Init(&uartPort->Handle); @@ -111,6 +117,7 @@ static void uartReconfigure(uartPort_t *uartPort) /* Enable the UART Transmit Data Register Empty Interrupt */ SET_BIT(uartPort->USARTx->CR1, USART_CR1_TXEIE); } + return; } @@ -155,7 +162,6 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, return (serialPort_t *)s; } - // common serial initialisation code should move to serialPort::init() s->port.rxBufferHead = s->port.rxBufferTail = 0; s->port.txBufferHead = s->port.txBufferTail = 0; diff --git a/src/main/fc/config.c b/src/main/fc/config.c index d3021317ae5..130576d742f 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -131,6 +131,13 @@ PG_RESET_TEMPLATE(beeperConfig_t, beeperConfig, .pwmMode = SETTING_BEEPER_PWM_MODE_DEFAULT, ); +PG_REGISTER_WITH_RESET_TEMPLATE(crsfRxPortConfig_t, crsfRxPortConfig, PG_CRSFRXPORT_CONFIG, 1); + +PG_RESET_TEMPLATE(crsfRxPortConfig_t, crsfRxPortConfig, + .swap = 0, + .preferred_swap = 0 +); + PG_REGISTER_WITH_RESET_TEMPLATE(adcChannelConfig_t, adcChannelConfig, PG_ADC_CHANNEL_CONFIG, 0); PG_RESET_TEMPLATE(adcChannelConfig_t, adcChannelConfig, diff --git a/src/main/fc/config.h b/src/main/fc/config.h index e3bde5f3eb7..f26ac0bc9b2 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -94,6 +94,13 @@ typedef struct beeperConfig_s { PG_DECLARE(beeperConfig_t, beeperConfig); +typedef struct CrsfRxPortConfig_s { + bool swap; + bool preferred_swap; +} crsfRxPortConfig_t; + +PG_DECLARE(crsfRxPortConfig_t, crsfRxPortConfig); + typedef struct adcChannelConfig_s { uint8_t adcFunctionChannel[ADC_FUNCTION_COUNT]; } adcChannelConfig_t; diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 3e353e9dfcd..c10d136ff5d 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -4249,6 +4249,16 @@ groups: default_value: OFF description: "Allows disabling PWM mode for beeper on some targets. Switch from ON to OFF if the external beeper sound is weak. Do not switch from OFF to ON without checking if the board supports PWM beeper mode" + - name: PG_CRSFRXPORT_CONFIG + type: crsfRxPortConfig_t + headers: [ "fc/config.h" ] + members: + - name: crsf_rx_swap + field: swap + type: bool + default_value: OFF + description: "Swaps rx/tx for CRSF RX uart" + - name: PG_POWER_LIMITS_CONFIG type: powerLimitsConfig_t headers: ["flight/power_limits.h"] diff --git a/src/main/rx/crsf.c b/src/main/rx/crsf.c index e5855205642..b287bb19b9f 100755 --- a/src/main/rx/crsf.c +++ b/src/main/rx/crsf.c @@ -29,6 +29,7 @@ #include "common/crc.h" #include "common/maths.h" #include "common/utils.h" +#include "common/log.h" #include "drivers/time.h" #include "drivers/serial.h" @@ -329,13 +330,25 @@ bool crsfRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig) return false; } + portOptions_t options = CRSF_PORT_OPTIONS | (tristateWithDefaultOffIsActive(rxConfig->halfDuplex) ? SERIAL_BIDIR : 0); + +#if defined(NEXUSX) + if ((portConfig->identifier == SERIAL_PORT_USART3) || // Port C + (portConfig->identifier == SERIAL_PORT_USART4) || // Port A + (portConfig->identifier == SERIAL_PORT_USART6)) // Port B + { + LOG_DEBUG(SERIAL, "crsfRxInit rxtx swap"); + options |= SERIAL_RXTX_SWAP; + } +#endif + serialPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, crsfDataReceive, NULL, CRSF_BAUDRATE, CRSF_PORT_MODE, - CRSF_PORT_OPTIONS | (tristateWithDefaultOffIsActive(rxConfig->halfDuplex) ? SERIAL_BIDIR : 0) + options ); return serialPort != NULL;