factored out panic file
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
mod display;
|
mod display;
|
||||||
mod keyboard;
|
mod keyboard;
|
||||||
|
mod panic;
|
||||||
|
|
||||||
use calc_math::{calc::StackCalc, Decimal};
|
use calc_math::{calc::StackCalc, Decimal};
|
||||||
use display::{DispalyState, SegmentPins, SegmentState, Show};
|
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
|
// Number of key presses to record for debounce
|
||||||
pub const DEBOUNCE_DEPTH: usize = 4;
|
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("<no message avaliable>")
|
|
||||||
)
|
|
||||||
.unwrap_infallible();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut led = pins.d13.into_output();
|
|
||||||
loop {
|
|
||||||
led.toggle();
|
|
||||||
arduino_hal::delay_ms(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IOSelect<'p> {
|
struct IOSelect<'p> {
|
||||||
display_no: usize,
|
display_no: usize,
|
||||||
pin: &'p mut Pin<Output>,
|
pin: &'p mut Pin<Output>,
|
||||||
|
|||||||
33
src/panic.rs
Normal file
33
src/panic.rs
Normal file
@@ -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("<no message avaliable>")
|
||||||
|
)
|
||||||
|
.unwrap_infallible();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut led = pins.d13.into_output();
|
||||||
|
loop {
|
||||||
|
led.toggle();
|
||||||
|
arduino_hal::delay_ms(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user