Skip to content

Commit 7d904f5

Browse files
committed
split the Serial trait in two: serial::Read and serial::Write
1 parent cb609ab commit 7d904f5

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

src/lib.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@
571571
extern crate nb;
572572

573573
pub mod prelude;
574+
pub mod serial;
574575

575576
/// Input capture
576577
///
@@ -738,26 +739,6 @@ pub enum Direction {
738739
Upcounting,
739740
}
740741

741-
/// Serial interface
742-
///
743-
/// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
744-
/// This can be encoded in this trait via the `Word` type parameter.
745-
pub trait Serial<Word> {
746-
/// Serial interface error
747-
///
748-
/// Possible errors
749-
///
750-
/// - *overrun*, the previous received data was overwritten because it was
751-
/// not read in a timely manner
752-
type Error;
753-
754-
/// Reads a single word from the serial interface
755-
fn read(&self) -> nb::Result<Word, Self::Error>;
756-
757-
/// Writes a single word to the serial interface
758-
fn write(&self, word: Word) -> nb::Result<(), Self::Error>;
759-
}
760-
761742
/// Serial Peripheral Interface (full duplex master mode)
762743
///
763744
/// # Notes

src/prelude.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pub use ::Capture as _embedded_hal_Capture;
77
pub use ::Pwm as _embedded_hal_Pwm;
88
pub use ::Qei as _embedded_hal_Qei;
9-
pub use ::Serial as _embedded_hal_Serial;
9+
pub use ::serial::Read as _embedded_hal_serial_Read;
10+
pub use ::serial::Write as _embedded_hal_serial_Write;
1011
pub use ::Spi as _embedded_hal_Spi;
1112
pub use ::Timer as _embedded_hal_Timer;

src/serial.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Serial interface
2+
3+
use nb;
4+
5+
/// Read half of a serial interface
6+
///
7+
/// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
8+
/// This can be encoded in this trait via the `Word` type parameter.
9+
pub trait Read<Word> {
10+
/// Read error
11+
///
12+
/// Possible errors
13+
///
14+
/// - *overrun*, the previous received data was overwritten because it was
15+
/// not read in a timely manner
16+
type Error;
17+
18+
/// Reads a single word from the serial interface
19+
fn read(&self) -> nb::Result<Word, Self::Error>;
20+
}
21+
22+
/// Write half of a serial interface
23+
pub trait Write<Word> {
24+
/// Write error
25+
type Error;
26+
27+
/// Writes a single word to the serial interface
28+
fn write(&self, word: Word) -> nb::Result<(), Self::Error>;
29+
}

0 commit comments

Comments
 (0)