Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement embedded_io::ReadReady and WriteReady traits for uart peripheral #837

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions rp2040-hal/src/uart/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Read for UartPeripheral<
}
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ReadReady
for UartPeripheral<Enabled, D, P>
{
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Ok(self.uart_is_readable())
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for UartPeripheral<Enabled, D, P> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.write_full_blocking(buf);
Expand All @@ -500,3 +509,11 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for UartPeripheral
Ok(())
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::WriteReady
for UartPeripheral<Enabled, D, P>
{
fn write_ready(&mut self) -> Result<bool, Self::Error> {
Ok(self.uart_is_writable())
}
}
6 changes: 6 additions & 0 deletions rp2040-hal/src/uart/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Read for Reader<D, P> {
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ReadReady for Reader<D, P> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Ok(is_readable(&self.device))
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> Read02<u8> for Reader<D, P> {
type Error = ReadErrorType;

Expand Down
6 changes: 6 additions & 0 deletions rp2040-hal/src/uart/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for Writer<D, P> {
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::WriteReady for Writer<D, P> {
fn write_ready(&mut self) -> Result<bool, Self::Error> {
Ok(uart_is_writable(&self.device))
}
}

impl<D: UartDevice, P: ValidUartPinout<D>> Write02<u8> for Writer<D, P> {
type Error = Infallible;

Expand Down