Skip to content

Commit

Permalink
Added inverted mode to Serial interface API
Browse files Browse the repository at this point in the history
  • Loading branch information
katzfey committed Mar 26, 2024
1 parent a6c1105 commit dcc76ce
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions platforms/common/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ bool Serial::setSwapRxTxMode()
return _impl.setSwapRxTxMode();
}

bool Serial::getInvertedMode() const
{
return _impl.getInvertedMode();
}

bool Serial::setInvertedMode(bool enable)
{
return _impl.setInvertedMode(enable);
}

const char *Serial::getPort() const
{
return _impl.getPort();
Expand Down
3 changes: 3 additions & 0 deletions platforms/common/include/px4_platform_common/Serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class Serial
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();

bool getInvertedMode() const;
bool setInvertedMode(bool enable);

const char *getPort() const;

private:
Expand Down
28 changes: 28 additions & 0 deletions platforms/nuttx/src/px4/common/SerialImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ bool SerialImpl::open()

_open = true;

// Do pin operations after port has been opened
if (_single_wire_mode) {
setSingleWireMode();
}
Expand All @@ -218,6 +219,8 @@ bool SerialImpl::open()
setSwapRxTxMode();
}

setInvertedMode(_inverted_mode);

return _open;
}

Expand Down Expand Up @@ -446,4 +449,29 @@ bool SerialImpl::setSwapRxTxMode()
#endif // TIOCSSWAP
}

bool SerialImpl::getInvertedMode() const
{
return _inverted_mode;
}

bool SerialImpl::setInvertedMode(bool enable)
{
#if defined(TIOCSINVERT)

if (_open) {
if (enable) {
ioctl(_serial_fd, TIOCSINVERT, SER_INVERT_ENABLED_RX | SER_INVERT_ENABLED_TX);

} else {
ioctl(_serial_fd, TIOCSINVERT, 0);
}
}

_inverted_mode = enable;
return true;
#else
return _inverted_mode == enable;
#endif // TIOCSINVERT
}

} // namespace device
4 changes: 4 additions & 0 deletions platforms/nuttx/src/px4/common/include/SerialImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class SerialImpl
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();

bool getInvertedMode() const;
bool setInvertedMode(bool enable);

private:

int _serial_fd{-1};
Expand All @@ -109,6 +112,7 @@ class SerialImpl

bool _single_wire_mode{false};
bool _swap_rx_tx_mode{false};
bool _inverted_mode{false};
};

} // namespace device
4 changes: 4 additions & 0 deletions platforms/posix/include/SerialImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class SerialImpl
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();

bool getInvertedMode() const;
bool setInvertedMode(bool enable);

private:

int _serial_fd{-1};
Expand All @@ -109,6 +112,7 @@ class SerialImpl

bool _single_wire_mode{false};
bool _swap_rx_tx_mode{false};
bool _inverted_mode{false};
};

} // namespace device
27 changes: 27 additions & 0 deletions platforms/posix/src/px4/common/SerialImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ bool SerialImpl::open()
setSwapRxTxMode();
}

setInvertedMode(_inverted_mode);

return _open;
}

Expand Down Expand Up @@ -439,4 +441,29 @@ bool SerialImpl::setSwapRxTxMode()
#endif // TIOCSSWAP
}

bool SerialImpl::getInvertedMode() const
{
return _inverted_mode;
}

bool SerialImpl::setInvertedMode(bool enable)
{
#if defined(TIOCSINVERT)

if (_open) {
if (enable) {
ioctl(_serial_fd, TIOCSINVERT, SER_INVERT_ENABLED_RX | SER_INVERT_ENABLED_TX);

} else {
ioctl(_serial_fd, TIOCSINVERT, 0);
}
}

_inverted_mode = enable;
return true;
#else
return _inverted_mode == enable;
#endif // TIOCSINVERT
}

} // namespace device
3 changes: 3 additions & 0 deletions platforms/qurt/include/SerialImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class SerialImpl
bool getSwapRxTxMode() const;
bool setSwapRxTxMode();

bool getInvertedMode() const;
bool setInvertedMode(bool enable);

private:

int _serial_fd{-1};
Expand Down
10 changes: 10 additions & 0 deletions platforms/qurt/src/px4/SerialImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,14 @@ bool SerialImpl::setSwapRxTxMode()
return false;
}

bool SerialImpl::setInvertedMode(bool enable)
{
// Qurt platform does not support inverted mode
return false == enable;
}
bool SerialImpl::getInvertedMode() const
{
return false;
}

} // namespace device

0 comments on commit dcc76ce

Please sign in to comment.