@@ -73,7 +73,49 @@ impl<T: ErrorType> ErrorType for &mut T {
73
73
type Error = T :: Error ;
74
74
}
75
75
76
- /// Write half of a serial interface (blocking variant)
76
+ /// Read an exact amount of words from a serial interface
77
+ ///
78
+ /// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
79
+ /// This can be encoded in this trait via the `Word` type parameter.
80
+ pub trait ReadExact < Word : ' static + Copy = u8 > : ErrorType {
81
+ /// Read an exact amount of words.
82
+ ///
83
+ /// This does not return until exactly `read.len()` words have been read.
84
+ fn read_exact ( & mut self , read : & mut [ Word ] ) -> Result < ( ) , Self :: Error > ;
85
+ }
86
+
87
+ impl < T : ReadExact < Word > , Word : ' static + Copy > ReadExact < Word > for & mut T {
88
+ fn read_exact ( & mut self , read : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
89
+ T :: read_exact ( self , read)
90
+ }
91
+ }
92
+
93
+ /// Read words from a serial interface, until the line becomes idle.
94
+ ///
95
+ /// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
96
+ /// This can be encoded in this trait via the `Word` type parameter.
97
+ pub trait ReadUntilIdle < Word : ' static + Copy = u8 > : ErrorType {
98
+ /// Read words until the line becomes idle.
99
+ ///
100
+ /// Returns the amount of words received.
101
+ ///
102
+ /// This returns at the earliest of either:
103
+ /// - at least 1 word has been received, and then the line becomes idle
104
+ /// - exactly `read.len()` words have been read (the buffer is full)
105
+ ///
106
+ /// The serial line is considered idle after a timeout of it being constantly
107
+ /// at high level. The exact timeout is implementation-defined, but it should be
108
+ /// short, around 1 or 2 words' worth of time.
109
+ fn read_until_idle ( & mut self , read : & mut [ Word ] ) -> Result < usize , Self :: Error > ;
110
+ }
111
+
112
+ impl < T : ReadUntilIdle < Word > , Word : ' static + Copy > ReadUntilIdle < Word > for & mut T {
113
+ fn read_until_idle ( & mut self , read : & mut [ Word ] ) -> Result < usize , Self :: Error > {
114
+ T :: read_until_idle ( self , read)
115
+ }
116
+ }
117
+
118
+ /// Write half of a serial interface.
77
119
pub trait Write < Word : Copy = u8 > : ErrorType {
78
120
/// Writes a slice, blocking until everything has been written
79
121
///
0 commit comments