diff options
Diffstat (limited to 'demo')
-rw-r--r-- | demo/Cargo.toml | 13 | ||||
-rw-r--r-- | demo/src/.main.rs.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | demo/src/.panique.rs.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | demo/src/console.rs | 102 | ||||
-rw-r--r-- | demo/src/main.rs | 46 | ||||
-rw-r--r-- | demo/src/panique.rs | 41 |
6 files changed, 202 insertions, 0 deletions
diff --git a/demo/Cargo.toml b/demo/Cargo.toml new file mode 100644 index 0000000..cc4498b --- /dev/null +++ b/demo/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "demo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ibugger_rt = { path = "../ibugger_rt" } +s5l87xx = { path = "../s5l87xx" } +nano5g = { path = "../nano5g" } +heapless = "0" +embedded-graphics = "0" diff --git a/demo/src/.main.rs.swp b/demo/src/.main.rs.swp Binary files differnew file mode 100644 index 0000000..a00a22b --- /dev/null +++ b/demo/src/.main.rs.swp diff --git a/demo/src/.panique.rs.swp b/demo/src/.panique.rs.swp Binary files differnew file mode 100644 index 0000000..910fa5a --- /dev/null +++ b/demo/src/.panique.rs.swp diff --git a/demo/src/console.rs b/demo/src/console.rs new file mode 100644 index 0000000..5e82aba --- /dev/null +++ b/demo/src/console.rs @@ -0,0 +1,102 @@ +use embedded_graphics::{ + Drawable, + geometry::{Point, Size}, + mono_font::{ascii::FONT_6X10, MonoTextStyle}, + prelude::{RgbColor}, + primitives::rectangle::Rectangle, + text::{Text, Baseline}, + draw_target::DrawTarget, +}; + +pub struct Console<const W: usize, const H: usize> { + array: [[char; W]; H], + dirty: [bool; H], + curline: usize, + curcol: usize, +} + +impl<const W: usize, const H: usize> Console<W, H> { + const FONT_H: i32 = 12; + const FONT_W: i32 = 6; + + pub fn new() -> Self { + Self { + array: [[' '; W]; H], + dirty: [true; H], + curline: 0, + curcol: 0, + } + } + + pub fn write_char(&mut self, c: char) { + let mut wrapped = false; + if self.curcol >= W { + self.curcol = 0; + self.curline += 1; + } + if self.curline >= H { + self.curline = 0; + for i in 0..W { + self.array[0][i] = ' '; + } + wrapped = true; + } + + if c == '\n' { + self.curline += 1; + self.curcol = 0; + } else { + self.array[self.curline][self.curcol] = c; + self.curcol += 1; + self.dirty[self.curline] = true; + } + + if wrapped { + //self.array.rotate_left(1); + for i in 0..H { + self.dirty[i] = true; + } + for i in 1..H { + for j in 0..W { + self.array[i][j] = ' '; + } + } + } + } + + pub fn blit<D, C: RgbColor>(&mut self, target: &mut D) + where + D: DrawTarget<Color=C>, + { + let style = MonoTextStyle::new(&FONT_6X10, C::WHITE); + for (i, dirty) in self.dirty.iter().enumerate() { + if !dirty { + continue + } + + let mut s = heapless::String::<W>::new(); + for c in self.array[i] { + s.push(c); + } + + let tl = Point::new(0, Self::FONT_H * (i as i32)); + let sz = Size::new((Self::FONT_W * (W as i32)) as u32, Self::FONT_H as u32); + let rect = Rectangle::new(tl, sz); + target.fill_solid(&rect, C::BLACK); + Text::with_baseline(&s, tl, style, Baseline::Top).draw(target); + } + for i in 0..H { + self.dirty[i] = false; + } + } +} + +impl<const W: usize, const H: usize> core::fmt::Write for Console<W, H> { + fn write_str(&mut self, text: &str) -> core::fmt::Result { + for c in text.chars() { + self.write_char(c); + } + Ok(()) + } +} + diff --git a/demo/src/main.rs b/demo/src/main.rs new file mode 100644 index 0000000..5f2cd99 --- /dev/null +++ b/demo/src/main.rs @@ -0,0 +1,46 @@ +#![feature(asm)] +#![feature(asm_const)] +#![feature(asm_sym)] +#![feature(naked_functions)] +#![feature(panic_info_message)] + +#![no_std] +#![no_main] + +use ibugger_rt::entry; +use s5l87xx::Peripherals; +use nano5g::lcd::{LCD, Display}; + +use core::fmt::Write; + +mod console; +mod panique; + +entry!(main); + +fn main() -> ! { + let periphs = unsafe { Peripherals::steal() }; + let lcd = LCD::new(periphs.LCD); + let mut display = Display::new(lcd); + + let mut console = console::Console::<{240/6}, {320/14}>::new(); + console.write_str("Hello, world!\n"); + console.blit(&mut display); + display.flush(); + + let mut i = 0; + loop { + core::fmt::write(&mut console, format_args!("tick {}\n", i)); + i += 1; + console.blit(&mut display); + display.flush(); + if i > 10 { + break + } + } + + let foo: Option<i32> = None; + foo.unwrap(); + + loop {} +} diff --git a/demo/src/panique.rs b/demo/src/panique.rs new file mode 100644 index 0000000..17934a3 --- /dev/null +++ b/demo/src/panique.rs @@ -0,0 +1,41 @@ +use core::panic::PanicInfo; +use core::fmt::Write; + +use crate::console::Console; +use nano5g::lcd::{LCD, Display}; +use s5l87xx::Peripherals; + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + let periphs = unsafe { Peripherals::steal() }; + let lcd = LCD::new(periphs.LCD); + let mut display = Display::new(lcd); + + let mut console = Console::<{240/6}, {320/14}>::new(); + + console.write_str("Panic!\n"); + console.blit(&mut display); + display.flush(); + + if let Some(s) = info.payload().downcast_ref::<&str>() { + core::fmt::write(&mut console, format_args!( + "Payload: {:?}\n", s, + )); + } else if let Some(a) = info.message() { + console.write_str("Message: "); + core::fmt::write(&mut console, *a); + console.write_str("\n"); + } + console.blit(&mut display); + display.flush(); + + if let Some(location) = info.location() { + core::fmt::write(&mut console, format_args!("In {}:{}\n", location.file(), location.line())); + } else { + console.write_str("No location information.\n"); + } + console.blit(&mut display); + display.flush(); + + loop {} +} |