extern crate cortex_m_semihosting as sh;
pub use self::sh::hio;
use crate::destination::semihosting::SemihostingComp;
use crate::modes::InterruptModer;
use core::marker::PhantomData;
pub struct Semihosting<M: InterruptModer, T: SemihostingComp> {
inner: T,
_mod: PhantomData<M>
}
impl<M: InterruptModer, T: SemihostingComp> Semihosting<M, T> {
#[inline(always)]
pub fn new(inner: T) -> Self {
Self { inner, _mod: PhantomData }
}
}
impl<M: InterruptModer> Semihosting<M, hio::HostStream> {
#[inline(always)]
pub fn stdout() -> Result<Self, ()> {
hio::hstdout().map(Self::new)
}
#[inline(always)]
pub fn stderr() -> Result<Self, ()> {
hio::hstderr().map(Self::new)
}
}
impl<Mode: InterruptModer, T: SemihostingComp> super::Printer for Semihosting<Mode, T> {
type W = T;
type M = Mode;
#[inline]
fn destination(&mut self) -> &mut Self::W {
&mut self.inner
}
}
pub type InterruptFree<T> = Semihosting<crate::modes::InterruptFree, T>;
pub type InterruptOk<T> = Semihosting<crate::modes::InterruptOk, T>;