Skip to content

Commit 1533716

Browse files
bors[bot]Dirbaio
andauthored
Merge #442
442: async/serial: add Write. r=eldruin a=Dirbaio Extracted out of #349 This is just `Write`, mirroring the blocking version. so it should hopefully be uncontroversial. Co-authored-by: Dario Nieuwenhuis <[email protected]>
2 parents 49a42e8 + 002786d commit 1533716

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

embedded-hal-async/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
pub mod delay;
1616
pub mod digital;
1717
pub mod i2c;
18+
pub mod serial;
1819
pub mod spi;

embedded-hal-async/src/serial.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Serial interface
2+
3+
pub use embedded_hal::serial::{Error, ErrorKind, ErrorType};
4+
5+
/// Write half of a serial interface
6+
pub trait Write<Word: 'static + Copy = u8>: ErrorType {
7+
/// Writes a slice, blocking until everything has been written.
8+
///
9+
/// An implementation can choose to buffer the write, returning `Ok(())`
10+
/// after the complete slice has been written to a buffer, but before all
11+
/// words have been sent via the serial interface. To make sure that
12+
/// everything has been sent, call [`flush`](Write::flush) after this function returns.
13+
async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error>;
14+
15+
/// Ensures that none of the previously written data is still buffered
16+
async fn flush(&mut self) -> Result<(), Self::Error>;
17+
}
18+
19+
impl<T: Write<Word>, Word: 'static + Copy> Write<Word> for &mut T {
20+
async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error> {
21+
T::write(self, words).await
22+
}
23+
24+
async fn flush(&mut self) -> Result<(), Self::Error> {
25+
T::flush(self).await
26+
}
27+
}

embedded-hal/src/serial.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ pub trait Write<Word: Copy = u8>: ErrorType {
8080
/// An implementation can choose to buffer the write, returning `Ok(())`
8181
/// after the complete slice has been written to a buffer, but before all
8282
/// words have been sent via the serial interface. To make sure that
83-
/// everything has been sent, call [`flush`] after this function returns.
84-
///
85-
/// [`flush`]: #tymethod.flush
83+
/// everything has been sent, call [`flush`](Write::flush) after this function returns.
8684
fn write(&mut self, buffer: &[Word]) -> Result<(), Self::Error>;
8785

8886
/// Block until the serial interface has sent all buffered words

0 commit comments

Comments
 (0)