Triforce/SerialDevice: Add PassThroughTxBytes function and some minor cleanups.
This commit is contained in:
@@ -16,9 +16,7 @@ void SerialDevice::WriteRxBytes(std::span<const u8> bytes)
|
|||||||
#if defined(__cpp_lib_containers_ranges)
|
#if defined(__cpp_lib_containers_ranges)
|
||||||
m_rx_buffer.append_range(bytes);
|
m_rx_buffer.append_range(bytes);
|
||||||
#else
|
#else
|
||||||
const auto prev_size = m_rx_buffer.size();
|
m_rx_buffer.insert(m_rx_buffer.end(), bytes.begin(), bytes.end());
|
||||||
m_rx_buffer.resize(prev_size + bytes.size());
|
|
||||||
std::ranges::copy(bytes, m_rx_buffer.begin() + prev_size);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +40,34 @@ void SerialDevice::WriteTxBytes(std::span<const u8> bytes)
|
|||||||
#if defined(__cpp_lib_containers_ranges)
|
#if defined(__cpp_lib_containers_ranges)
|
||||||
m_tx_buffer.append_range(bytes);
|
m_tx_buffer.append_range(bytes);
|
||||||
#else
|
#else
|
||||||
const auto prev_size = m_tx_buffer.size();
|
m_tx_buffer.insert(m_tx_buffer.end(), bytes.begin(), bytes.end());
|
||||||
m_tx_buffer.resize(prev_size + bytes.size());
|
|
||||||
std::ranges::copy(bytes, m_tx_buffer.begin() + prev_size);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SerialDevice::PassThroughTxBytes(SerialDevice& other)
|
||||||
|
{
|
||||||
|
// The destination buffer will often be empty or near-empty.
|
||||||
|
if (m_tx_buffer.size() < other.m_tx_buffer.size()) [[likely]]
|
||||||
|
{
|
||||||
|
#if defined(__cpp_lib_containers_ranges)
|
||||||
|
other.m_tx_buffer.prepend_range(m_tx_buffer);
|
||||||
|
#else
|
||||||
|
other.m_tx_buffer.insert(other.m_tx_buffer.begin(), m_tx_buffer.begin(), m_tx_buffer.end());
|
||||||
|
#endif
|
||||||
|
m_tx_buffer.swap(other.m_tx_buffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(__cpp_lib_containers_ranges)
|
||||||
|
m_tx_buffer.append_range(other.m_tx_buffer);
|
||||||
|
#else
|
||||||
|
m_tx_buffer.insert(m_tx_buffer.end(), other.m_tx_buffer.begin(), other.m_tx_buffer.end());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
other.m_tx_buffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void SerialDevice::DoState(PointerWrap& p)
|
void SerialDevice::DoState(PointerWrap& p)
|
||||||
{
|
{
|
||||||
p.Do(m_rx_buffer);
|
p.Do(m_rx_buffer);
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ protected:
|
|||||||
void WriteTxByte(u8 byte) { m_tx_buffer.emplace_back(byte); }
|
void WriteTxByte(u8 byte) { m_tx_buffer.emplace_back(byte); }
|
||||||
void WriteTxBytes(std::span<const u8> bytes);
|
void WriteTxBytes(std::span<const u8> bytes);
|
||||||
|
|
||||||
|
// Transfer the entirety of other's tx buffer to this tx buffer.
|
||||||
|
void PassThroughTxBytes(SerialDevice& other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The stream of bytes from the baseboard to the device.
|
// The stream of bytes from the baseboard to the device.
|
||||||
// FYI: Current device implementations tend to empty the entire buffer in one go,
|
// FYI: Current device implementations tend to empty the entire buffer in one go,
|
||||||
|
|||||||
Reference in New Issue
Block a user