print syscall

This commit is contained in:
2025-08-29 15:05:19 -06:00
parent f3c67beb00
commit 1bbd988ef7
4 changed files with 26 additions and 1 deletions

View File

@@ -3,6 +3,16 @@
use abi_sys::{Syscall, call_abi};
use shared::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
pub fn print(msg: &str) {
let syscall = Syscall::Print {
msg: msg.as_ptr(),
len: msg.len(),
};
unsafe {
call_abi(&syscall);
}
}
pub mod display {
use crate::{Syscall, call_abi};
use embedded_graphics::{

View File

@@ -25,4 +25,8 @@ pub enum Syscall {
pixels: *const Pixel<Rgb565>,
len: usize,
},
Print {
msg: *const u8,
len: usize,
},
}

View File

@@ -28,5 +28,15 @@ pub extern "C" fn call_abi(call: *const Syscall) {
.draw_iter(slice.iter().copied())
.unwrap();
}
Syscall::Print { msg, len } => {
// SAFETY: we're trusting the user program here
let slice = unsafe { core::slice::from_raw_parts(*msg, *len) };
if let Ok(str) = str::from_utf8(slice) {
defmt::info!("{:?}", str);
} else {
defmt::error!("Failed to parse user print str")
}
}
}
}

View File

@@ -1,7 +1,7 @@
#![no_std]
#![no_main]
use abi::display::Display;
use abi::{display::Display, print};
use core::panic::PanicInfo;
use embedded_graphics::{
Drawable,
@@ -19,6 +19,7 @@ fn panic(_info: &PanicInfo) -> ! {
#[unsafe(no_mangle)]
pub extern "C" fn _start() {
print("Starting Calculator app");
let mut display = Display;
let character_style = MonoTextStyle::new(&FONT_6X10, Rgb565::RED);