File tree 3 files changed +29
-3
lines changed
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 15
15
pub mod delay;
16
16
pub mod digital;
17
17
pub mod i2c;
18
+ pub mod serial;
18
19
pub mod spi;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -80,9 +80,7 @@ pub trait Write<Word: Copy = u8>: ErrorType {
80
80
/// An implementation can choose to buffer the write, returning `Ok(())`
81
81
/// after the complete slice has been written to a buffer, but before all
82
82
/// 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.
86
84
fn write ( & mut self , buffer : & [ Word ] ) -> Result < ( ) , Self :: Error > ;
87
85
88
86
/// Block until the serial interface has sent all buffered words
You can’t perform that action at this time.
0 commit comments