1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Semihosting module

extern crate cortex_m_semihosting as sh;

use core::fmt;
use core::fmt::Write;

/// Trait implemented for writes that can be used with [SH](struct.SH.html)
pub trait SemihostingComp: Write {}

impl SemihostingComp for sh::hio::HStdout {}
impl SemihostingComp for sh::hio::HStderr {}

/// Semihosting destination
pub struct SH<T: SemihostingComp> {
    inner: T,
}

impl<T: SemihostingComp> SH<T> {
    pub fn new(typ: T) -> SH<T> {
        Self { inner: typ }
    }
}

impl<T: SemihostingComp> Write for SH<T> {
    #[inline]
    fn write_str(&mut self, s: &str) -> fmt::Result {
        self.inner.write_str(s)
    }
}

/// Alias to semihosting's stdout
pub type SHout = SH<sh::hio::HStdout>;
/// Alias to semihosting's stderr
pub type SHerr = SH<sh::hio::HStderr>;