Skip to content

Commit 931dd37

Browse files
committed
Remove serial traits (blocking and async).
1 parent 2c818b8 commit 931dd37

File tree

5 files changed

+73
-130
lines changed

5 files changed

+73
-130
lines changed

embedded-hal-async/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
pub mod delay;
88
pub mod digital;
99
pub mod i2c;
10-
pub mod serial;
1110
pub mod spi;

embedded-hal-async/src/serial.rs

-27
This file was deleted.

embedded-hal-nb/src/serial.rs

+73-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,77 @@
11
//! Serial interface
22
3-
pub use embedded_hal::serial::{Error, ErrorKind, ErrorType};
3+
/// Serial error
4+
pub trait Error: core::fmt::Debug {
5+
/// Convert error to a generic serial error kind
6+
///
7+
/// By using this method, serial errors freely defined by HAL implementations
8+
/// can be converted to a set of generic serial errors upon which generic
9+
/// code can act.
10+
fn kind(&self) -> ErrorKind;
11+
}
12+
13+
impl Error for core::convert::Infallible {
14+
fn kind(&self) -> ErrorKind {
15+
match *self {}
16+
}
17+
}
18+
19+
/// Serial error kind
20+
///
21+
/// This represents a common set of serial operation errors. HAL implementations are
22+
/// free to define more specific or additional error types. However, by providing
23+
/// a mapping to these common serial errors, generic code can still react to them.
24+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25+
#[non_exhaustive]
26+
pub enum ErrorKind {
27+
/// The peripheral receive buffer was overrun.
28+
Overrun,
29+
/// Received data does not conform to the peripheral configuration.
30+
/// Can be caused by a misconfigured device on either end of the serial line.
31+
FrameFormat,
32+
/// Parity check failed.
33+
Parity,
34+
/// Serial line is too noisy to read valid data.
35+
Noise,
36+
/// A different error occurred. The original error may contain more information.
37+
Other,
38+
}
39+
40+
impl Error for ErrorKind {
41+
fn kind(&self) -> ErrorKind {
42+
*self
43+
}
44+
}
45+
46+
impl core::fmt::Display for ErrorKind {
47+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48+
match self {
49+
Self::Overrun => write!(f, "The peripheral receive buffer was overrun"),
50+
Self::Parity => write!(f, "Parity check failed"),
51+
Self::Noise => write!(f, "Serial line is too noisy to read valid data"),
52+
Self::FrameFormat => write!(
53+
f,
54+
"Received data does not conform to the peripheral configuration"
55+
),
56+
Self::Other => write!(
57+
f,
58+
"A different error occurred. The original error may contain more information"
59+
),
60+
}
61+
}
62+
}
63+
64+
/// Serial error type trait
65+
///
66+
/// This just defines the error type, to be used by the other traits.
67+
pub trait ErrorType {
68+
/// Error type
69+
type Error: Error;
70+
}
71+
72+
impl<T: ErrorType> ErrorType for &mut T {
73+
type Error = T::Error;
74+
}
475

576
/// Read half of a serial interface
677
///
@@ -40,8 +111,7 @@ impl<T: Write<Word>, Word: Copy> Write<Word> for &mut T {
40111
///
41112
/// TODO write example of usage
42113
43-
impl<Word, Error: embedded_hal::serial::Error> core::fmt::Write
44-
for dyn Write<Word, Error = Error> + '_
114+
impl<Word, Error: self::Error> core::fmt::Write for dyn Write<Word, Error = Error> + '_
45115
where
46116
Word: Copy + From<u8>,
47117
{

embedded-hal/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub mod delay;
8181
pub mod digital;
8282
pub mod i2c;
8383
pub mod pwm;
84-
pub mod serial;
8584
pub mod spi;
8685

8786
mod private {

embedded-hal/src/serial.rs

-98
This file was deleted.

0 commit comments

Comments
 (0)