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 {
5959
6060impl Read for SerialDevice {
6161 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) ?)
7563 }
7664}
7765
7866impl ReadReady for SerialDevice {
7967 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 ( ) ? )
8169 }
8270}
8371
Original file line number Diff line number Diff line change 11use alloc:: collections:: VecDeque ;
2- use alloc:: vec:: Vec ;
32
43use embedded_io:: { ErrorType , Read , ReadReady , Write } ;
54use hermit_sync:: { InterruptTicketMutex , Lazy } ;
@@ -52,22 +51,13 @@ impl ErrorType for SerialDevice {
5251
5352impl Read for SerialDevice {
5453 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) ?)
6455 }
6556}
6657
6758impl ReadReady for SerialDevice {
6859 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 ( ) ?)
7161 }
7262}
7363
You can’t perform that action at this time.
0 commit comments