1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::uart::UART;
pub trait Device: Send + Sync {
fn read(&self, content: &mut [u8]) -> i32;
fn write(&self, content: &[u8]) -> i32;
}
pub struct Console {}
impl Device for Console {
fn read(&self, content: &mut [u8]) -> i32 {
let mut uart = UART().lock();
for i in 0..content.len() {
match uart.get() {
Some(ch) => { content[i] = ch; }
_ => { return i as i32; }
}
}
return content.len() as i32;
}
fn write(&self, content: &[u8]) -> i32 {
let mut uart = UART().lock();
for i in 0..content.len() {
uart.put(content[i]);
}
return content.len() as i32;
}
}