mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2026-02-11 06:15:25 +00:00
Compare commits
7 Commits
audio-driv
...
49c11978d5
| Author | SHA1 | Date | |
|---|---|---|---|
| 49c11978d5 | |||
| 9035ebc757 | |||
| f015f67c87 | |||
| 02877d03a6 | |||
| d77320d445 | |||
| 55347be232 | |||
| ccf4499f89 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
||||
/target
|
||||
*.uf2
|
||||
abi_sys.h
|
||||
userlib_sys.h
|
||||
assets/gif/bad_apple.gif
|
||||
picolibc
|
||||
user-apps/gboy/Peanut-GB
|
||||
|
||||
64
Cargo.lock
generated
64
Cargo.lock
generated
@@ -12,27 +12,6 @@ dependencies = [
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "abi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi_sys",
|
||||
"embedded-graphics",
|
||||
"once_cell",
|
||||
"rand_core 0.9.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "abi_sys"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"cbindgen",
|
||||
"defmt 0.3.100",
|
||||
"embedded-graphics",
|
||||
"strum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
@@ -243,9 +222,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
name = "calculator"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi",
|
||||
"embedded-graphics",
|
||||
"embedded-layout",
|
||||
"userlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -377,9 +356,9 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
@@ -1230,16 +1209,16 @@ dependencies = [
|
||||
name = "gallery"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi",
|
||||
"embedded-graphics",
|
||||
"tinybmp",
|
||||
"userlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.9"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
@@ -1272,10 +1251,10 @@ dependencies = [
|
||||
name = "gif"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi",
|
||||
"embedded-graphics",
|
||||
"selection_ui",
|
||||
"tinygif",
|
||||
"userlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1450,7 +1429,6 @@ dependencies = [
|
||||
name = "kernel"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"abi_sys",
|
||||
"assign-resources",
|
||||
"bitflags 2.10.0",
|
||||
"bt-hci",
|
||||
@@ -1493,6 +1471,7 @@ dependencies = [
|
||||
"strum",
|
||||
"talc",
|
||||
"trouble-host",
|
||||
"userlib_sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2157,10 +2136,10 @@ checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add"
|
||||
name = "selection_ui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi",
|
||||
"embedded-graphics",
|
||||
"embedded-layout",
|
||||
"embedded-text",
|
||||
"userlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2271,10 +2250,10 @@ dependencies = [
|
||||
name = "snake"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi",
|
||||
"embedded-graphics",
|
||||
"embedded-snake",
|
||||
"rand",
|
||||
"userlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2647,6 +2626,27 @@ dependencies = [
|
||||
"usbd-hid-descriptors",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "userlib"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"embedded-graphics",
|
||||
"once_cell",
|
||||
"rand_core 0.9.3",
|
||||
"userlib_sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "userlib_sys"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"cbindgen",
|
||||
"defmt 0.3.100",
|
||||
"embedded-graphics",
|
||||
"strum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.18.1"
|
||||
@@ -2758,11 +2758,11 @@ dependencies = [
|
||||
name = "wav_player"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi",
|
||||
"embedded-audio",
|
||||
"embedded-graphics",
|
||||
"rand",
|
||||
"selection_ui",
|
||||
"userlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
14
Cargo.toml
14
Cargo.toml
@@ -2,14 +2,14 @@
|
||||
resolver = "3"
|
||||
members = [
|
||||
"kernel",
|
||||
"abi_sys",
|
||||
"abi",
|
||||
"userlib_sys",
|
||||
"userlib",
|
||||
"selection_ui",
|
||||
"user-apps/calculator",
|
||||
"user-apps/snake",
|
||||
"user-apps/gallery",
|
||||
"user-apps/gif",
|
||||
"user-apps/wav_player",
|
||||
"user_apps/calculator",
|
||||
"user_apps/snake",
|
||||
"user_apps/gallery",
|
||||
"user_apps/gif",
|
||||
"user_apps/wav_player",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
||||
19
README.md
19
README.md
@@ -1,26 +1,27 @@
|
||||
# PicoCalc OS (Rust)
|
||||
|
||||
A simple operating system for the **Clockwork PicoCalc**, written in Rust.
|
||||
This project provides a minimal kernel, ABI, and user-space applications to experiment with OS development on constrained hardware.
|
||||
A simple kernel and applications for the **Clockwork PicoCalc**, written in Rust.
|
||||
This project provides a minimal kernel, syscall table, and user-space applications to experiment with kernel development on constrained hardware.
|
||||
|
||||
## Status
|
||||
|
||||
Basic synchronous applications are working great.
|
||||
Current focus is on **expanding the ABI syscalls** and **fixing the MSC/USB-SCSI driver** to make application development easier and smoother.
|
||||
Current focus is on exanding applications and porting software, finding bugs in ffi, and making sure the kernel is as stable as possible.
|
||||
|
||||
## Project Structure
|
||||
|
||||
- **`kernel/`** – The core OS kernel (task scheduling, drivers, memory, etc.)
|
||||
- **`abi_sys/`** – Shared application binary interface definitions for kernel ↔ userspace (Repr "C")
|
||||
- **`abi/`** – Rust focused ABI helpers and abstractions for easier development
|
||||
- **`user-apps/`** – Collection of userspace programs (calculator, snake, etc.)
|
||||
- **`kernel/`** – The core OS kernel
|
||||
- **`userlib_sys/`** – C FFI bindings for kernel syscall
|
||||
- **`userlib/`** – Rust wrapper on top of `userlib_sys`
|
||||
- **`picolib/`** – Built with ```just newlib```, and provides libc symbols when linking with C libraries
|
||||
- **`user-apps/`** – Collection of userspace programs (gif player, wav player, calculator, snake, etc.)
|
||||
|
||||
## Features
|
||||
|
||||
- Minimal Rust-based kernel targeting the PicoCalc
|
||||
- Custom ABI for safe communication between kernel and applications
|
||||
- Custom ABI for *Mostly* safe communication between kernel and applications
|
||||
- Support for multiple user-space applications
|
||||
- Hardware drivers tailored for the PicoCalc
|
||||
- Hardware drivers tailored for the PicoCalc( Audio, Display, Keyboard, ans Storage )
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
8
justfile
8
justfile
@@ -1,15 +1,17 @@
|
||||
target := "thumbv8m.main-none-eabihf"
|
||||
|
||||
kernel-dev board:
|
||||
cargo run --bin kernel --features {{board}} --features fps
|
||||
kernel-release-probe board:
|
||||
cargo run --bin kernel --profile release --features {{board}} --features fps
|
||||
kernel-release board:
|
||||
cargo build --bin kernel --release --no-default-features --features {{board}}
|
||||
elf2uf2-rs -d target/thumbv8m.main-none-eabihf/release/kernel
|
||||
elf2uf2-rs -d target/{{target}}/release/kernel
|
||||
|
||||
binary-args := "RUSTFLAGS=\"-C link-arg=-pie -C relocation-model=pic\""
|
||||
|
||||
cbindgen:
|
||||
cbindgen abi_sys --output abi_sys.h -q
|
||||
cbindgen userlib_sys --output userlib_sys.h -q
|
||||
|
||||
newlib:
|
||||
#!/bin/bash
|
||||
@@ -42,7 +44,7 @@ userapps: cbindgen
|
||||
just userapp wav_player
|
||||
|
||||
copy-userapp app:
|
||||
cp ./target/thumbv8m.main-none-eabihf/release-binary/{{app}} /run/media/$(whoami)/PICOCALC/{{app}}.bin
|
||||
cp ./target/{{target}}/release-binary/{{app}} /run/media/$(whoami)/PICOCALC/{{app}}.bin
|
||||
|
||||
copy-userapps:
|
||||
#!/bin/bash
|
||||
|
||||
@@ -99,4 +99,4 @@ embedded-alloc = { version = "0.6.0", features = [
|
||||
], optional = true }
|
||||
bumpalo = "3.19.0"
|
||||
|
||||
abi_sys = { path = "../abi_sys" }
|
||||
userlib_sys = { path = "../userlib_sys" }
|
||||
|
||||
@@ -15,7 +15,7 @@ use fixed::traits::ToFixed;
|
||||
|
||||
pub const SAMPLE_RATE_HZ: u32 = 22_050;
|
||||
const AUDIO_BUFFER_SAMPLES: usize = 1024;
|
||||
const _: () = assert!(AUDIO_BUFFER_SAMPLES == abi_sys::AUDIO_BUFFER_SAMPLES);
|
||||
const _: () = assert!(AUDIO_BUFFER_SAMPLES == userlib_sys::AUDIO_BUFFER_SAMPLES);
|
||||
|
||||
// 8bit stereo interleaved PCM audio buffers
|
||||
pub static mut AUDIO_BUFFER: [u8; AUDIO_BUFFER_SAMPLES * 2] = [0; AUDIO_BUFFER_SAMPLES * 2];
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use crate::{
|
||||
abi,
|
||||
storage::{File, SDCARD},
|
||||
syscalls,
|
||||
};
|
||||
use abi_sys::{CallTable, EntryFn};
|
||||
use alloc::{vec, vec::Vec};
|
||||
use bumpalo::Bump;
|
||||
use core::ptr;
|
||||
@@ -17,6 +16,7 @@ use goblin::{
|
||||
elf32::{header, reloc::Rel, section_header::SectionHeader, sym::Sym},
|
||||
};
|
||||
use strum::IntoEnumIterator;
|
||||
use userlib_sys::{EntryFn, SyscallTable};
|
||||
|
||||
const ELF32_HDR_SIZE: usize = 52;
|
||||
|
||||
@@ -70,7 +70,7 @@ pub async unsafe fn load_binary(name: &ShortFileName) -> Option<(EntryFn, Bump)>
|
||||
}
|
||||
}
|
||||
|
||||
patch_abi(&elf_header, base.as_mut_ptr(), min_vaddr, &mut file).unwrap();
|
||||
patch_syscalls(&elf_header, base.as_mut_ptr(), min_vaddr, &mut file).unwrap();
|
||||
|
||||
// entry pointer is base_ptr + (entry - min_vaddr)
|
||||
let entry_ptr: EntryFn = unsafe {
|
||||
@@ -150,7 +150,7 @@ fn apply_relocations(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn patch_abi(
|
||||
fn patch_syscalls(
|
||||
elf_header: &Header,
|
||||
base: *mut u8,
|
||||
min_vaddr: u32,
|
||||
@@ -188,27 +188,27 @@ fn patch_abi(
|
||||
}
|
||||
|
||||
let symbol_name = core::str::from_utf8(&name).unwrap();
|
||||
if symbol_name == "CALL_ABI_TABLE" {
|
||||
if symbol_name == stringify!(SYS_CALL_TABLE) {
|
||||
let table_base =
|
||||
unsafe { base.add((sym.st_value as usize) - min_vaddr as usize) }
|
||||
as *mut usize;
|
||||
|
||||
for (idx, call) in CallTable::iter().enumerate() {
|
||||
for (idx, call) in SyscallTable::iter().enumerate() {
|
||||
let ptr = match call {
|
||||
CallTable::Alloc => abi::alloc as usize,
|
||||
CallTable::Dealloc => abi::dealloc as usize,
|
||||
CallTable::PrintString => abi::print as usize,
|
||||
CallTable::SleepMs => abi::sleep as usize,
|
||||
CallTable::GetMs => abi::get_ms as usize,
|
||||
CallTable::DrawIter => abi::draw_iter as usize,
|
||||
CallTable::GetKey => abi::get_key as usize,
|
||||
CallTable::GenRand => abi::gen_rand as usize,
|
||||
CallTable::ListDir => abi::list_dir as usize,
|
||||
CallTable::ReadFile => abi::read_file as usize,
|
||||
CallTable::WriteFile => abi::write_file as usize,
|
||||
CallTable::FileLen => abi::file_len as usize,
|
||||
CallTable::AudioBufferReady => abi::audio_buffer_ready as usize,
|
||||
CallTable::SendAudioBuffer => abi::send_audio_buffer as usize,
|
||||
SyscallTable::Alloc => syscalls::alloc as usize,
|
||||
SyscallTable::Dealloc => syscalls::dealloc as usize,
|
||||
SyscallTable::PrintString => syscalls::print as usize,
|
||||
SyscallTable::SleepMs => syscalls::sleep as usize,
|
||||
SyscallTable::GetMs => syscalls::get_ms as usize,
|
||||
SyscallTable::DrawIter => syscalls::draw_iter as usize,
|
||||
SyscallTable::GetKey => syscalls::get_key as usize,
|
||||
SyscallTable::GenRand => syscalls::gen_rand as usize,
|
||||
SyscallTable::ListDir => syscalls::list_dir as usize,
|
||||
SyscallTable::ReadFile => syscalls::read_file as usize,
|
||||
SyscallTable::WriteFile => syscalls::write_file as usize,
|
||||
SyscallTable::FileLen => syscalls::file_len as usize,
|
||||
SyscallTable::AudioBufferReady => syscalls::audio_buffer_ready as usize,
|
||||
SyscallTable::SendAudioBuffer => syscalls::send_audio_buffer as usize,
|
||||
};
|
||||
unsafe {
|
||||
table_base.add(idx as usize).write(ptr);
|
||||
|
||||
@@ -22,7 +22,7 @@ impl Region {
|
||||
|
||||
fn contains(&self, address: usize) -> bool {
|
||||
let start = self.start.load(Ordering::Relaxed);
|
||||
let end = self.start.load(Ordering::Relaxed);
|
||||
let end = start + self.size.load(Ordering::Relaxed);
|
||||
(start..start + end).contains(&address)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
mod abi;
|
||||
mod audio;
|
||||
mod display;
|
||||
mod elf;
|
||||
@@ -16,6 +15,7 @@ mod framebuffer;
|
||||
mod peripherals;
|
||||
mod scsi;
|
||||
mod storage;
|
||||
mod syscalls;
|
||||
mod ui;
|
||||
mod usb;
|
||||
mod utils;
|
||||
@@ -31,18 +31,14 @@ mod psram;
|
||||
use crate::{heap::HEAP, heap::init_qmi_psram_heap, psram::init_psram, psram::init_psram_qmi};
|
||||
|
||||
use crate::{
|
||||
abi::{KEY_CACHE, MS_SINCE_LAUNCH},
|
||||
audio::audio_handler,
|
||||
display::{FRAMEBUFFER, display_handler, init_display},
|
||||
peripherals::{
|
||||
conf_peripherals,
|
||||
keyboard::{KeyState, read_keyboard_fifo},
|
||||
},
|
||||
peripherals::{conf_peripherals, keyboard::read_keyboard_fifo},
|
||||
scsi::MSC_SHUTDOWN,
|
||||
storage::{SDCARD, SdCard},
|
||||
syscalls::{KEY_CACHE, MS_SINCE_LAUNCH},
|
||||
ui::{SELECTIONS, clear_selection, ui_handler},
|
||||
};
|
||||
use abi_sys::EntryFn;
|
||||
use bumpalo::Bump;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use embassy_executor::{Executor, Spawner};
|
||||
@@ -76,6 +72,7 @@ use embedded_hal_bus::spi::ExclusiveDevice;
|
||||
use embedded_sdmmc::SdCard as SdmmcSdCard;
|
||||
use static_cell::StaticCell;
|
||||
use talc::*;
|
||||
use userlib_sys::EntryFn;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
embassy_rp::bind_interrupts!(struct Irqs {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::peripherals::PERIPHERAL_BUS;
|
||||
pub use abi_sys::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
|
||||
pub use userlib_sys::keyboard::{KeyCode, KeyEvent, KeyState, Modifiers};
|
||||
|
||||
const REG_ID_KEY: u8 = 0x04;
|
||||
const REG_ID_FIF: u8 = 0x09;
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
use abi_sys::{
|
||||
AUDIO_BUFFER_SAMPLES, AllocAbi, AudioBufferReady, CLayout, CPixel, DeallocAbi, DrawIterAbi,
|
||||
FileLen, GenRand, GetMsAbi, ListDir, PrintAbi, ReadFile, RngRequest, SendAudioBuffer,
|
||||
SleepMsAbi, WriteFile, keyboard::*,
|
||||
};
|
||||
use alloc::{string::ToString, vec::Vec};
|
||||
use core::{ffi::c_char, ptr, sync::atomic::Ordering};
|
||||
use embassy_rp::clocks::{RoscRng, clk_sys_freq};
|
||||
@@ -10,6 +5,11 @@ use embassy_time::Instant;
|
||||
use embedded_graphics::draw_target::DrawTarget;
|
||||
use embedded_sdmmc::LfnBuffer;
|
||||
use heapless::spsc::Queue;
|
||||
use userlib_sys::{
|
||||
AUDIO_BUFFER_SAMPLES, Alloc, AudioBufferReady, CLayout, CPixel, Dealloc, DrawIter, FileLen,
|
||||
GenRand, GetMs, ListDir, Print, ReadFile, RngRequest, SendAudioBuffer, SleepMs, WriteFile,
|
||||
keyboard::*,
|
||||
};
|
||||
|
||||
#[cfg(feature = "psram")]
|
||||
use crate::heap::HEAP;
|
||||
@@ -24,7 +24,7 @@ use crate::{
|
||||
storage::{Dir, File, SDCARD},
|
||||
};
|
||||
|
||||
const _: AllocAbi = alloc;
|
||||
const _: Alloc = alloc;
|
||||
pub extern "C" fn alloc(layout: CLayout) -> *mut u8 {
|
||||
// SAFETY: caller guarantees layout is valid
|
||||
unsafe {
|
||||
@@ -40,7 +40,7 @@ pub extern "C" fn alloc(layout: CLayout) -> *mut u8 {
|
||||
}
|
||||
}
|
||||
|
||||
const _: DeallocAbi = dealloc;
|
||||
const _: Dealloc = dealloc;
|
||||
pub extern "C" fn dealloc(ptr: *mut u8, layout: CLayout) {
|
||||
// SAFETY: caller guarantees ptr and layout are valid
|
||||
#[cfg(feature = "psram")]
|
||||
@@ -54,7 +54,7 @@ pub extern "C" fn dealloc(ptr: *mut u8, layout: CLayout) {
|
||||
}
|
||||
}
|
||||
|
||||
const _: PrintAbi = print;
|
||||
const _: Print = print;
|
||||
pub extern "C" fn print(ptr: *const u8, len: usize) {
|
||||
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
|
||||
let slice = unsafe { core::slice::from_raw_parts(ptr, len) };
|
||||
@@ -68,7 +68,7 @@ pub extern "C" fn print(ptr: *const u8, len: usize) {
|
||||
}
|
||||
}
|
||||
|
||||
const _: SleepMsAbi = sleep;
|
||||
const _: SleepMs = sleep;
|
||||
pub extern "C" fn sleep(ms: u64) {
|
||||
let cycles_per_ms = clk_sys_freq() / 1000;
|
||||
let total_cycles = ms * cycles_per_ms as u64;
|
||||
@@ -80,14 +80,14 @@ pub extern "C" fn sleep(ms: u64) {
|
||||
|
||||
pub static mut MS_SINCE_LAUNCH: Option<Instant> = None;
|
||||
|
||||
const _: GetMsAbi = get_ms;
|
||||
const _: GetMs = get_ms;
|
||||
pub extern "C" fn get_ms() -> u64 {
|
||||
Instant::now()
|
||||
.duration_since(unsafe { MS_SINCE_LAUNCH.unwrap() })
|
||||
.as_millis()
|
||||
}
|
||||
|
||||
const _: DrawIterAbi = draw_iter;
|
||||
const _: DrawIter = draw_iter;
|
||||
pub extern "C" fn draw_iter(cpixels: *const CPixel, len: usize) {
|
||||
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
|
||||
let cpixels = unsafe { core::slice::from_raw_parts(cpixels, len) };
|
||||
@@ -101,7 +101,7 @@ pub extern "C" fn draw_iter(cpixels: *const CPixel, len: usize) {
|
||||
|
||||
pub static mut KEY_CACHE: Queue<KeyEvent, 32> = Queue::new();
|
||||
|
||||
const _: GetKeyAbi = get_key;
|
||||
const _: GetKey = get_key;
|
||||
pub extern "C" fn get_key() -> KeyEventC {
|
||||
if let Some(event) = unsafe { KEY_CACHE.dequeue() } {
|
||||
event.into()
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
BINARY_CH, display::FRAMEBUFFER, elf::load_binary, framebuffer::FB_PAUSED,
|
||||
peripherals::keyboard, storage::FileName,
|
||||
};
|
||||
use abi_sys::keyboard::{KeyCode, KeyState};
|
||||
use userlib_sys::keyboard::{KeyCode, KeyState};
|
||||
use alloc::{str::FromStr, string::String, vec::Vec};
|
||||
use core::sync::atomic::Ordering;
|
||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
|
||||
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../abi" }
|
||||
userlib = { path = "../userlib" }
|
||||
embedded-graphics = "0.8.1"
|
||||
embedded-layout = "0.4.2"
|
||||
embedded-text = "0.7.3"
|
||||
|
||||
@@ -2,25 +2,25 @@
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use abi::{
|
||||
display::Display,
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use embedded_graphics::{
|
||||
Drawable,
|
||||
mono_font::{MonoTextStyle, ascii::FONT_10X20},
|
||||
mono_font::{ascii::FONT_10X20, MonoTextStyle},
|
||||
pixelcolor::Rgb565,
|
||||
prelude::{Dimensions, DrawTarget, Point, Primitive, RgbColor},
|
||||
primitives::{PrimitiveStyle, Rectangle},
|
||||
text::{Alignment, Text, renderer::TextRenderer},
|
||||
text::{renderer::TextRenderer, Alignment, Text},
|
||||
Drawable,
|
||||
};
|
||||
use embedded_layout::{
|
||||
align::{horizontal, vertical},
|
||||
layout::linear::{FixedMargin, LinearLayout},
|
||||
prelude::*,
|
||||
};
|
||||
use userlib::{
|
||||
display::Display,
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SelectionUiError<DisplayError> {
|
||||
@@ -144,5 +144,11 @@ pub fn draw_text_center<'a, S>(
|
||||
where
|
||||
S: TextRenderer<Color = <Display as DrawTarget>::Color>,
|
||||
{
|
||||
Text::with_alignment(text, Point::zero(), style, Alignment::Center).draw(display)
|
||||
Text::with_alignment(
|
||||
text,
|
||||
display.bounding_box().center(),
|
||||
style,
|
||||
Alignment::Center,
|
||||
)
|
||||
.draw(display)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
userlib = { path = "../../userlib" }
|
||||
embedded-graphics = "0.8.1"
|
||||
embedded-layout = "0.4.2"
|
||||
@@ -2,12 +2,6 @@
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
display::Display,
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println,
|
||||
};
|
||||
use alloc::{format, string::String, vec, vec::Vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{
|
||||
@@ -25,6 +19,12 @@ use embedded_layout::{
|
||||
layout::linear::LinearLayout,
|
||||
prelude::Chain,
|
||||
};
|
||||
use userlib::{
|
||||
display::Display,
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
@@ -4,6 +4,6 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
userlib = { path = "../../userlib" }
|
||||
embedded-graphics = "0.8.1"
|
||||
tinybmp = "0.6.0"
|
||||
@@ -3,13 +3,6 @@
|
||||
#![allow(static_mut_refs)]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
fs::{Entries, list_dir, read_file},
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println,
|
||||
};
|
||||
use alloc::{format, vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{
|
||||
@@ -17,6 +10,13 @@ use embedded_graphics::{
|
||||
pixelcolor::Rgb565, prelude::*, text::Text,
|
||||
};
|
||||
use tinybmp::Bmp;
|
||||
use userlib::{
|
||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
fs::{Entries, list_dir, read_file},
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
userlib = { path = "../../userlib" }
|
||||
selection_ui = { path = "../../selection_ui" }
|
||||
embedded-graphics = "0.8.1"
|
||||
tinygif = { git = "https://github.com/LegitCamper/tinygif" }
|
||||
@@ -2,24 +2,24 @@
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
fs::{Entries, file_len, list_dir, read_file},
|
||||
get_key, get_ms,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println, sleep,
|
||||
};
|
||||
use alloc::{format, vec, vec::Vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{
|
||||
image::ImageDrawable,
|
||||
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
||||
mono_font::{ascii::FONT_6X10, MonoTextStyle},
|
||||
pixelcolor::Rgb565,
|
||||
prelude::{Point, RgbColor},
|
||||
transform::Transform,
|
||||
};
|
||||
use selection_ui::{SelectionUi, SelectionUiError, draw_text_center};
|
||||
use selection_ui::{draw_text_center, SelectionUi, SelectionUiError};
|
||||
use tinygif::Gif;
|
||||
use userlib::{
|
||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
fs::{file_len, list_dir, read_file, Entries},
|
||||
get_key, get_ms,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println, sleep,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
userlib = { path = "../../userlib" }
|
||||
embedded-graphics = "0.8.1"
|
||||
embedded-snake = { git = "https://github.com/LegitCamper/embedded-snake-rs" }
|
||||
rand = { version = "0.9.0", default-features = false }
|
||||
@@ -2,16 +2,16 @@
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
|
||||
use embedded_snake::{Direction, SnakeGame};
|
||||
use userlib::{
|
||||
Rng,
|
||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println, sleep,
|
||||
};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
|
||||
use embedded_snake::{Direction, SnakeGame};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
userlib = { path = "../../userlib" }
|
||||
selection_ui = { path = "../../selection_ui" }
|
||||
embedded-graphics = "0.8.1"
|
||||
rand = { version = "0.9.0", default-features = false }
|
||||
@@ -2,24 +2,24 @@
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
audio::{AUDIO_BUFFER_LEN, audio_buffer_ready, send_audio_buffer},
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_audio::{wav::Wav, AudioFile, PlatformFile, PlatformFileError};
|
||||
use embedded_graphics::{
|
||||
mono_font::{ascii::FONT_6X10, MonoTextStyle},
|
||||
pixelcolor::Rgb565,
|
||||
prelude::RgbColor,
|
||||
};
|
||||
use selection_ui::{draw_text_center, SelectionUi, SelectionUiError};
|
||||
use userlib::{
|
||||
audio::{audio_buffer_ready, send_audio_buffer, AUDIO_BUFFER_LEN},
|
||||
display::Display,
|
||||
format,
|
||||
fs::{Entries, file_len, list_dir, read_file},
|
||||
fs::{file_len, list_dir, read_file, Entries},
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
println,
|
||||
};
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_audio::{AudioFile, PlatformFile, PlatformFileError, wav::Wav};
|
||||
use embedded_graphics::{
|
||||
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
||||
pixelcolor::Rgb565,
|
||||
prelude::RgbColor,
|
||||
};
|
||||
use selection_ui::{SelectionUi, SelectionUiError, draw_text_center};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
@@ -52,7 +52,7 @@ pub fn main() {
|
||||
SelectionUiError::SelectionListEmpty => {
|
||||
draw_text_center(
|
||||
&mut display,
|
||||
"No Wavs were found in /gifs",
|
||||
"No Wavs were found in /music",
|
||||
MonoTextStyle::new(&FONT_6X10, Rgb565::RED),
|
||||
)
|
||||
.expect("Display Error");
|
||||
@@ -64,6 +64,13 @@ pub fn main() {
|
||||
|
||||
assert!(selection.is_some());
|
||||
|
||||
draw_text_center(
|
||||
&mut display,
|
||||
&format!("Now playing {}", wavs[selection.unwrap()]),
|
||||
MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE),
|
||||
)
|
||||
.expect("Display Error");
|
||||
|
||||
let file_name = format!("/music/{}", wavs[selection.unwrap()]);
|
||||
let file = File::new(String::from(file_name));
|
||||
let mut wav = Wav::new(file).unwrap();
|
||||
@@ -1,10 +1,10 @@
|
||||
[package]
|
||||
name = "abi"
|
||||
name = "userlib"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi_sys = { path = "../abi_sys" }
|
||||
userlib_sys = { path = "../userlib_sys" }
|
||||
embedded-graphics = "0.8.1"
|
||||
once_cell = { version = "1", default-features = false }
|
||||
rand_core = "0.9.3"
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use abi_sys::{RngRequest, keyboard::KeyEvent};
|
||||
pub use abi_sys::{keyboard, print};
|
||||
pub use alloc::format;
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use rand_core::RngCore;
|
||||
use userlib_sys::{RngRequest, keyboard::KeyEvent};
|
||||
pub use userlib_sys::{keyboard, print};
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOC: Alloc = Alloc;
|
||||
@@ -16,11 +16,11 @@ struct Alloc;
|
||||
|
||||
unsafe impl GlobalAlloc for Alloc {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
abi_sys::alloc(layout.into())
|
||||
userlib_sys::alloc(layout.into())
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
abi_sys::dealloc(ptr, layout.into());
|
||||
userlib_sys::dealloc(ptr, layout.into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,21 +33,20 @@ macro_rules! println {
|
||||
}
|
||||
|
||||
pub fn sleep(ms: u64) {
|
||||
abi_sys::sleep(ms);
|
||||
userlib_sys::sleep(ms);
|
||||
}
|
||||
|
||||
pub fn get_ms() -> u64 {
|
||||
abi_sys::get_ms()
|
||||
userlib_sys::get_ms()
|
||||
}
|
||||
|
||||
pub fn get_key() -> KeyEvent {
|
||||
abi_sys::keyboard::get_key().into()
|
||||
userlib_sys::keyboard::get_key().into()
|
||||
}
|
||||
|
||||
pub mod display {
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use abi_sys::CPixel;
|
||||
use embedded_graphics::{
|
||||
Pixel,
|
||||
geometry::{Dimensions, Point},
|
||||
@@ -55,6 +54,7 @@ pub mod display {
|
||||
prelude::{DrawTarget, Size},
|
||||
primitives::Rectangle,
|
||||
};
|
||||
use userlib_sys::CPixel;
|
||||
|
||||
pub const SCREEN_WIDTH: usize = 320;
|
||||
pub const SCREEN_HEIGHT: usize = 320;
|
||||
@@ -110,13 +110,13 @@ pub mod display {
|
||||
count += 1;
|
||||
|
||||
if count == BUF_SIZE - 1 {
|
||||
abi_sys::draw_iter(unsafe { BUF.as_ptr() }, count);
|
||||
userlib_sys::draw_iter(unsafe { BUF.as_ptr() }, count);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
abi_sys::draw_iter(unsafe { BUF.as_ptr() }, count);
|
||||
userlib_sys::draw_iter(unsafe { BUF.as_ptr() }, count);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -125,7 +125,7 @@ pub mod display {
|
||||
}
|
||||
|
||||
fn gen_rand(req: &mut RngRequest) {
|
||||
abi_sys::gen_rand(req);
|
||||
userlib_sys::gen_rand(req);
|
||||
}
|
||||
|
||||
pub struct Rng;
|
||||
@@ -162,7 +162,7 @@ pub mod fs {
|
||||
use core::fmt::Display;
|
||||
|
||||
pub fn read_file(file: &str, start_from: usize, buf: &mut [u8]) -> usize {
|
||||
abi_sys::read_file(
|
||||
userlib_sys::read_file(
|
||||
file.as_ptr(),
|
||||
file.len(),
|
||||
start_from,
|
||||
@@ -172,7 +172,7 @@ pub mod fs {
|
||||
}
|
||||
|
||||
pub fn write_file(file: &str, start_from: usize, buf: &[u8]) {
|
||||
abi_sys::write_file(
|
||||
userlib_sys::write_file(
|
||||
file.as_ptr(),
|
||||
file.len(),
|
||||
start_from,
|
||||
@@ -254,7 +254,7 @@ pub mod fs {
|
||||
}
|
||||
|
||||
pub fn list_dir(path: &str, entries: &mut Entries) -> usize {
|
||||
abi_sys::list_dir(
|
||||
userlib_sys::list_dir(
|
||||
path.as_ptr(),
|
||||
path.len(),
|
||||
entries.as_ptrs().as_mut_ptr(),
|
||||
@@ -264,14 +264,14 @@ pub mod fs {
|
||||
}
|
||||
|
||||
pub fn file_len(str: &str) -> usize {
|
||||
abi_sys::file_len(str.as_ptr(), str.len())
|
||||
userlib_sys::file_len(str.as_ptr(), str.len())
|
||||
}
|
||||
}
|
||||
|
||||
pub mod audio {
|
||||
pub use abi_sys::{AUDIO_BUFFER_LEN, AUDIO_BUFFER_SAMPLES, audio_buffer_ready};
|
||||
pub use userlib_sys::{AUDIO_BUFFER_LEN, AUDIO_BUFFER_SAMPLES, audio_buffer_ready};
|
||||
|
||||
pub fn send_audio_buffer(buf: &[u8]) {
|
||||
abi_sys::send_audio_buffer(buf.as_ptr(), buf.len())
|
||||
userlib_sys::send_audio_buffer(buf.as_ptr(), buf.len())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "abi_sys"
|
||||
name = "userlib_sys"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
@@ -12,12 +12,12 @@ use strum::{EnumCount, EnumIter};
|
||||
|
||||
pub type EntryFn = fn();
|
||||
|
||||
pub const ABI_CALL_TABLE_COUNT: usize = 14;
|
||||
const _: () = assert!(ABI_CALL_TABLE_COUNT == CallTable::COUNT);
|
||||
pub const SYS_CALL_TABLE_COUNT: usize = 14;
|
||||
const _: () = assert!(SYS_CALL_TABLE_COUNT == SyscallTable::COUNT);
|
||||
|
||||
#[derive(Clone, Copy, EnumIter, EnumCount)]
|
||||
#[repr(u8)]
|
||||
pub enum CallTable {
|
||||
pub enum SyscallTable {
|
||||
Alloc = 0,
|
||||
Dealloc = 1,
|
||||
PrintString = 2,
|
||||
@@ -36,7 +36,7 @@ pub enum CallTable {
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
#[unsafe(link_section = ".syscall_table")]
|
||||
pub static mut CALL_ABI_TABLE: [usize; ABI_CALL_TABLE_COUNT] = [0; ABI_CALL_TABLE_COUNT];
|
||||
pub static mut SYS_CALL_TABLE: [usize; SYS_CALL_TABLE_COUNT] = [0; SYS_CALL_TABLE_COUNT];
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[repr(C)]
|
||||
@@ -62,46 +62,46 @@ impl From<Layout> for CLayout {
|
||||
}
|
||||
}
|
||||
|
||||
pub type AllocAbi = extern "C" fn(layout: CLayout) -> *mut u8;
|
||||
pub type Alloc = extern "C" fn(layout: CLayout) -> *mut u8;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn alloc(layout: CLayout) -> *mut u8 {
|
||||
let f: AllocAbi = unsafe { core::mem::transmute(CALL_ABI_TABLE[CallTable::Alloc as usize]) };
|
||||
let f: Alloc = unsafe { core::mem::transmute(SYS_CALL_TABLE[SyscallTable::Alloc as usize]) };
|
||||
f(layout)
|
||||
}
|
||||
|
||||
pub type DeallocAbi = extern "C" fn(ptr: *mut u8, layout: CLayout);
|
||||
pub type Dealloc = extern "C" fn(ptr: *mut u8, layout: CLayout);
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn dealloc(ptr: *mut u8, layout: CLayout) {
|
||||
let f: DeallocAbi =
|
||||
unsafe { core::mem::transmute(CALL_ABI_TABLE[CallTable::Dealloc as usize]) };
|
||||
let f: Dealloc =
|
||||
unsafe { core::mem::transmute(SYS_CALL_TABLE[SyscallTable::Dealloc as usize]) };
|
||||
f(ptr, layout)
|
||||
}
|
||||
|
||||
pub type PrintAbi = extern "C" fn(ptr: *const u8, len: usize);
|
||||
pub type Print = extern "C" fn(ptr: *const u8, len: usize);
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn print(ptr: *const u8, len: usize) {
|
||||
let f: PrintAbi =
|
||||
unsafe { core::mem::transmute(CALL_ABI_TABLE[CallTable::PrintString as usize]) };
|
||||
let f: Print =
|
||||
unsafe { core::mem::transmute(SYS_CALL_TABLE[SyscallTable::PrintString as usize]) };
|
||||
f(ptr, len);
|
||||
}
|
||||
|
||||
pub type SleepMsAbi = extern "C" fn(ms: u64);
|
||||
pub type SleepMs = extern "C" fn(ms: u64);
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn sleep(ms: u64) {
|
||||
let f: SleepMsAbi =
|
||||
unsafe { core::mem::transmute(CALL_ABI_TABLE[CallTable::SleepMs as usize]) };
|
||||
let f: SleepMs =
|
||||
unsafe { core::mem::transmute(SYS_CALL_TABLE[SyscallTable::SleepMs as usize]) };
|
||||
f(ms);
|
||||
}
|
||||
|
||||
pub type GetMsAbi = extern "C" fn() -> u64;
|
||||
pub type GetMs = extern "C" fn() -> u64;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn get_ms() -> u64 {
|
||||
let f: GetMsAbi = unsafe { core::mem::transmute(CALL_ABI_TABLE[CallTable::GetMs as usize]) };
|
||||
let f: GetMs = unsafe { core::mem::transmute(SYS_CALL_TABLE[SyscallTable::GetMs as usize]) };
|
||||
f()
|
||||
}
|
||||
|
||||
@@ -139,17 +139,17 @@ impl Into<Pixel<Rgb565>> for CPixel {
|
||||
}
|
||||
}
|
||||
|
||||
pub type DrawIterAbi = extern "C" fn(ptr: *const CPixel, len: usize);
|
||||
pub type DrawIter = extern "C" fn(ptr: *const CPixel, len: usize);
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn draw_iter(ptr: *const CPixel, len: usize) {
|
||||
let f: DrawIterAbi =
|
||||
unsafe { core::mem::transmute(CALL_ABI_TABLE[CallTable::DrawIter as usize]) };
|
||||
let f: DrawIter =
|
||||
unsafe { core::mem::transmute(SYS_CALL_TABLE[SyscallTable::DrawIter as usize]) };
|
||||
f(ptr, len);
|
||||
}
|
||||
|
||||
pub mod keyboard {
|
||||
use crate::{CALL_ABI_TABLE, CallTable};
|
||||
use crate::{SYS_CALL_TABLE, SyscallTable};
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
|
||||
@@ -367,12 +367,12 @@ pub mod keyboard {
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetKeyAbi = extern "C" fn() -> KeyEventC;
|
||||
pub type GetKey = extern "C" fn() -> KeyEventC;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn get_key() -> KeyEventC {
|
||||
let f: GetKeyAbi =
|
||||
unsafe { core::mem::transmute(CALL_ABI_TABLE[CallTable::GetKey as usize]) };
|
||||
let f: GetKey =
|
||||
unsafe { core::mem::transmute(SYS_CALL_TABLE[SyscallTable::GetKey as usize]) };
|
||||
f()
|
||||
}
|
||||
}
|
||||
@@ -389,7 +389,7 @@ pub type GenRand = extern "C" fn(req: &mut RngRequest);
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn gen_rand(req: &mut RngRequest) {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallTable::GenRand as usize];
|
||||
let ptr = SYS_CALL_TABLE[SyscallTable::GenRand as usize];
|
||||
let f: GenRand = core::mem::transmute(ptr);
|
||||
f(req)
|
||||
}
|
||||
@@ -412,7 +412,7 @@ pub extern "C" fn list_dir(
|
||||
max_entry_str_len: usize,
|
||||
) -> usize {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallTable::ListDir as usize];
|
||||
let ptr = SYS_CALL_TABLE[SyscallTable::ListDir as usize];
|
||||
let f: ListDir = core::mem::transmute(ptr);
|
||||
f(str, len, entries, entry_count, max_entry_str_len)
|
||||
}
|
||||
@@ -435,7 +435,7 @@ pub extern "C" fn read_file(
|
||||
buf_len: usize,
|
||||
) -> usize {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallTable::ReadFile as usize];
|
||||
let ptr = SYS_CALL_TABLE[SyscallTable::ReadFile as usize];
|
||||
let f: ReadFile = core::mem::transmute(ptr);
|
||||
f(str, len, read_from, buf, buf_len)
|
||||
}
|
||||
@@ -453,7 +453,7 @@ pub extern "C" fn write_file(
|
||||
buf_len: usize,
|
||||
) {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallTable::WriteFile as usize];
|
||||
let ptr = SYS_CALL_TABLE[SyscallTable::WriteFile as usize];
|
||||
let f: WriteFile = core::mem::transmute(ptr);
|
||||
f(str, len, write_from, buf, buf_len)
|
||||
}
|
||||
@@ -464,7 +464,7 @@ pub type FileLen = extern "C" fn(str: *const u8, len: usize) -> usize;
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn file_len(str: *const u8, len: usize) -> usize {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallTable::FileLen as usize];
|
||||
let ptr = SYS_CALL_TABLE[SyscallTable::FileLen as usize];
|
||||
let f: FileLen = core::mem::transmute(ptr);
|
||||
f(str, len)
|
||||
}
|
||||
@@ -475,7 +475,7 @@ pub type AudioBufferReady = extern "C" fn() -> bool;
|
||||
#[allow(unused)]
|
||||
pub fn audio_buffer_ready() -> bool {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallTable::AudioBufferReady as usize];
|
||||
let ptr = SYS_CALL_TABLE[SyscallTable::AudioBufferReady as usize];
|
||||
let f: AudioBufferReady = core::mem::transmute(ptr);
|
||||
f()
|
||||
}
|
||||
@@ -489,7 +489,7 @@ pub type SendAudioBuffer = extern "C" fn(ptr: *const u8, len: usize);
|
||||
#[allow(unused)]
|
||||
pub fn send_audio_buffer(buf: *const u8, len: usize) {
|
||||
unsafe {
|
||||
let ptr = CALL_ABI_TABLE[CallTable::SendAudioBuffer as usize];
|
||||
let ptr = SYS_CALL_TABLE[SyscallTable::SendAudioBuffer as usize];
|
||||
let f: SendAudioBuffer = core::mem::transmute(ptr);
|
||||
f(buf, len)
|
||||
}
|
||||
Reference in New Issue
Block a user