File tree Expand file tree Collapse file tree 2 files changed +4
-26
lines changed Expand file tree Collapse file tree 2 files changed +4
-26
lines changed Original file line number Diff line number Diff line change @@ -59,25 +59,13 @@ impl ErrorType for SerialDevice {
59
59
60
60
impl Read for SerialDevice {
61
61
fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > {
62
- let mut guard = UART_DEVICE . lock ( ) ;
63
-
64
- if guard. buffer . is_empty ( ) {
65
- Ok ( 0 )
66
- } else {
67
- let min = buf. len ( ) . min ( guard. buffer . len ( ) ) ;
68
-
69
- for ( dst, src) in buf[ ..min] . iter_mut ( ) . zip ( guard. buffer . drain ( ..min) ) {
70
- * dst = src;
71
- }
72
-
73
- Ok ( min)
74
- }
62
+ Ok ( UART_DEVICE . lock ( ) . buffer . read ( buf) ?)
75
63
}
76
64
}
77
65
78
66
impl ReadReady for SerialDevice {
79
67
fn read_ready ( & mut self ) -> Result < bool , Self :: Error > {
80
- Ok ( ! UART_DEVICE . lock ( ) . buffer . is_empty ( ) )
68
+ Ok ( UART_DEVICE . lock ( ) . buffer . read_ready ( ) ? )
81
69
}
82
70
}
83
71
Original file line number Diff line number Diff line change 1
1
use alloc:: collections:: VecDeque ;
2
- use alloc:: vec:: Vec ;
3
2
4
3
use embedded_io:: { ErrorType , Read , ReadReady , Write } ;
5
4
use hermit_sync:: { InterruptTicketMutex , Lazy } ;
@@ -52,22 +51,13 @@ impl ErrorType for SerialDevice {
52
51
53
52
impl Read for SerialDevice {
54
53
fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > {
55
- let mut guard = UART_DEVICE . lock ( ) ;
56
- if guard. buffer . is_empty ( ) {
57
- Ok ( 0 )
58
- } else {
59
- let min = core:: cmp:: min ( buf. len ( ) , guard. buffer . len ( ) ) ;
60
- let drained = guard. buffer . drain ( ..min) . collect :: < Vec < _ > > ( ) ;
61
- buf[ ..min] . copy_from_slice ( drained. as_slice ( ) ) ;
62
- Ok ( min)
63
- }
54
+ Ok ( UART_DEVICE . lock ( ) . buffer . read ( buf) ?)
64
55
}
65
56
}
66
57
67
58
impl ReadReady for SerialDevice {
68
59
fn read_ready ( & mut self ) -> Result < bool , Self :: Error > {
69
- let read_ready = !UART_DEVICE . lock ( ) . buffer . is_empty ( ) ;
70
- Ok ( read_ready)
60
+ Ok ( UART_DEVICE . lock ( ) . buffer . read_ready ( ) ?)
71
61
}
72
62
}
73
63
You can’t perform that action at this time.
0 commit comments