aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main.rs')
-rwxr-xr-xapp/src/main.rs52
1 files changed, 36 insertions, 16 deletions
diff --git a/app/src/main.rs b/app/src/main.rs
index 1025fae..b9f626e 100755
--- a/app/src/main.rs
+++ b/app/src/main.rs
@@ -5,7 +5,7 @@
#![allow(dead_code)]
mod dotstar;
-mod log;
+mod logger;
mod macros;
mod rtc;
mod usb;
@@ -17,12 +17,14 @@ use clint::HandlerArray;
use cortex_m::asm::wfi;
use cortex_m_rt::{entry, exception, ExceptionFrame};
use embedded_hal::digital::v2::OutputPin;
+use log::{error, info, LevelFilter};
use smart_leds::colors;
use smart_leds_trait::SmartLedsWrite;
use trinket_m0::{
self as hal,
clock::GenericClockController,
- gpio::{OpenDrain, Output, Pa10},
+ gpio::{OpenDrain, Output, Pa10, Pa6, Pa7, PfD},
+ sercom,
target_device::{interrupt, Interrupt},
time::*,
CorePeripherals, Peripherals,
@@ -61,8 +63,23 @@ fn main() -> ! {
red_led.set_low().expect("turning off red LED");
unsafe { LED = core::mem::transmute(&red_led) }
- let mut processor = log::Processor::new(uart, red_led);
- logln_now!("setting up dotstar");
+ // We do the transmute because, while all the underlying data is
+ // static, we're unable to get a referecence to the UART or LED
+ // until run-time. Another option would be to use Option in the
+ // SerialLogger definition, but that requires a check every time
+ // they might be used.
+ let uart_wrapped = logger::WriteWrapper::new(uart);
+ let logger = logger::SerialLogger::new(uart_wrapped, red_led);
+
+ // Wow, would I love to not be annotating this type.
+ let logger_ref: &'static logger::SerialLogger<
+ sercom::UART0<sercom::Sercom0Pad3<Pa7<PfD>>, sercom::Sercom0Pad2<Pa6<PfD>>, (), ()>,
+ Pa10<Output<OpenDrain>>,
+ > = unsafe { core::mem::transmute(&logger) };
+ unsafe { log::set_logger_racy(logger_ref).expect("couldn't set logger") };
+ log::set_max_level(LevelFilter::Trace);
+
+ info!("setting up dotstar");
let mut dotstar = dotstar::new(
peripherals.SERCOM1,
@@ -77,10 +94,10 @@ fn main() -> ! {
let black = [colors::BLACK];
let blue = [colors::DARK_MAGENTA];
- logln_now!("setting up timer");
+ info!("setting up timer");
let mut rtc_handler = rtc::setup(peripherals.RTC, &mut clocks);
- logln_now!("setting up usb host");
+ info!("setting up usb host");
let (mut usb_host, mut usb_handler) = usb::USBHost::new(
peripherals.USB,
pins.usb_sof,
@@ -92,7 +109,7 @@ fn main() -> ! {
&mut peripherals.PM,
);
- logln!("setting up handlers");
+ info!("setting up handlers");
HANDLERS.with_overrides(|hs| {
hs.register(0, &mut rtc_handler);
core.NVIC.enable(Interrupt::RTC);
@@ -101,7 +118,7 @@ fn main() -> ! {
unsafe { core.NVIC.set_priority(Interrupt::USB, 0) };
core.NVIC.enable(Interrupt::USB);
- logln!("Boot up complete.");
+ info!("Boot up complete.");
let mut last_tick = 0;
loop {
@@ -112,13 +129,11 @@ fn main() -> ! {
let tick = rtc::millis();
if tick >= last_tick + 1_024 {
last_tick = tick;
- //logln!("{}: tick", rtc::millis());
+ // info!("{}: tick\r\n", rtc::millis());
}
usb_host.task();
- processor.task();
-
dotstar
.write(blue.iter().cloned())
.expect("turning on dotstar");
@@ -135,7 +150,9 @@ fn panic_handler(pi: &core::panic::PanicInfo) -> ! {
logln_now!("~~~ PANIC ~~~");
logln_now!("{}", pi);
+ logln_now!("flushing log");
loop {
+ log::logger().flush();
wfi()
}
}
@@ -145,8 +162,11 @@ fn HardFault(ef: &ExceptionFrame) -> ! {
let red_led: &mut Pa10<Output<OpenDrain>> = unsafe { core::mem::transmute(LED) };
red_led.set_high().ok();
+ log::logger().flush();
logln_now!("!!! Hard Fault - ef: {:?} !!!", ef);
+ logln_now!("flushing log");
loop {
+ log::logger().flush();
wfi()
}
}
@@ -156,7 +176,7 @@ fn DefaultHandler(interrupt: i16) {
let red_led: &mut Pa10<Output<OpenDrain>> = unsafe { core::mem::transmute(LED) };
red_led.set_high().ok();
- logln_now!("*** Default Handler: {} ***", interrupt);
+ info!("*** Default Handler: {} ***", interrupt);
}
#[exception]
@@ -164,7 +184,7 @@ fn NonMaskableInt() {
let red_led: &mut Pa10<Output<OpenDrain>> = unsafe { core::mem::transmute(LED) };
red_led.set_high().ok();
- logln_now!("+++ NonMaskableInt +++");
+ info!("+++ NonMaskableInt +++");
}
#[exception]
@@ -172,7 +192,7 @@ fn SVCall() {
let red_led: &mut Pa10<Output<OpenDrain>> = unsafe { core::mem::transmute(LED) };
red_led.set_high().ok();
- logln_now!("+++ SVCall +++");
+ info!("+++ SVCall +++");
}
#[exception]
@@ -180,7 +200,7 @@ fn PendSV() {
let red_led: &mut Pa10<Output<OpenDrain>> = unsafe { core::mem::transmute(LED) };
red_led.set_high().ok();
- logln_now!("+++ PendSV +++");
+ info!("+++ PendSV +++");
}
#[exception]
@@ -188,7 +208,7 @@ fn SysTick() {
let red_led: &mut Pa10<Output<OpenDrain>> = unsafe { core::mem::transmute(LED) };
red_led.set_high().ok();
- logln_now!("+++ SysTick +++");
+ info!("+++ SysTick +++");
}
#[interrupt]