Skip to content

Commit fe13ba7

Browse files
dbrgnrnestler
authored andcommitted
Switch from serial to serial_unix
By not using the platform-independent implementation, we can simplify some things.
1 parent 1128b80 commit fe13ba7

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ embedded-hal = { version = "0.2.0", features = ["unproven"] }
1313
i2cdev = "0.4.1"
1414
spidev = "0.3.0"
1515
sysfs_gpio = "0.5.1"
16-
serial = "0.4.0"
16+
serial-unix = "0.4.0"
1717
nb = "0.1.1"
1818

1919
[dev-dependencies]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern crate embedded_hal as hal;
1717
pub extern crate i2cdev;
1818
pub extern crate spidev;
1919
pub extern crate sysfs_gpio;
20-
pub extern crate serial;
20+
pub extern crate serial_unix;
2121
pub extern crate nb;
2222

2323
use std::io::{self, Write};

src/serial_impl.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
//! Implementation of [`Serial`](https://docs.rs/embedded-hal/0.2.1/embedded_hal/serial/index.html)
22
3-
use hal::serial::{Read, Write};
3+
use std::io::{Error as IoError, Read, Write};
4+
45
use nb;
5-
use serial;
66

7-
/// Newtype around [`serial::SystemPort`] that implements the `embedded-hal` traits
8-
pub struct Serial(pub serial::SystemPort);
7+
use hal;
8+
use serial_unix::TTYPort;
9+
10+
/// Newtype around [`serial_unix::TTYPort`] that implements
11+
/// the `embedded-hal` traits.
12+
pub struct Serial(pub TTYPort);
913

10-
impl Read<u8> for Serial {
11-
type Error = serial::Error;
14+
impl hal::serial::Read<u8> for Serial {
15+
type Error = IoError;
1216

1317
fn read(&mut self) -> nb::Result<u8, Self::Error> {
14-
use std::io::Read;
1518
let mut buffer = [0; 1];
1619
let bytes_read = self
1720
.0
@@ -25,19 +28,17 @@ impl Read<u8> for Serial {
2528
}
2629
}
2730

28-
impl Write<u8> for Serial {
29-
type Error = serial::Error;
31+
impl hal::serial::Write<u8> for Serial {
32+
type Error = IoError;
3033

3134
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
32-
use std::io::Write;
3335
self.0
3436
.write(&[word])
3537
.map_err(|err| nb::Error::Other(Self::Error::from(err)))?;
3638
Ok(())
3739
}
3840

3941
fn flush(&mut self) -> nb::Result<(), Self::Error> {
40-
use std::io::Write;
4142
self.0
4243
.flush()
4344
.map_err(|err| nb::Error::Other(Self::Error::from(err)))
@@ -58,7 +59,7 @@ mod test {
5859
let (mut master, _slave, name) =
5960
openpty::openpty(None, None, None).expect("Creating pty failed");
6061
println!("{:?}", name);
61-
let port = serial::open(Path::new(&name)).unwrap();
62+
let port = TTYPort::open(Path::new(&name)).unwrap();
6263
let mut serial = Serial(port);
6364
master.write(&[1]).unwrap();
6465
serial.read().unwrap();

0 commit comments

Comments
 (0)