summaryrefslogtreecommitdiffstats
path: root/demo/src/panique.rs
diff options
context:
space:
mode:
Diffstat (limited to 'demo/src/panique.rs')
-rw-r--r--demo/src/panique.rs41
1 files changed, 41 insertions, 0 deletions
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 {}
+}