Add display demo in main

This commit is contained in:
Berkus Decker 2020-11-16 01:27:54 +02:00
parent e72fac01b0
commit 3147e5327a
1 changed files with 41 additions and 0 deletions

View File

@ -41,6 +41,11 @@ mod sync;
mod tests;
mod write_to;
use crate::platform::rpi3::{
display::{Color, DrawError},
vc::VC,
};
entry!(kmain);
/// The global console. Output of the kernel print! and println! macros goes here.
@ -154,10 +159,46 @@ pub fn kmain() -> ! {
#[cfg(test)]
test_main();
check_display_init();
println!("Bye, hanging forever...");
endless_sleep()
}
fn check_display_init() {
display_graphics()
.map_err(|e| {
println!("Error in display: {}", e);
})
.ok();
}
fn display_graphics() -> Result<(), DrawError> {
if let Ok(mut display) = VC::init_fb(800, 600, 32) {
println!("Display created");
display.clear(Color::black());
println!("Display cleared");
display.rect(10, 10, 250, 250, Color::rgb(32, 96, 64));
display.draw_text(50, 50, "Hello there!", Color::rgb(128, 192, 255))?;
let mut buf = [0u8; 64];
let s = write_to::show(&mut buf, format_args!("Display width {}", display.width));
if s.is_err() {
display.draw_text(50, 150, "Error displaying", Color::red())?
} else {
display.draw_text(50, 150, s.unwrap(), Color::white())?
}
display.draw_text(150, 50, "RED", Color::red())?;
display.draw_text(160, 60, "GREEN", Color::green())?;
display.draw_text(170, 70, "BLUE", Color::blue())?;
}
Ok(())
}
#[cfg(test)]
mod main_tests {
use super::*;