-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathserial.rs
37 lines (30 loc) · 1.03 KB
/
serial.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Serial interface
use nb;
/// Read half of a serial interface
///
/// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
/// This can be encoded in this trait via the `Word` type parameter.
pub trait Read<Word> {
/// Read error
type Error;
/// Reads a single word from the serial interface
fn try_read(&mut self) -> nb::Result<Word, Self::Error>;
}
/// Write half of a serial interface
pub trait Write<Word> {
/// Write error
type Error;
/// Writes a single word to the serial interface
fn try_write(&mut self, word: Word) -> nb::Result<(), Self::Error>;
/// Ensures that none of the previously written words are still buffered
fn try_flush(&mut self) -> nb::Result<(), Self::Error>;
}
/// Enable changing the baudrate after initiation of serial interface
pub trait ConfigureBaud {
/// Baudrate type
type BaudRate;
/// Set baud error
type Error;
/// Change baud rate
fn set_baud_rate(&mut self, baud_rate: Self::BaudRate) -> Result<(), Self::Error>;
}