From 275f2973095251817fe49e56c9db2182ae3b4729 Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 7 May 2019 16:45:31 +0200 Subject: [PATCH] uart: impl fmt::Write --- src/main.rs | 8 ++++---- src/uart/mod.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) 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(()) + } +}