From 804964cb8dd753257b3fd1c42b52247698baa8cb Mon Sep 17 00:00:00 2001 From: Hexa Dust Date: Fri, 18 Jul 2025 20:31:23 +0100 Subject: [PATCH] factored out panic file --- src/main.rs | 32 +------------------------------- src/panic.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 src/panic.rs diff --git a/src/main.rs b/src/main.rs index 5a473fc..20aa2f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod display; mod keyboard; +mod panic; use calc_math::{calc::StackCalc, Decimal}; use display::{DispalyState, SegmentPins, SegmentState, Show}; @@ -24,37 +25,6 @@ pub const KEYBOARD_ADC_THRESHOLD: u16 = 500; // Number of key presses to record for debounce pub const DEBOUNCE_DEPTH: usize = 4; -#[cfg(not(doc))] -#[panic_handler] -fn panic(info: &core::panic::PanicInfo) -> ! { - // disable interrupts - firmware has panicked so no ISRs should continue running - // avr_device::interrupt::disable(); - - // SAFETY: Main code aborted. - let dp = unsafe { arduino_hal::Peripherals::steal() }; - let pins = arduino_hal::pins!(dp); - let mut serial = arduino_hal::default_serial!(dp, pins, SERIAL_BAUD); - - ufmt::uwriteln!(&mut serial, "Firmware panic!\r").unwrap_infallible(); - if let Some(loc) = info.location() { - ufmt::uwriteln!( - &mut serial, - " At {}:{}:{} - {}\r", - loc.file(), - loc.line(), - loc.column(), - info.message().as_str().unwrap_or("") - ) - .unwrap_infallible(); - } - - let mut led = pins.d13.into_output(); - loop { - led.toggle(); - arduino_hal::delay_ms(100); - } -} - struct IOSelect<'p> { display_no: usize, pin: &'p mut Pin, diff --git a/src/panic.rs b/src/panic.rs new file mode 100644 index 0000000..a59c7d8 --- /dev/null +++ b/src/panic.rs @@ -0,0 +1,33 @@ +use crate::SERIAL_BAUD; +use arduino_hal::prelude::_unwrap_infallible_UnwrapInfallible; + +#[cfg(not(doc))] +#[panic_handler] +fn panic(info: &core::panic::PanicInfo) -> ! { + // disable interrupts - firmware has panicked so no ISRs should continue running + // avr_device::interrupt::disable(); + + // SAFETY: Main code aborted. + let dp = unsafe { arduino_hal::Peripherals::steal() }; + let pins = arduino_hal::pins!(dp); + let mut serial = arduino_hal::default_serial!(dp, pins, SERIAL_BAUD); + + ufmt::uwriteln!(&mut serial, "Firmware panic!\r").unwrap_infallible(); + if let Some(loc) = info.location() { + ufmt::uwriteln!( + &mut serial, + " At {}:{}:{} - {}\r", + loc.file(), + loc.line(), + loc.column(), + info.message().as_str().unwrap_or("") + ) + .unwrap_infallible(); + } + + let mut led = pins.d13.into_output(); + loop { + led.toggle(); + arduino_hal::delay_ms(100); + } +}