2
2
3
3
use core:: { fmt, mem} ;
4
4
5
- use embedded_io:: { ErrorType , Read , Write } ;
5
+ use embedded_io:: { ErrorType , Read , ReadReady , Write } ;
6
6
use heapless:: Vec ;
7
7
use hermit_sync:: { InterruptTicketMutex , Lazy } ;
8
8
@@ -24,18 +24,6 @@ pub(crate) enum IoDevice {
24
24
Virtio ( VirtioUART ) ,
25
25
}
26
26
27
- impl IoDevice {
28
- pub fn can_read ( & self ) -> bool {
29
- match self {
30
- #[ cfg( not( target_arch = "riscv64" ) ) ]
31
- IoDevice :: Uhyve ( s) => s. can_read ( ) ,
32
- IoDevice :: Uart ( s) => s. can_read ( ) ,
33
- #[ cfg( feature = "console" ) ]
34
- IoDevice :: Virtio ( s) => s. can_read ( ) ,
35
- }
36
- }
37
- }
38
-
39
27
impl ErrorType for IoDevice {
40
28
type Error = Errno ;
41
29
}
@@ -52,6 +40,18 @@ impl Read for IoDevice {
52
40
}
53
41
}
54
42
43
+ impl ReadReady for IoDevice {
44
+ fn read_ready ( & mut self ) -> Result < bool , Self :: Error > {
45
+ match self {
46
+ #[ cfg( not( target_arch = "riscv64" ) ) ]
47
+ IoDevice :: Uhyve ( s) => s. read_ready ( ) ,
48
+ IoDevice :: Uart ( s) => s. read_ready ( ) ,
49
+ #[ cfg( feature = "console" ) ]
50
+ IoDevice :: Virtio ( s) => s. read_ready ( ) ,
51
+ }
52
+ }
53
+ }
54
+
55
55
impl Write for IoDevice {
56
56
fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
57
57
match self {
@@ -85,10 +85,6 @@ impl UhyveSerial {
85
85
pub const fn new ( ) -> Self {
86
86
Self { }
87
87
}
88
-
89
- pub fn can_read ( & self ) -> bool {
90
- false
91
- }
92
88
}
93
89
94
90
#[ cfg( not( target_arch = "riscv64" ) ) ]
@@ -104,6 +100,13 @@ impl Read for UhyveSerial {
104
100
}
105
101
}
106
102
103
+ #[ cfg( not( target_arch = "riscv64" ) ) ]
104
+ impl ReadReady for UhyveSerial {
105
+ fn read_ready ( & mut self ) -> Result < bool , Self :: Error > {
106
+ Ok ( false )
107
+ }
108
+ }
109
+
107
110
#[ cfg( not( target_arch = "riscv64" ) ) ]
108
111
impl Write for UhyveSerial {
109
112
fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
@@ -129,10 +132,6 @@ impl Console {
129
132
}
130
133
}
131
134
132
- pub fn can_read ( & self ) -> bool {
133
- self . device . can_read ( )
134
- }
135
-
136
135
#[ cfg( feature = "console" ) ]
137
136
pub fn replace_device ( & mut self , device : IoDevice ) {
138
137
self . device = device;
@@ -149,6 +148,12 @@ impl Read for Console {
149
148
}
150
149
}
151
150
151
+ impl ReadReady for Console {
152
+ fn read_ready ( & mut self ) -> Result < bool , Self :: Error > {
153
+ self . device . read_ready ( )
154
+ }
155
+ }
156
+
152
157
impl Write for Console {
153
158
/// Writes a buffer to the console.
154
159
/// The content is buffered until a newline is encountered or the internal buffer is full.
0 commit comments