Skip to content

Commit e29c2c5

Browse files
authored
Merge pull request #837 from antbern/main
implement `embedded_io::ReadReady` and `WriteReady` traits for uart peripheral
2 parents 4e2f01c + 07166ed commit e29c2c5

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

rp2040-hal/src/uart/peripheral.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,15 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Read for UartPeripheral<
490490
}
491491
}
492492
}
493+
494+
impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ReadReady
495+
for UartPeripheral<Enabled, D, P>
496+
{
497+
fn read_ready(&mut self) -> Result<bool, Self::Error> {
498+
Ok(self.uart_is_readable())
499+
}
500+
}
501+
493502
impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for UartPeripheral<Enabled, D, P> {
494503
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
495504
self.write_full_blocking(buf);
@@ -500,3 +509,11 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for UartPeripheral
500509
Ok(())
501510
}
502511
}
512+
513+
impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::WriteReady
514+
for UartPeripheral<Enabled, D, P>
515+
{
516+
fn write_ready(&mut self) -> Result<bool, Self::Error> {
517+
Ok(self.uart_is_writable())
518+
}
519+
}

rp2040-hal/src/uart/reader.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Read for Reader<D, P> {
244244
}
245245
}
246246

247+
impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::ReadReady for Reader<D, P> {
248+
fn read_ready(&mut self) -> Result<bool, Self::Error> {
249+
Ok(is_readable(&self.device))
250+
}
251+
}
252+
247253
impl<D: UartDevice, P: ValidUartPinout<D>> Read02<u8> for Reader<D, P> {
248254
type Error = ReadErrorType;
249255

rp2040-hal/src/uart/writer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::Write for Writer<D, P> {
223223
}
224224
}
225225

226+
impl<D: UartDevice, P: ValidUartPinout<D>> embedded_io::WriteReady for Writer<D, P> {
227+
fn write_ready(&mut self) -> Result<bool, Self::Error> {
228+
Ok(uart_is_writable(&self.device))
229+
}
230+
}
231+
226232
impl<D: UartDevice, P: ValidUartPinout<D>> Write02<u8> for Writer<D, P> {
227233
type Error = Infallible;
228234

0 commit comments

Comments
 (0)