diff options
| author | huntc <[email protected]> | 2021-12-10 12:08:00 +1100 |
|---|---|---|
| committer | huntc <[email protected]> | 2021-12-10 12:16:08 +1100 |
| commit | 7256ff3e71ceea9091349b040a2ebc987aca590c (patch) | |
| tree | 6f23c25b08c027db1dd133a7489b50661e08da7c /embassy-hal-common | |
| parent | 60b7c50d8b02f92844287b150c5f504750846625 (diff) | |
Provides AsyncWrite with flush
As per Tokio and others, this commit provides a `poll_flush` method on `AsyncWrite` so that a best-effort attempt at wakening once all bytes are flushed can be made.
Diffstat (limited to 'embassy-hal-common')
| -rw-r--r-- | embassy-hal-common/src/ring_buffer.rs | 7 | ||||
| -rw-r--r-- | embassy-hal-common/src/usb/usb_serial.rs | 15 |
2 files changed, 22 insertions, 0 deletions
diff --git a/embassy-hal-common/src/ring_buffer.rs b/embassy-hal-common/src/ring_buffer.rs index 6829f62f5..fcad68bb1 100644 --- a/embassy-hal-common/src/ring_buffer.rs +++ b/embassy-hal-common/src/ring_buffer.rs | |||
| @@ -125,5 +125,12 @@ mod tests { | |||
| 125 | let buf = rb.pop_buf(); | 125 | let buf = rb.pop_buf(); |
| 126 | assert_eq!(1, buf.len()); | 126 | assert_eq!(1, buf.len()); |
| 127 | assert_eq!(4, buf[0]); | 127 | assert_eq!(4, buf[0]); |
| 128 | rb.pop(1); | ||
| 129 | |||
| 130 | let buf = rb.pop_buf(); | ||
| 131 | assert_eq!(0, buf.len()); | ||
| 132 | |||
| 133 | let buf = rb.push_buf(); | ||
| 134 | assert_eq!(4, buf.len()); | ||
| 128 | } | 135 | } |
| 129 | } | 136 | } |
diff --git a/embassy-hal-common/src/usb/usb_serial.rs b/embassy-hal-common/src/usb/usb_serial.rs index ca43a4d73..2592d05a6 100644 --- a/embassy-hal-common/src/usb/usb_serial.rs +++ b/embassy-hal-common/src/usb/usb_serial.rs | |||
| @@ -106,6 +106,17 @@ where | |||
| 106 | serial.poll_write(cx, buf) | 106 | serial.poll_write(cx, buf) |
| 107 | }) | 107 | }) |
| 108 | } | 108 | } |
| 109 | |||
| 110 | fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> { | ||
| 111 | let this = self.get_mut(); | ||
| 112 | let mut mutex = this.inner.borrow_mut(); | ||
| 113 | mutex.with(|state| { | ||
| 114 | let serial = state.classes.get_serial(); | ||
| 115 | let serial = Pin::new(serial); | ||
| 116 | |||
| 117 | serial.poll_flush(cx) | ||
| 118 | }) | ||
| 119 | } | ||
| 109 | } | 120 | } |
| 110 | 121 | ||
| 111 | pub struct UsbSerial<'bus, 'a, B: UsbBus> { | 122 | pub struct UsbSerial<'bus, 'a, B: UsbBus> { |
| @@ -167,6 +178,10 @@ impl<'bus, 'a, B: UsbBus> AsyncWrite for UsbSerial<'bus, 'a, B> { | |||
| 167 | this.flush_write(); | 178 | this.flush_write(); |
| 168 | Poll::Ready(Ok(count)) | 179 | Poll::Ready(Ok(count)) |
| 169 | } | 180 | } |
| 181 | |||
| 182 | fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> { | ||
| 183 | Poll::Ready(Ok(())) | ||
| 184 | } | ||
| 170 | } | 185 | } |
| 171 | 186 | ||
| 172 | /// Keeps track of the type of the last written packet. | 187 | /// Keeps track of the type of the last written packet. |
