mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 15:55:25 +00:00
basic fs syscall(s)
This commit is contained in:
@@ -8,6 +8,7 @@ use embedded_graphics::{
|
||||
geometry::Point,
|
||||
pixelcolor::{Rgb565, RgbColor},
|
||||
};
|
||||
use embedded_sdmmc::DirEntry;
|
||||
pub use shared::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
|
||||
use strum::{EnumCount, EnumIter};
|
||||
|
||||
@@ -21,19 +22,22 @@ pub static mut CALL_ABI_TABLE: [usize; CallAbiTable::COUNT] = [0; CallAbiTable::
|
||||
#[derive(Clone, Copy, EnumIter, EnumCount)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum CallAbiTable {
|
||||
Print = 0,
|
||||
Sleep = 1,
|
||||
PrintString = 0,
|
||||
SleepMs = 1,
|
||||
LockDisplay = 2,
|
||||
DrawIter = 3,
|
||||
GetKey = 4,
|
||||
GenRand = 5,
|
||||
ListDir = 6,
|
||||
ReadFile = 7,
|
||||
}
|
||||
|
||||
pub type PrintAbi = extern "C" fn(ptr: *const u8, len: usize);
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn print(msg: &str) {
|
||||
let f: PrintAbi = unsafe { core::mem::transmute(CALL_ABI_TABLE[CallAbiTable::Print as usize]) };
|
||||
let f: PrintAbi =
|
||||
unsafe { core::mem::transmute(CALL_ABI_TABLE[CallAbiTable::PrintString as usize]) };
|
||||
f(msg.as_ptr(), msg.len());
|
||||
}
|
||||
|
||||
@@ -41,7 +45,8 @@ pub type SleepAbi = extern "C" fn(ms: u64);
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn sleep(ms: u64) {
|
||||
let f: SleepAbi = unsafe { core::mem::transmute(CALL_ABI_TABLE[CallAbiTable::Sleep as usize]) };
|
||||
let f: SleepAbi =
|
||||
unsafe { core::mem::transmute(CALL_ABI_TABLE[CallAbiTable::SleepMs as usize]) };
|
||||
f(ms);
|
||||
}
|
||||
|
||||
@@ -89,3 +94,38 @@ pub fn gen_rand(req: &mut RngRequest) {
|
||||
f(req)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ListDir =
|
||||
extern "C" fn(str: *const u8, len: usize, files: *mut Option<DirEntry>, file_len: usize);
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn list_dir(path: &str, files: &mut [Option<DirEntry>]) {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallAbiTable::ListDir as usize];
|
||||
let f: ListDir = core::mem::transmute(ptr);
|
||||
f(path.as_ptr(), path.len(), files.as_mut_ptr(), files.len())
|
||||
}
|
||||
}
|
||||
|
||||
pub type ReadFile = extern "C" fn(
|
||||
str: *const u8,
|
||||
len: usize,
|
||||
read_from: usize,
|
||||
buf: *mut u8,
|
||||
buf_len: usize,
|
||||
) -> usize;
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn read_file(file: &str, read_from: usize, buf: &mut [u8]) -> usize {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallAbiTable::ReadFile as usize];
|
||||
let f: ReadFile = core::mem::transmute(ptr);
|
||||
f(
|
||||
file.as_ptr(),
|
||||
file.len(),
|
||||
read_from,
|
||||
buf.as_mut_ptr(),
|
||||
buf.len(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user