[−][src]Crate ruspiro_console
Console abstraction
This crate provides a console abstraction to enable string output to a configurable output channel.
It also provides the convinient macros (print!
and println!
) to output text that are usually not
available in [no_std]
environments. However this crate also provide macros to indicate the severity of the
message that shall be printed. Those are info!
, warn!
and error!
.
Dependencies
This crate uses macros to provide formatted strings. This formatting requires a memory allocator to
be present (as part of the alloc
crate). So when using this crate provide an allocator such as
ruspiro_allocator
.
Example
To actually set an active output channel you need to provide a structure that implements the core::fmt::Write
trait.
If this trait has been implemented this structure can be used as actual console. To use it there should be the following code written at the earliest possible point in the main crate of the binary (e.g. the kernel)
use ruspiro_console::*; use ruspiro_uart::*; // as we demonstrate with the Uart as output device/channel. fn main() { let mut uart = Uart1::new(); // create a new uart struct if uart.initialize(250_000_000, 115_200).is_ok() { // initialize the Uart with fixed core rate and baud rate CONSOLE.with_mut(|cons| cons.replace(uart)); // from this point CONSOLE takes ownership of uart } // if everything went fine uart should be assigned to the console for generic output println!("Console is ready and display's through uart"); }
Re-exports
pub extern crate alloc; |
pub use macros::*; |
Modules
macros | Convinient output macros to print formatted strings to the configured channel of the console |
Macros
error | This macro prefixes the output with "E: <module-path> -". Other than this it works like the |
info | This macro prefixes the output with "I: <module-path> -". Other than this it works like the |
This macro works like the | |
println | This macro works like the |
warn | This macro prefixes the output with "W: <module-path> -". Other than this it works like the |
Structs
Console | The representation of the abstract console |
Statics
CONSOLE | The Console singleton used by print! and println! macros |