Added implementations of Rx Tx swap and single wire for new UART API needed by CRSF driver

This commit is contained in:
Eric Katzfey 2024-03-22 11:17:02 -07:00
parent d6f3a206e0
commit eb9f71892f
9 changed files with 167 additions and 6 deletions

View File

@ -135,6 +135,24 @@ bool Serial::setFlowcontrol(FlowControl flowcontrol)
return _impl.setFlowcontrol(flowcontrol);
}
bool Serial::getSingleWireMode() const
{
return _impl.getSingleWireMode();
}
bool Serial::setSingleWireMode()
{
return _impl.setSingleWireMode();
}
bool Serial::getSwapRxTxMode() const
{
return _impl.getSwapRxTxMode();
}
bool Serial::setSwapRxTxMode()
{
return _impl.setSwapRxTxMode();
}
const char *Serial::getPort() const
{
return _impl.getPort();

View File

@ -85,6 +85,12 @@ public:
FlowControl getFlowcontrol() const;
bool setFlowcontrol(FlowControl flowcontrol);
bool getSingleWireMode() const;
bool setSingleWireMode();
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();
const char *getPort() const;
private:

View File

@ -210,6 +210,14 @@ bool SerialImpl::open()
_open = true;
if (_single_wire_mode) {
setSingleWireMode();
}
if (_swap_rx_tx_mode) {
setSwapRxTxMode();
}
return _open;
}
@ -398,4 +406,44 @@ bool SerialImpl::setFlowcontrol(FlowControl flowcontrol)
return flowcontrol == FlowControl::Disabled;
}
bool SerialImpl::getSingleWireMode() const
{
return _single_wire_mode;
}
bool SerialImpl::setSingleWireMode()
{
#if defined(TIOCSSINGLEWIRE)
if (_open) {
ioctl(_serial_fd, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED);
}
_single_wire_mode = true;
return true;
#else
return false;
#endif // TIOCSSINGLEWIRE
}
bool SerialImpl::getSwapRxTxMode() const
{
return _swap_rx_tx_mode;
}
bool SerialImpl::setSwapRxTxMode()
{
#if defined(TIOCSSWAP)
if (_open) {
ioctl(_serial_fd, TIOCSSWAP, SER_SWAP_ENABLED);
}
_swap_rx_tx_mode = true;
return true;
#else
return false;
#endif // TIOCSSWAP
}
} // namespace device

View File

@ -83,6 +83,12 @@ public:
FlowControl getFlowcontrol() const;
bool setFlowcontrol(FlowControl flowcontrol);
bool getSingleWireMode() const;
bool setSingleWireMode();
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();
private:
int _serial_fd{-1};
@ -101,6 +107,8 @@ private:
bool validateBaudrate(uint32_t baudrate);
bool configure();
bool _single_wire_mode{false};
bool _swap_rx_tx_mode{false};
};
} // namespace device

View File

@ -83,6 +83,12 @@ public:
FlowControl getFlowcontrol() const;
bool setFlowcontrol(FlowControl flowcontrol);
bool getSingleWireMode() const;
bool setSingleWireMode();
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();
private:
int _serial_fd{-1};
@ -100,6 +106,9 @@ private:
bool validateBaudrate(uint32_t baudrate);
bool configure();
bool _single_wire_mode{false};
bool _swap_rx_tx_mode{false};
};
} // namespace device

View File

@ -208,6 +208,14 @@ bool SerialImpl::open()
_open = true;
if (_single_wire_mode) {
setSingleWireMode();
}
if (_swap_rx_tx_mode) {
setSwapRxTxMode();
}
return _open;
}
@ -391,4 +399,44 @@ bool SerialImpl::setFlowcontrol(FlowControl flowcontrol)
return flowcontrol == FlowControl::Disabled;
}
bool SerialImpl::getSingleWireMode() const
{
return _single_wire_mode;
}
bool SerialImpl::setSingleWireMode()
{
#if defined(TIOCSSINGLEWIRE)
if (_open) {
ioctl(_serial_fd, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED);
}
_single_wire_mode = true;
return true;
#else
return false;
#endif // TIOCSSINGLEWIRE
}
bool SerialImpl::getSwapRxTxMode() const
{
return _swap_rx_tx_mode;
}
bool SerialImpl::setSwapRxTxMode()
{
#if defined(TIOCSSWAP)
if (_open) {
ioctl(_serial_fd, TIOCSSWAP, SER_SWAP_ENABLED);
}
_swap_rx_tx_mode = true;
return true;
#else
return false;
#endif // TIOCSSWAP
}
} // namespace device

View File

@ -83,6 +83,12 @@ public:
FlowControl getFlowcontrol() const;
bool setFlowcontrol(FlowControl flowcontrol);
bool getSingleWireMode() const;
bool setSingleWireMode();
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();
private:
int _serial_fd{-1};

View File

@ -328,4 +328,26 @@ bool SerialImpl::setFlowcontrol(FlowControl flowcontrol)
return flowcontrol == FlowControl::Disabled;
}
bool SerialImpl::getSingleWireMode() const
{
return false;
}
bool SerialImpl::setSingleWireMode()
{
// Qurt platform does not support single wire mode
return false;
}
bool SerialImpl::getSwapRxTxMode() const
{
return false;
}
bool SerialImpl::setSwapRxTxMode()
{
// Qurt platform does not support swap rx tx mode
return false;
}
} // namespace device

View File

@ -155,16 +155,12 @@ void CrsfRc::Run()
}
if (board_rc_swap_rxtx(_device)) {
#if defined(TIOCSSWAP)
ioctl(_rc_fd, TIOCSSWAP, SER_SWAP_ENABLED);
#endif // TIOCSSWAP
_uart->setSwapRxTxMode();
}
if (board_rc_singlewire(_device)) {
_is_singlewire = true;
#if defined(TIOCSSINGLEWIRE)
ioctl(_rc_fd, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED);
#endif // TIOCSSINGLEWIRE
_uart->setSingleWireMode();
}
PX4_INFO("Crsf serial opened sucessfully");