From 3147e5327ae2c4e7e1ce64cb415cea6ae06e3a7d Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Mon, 16 Nov 2020 01:27:54 +0200 Subject: [PATCH] Add display demo in main --- nucleus/src/main.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/nucleus/src/main.rs b/nucleus/src/main.rs index 1badcf1..84be6fc 100644 --- a/nucleus/src/main.rs +++ b/nucleus/src/main.rs @@ -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::*;