1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-04 21:48:17 +00:00
trezor-firmware/core/embed/rust/src/debug.rs
matejcik 8134490e2e feat(core): introduce uformat!, use uDebug in favor of Debug
now that we have ufmt, this is just much nicer
2024-06-19 09:14:51 +02:00

30 lines
668 B
Rust

mod unix_ffi {
const STDOUT_FILENO: cty::c_int = 1;
extern "C" {
pub fn write(fd: cty::c_int, buf: *const u8, count: cty::size_t) -> cty::ssize_t;
}
pub fn print(to_log: &str) {
unsafe {
write(STDOUT_FILENO, to_log.as_ptr(), to_log.len() as cty::size_t);
}
}
}
#[cfg(feature = "micropython")]
use crate::micropython::print::print;
#[cfg(not(feature = "micropython"))]
pub use unix_ffi::print;
pub struct DebugConsole;
impl ufmt::uWrite for DebugConsole {
type Error = core::convert::Infallible;
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
print(s);
Ok(())
}
}