diff --git a/pw_uart/public/pw_uart/uart.h b/pw_uart/public/pw_uart/uart.h index 16d1f9e656..3be6ceceb5 100644 --- a/pw_uart/public/pw_uart/uart.h +++ b/pw_uart/public/pw_uart/uart.h @@ -230,15 +230,6 @@ class Uart : public UartBase { return DoTryWriteFor(tx_buffer, timeout); } - /// Returns the number of bytes currently available for reading. - /// - /// This function checks the receive buffer to determine how many bytes of - /// data are ready to be read. - /// - /// @returns The number of bytes available for reading. When no data is - /// available or in case of an error this function returns 0. - size_t ConservativeReadAvailable() { return DoConservativeReadAvailable(); } - /// Blocks until all queued data in the UART has been transmitted and the /// FIFO is empty. /// @@ -257,23 +248,6 @@ class Uart : public UartBase { /// @endrst Status FlushOutput() { return DoFlushOutput(); } - /// Empties the UART's receive buffer and discards any unread data. - /// - /// This function removes all data from the receive buffer, resetting the - /// buffer to an empty state. This is useful for situations where you want to - /// disregard any previously received data and resynchronize. - /// - /// @returns @rst - /// - /// .. pw-status-codes:: - /// - /// OK: The operation was successful. - /// - /// May return other implementation-specific status codes. - /// - /// @endrst - Status ClearPendingReceiveBytes() { return DoClearPendingReceiveBytes(); } - private: /// Reads data from the UART into a provided buffer with an optional timeout /// provided. @@ -377,9 +351,7 @@ class Uart : public UartBase { virtual StatusWithSize DoTryWriteFor( ConstByteSpan tx_buffer, std::optional timeout) = 0; - virtual size_t DoConservativeReadAvailable() = 0; virtual Status DoFlushOutput() = 0; - virtual Status DoClearPendingReceiveBytes() = 0; }; } // namespace pw::uart diff --git a/pw_uart/public/pw_uart/uart_base.h b/pw_uart/public/pw_uart/uart_base.h index bd58d0ede9..345f6f6e1f 100644 --- a/pw_uart/public/pw_uart/uart_base.h +++ b/pw_uart/public/pw_uart/uart_base.h @@ -109,12 +109,40 @@ class UartBase { /// @endrst Status SetFlowControl(bool enable) { return DoSetFlowControl(enable); } + /// Returns the number of bytes currently available for reading. + /// + /// This function checks the receive buffer to determine how many bytes of + /// data are ready to be read. + /// + /// @returns The number of bytes available for reading. When no data is + /// available or in case of an error this function returns 0. + size_t ConservativeReadAvailable() { return DoConservativeReadAvailable(); } + + /// Empties the UART's receive buffer and discards any unread data. + /// + /// This function removes all data from the receive buffer, resetting the + /// buffer to an empty state. This is useful for situations where you want to + /// disregard any previously received data and resynchronize. + /// + /// @returns @rst + /// + /// .. pw-status-codes:: + /// + /// OK: The operation was successful. + /// + /// May return other implementation-specific status codes. + /// + /// @endrst + Status ClearPendingReceiveBytes() { return DoClearPendingReceiveBytes(); } + private: virtual Status DoEnable(bool enable) = 0; virtual Status DoSetBaudRate(uint32_t baud_rate) = 0; virtual Status DoSetFlowControl(bool /*enable*/) { return pw::Status::Unimplemented(); } + virtual size_t DoConservativeReadAvailable() = 0; + virtual Status DoClearPendingReceiveBytes() = 0; }; } // namespace pw::uart diff --git a/pw_uart/uart_non_blocking_test.cc b/pw_uart/uart_non_blocking_test.cc index e69f2ddc13..8bb05a0bdb 100644 --- a/pw_uart/uart_non_blocking_test.cc +++ b/pw_uart/uart_non_blocking_test.cc @@ -44,6 +44,8 @@ class UartNonBlockingStub : public UartNonBlocking { return OkStatus(); } bool DoCancelWrite() override { return true; } + size_t DoConservativeReadAvailable() override { return 0; } + Status DoClearPendingReceiveBytes() override { return OkStatus(); } }; class UartNonBlockingTest : public ::testing::Test { @@ -57,4 +59,4 @@ class UartNonBlockingTest : public ::testing::Test { TEST_F(UartNonBlockingTest, CompilationSucceeds) { EXPECT_TRUE(true); } } // namespace -} // namespace pw::uart \ No newline at end of file +} // namespace pw::uart