summaryrefslogtreecommitdiffstats
path: root/ble/src/logger.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ble/src/logger.rs')
-rw-r--r--ble/src/logger.rs26
1 files changed, 8 insertions, 18 deletions
diff --git a/ble/src/logger.rs b/ble/src/logger.rs
index f102b74..b4167b2 100644
--- a/ble/src/logger.rs
+++ b/ble/src/logger.rs
@@ -2,6 +2,7 @@ use crate::rtc;
use core::cell::UnsafeCell;
use core::fmt::{self, Write};
+use core::mem::MaybeUninit;
use log::{Metadata, Record};
use nrf52840_hal::{target::UARTE0, uarte, Uarte};
use starb::{Reader, RingBuffer, Writer};
@@ -22,12 +23,9 @@ impl<'a> JoinedRingBuffer<'a> {
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) {
- // Ignore buffer full errors for logging.
- return Ok(());
- }
- }
+ // Drop anything that couldn't fit on the ground so we don't
+ // back up.
+ self.lbw.unshift_from(s.as_bytes());
Ok(())
}
}
@@ -94,20 +92,12 @@ where
}
fn flush(&self) {
- // Unsafe due to mutable static. We can only deal with the
- // tail position of the buffer here to keep things safe.
let jrb = unsafe { &mut JRB };
- if jrb.lbr.is_empty() {
- return;
- }
-
let writer = unsafe { &mut (*self.writer.get()) };
- while let Some(b) = jrb.lbr.shift() {
- // TODO: The UARTE peripheral uses DMA to send a bunch of
- // stuff at speed, in hardware. It would be nice to use
- // it, but we can't just take a slice of the ring buffer,
- // since we don't know about its internal structure here.
- writer.w.write(&[b]).expect("writing log");
+ let mut buf: [u8; 256] = unsafe { MaybeUninit::<[u8; 256]>::uninit().assume_init() };
+ let len = jrb.lbr.shift_into(&mut buf);
+ if len > 0 {
+ writer.w.write(&buf[0..len]).expect("writing log")
}
}
}