Add RTT console
This commit is contained in:
parent
3923e7c838
commit
39ae164aec
|
@ -22,8 +22,9 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
use crate::jlink_rtt::Output as JLinkOutput;
|
||||
use crate::platform;
|
||||
use core::fmt;
|
||||
use core::fmt::{self, Write};
|
||||
|
||||
/// A trait that must be implemented by devices that are candidates for the
|
||||
/// global console.
|
||||
|
@ -49,6 +50,7 @@ pub enum Output {
|
|||
None(NullConsole),
|
||||
MiniUart(platform::MiniUart),
|
||||
PL011Uart(platform::PL011Uart),
|
||||
RTT(JLinkOutput),
|
||||
}
|
||||
|
||||
impl From<platform::MiniUart> for Output {
|
||||
|
@ -63,6 +65,12 @@ impl From<platform::PL011Uart> for Output {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<JLinkOutput> for Output {
|
||||
fn from(instance: JLinkOutput) -> Self {
|
||||
Output::RTT(instance)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Console {
|
||||
output: Output,
|
||||
}
|
||||
|
@ -80,6 +88,7 @@ impl Console {
|
|||
Output::None(i) => i,
|
||||
Output::MiniUart(i) => i,
|
||||
Output::PL011Uart(i) => i,
|
||||
Output::RTT(i) => i,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -216,11 +216,28 @@ impl Output {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for Output {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
impl Drop for Output {
|
||||
fn drop(&mut self) {}
|
||||
}
|
||||
|
||||
impl crate::devices::ConsoleOps for Output {
|
||||
fn puts(&self, s: &str) {
|
||||
unsafe {
|
||||
_SEGGER_RTT.up.write(s.as_bytes(), true);
|
||||
}
|
||||
}
|
||||
|
||||
fn putc(&self, c: char) {
|
||||
let mut buf = [0u8; 4];
|
||||
let s = c.encode_utf8(&mut buf);
|
||||
self.puts(s);
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for Output {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
use crate::devices::console::ConsoleOps;
|
||||
self.puts(s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ fn kmain() -> ! {
|
|||
// }
|
||||
|
||||
// jtag_dbg_wait();
|
||||
CONSOLE.lock(|c| {
|
||||
c.replace_with(Output::new().into());
|
||||
});
|
||||
|
||||
let mut out = Output::new();
|
||||
writeln!(out, "JLink RTT is working!"); // @todo RttConsole
|
||||
|
|
Loading…
Reference in New Issue