aboutsummaryrefslogtreecommitdiff
path: root/src/console.rs
blob: 1a732a7629067cea5b8cdd1e493391f45af31806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! # UART Console module
//! 
//! ## Encapsulates base trait for any console.
//! ## Wraps the UART console.

/// # Interface module
///
/// ## Provides trait for consoles.
pub mod interface {
	use core::fmt;
	/// # Write Trait
	///
	/// Structure must provide ways to:
	///  - Write individual characters
	///  - Write formatted strings
	///  - Flush write queue
	pub trait Write {
		/// # Write Character
		///
		/// Writes an individual character to a console
		fn write_char(&self, c: char);
		/// # Write Format
		///
		/// Writes a formatted string to a console
		fn write_fmt(&self, args: fmt::Arguments) -> fmt::Result;
		/// # Flush
		///
		/// Flush console write queue
		fn flush(&self);
	}

	/// # Statistics Trait
	///
	/// Structure must provide a way to:
	///  - Get how many characters have been written
	pub trait Statistics {
		/// # Get Written Chars
		///
		/// Gets the statistic associated with how many
		/// characters have been written to a console.
		fn chars_written(&self) -> usize { 0 }
	}

	/// # All Trait
	///
	/// Structure must provide both Write + Statistics
	pub trait All: Write + Statistics {}
}

/// # UART console
///
/// Returns a borrow for the UART writer
pub fn console() -> &'static crate::uart::Uart {
	&crate::uart::UART_WRITER
}