diff options
| author | James Munns <[email protected]> | 2024-07-14 17:14:37 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-07-14 17:14:37 +0000 |
| commit | 4472e08bcaf0adbd5d87d55818a5b3ef3602abb1 (patch) | |
| tree | 115d59221f725b9faa76c4be22b4c70d9d7079ef | |
| parent | f5e3f31df77056ddd5ffe376ed5dc829ca851de5 (diff) | |
| parent | d9ea5cb015f015c84013250db36a1332f6df3986 (diff) | |
Merge pull request #3179 from 1-rafael-1/impl-ReadReady-for-buffered-uart
Impl read ready for buffered uart
| -rw-r--r-- | embassy-nrf/src/buffered_uarte.rs | 18 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/buffered.rs | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 8e4064aaa..b368a3d33 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -766,6 +766,12 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> { | |||
| 766 | rx.pop_done(amt); | 766 | rx.pop_done(amt); |
| 767 | U::regs().intenset.write(|w| w.rxstarted().set()); | 767 | U::regs().intenset.write(|w| w.rxstarted().set()); |
| 768 | } | 768 | } |
| 769 | |||
| 770 | /// we are ready to read if there is data in the buffer | ||
| 771 | fn read_ready() -> Result<bool, Error> { | ||
| 772 | let state = U::buffered_state(); | ||
| 773 | Ok(!state.rx_buf.is_empty()) | ||
| 774 | } | ||
| 769 | } | 775 | } |
| 770 | 776 | ||
| 771 | impl<'a, U: UarteInstance, T: TimerInstance> Drop for BufferedUarteRx<'a, U, T> { | 777 | impl<'a, U: UarteInstance, T: TimerInstance> Drop for BufferedUarteRx<'a, U, T> { |
| @@ -827,6 +833,18 @@ mod _embedded_io { | |||
| 827 | } | 833 | } |
| 828 | } | 834 | } |
| 829 | 835 | ||
| 836 | impl<'d, U: UarteInstance, T: TimerInstance + 'd> embedded_io_async::ReadReady for BufferedUarte<'d, U, T> { | ||
| 837 | fn read_ready(&mut self) -> Result<bool, Self::Error> { | ||
| 838 | BufferedUarteRx::<'d, U, T>::read_ready() | ||
| 839 | } | ||
| 840 | } | ||
| 841 | |||
| 842 | impl<'d, U: UarteInstance, T: TimerInstance + 'd> embedded_io_async::ReadReady for BufferedUarteRx<'d, U, T> { | ||
| 843 | fn read_ready(&mut self) -> Result<bool, Self::Error> { | ||
| 844 | Self::read_ready() | ||
| 845 | } | ||
| 846 | } | ||
| 847 | |||
| 830 | impl<'d, U: UarteInstance, T: TimerInstance> embedded_io_async::BufRead for BufferedUarte<'d, U, T> { | 848 | impl<'d, U: UarteInstance, T: TimerInstance> embedded_io_async::BufRead for BufferedUarte<'d, U, T> { |
| 831 | async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { | 849 | async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { |
| 832 | self.fill_buf().await | 850 | self.fill_buf().await |
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 33bc009a8..06cc0e41d 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -436,6 +436,12 @@ impl<'d> BufferedUartRx<'d> { | |||
| 436 | } | 436 | } |
| 437 | } | 437 | } |
| 438 | 438 | ||
| 439 | /// we are ready to read if there is data in the buffer | ||
| 440 | fn read_ready(&mut self) -> Result<bool, Error> { | ||
| 441 | let state = self.state; | ||
| 442 | Ok(!state.rx_buf.is_empty()) | ||
| 443 | } | ||
| 444 | |||
| 439 | /// Reconfigure the driver | 445 | /// Reconfigure the driver |
| 440 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { | 446 | pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> { |
| 441 | reconfigure(self.info, self.kernel_clock, config)?; | 447 | reconfigure(self.info, self.kernel_clock, config)?; |
| @@ -610,6 +616,18 @@ impl<'d> embedded_io_async::Read for BufferedUartRx<'d> { | |||
| 610 | } | 616 | } |
| 611 | } | 617 | } |
| 612 | 618 | ||
| 619 | impl<'d> embedded_io_async::ReadReady for BufferedUart<'d> { | ||
| 620 | fn read_ready(&mut self) -> Result<bool, Self::Error> { | ||
| 621 | BufferedUartRx::<'d>::read_ready(&mut self.rx) | ||
| 622 | } | ||
| 623 | } | ||
| 624 | |||
| 625 | impl<'d> embedded_io_async::ReadReady for BufferedUartRx<'d> { | ||
| 626 | fn read_ready(&mut self) -> Result<bool, Self::Error> { | ||
| 627 | Self::read_ready(self) | ||
| 628 | } | ||
| 629 | } | ||
| 630 | |||
| 613 | impl<'d> embedded_io_async::BufRead for BufferedUart<'d> { | 631 | impl<'d> embedded_io_async::BufRead for BufferedUart<'d> { |
| 614 | async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { | 632 | async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { |
| 615 | self.rx.fill_buf().await | 633 | self.rx.fill_buf().await |
