29 lines
639 B
Rust
29 lines
639 B
Rust
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(())
|
|
}
|
|
}
|