diff --git a/src/main.rs b/src/main.rs index d3b777e..f2ea212 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ //[feature(global_asm)] #![feature(naked_functions)] +use core::fmt::Write; + use panic_abort as _; use r0::zero_bss; @@ -44,8 +46,6 @@ pub unsafe extern "C" fn _boot_cores() -> ! { } fn main() { - let uart = Uart::uart0(); - for b in "Hello World\r\n".bytes() { - uart.write_byte(b); - } + let mut uart = Uart::uart0(); + writeln!(uart, "Hello World\r").unwrap(); } diff --git a/src/uart/mod.rs b/src/uart/mod.rs index 13c9eee..ec87469 100644 --- a/src/uart/mod.rs +++ b/src/uart/mod.rs @@ -1,5 +1,7 @@ #![allow(unused)] +use core::fmt; + mod regs; pub use regs::RegisterBlock; @@ -32,3 +34,12 @@ impl Uart { self.regs.write_byte(v); } } + +impl fmt::Write for Uart { + fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { + for b in s.bytes() { + self.write_byte(b); + } + Ok(()) + } +}