Skip to content

Commit

Permalink
implement embedded_io ReadReady and WriteReady traits for uart
Browse files Browse the repository at this point in the history
  • Loading branch information
antbern committed Aug 22, 2024
1 parent 32a29e0 commit 07166ed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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

0 comments on commit 07166ed

Please sign in to comment.