Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/main/config/parameter_group_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/drivers/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/main/drivers/serial_uart_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "platform.h"

#include "build/build_config.h"
#include "build/debug.h"

#include "common/utils.h"
#include "drivers/io.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/fc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/main/fc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4244,6 +4244,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"]
Expand Down
15 changes: 14 additions & 1 deletion src/main/rx/crsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down