#include <uart.h>
Public Member Functions | |
StatusWithSize | ReadAtLeast (ByteSpan rx_buffer, size_t min_bytes) |
StatusWithSize | ReadExactly (ByteSpan rx_buffer) |
Status | Read (ByteSpan rx_buffer) |
StatusWithSize | TryReadAtLeastFor (ByteSpan rx_buffer, size_t min_bytes, chrono::SystemClock::duration timeout) |
StatusWithSize | TryReadExactlyFor (ByteSpan rx_buffer, chrono::SystemClock::duration timeout) |
StatusWithSize | TryReadFor (ByteSpan rx_buffer, chrono::SystemClock::duration timeout) |
Status | Write (ConstByteSpan tx_buffer) |
StatusWithSize | TryWriteFor (ConstByteSpan tx_buffer, chrono::SystemClock::duration timeout) |
Status | FlushOutput () |
![]() | |
Status | Enable () |
Status | Disable () |
Status | SetBaudRate (uint32_t baud_rate) |
Status | SetFlowControl (bool enable) |
size_t | ConservativeReadAvailable () |
Status | ClearPendingReceiveBytes () |
Private Member Functions | |
virtual StatusWithSize | DoTryReadFor (ByteSpan rx_buffer, std::optional< chrono::SystemClock::duration > timeout) |
virtual StatusWithSize | DoTryReadFor (ByteSpan, size_t, std::optional< chrono::SystemClock::duration >) |
virtual StatusWithSize | DoTryWriteFor (ConstByteSpan tx_buffer, std::optional< chrono::SystemClock::duration > timeout)=0 |
Writes data from a provided buffer to the UART with an optional timeout. | |
Represents an abstract UART interface.
The Uart
interface provides a basic set of methods for performing blocking UART communication.
|
inlineprivatevirtual |
Reads data from the UART into a provided buffer with an optional timeout provided.
This virtual function attempts to read data into the provided byte buffer (rx_buffer
). The operation will continue until either the buffer is full, an error occurs, or the optional timeout duration expires.
rx_buffer | The buffer to read data into. |
timeout | An optional timeout duration. If specified, the function will block for no longer than this duration. If zero, the function will immediately return with at least one hardware read operation attempt. If not specified, the function blocks until the buffer is full. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful and the entire buffer has been * filled with data. * * DEADLINE_EXCEEDED: The operation timed out before the entire buffer * could be filled. * * May return other implementation-specific status codes. * *
|
inlineprivatevirtual |
Reads data from the UART into a provided buffer with an optional timeout provided.
This virtual function attempts to read data into the provided byte buffer (rx_buffer
). The operation will continue until either min_bytes
have been read into the buffer, an error occurs, or the optional timeout duration expires.
rx_buffer | The buffer to read data into. |
min_bytes | The minimum number of bytes to read before returning. |
timeout | An optional timeout duration. If specified, the function will block for no longer than this duration. If zero, the function will immediately return with at least one hardware read operation attempt. If not specified, the function blocks until the buffer is full. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful and the entire buffer has been * filled with data. * * DEADLINE_EXCEEDED: The operation timed out before the entire buffer * could be filled. * * May return other implementation-specific status codes. * *
Reimplemented in pw::uart::UartBlockingAdapter.
|
privatepure virtual |
Writes data from a provided buffer to the UART with an optional timeout.
This virtual function attempts to write data from the provided byte buffer (tx_buffer
) to the UART. The operation will continue until either the buffer is empty, an error occurs, or the optional timeout duration expires.
tx_buffer | The buffer containing data to be written. |
timeout | An optional timeout duration. If specified, the function will block for no longer than this duration. If zero, the function will immediately return after at least one hardware write operation attempt. If not specified, the function blocks until the buffer is empty. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful and the entire buffer has been * written. * * DEADLINE_EXCEEDED: The operation timed out before the entire buffer * could be written. * * May return other implementation-specific status codes. * *
Implemented in pw::uart::UartBlockingAdapter.
|
inline |
Blocks until all queued data in the UART has been transmitted and the FIFO is empty.
This function ensures that all data enqueued before calling this function has been transmitted. Any data enqueued after calling this function will be transmitted immediately.
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful. * * May return other implementation-specific status codes. * *
|
inline |
Deprecated: Prefer ReadExactly in new code.
Reads data from the UART into a provided buffer.
This function blocks until the entire buffer has been filled.
rx_buffer | The buffer to read data into. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful. * * May return other implementation-specific status codes. * *
|
inline |
Reads data from the UART into a provided buffer.
This function blocks until min_bytes
have been read into rx_buffer
.
rx_buffer | The buffer to read data into. |
min_bytes | The minimum number of bytes to read before returning. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful. * * May return other implementation-specific status codes. * *
|
inline |
Reads data from the UART into a provided buffer.
This function blocks until the entire buffer has been filled.
rx_buffer | The buffer to read data into. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful. * * May return other implementation-specific status codes. * *
|
inline |
Reads data from the UART into a provided buffer.
This function blocks until either min_bytes
have been read into buffer or the specified timeout has elapsed, whichever occurs first.
rx_buffer | The buffer to read data into. |
min_bytes | The minimum number of bytes to read before returning. |
timeout | The maximum time to wait for data to be read. If zero, the function will immediately return with at least one hardware read operation attempt. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful and the entire buffer has been filled * with data. * * DEADLINE_EXCEEDED: The operation timed out before the entire buffer * could be filled. * * May return other implementation-specific status codes. * *
|
inline |
Reads data from the UART into a provided buffer.
This function blocks until either rx_buffer.size()
bytes have been read into buffer or the specified timeout has elapsed, whichever occurs first.
rx_buffer | The buffer to read data into. |
timeout | The maximum time to wait for data to be read. If zero, the function will immediately return with at least one hardware read operation attempt. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful and the entire buffer has been filled * with data. * * DEADLINE_EXCEEDED: The operation timed out before the entire buffer * could be filled. * * May return other implementation-specific status codes. * *
|
inline |
Deprecated: Prefer TryReadExactlyFor in new code. Reads data from the UART into a provided buffer.
This function blocks until either rx_buffer.size()
bytes have been read into buffer or the specified timeout has elapsed, whichever occurs first.
rx_buffer | The buffer to read data into. |
timeout | The maximum time to wait for data to be read. If zero, the function will immediately return with at least one hardware read operation attempt. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful and the entire buffer has been filled * with data. * * DEADLINE_EXCEEDED: The operation timed out before the entire buffer * could be filled. * * May return other implementation-specific status codes. * *
|
inline |
Writes data from the provided buffer to the UART. The function blocks until either the entire buffer has been written or the specified timeout has elapsed, whichever occurs first.
tx_buffer | The buffer to write data from. |
timeout | The maximum time to wait for data to be written. If zero, the function will immediately return with at least one hardware write operation attempt. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful and the entire buffer has been * written. * * DEADLINE_EXCEEDED: The operation timed out before the entire buffer * could be written. * * May return other implementation-specific status codes. * *
|
inline |
Writes data from the provided buffer to the UART. The function blocks until the entire buffer has been written.
tx_buffer | - The buffer to write data from. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The operation was successful. * * May return other implementation-specific status codes. * *