This commit is contained in:
2023-06-12 17:39:07 +02:00
parent 59f91e2f6b
commit 9854e0c0a8
45 changed files with 4708 additions and 400 deletions

42
lib/src/rtt.rs Normal file
View File

@ -0,0 +1,42 @@
use core::cell::RefCell;
use critical_section::Mutex;
use rtt_target::{rtt_init, UpChannel};
pub type RttWriteFn = fn(&[u8]);
static CHANNEL: Mutex<RefCell<Option<UpChannel>>> = Mutex::new(RefCell::new(None));
/// Write directly to the rtt output. Must call [init_rtt_logger] first.
pub fn rtt_write(bytes: &[u8]) {
critical_section::with(|cs| {
let mut slot = CHANNEL.borrow_ref_mut(cs);
if let Some(channel) = slot.as_mut() {
channel.write(bytes);
};
});
}
pub fn init_rtt_logger() -> RttWriteFn {
let channels = rtt_init! {
up: {
0: {
size: 1024
mode: NoBlockSkip
name: "Terminal"
}
}
};
critical_section::with(|cs| {
let mut slot = CHANNEL.borrow_ref_mut(cs);
if slot.is_some() {
return rtt_write;
}
*slot = Some(channels.up.0);
rtt_write
})
}