mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 07:45:28 +00:00
print syscall
This commit is contained in:
@@ -3,6 +3,16 @@
|
|||||||
use abi_sys::{Syscall, call_abi};
|
use abi_sys::{Syscall, call_abi};
|
||||||
use shared::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
|
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 {
|
pub mod display {
|
||||||
use crate::{Syscall, call_abi};
|
use crate::{Syscall, call_abi};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
|
|||||||
@@ -25,4 +25,8 @@ pub enum Syscall {
|
|||||||
pixels: *const Pixel<Rgb565>,
|
pixels: *const Pixel<Rgb565>,
|
||||||
len: usize,
|
len: usize,
|
||||||
},
|
},
|
||||||
|
Print {
|
||||||
|
msg: *const u8,
|
||||||
|
len: usize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,5 +28,15 @@ pub extern "C" fn call_abi(call: *const Syscall) {
|
|||||||
.draw_iter(slice.iter().copied())
|
.draw_iter(slice.iter().copied())
|
||||||
.unwrap();
|
.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")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use abi::display::Display;
|
use abi::{display::Display, print};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Drawable,
|
Drawable,
|
||||||
@@ -19,6 +19,7 @@ fn panic(_info: &PanicInfo) -> ! {
|
|||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn _start() {
|
pub extern "C" fn _start() {
|
||||||
|
print("Starting Calculator app");
|
||||||
let mut display = Display;
|
let mut display = Display;
|
||||||
|
|
||||||
let character_style = MonoTextStyle::new(&FONT_6X10, Rgb565::RED);
|
let character_style = MonoTextStyle::new(&FONT_6X10, Rgb565::RED);
|
||||||
|
|||||||
Reference in New Issue
Block a user