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+
45use 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