diff options
Diffstat (limited to 'usb/src')
-rw-r--r-- | usb/src/dotstar.rs | 16 | ||||
-rw-r--r-- | usb/src/logger.rs | 8 | ||||
-rw-r--r-- | usb/src/main.rs | 12 |
3 files changed, 20 insertions, 16 deletions
diff --git a/usb/src/dotstar.rs b/usb/src/dotstar.rs index c7eed7d..13ccb8d 100644 --- a/usb/src/dotstar.rs +++ b/usb/src/dotstar.rs @@ -8,6 +8,14 @@ use trinket_m0::{ use apa102_spi::Apa102; +type TrinketDotStar = Apa102< + SPIMaster1< + sercom::Sercom1Pad3<gpio::Pa31<gpio::PfD>>, + sercom::Sercom1Pad0<gpio::Pa0<gpio::PfD>>, + sercom::Sercom1Pad1<gpio::Pa1<gpio::PfD>>, + >, +>; + pub fn new( sercom: SERCOM1, miso: gpio::Pa31<Input<Floating>>, @@ -16,13 +24,7 @@ pub fn new( port: &mut gpio::Port, pm: &mut PM, clocks: &mut GenericClockController, -) -> Apa102< - SPIMaster1< - sercom::Sercom1Pad3<gpio::Pa31<gpio::PfD>>, - sercom::Sercom1Pad0<gpio::Pa0<gpio::PfD>>, - sercom::Sercom1Pad1<gpio::Pa1<gpio::PfD>>, - >, -> { +) -> TrinketDotStar { let gclk = clocks.gclk0(); let miso = miso.into_pad(port); let mosi = mosi.into_pad(port); diff --git a/usb/src/logger.rs b/usb/src/logger.rs index 7357c22..170607c 100644 --- a/usb/src/logger.rs +++ b/usb/src/logger.rs @@ -20,14 +20,14 @@ struct JoinedRingBuffer<'a> { impl<'a> JoinedRingBuffer<'a> { const fn new(rb: &'a RingBuffer<u8>) -> Self { let (lbr, lbw) = rb.split(); - Self { lbr: lbr, lbw: lbw } + Self { lbr, lbw } } } impl fmt::Write for JoinedRingBuffer<'_> { fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { for b in s.bytes() { - if let Err(_) = self.lbw.unshift(b) { + if self.lbw.unshift(b).is_err() { // Ignore buffer full errors for logging. return Ok(()); } @@ -93,9 +93,9 @@ where } let jrb = unsafe { &mut JRB }; - write!( + writeln!( jrb, - "[{}] {} {} -- {}\r\n", + "[{}] {} {} -- {}\r", rtc::millis(), record.level(), record.target(), diff --git a/usb/src/main.rs b/usb/src/main.rs index 42cdf55..a87ecfb 100644 --- a/usb/src/main.rs +++ b/usb/src/main.rs @@ -39,6 +39,12 @@ use smart_leds::colors; use smart_leds_trait::SmartLedsWrite; use usb_host::Driver; +// Wow, would I love to not be annotating this type. +type UARTLogger = logger::SerialLogger< + sercom::UART0<sercom::Sercom0Pad3<Pa7<PfD>>, sercom::Sercom0Pad2<Pa6<PfD>>, (), ()>, + Pa10<Output<OpenDrain>>, +>; + // A very unsafe copy of an LED to turn on when things go really, really wrong. static mut LED: usize = 0; @@ -111,11 +117,7 @@ fn main() -> ! { 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 { mem::transmute(&logger) }; + let logger_ref: &'static UARTLogger = unsafe { mem::transmute(&logger) }; unsafe { log::set_logger_racy(logger_ref).expect("couldn't set logger") }; log::set_max_level(LevelFilter::Trace); |