2016-09-01 19:51:33 +02:00
|
|
|
use core::fmt::{self, Write};
|
|
|
|
use spin::Mutex;
|
|
|
|
|
2016-09-01 22:39:45 +02:00
|
|
|
use device::display;
|
2016-09-01 19:51:33 +02:00
|
|
|
use device::serial::COM1;
|
|
|
|
|
|
|
|
pub static CONSOLE: Mutex<Console> = Mutex::new(Console::new());
|
|
|
|
|
|
|
|
pub struct Console;
|
|
|
|
|
|
|
|
impl Console {
|
|
|
|
const fn new() -> Self {
|
|
|
|
Console
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Write for Console {
|
|
|
|
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
2016-09-01 22:39:45 +02:00
|
|
|
if let Some(ref mut console) = *display::CONSOLE.lock() {
|
|
|
|
if let Some(ref mut display) = *display::DISPLAY.lock() {
|
|
|
|
console.write(s.as_bytes(), |event| {
|
|
|
|
display.event(event);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-01 19:51:33 +02:00
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
COM1.lock().write_str(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|