mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 07:45:28 +00:00
alloc user to access kernel backed heap (psram, if equiped)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use abi_sys::{
|
||||
CPixel, DrawIterAbi, FileLen, GenRand, GetMsAbi, ListDir, LockDisplay, PrintAbi, ReadFile,
|
||||
RngRequest, SleepMsAbi, keyboard::*,
|
||||
AllocAbi, CLayout, CPixel, DeallocAbi, DrawIterAbi, FileLen, GenRand, GetMsAbi, ListDir,
|
||||
LockDisplay, PrintAbi, ReadFile, RngRequest, SleepMsAbi, keyboard::*,
|
||||
};
|
||||
use alloc::{string::ToString, vec::Vec};
|
||||
use core::sync::atomic::Ordering;
|
||||
@@ -15,6 +15,18 @@ use crate::{
|
||||
storage::{Dir, File, SDCARD},
|
||||
};
|
||||
|
||||
const _: AllocAbi = alloc;
|
||||
pub extern "C" fn alloc(layout: CLayout) -> *mut u8 {
|
||||
// SAFETY: caller guarantees layout is valid
|
||||
unsafe { alloc::alloc::alloc(layout.into()) }
|
||||
}
|
||||
|
||||
const _: DeallocAbi = dealloc;
|
||||
pub extern "C" fn dealloc(ptr: *mut u8, layout: CLayout) {
|
||||
// SAFETY: caller guarantees ptr and layout are valid
|
||||
unsafe { alloc::alloc::dealloc(ptr, layout.into()) };
|
||||
}
|
||||
|
||||
const _: PrintAbi = print;
|
||||
pub extern "C" fn print(ptr: *const u8, len: usize) {
|
||||
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
|
||||
|
||||
@@ -21,7 +21,7 @@ type DISPLAY = ST7365P<
|
||||
pub const SCREEN_WIDTH: usize = 320;
|
||||
pub const SCREEN_HEIGHT: usize = 320;
|
||||
|
||||
pub static mut FRAMEBUFFER: AtomicFrameBuffer = AtomicFrameBuffer::new();
|
||||
pub static mut FRAMEBUFFER: AtomicFrameBuffer = AtomicFrameBuffer;
|
||||
pub static FB_PAUSED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub async fn init_display(
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
abi,
|
||||
storage::{File, SDCARD},
|
||||
};
|
||||
use abi_sys::CallAbiTable;
|
||||
use abi_sys::CallTable;
|
||||
use abi_sys::EntryFn;
|
||||
use alloc::{vec, vec::Vec};
|
||||
use bumpalo::Bump;
|
||||
@@ -194,18 +194,20 @@ fn patch_abi(
|
||||
unsafe { base.add((sym.st_value as usize) - min_vaddr as usize) }
|
||||
as *mut usize;
|
||||
|
||||
for (idx, call) in CallAbiTable::iter().enumerate() {
|
||||
for (idx, call) in CallTable::iter().enumerate() {
|
||||
let ptr = match call {
|
||||
CallAbiTable::PrintString => abi::print as usize,
|
||||
CallAbiTable::SleepMs => abi::sleep as usize,
|
||||
CallAbiTable::GetMs => abi::get_ms as usize,
|
||||
CallAbiTable::LockDisplay => abi::lock_display as usize,
|
||||
CallAbiTable::DrawIter => abi::draw_iter as usize,
|
||||
CallAbiTable::GetKey => abi::get_key as usize,
|
||||
CallAbiTable::GenRand => abi::gen_rand as usize,
|
||||
CallAbiTable::ListDir => abi::list_dir as usize,
|
||||
CallAbiTable::ReadFile => abi::read_file as usize,
|
||||
CallAbiTable::FileLen => abi::file_len as usize,
|
||||
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::LockDisplay => abi::lock_display 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::FileLen => abi::file_len as usize,
|
||||
};
|
||||
unsafe {
|
||||
table_base.add(idx as usize).write(ptr);
|
||||
|
||||
@@ -241,19 +241,21 @@ async fn setup_display(display: Display, spawner: Spawner) {
|
||||
spawner.spawn(display_handler(display)).unwrap();
|
||||
}
|
||||
|
||||
// psram is kind of useless on the pico calc
|
||||
// ive opted to use the pimoroni with on onboard xip psram instead
|
||||
async fn setup_psram(psram: Psram) {
|
||||
let psram = init_psram(
|
||||
psram.pio, psram.sclk, psram.mosi, psram.miso, psram.cs, psram.dma1, psram.dma2,
|
||||
)
|
||||
.await;
|
||||
// let psram = init_psram(
|
||||
// psram.pio, psram.sclk, psram.mosi, psram.miso, psram.cs, psram.dma1, psram.dma2,
|
||||
// )
|
||||
// .await;
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::info!("psram size: {}", psram.size);
|
||||
// #[cfg(feature = "defmt")]
|
||||
// defmt::info!("psram size: {}", psram.size);
|
||||
|
||||
if psram.size == 0 {
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::info!("\u{1b}[1mExternal PSRAM was NOT found!\u{1b}[0m");
|
||||
}
|
||||
// if psram.size == 0 {
|
||||
// #[cfg(feature = "defmt")]
|
||||
// defmt::info!("\u{1b}[1mExternal PSRAM was NOT found!\u{1b}[0m");
|
||||
// }
|
||||
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
{
|
||||
@@ -291,6 +293,7 @@ async fn kernel_task(
|
||||
setup_mcu(mcu).await;
|
||||
Timer::after_millis(250).await;
|
||||
setup_display(display, spawner).await;
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
setup_psram(psram).await;
|
||||
setup_sd(sd).await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user