feat: Add serial logging (#3)

Reviewed-on: #3
This commit is contained in:
2025-07-22 19:17:20 +02:00
parent d8159a373e
commit 4bd1e3bc6a
6 changed files with 111 additions and 9 deletions

View File

@@ -0,0 +1,28 @@
use core::fmt;
pub struct SerialPort {
port: uart_16550::SerialPort,
}
impl SerialPort {
/// # Safety
///
/// unsafe because this function must only be called once
pub unsafe fn init() -> Self {
let mut port = unsafe { uart_16550::SerialPort::new(0x3F8) };
port.init();
Self { port }
}
}
impl fmt::Write for SerialPort {
fn write_str(&mut self, s: &str) -> fmt::Result {
for char in s.bytes() {
match char {
b'\n' => self.port.write_str("\r\n").unwrap(),
byte => self.port.send(byte),
}
}
Ok(())
}
}