[BACKPORT] RCInput:Add Support for RX-TX SWAP using onewire

A board can optionaly define RC_SERIAL_SWAP_USING_SINGLEWIRE
   If the board is wired board with TX to the input (Swapped) and
   the SoC does not support U[S]ART level RX-TX swapping to allow
   useing onewire to do the swap if and only if:

     RC_SERIAL_SWAP_USING_SINGLEWIRE   is defined
     RC_SERIAL_SWAP_RXTX               is defined
     TIOCSSWAP                         is defined and retuns !OK
     TIOCSSINGLEWIRE                   is defined
This commit is contained in:
David Sidrane
2023-11-16 06:29:44 -08:00
parent 0cf9d4abc7
commit 14a532c24d
3 changed files with 34 additions and 0 deletions
@@ -465,6 +465,15 @@ static inline bool board_rc_singlewire(const char *device) { return false; }
* A board may define RC_SERIAL_SWAP_RXTX, so that RC_SERIAL_PORT is configured
* as UART with RX/TX swapped.
*
* It can optionaly define RC_SERIAL_SWAP_USING_SINGLEWIRE If the board is wired
* with TX to the input (Swapped) and the SoC does not support U[S]ART level
* HW swapping, then use onewire to do the swap if and only if:
*
* RC_SERIAL_SWAP_USING_SINGLEWIRE is defined
* RC_SERIAL_SWAP_RXTX is defined
* TIOCSSWAP is defined and retuns !OK
* TIOCSSINGLEWIRE is defined
*
* Input Parameters:
* device: serial device, e.g. "/dev/ttyS0"
*
+24
View File
@@ -296,6 +296,25 @@ void RCInput::rc_io_invert(bool invert)
}
}
void RCInput::swap_rx_tx()
{
#if defined(RC_SERIAL_SWAP_USING_SINGLEWIRE)
int rv = -ENOTTY;
# if defined(TIOCSSWAP)
rv = ioctl(_rcs_fd, TIOCSSWAP, SER_SWAP_ENABLED);
# endif // TIOCSSWAP
# ifdef TIOCSSINGLEWIRE
if (rv != OK) {
ioctl(_rcs_fd, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED);
}
# else
UNUSED(rv);
# endif // TIOCSSINGLEWIRE
#endif // RC_SERIAL_SWAP_USING_SINGLEWIRE
}
void RCInput::Run()
{
if (should_exit()) {
@@ -488,6 +507,7 @@ void RCInput::Run()
_rc_scan_begin = cycle_timestamp;
// Configure serial port for DSM
dsm_config(_rcs_fd);
swap_rx_tx();
// flush serial buffer and any existing buffered data
tcflush(_rcs_fd, TCIOFLUSH);
@@ -525,6 +545,7 @@ void RCInput::Run()
_rc_scan_begin = cycle_timestamp;
// Configure serial port for DSM
dsm_config(_rcs_fd);
swap_rx_tx();
// flush serial buffer and any existing buffered data
tcflush(_rcs_fd, TCIOFLUSH);
@@ -576,6 +597,7 @@ void RCInput::Run()
_rc_scan_begin = cycle_timestamp;
// Configure serial port for DSM
dsm_config(_rcs_fd);
swap_rx_tx();
// flush serial buffer and any existing buffered data
tcflush(_rcs_fd, TCIOFLUSH);
@@ -654,6 +676,7 @@ void RCInput::Run()
_rc_scan_begin = cycle_timestamp;
// Configure serial port for CRSF
crsf_config(_rcs_fd);
swap_rx_tx();
// flush serial buffer and any existing buffered data
tcflush(_rcs_fd, TCIOFLUSH);
@@ -702,6 +725,7 @@ void RCInput::Run()
_rc_scan_begin = cycle_timestamp;
// Configure serial port for GHST
ghst_config(_rcs_fd);
swap_rx_tx();
// flush serial buffer and any existing buffered data
tcflush(_rcs_fd, TCIOFLUSH);
+1
View File
@@ -126,6 +126,7 @@ private:
void set_rc_scan_state(RC_SCAN _rc_scan_state);
void rc_io_invert(bool invert);
void swap_rx_tx(void);
hrt_abstime _rc_scan_begin{0};