diff --git a/Cargo.lock b/Cargo.lock index d12ac45..3edd39d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,12 +161,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" -[[package]] -name = "bit_field" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" - [[package]] name = "bitfield" version = "0.13.2" @@ -972,18 +966,6 @@ dependencies = [ "nb 1.1.0", ] -[[package]] -name = "embedded-iconoir" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52b9899b636b56d4e66834f7a90766d0bc6600c0f067d91ed0711b11fa3f5c8" -dependencies = [ - "bit_field", - "embedded-graphics", - "paste", - "static_assertions", -] - [[package]] name = "embedded-io" version = "0.6.1" @@ -1144,12 +1126,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "funty" version = "2.0.0" @@ -1348,7 +1324,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ "hash32", - "serde", "stable_deref_trait", ] @@ -1502,7 +1477,6 @@ dependencies = [ "embedded-text", "goblin", "heapless", - "kolibri-embedded-gui", "num_enum 0.7.4", "once_cell", "panic-probe", @@ -1516,18 +1490,6 @@ dependencies = [ "trouble-host", ] -[[package]] -name = "kolibri-embedded-gui" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "011f8f415e8c2f03e4ad752afcf1bb156a18926250401b1fe29d8feda644c140" -dependencies = [ - "embedded-graphics", - "embedded-iconoir", - "foldhash", - "heapless", -] - [[package]] name = "lalrpop" version = "0.19.12" @@ -2352,12 +2314,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "static_cell" version = "2.1.1" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index eb55f78..943a1b0 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -11,11 +11,13 @@ doctest = false bench = false [features] -default = ["rp235x", "defmt", "fps"] -pimoroni2w = ["rp235x"] -rp2040 = ["embassy-rp/rp2040"] +default = ["rp235x", "defmt"] +pimoroni2w = ["rp235x", "psram"] +# rp2040 = ["embassy-rp/rp2040"] # unsupported, ram too small for fb rp235x = ["embassy-rp/rp235xb"] trouble = ["dep:bt-hci", "dep:cyw43", "dep:cyw43-pio", "dep:trouble-host"] +psram = ["dep:embedded-alloc"] +fps = [] defmt = [ "dep:defmt", "panic-probe/print-defmt", @@ -30,7 +32,6 @@ defmt = [ # "cyw43/defmt", # "cyw43-pio/defmt", ] -fps = [] [dependencies] embassy-executor = { version = "0.9", features = [ @@ -79,7 +80,6 @@ st7365p-lcd = { git = "https://github.com/legitcamper/st7365p-lcd-rs", rev = "a7 embedded-graphics = { version = "0.8.1" } embedded-text = "0.7.2" embedded-layout = "0.4.2" -kolibri-embedded-gui = "0.1.0" strum = { version = "0.27.2", default-features = false } rand = { version = "0.9.0", default-features = false } @@ -91,7 +91,9 @@ spin = "0.10.0" num_enum = { version = "0.7.4", default-features = false } goblin = { version = "0.10.1", default-features = false, features = ["elf32"] } talc = "4.4.3" -embedded-alloc = { version = "0.6.0", features = ["allocator_api"] } +embedded-alloc = { version = "0.6.0", features = [ + "allocator_api", +], optional = true } bumpalo = "3.19.0" abi_sys = { path = "../abi_sys" } diff --git a/kernel/src/abi.rs b/kernel/src/abi.rs index 4515ac0..4d8c52d 100644 --- a/kernel/src/abi.rs +++ b/kernel/src/abi.rs @@ -10,6 +10,9 @@ use embedded_graphics::draw_target::DrawTarget; use embedded_sdmmc::LfnBuffer; use heapless::spsc::Queue; +#[cfg(feature = "psram")] +use crate::heap::HEAP; + use crate::{ display::FRAMEBUFFER, framebuffer::FB_PAUSED, @@ -20,10 +23,14 @@ const _: AllocAbi = alloc; pub extern "C" fn alloc(layout: CLayout) -> *mut u8 { // SAFETY: caller guarantees layout is valid unsafe { - if cfg!(feature = "pimoroni2w") { - crate::heap::HEAP.alloc(layout.into()) - } else { - alloc::alloc::alloc(layout.into()) + #[cfg(feature = "psram")] + { + return HEAP.alloc(layout.into()); + } + + #[cfg(not(feature = "psram"))] + { + return alloc::alloc::alloc(layout.into()); } } } @@ -31,12 +38,14 @@ pub extern "C" fn alloc(layout: CLayout) -> *mut u8 { const _: DeallocAbi = dealloc; pub extern "C" fn dealloc(ptr: *mut u8, layout: CLayout) { // SAFETY: caller guarantees ptr and layout are valid - unsafe { - if cfg!(feature = "pimoroni2w") { - crate::heap::HEAP.dealloc(ptr, layout.into()) - } else { - alloc::alloc::dealloc(ptr, layout.into()) - } + #[cfg(feature = "psram")] + { + unsafe { HEAP.dealloc(ptr, layout.into()) } + } + + #[cfg(not(feature = "psram"))] + { + unsafe { alloc::alloc::dealloc(ptr, layout.into()) } } } diff --git a/kernel/src/display.rs b/kernel/src/display.rs index 062c854..2fdd9f2 100644 --- a/kernel/src/display.rs +++ b/kernel/src/display.rs @@ -15,6 +15,9 @@ use embedded_graphics::{ use embedded_hal_bus::spi::ExclusiveDevice; use st7365p_lcd::ST7365P; +#[cfg(feature = "psram")] +use crate::heap::HEAP; + #[cfg(feature = "fps")] pub use framebuffer::fps::{FPS_CANVAS, FPS_COUNTER}; @@ -32,18 +35,21 @@ pub static mut FRAMEBUFFER: Option = None; fn init_fb() { unsafe { - FRAMEBUFFER = Some(if cfg!(not(feature = "pimoroni2w")) { - static mut BUF: [u16; framebuffer::SIZE] = [0; framebuffer::SIZE]; - AtomicFrameBuffer::new(&mut BUF) - } else { - let slab = crate::heap::HEAP.alloc(Layout::array::(framebuffer::SIZE).unwrap()) - as *mut u16; + #[cfg(feature = "psram")] + { + let slab = HEAP.alloc(Layout::array::(framebuffer::SIZE).unwrap()) as *mut u16; let buf = core::slice::from_raw_parts_mut(slab, framebuffer::SIZE); let mut fb = AtomicFrameBuffer::new(buf); fb.clear(Rgb565::BLACK).unwrap(); - fb - }); + FRAMEBUFFER = Some(fb); + } + + #[cfg(not(feature = "psram"))] + { + static mut BUF: [u16; framebuffer::SIZE] = [0; framebuffer::SIZE]; + FRAMEBUFFER = Some(AtomicFrameBuffer::new(&mut BUF)); + } } } diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 1c438ff..9d864fc 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -12,29 +12,30 @@ mod abi; mod display; mod elf; mod framebuffer; -#[allow(unused)] -mod heap; mod peripherals; -#[allow(unused)] -mod psram; mod scsi; mod storage; mod ui; mod usb; mod utils; -#[cfg(feature = "pimoroni2w")] -use crate::{heap::init_qmi_psram_heap, psram::init_psram_qmi}; +#[cfg(feature = "psram")] +#[allow(unused)] +mod heap; +#[cfg(feature = "psram")] +#[allow(unused)] +mod psram; + +#[cfg(feature = "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}, display::{FRAMEBUFFER, display_handler, init_display}, - heap::HEAP, peripherals::{ conf_peripherals, keyboard::{KeyState, read_keyboard_fifo}, }, - psram::init_psram, scsi::MSC_SHUTDOWN, storage::{SDCARD, SdCard}, ui::{SELECTIONS, clear_selection, ui_handler}, @@ -270,22 +271,22 @@ async fn setup_display(display: Display, spawner: Spawner) { // 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; +// 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; - #[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")] +#[cfg(feature = "psram")] async fn setup_qmi_psram() { Timer::after_millis(250).await; let psram_qmi_size = init_psram_qmi(&embassy_rp::pac::QMI, &embassy_rp::pac::XIP_CTRL); @@ -322,7 +323,7 @@ async fn kernel_task( watchdog: Peri<'static, WATCHDOG>, display: Display, sd: Sd, - psram: Psram, + _psram: Psram, mcu: Mcu, usb: Peri<'static, USB>, ) { @@ -337,7 +338,7 @@ async fn kernel_task( Timer::after_millis(100).await; // setup_psram(psram).await; - #[cfg(feature = "pimoroni2w")] + #[cfg(feature = "psram")] setup_qmi_psram().await; Timer::after_millis(100).await;