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
use core::arch::asm;
pub struct SerialPort {
pub port_address: u32,
}
impl SerialPort {
pub const fn new(port_address: u32) -> Self {
Self { port_address }
}
pub fn write_byte(&self, byte: u8) {
let port = self.port_address as *mut u8;
// LF newline characters need to be extended to CRLF over a real serial port.
if byte == b'\n' {
unsafe {
asm!(
"strb w8, [{port}]",
port = in(reg) port,
in("x8") b'\r',
options(nostack),
);
}
}
unsafe {
asm!(
"strb w8, [{port}]",
port = in(reg) port,
in("x8") byte,
options(nostack),
);
}
}
pub fn init(&self, _baudrate: u32) {
// We don't do anything here (yet).
}
}