mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 15:55:25 +00:00
Compare commits
1 Commits
macros
...
double-buf
| Author | SHA1 | Date | |
|---|---|---|---|
| d7fb4b4058 |
136
Cargo.lock
generated
136
Cargo.lock
generated
@@ -19,7 +19,6 @@ dependencies = [
|
||||
"abi_sys",
|
||||
"embedded-graphics",
|
||||
"embedded-sdmmc",
|
||||
"main_proc_macro",
|
||||
"once_cell",
|
||||
"rand_core 0.9.3",
|
||||
]
|
||||
@@ -125,7 +124,7 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
"rustc_version 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -226,7 +225,7 @@ dependencies = [
|
||||
"embedded-io",
|
||||
"embedded-io-async",
|
||||
"futures-intrusive",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
@@ -351,7 +350,7 @@ checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -410,7 +409,7 @@ dependencies = [
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-io-async",
|
||||
"futures",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
"num_enum 0.5.11",
|
||||
]
|
||||
|
||||
@@ -448,7 +447,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim 0.11.1",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -459,7 +458,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -497,7 +496,7 @@ dependencies = [
|
||||
"proc-macro-error2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -646,7 +645,7 @@ dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -789,7 +788,7 @@ dependencies = [
|
||||
"embedded-io-async",
|
||||
"futures-sink",
|
||||
"futures-util",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -804,7 +803,7 @@ dependencies = [
|
||||
"embedded-io-async",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -857,7 +856,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80e2ee86063bd028a420a5fb5898c18c87a8898026da1d4c852af2c443d0a454"
|
||||
dependencies = [
|
||||
"embassy-executor-timer-queue",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -871,7 +870,7 @@ dependencies = [
|
||||
"embassy-sync 0.7.2",
|
||||
"embassy-usb-driver 0.2.0",
|
||||
"embedded-io-async",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
"ssmarshal",
|
||||
"usbd-hid",
|
||||
]
|
||||
@@ -1020,7 +1019,7 @@ checksum = "4f6e621fe4c7e05b695274b722dc0a60bacd1c8696b58191baa0154713d52400"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1033,7 +1032,7 @@ dependencies = [
|
||||
"defmt 0.3.100",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-io",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1213,7 +1212,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1313,6 +1312,15 @@ dependencies = [
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
@@ -1343,13 +1351,26 @@ version = "0.15.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.7.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f"
|
||||
dependencies = [
|
||||
"atomic-polyfill",
|
||||
"hash32 0.2.1",
|
||||
"rustc_version 0.4.1",
|
||||
"spin 0.9.8",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||
dependencies = [
|
||||
"hash32",
|
||||
"hash32 0.3.1",
|
||||
"serde",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
@@ -1503,14 +1524,14 @@ dependencies = [
|
||||
"embedded-sdmmc",
|
||||
"embedded-text",
|
||||
"goblin",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
"kolibri-embedded-gui",
|
||||
"num_enum 0.7.4",
|
||||
"once_cell",
|
||||
"panic-probe",
|
||||
"portable-atomic",
|
||||
"rand",
|
||||
"spin",
|
||||
"spin 0.10.0",
|
||||
"st7365p-lcd",
|
||||
"static_cell",
|
||||
"strum",
|
||||
@@ -1527,7 +1548,7 @@ dependencies = [
|
||||
"embedded-graphics",
|
||||
"embedded-iconoir",
|
||||
"foldhash",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1649,14 +1670,6 @@ version = "0.4.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
|
||||
[[package]]
|
||||
name = "main_proc_macro"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.5"
|
||||
@@ -1737,7 +1750,7 @@ checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1929,7 +1942,7 @@ dependencies = [
|
||||
"proc-macro-error2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1996,7 +2009,7 @@ dependencies = [
|
||||
"proc-macro-error-attr2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2010,9 +2023,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.41"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -2151,7 +2164,16 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver",
|
||||
"semver 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
|
||||
dependencies = [
|
||||
"semver 1.0.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2209,6 +2231,12 @@ dependencies = [
|
||||
"semver-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
@@ -2242,7 +2270,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2314,6 +2342,15 @@ dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.10.0"
|
||||
@@ -2342,7 +2379,7 @@ dependencies = [
|
||||
"embedded-graphics-core",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
@@ -2409,7 +2446,7 @@ dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2438,9 +2475,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.108"
|
||||
version = "2.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2537,7 +2574,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2548,7 +2585,7 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2572,10 +2609,11 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tinygif"
|
||||
version = "0.0.4"
|
||||
source = "git+https://github.com/LegitCamper/tinygif#083c0efbdbeb21835de30425e234247340f6e370"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09f1406b710986188de8d393c810213d4bbf940e327d90d52cff9930d007a248"
|
||||
dependencies = [
|
||||
"embedded-graphics",
|
||||
"heapless",
|
||||
"heapless 0.7.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2599,7 +2637,7 @@ dependencies = [
|
||||
"embassy-time 0.4.0",
|
||||
"embedded-io",
|
||||
"futures",
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
"rand_core 0.6.4",
|
||||
"static_cell",
|
||||
"trouble-host-macros",
|
||||
@@ -2616,7 +2654,7 @@ dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
@@ -2650,7 +2688,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6"
|
||||
dependencies = [
|
||||
"heapless",
|
||||
"heapless 0.8.0",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
@@ -2775,7 +2813,7 @@ dependencies = [
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@@ -2797,7 +2835,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
@@ -2947,5 +2985,5 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.108",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
@@ -8,7 +8,6 @@ members = [
|
||||
"user-apps/snake",
|
||||
"user-apps/gallery",
|
||||
"user-apps/gif",
|
||||
"main_proc_macro",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
||||
@@ -4,9 +4,8 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
abi_sys = { path = "../abi_sys" }
|
||||
main_proc_macro = { path = "../main_proc_macro" }
|
||||
embedded-sdmmc = { version = "0.9", default-features = false }
|
||||
embedded-sdmmc = { version = "0.9.0", default-features = false }
|
||||
embedded-graphics = "0.8.1"
|
||||
abi_sys = { path = "../abi_sys" }
|
||||
once_cell = { version = "1", default-features = false }
|
||||
rand_core = "0.9.3"
|
||||
|
||||
@@ -5,20 +5,10 @@ extern crate alloc;
|
||||
|
||||
pub use abi_sys::{self, keyboard};
|
||||
use abi_sys::{RngRequest, alloc, dealloc, keyboard::KeyEvent};
|
||||
use alloc::format;
|
||||
use core::{
|
||||
alloc::{GlobalAlloc, Layout},
|
||||
panic::PanicInfo,
|
||||
};
|
||||
pub use main_proc_macro::main;
|
||||
pub use alloc::format;
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use rand_core::RngCore;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOC: Alloc = Alloc;
|
||||
|
||||
@@ -37,7 +27,7 @@ unsafe impl GlobalAlloc for Alloc {
|
||||
#[macro_export]
|
||||
macro_rules! print {
|
||||
($($arg:tt)*) => {{
|
||||
let s = format!($($arg)*);
|
||||
let s = $crate::format!($($arg)*);
|
||||
$crate::abi_sys::print(s.as_ptr(), s.len());
|
||||
}};
|
||||
}
|
||||
@@ -56,6 +46,7 @@ pub fn get_key() -> KeyEvent {
|
||||
|
||||
pub mod display {
|
||||
use abi_sys::CPixel;
|
||||
// use alloc::{vec, vec::Vec};
|
||||
use embedded_graphics::{
|
||||
Pixel,
|
||||
geometry::{Dimensions, Point},
|
||||
@@ -63,6 +54,7 @@ pub mod display {
|
||||
prelude::{DrawTarget, Size},
|
||||
primitives::Rectangle,
|
||||
};
|
||||
// use once_cell::unsync::Lazy;
|
||||
|
||||
pub const SCREEN_WIDTH: usize = 320;
|
||||
pub const SCREEN_HEIGHT: usize = 320;
|
||||
|
||||
@@ -46,7 +46,7 @@ pub struct CLayout {
|
||||
#[cfg(feature = "alloc")]
|
||||
impl Into<Layout> for CLayout {
|
||||
fn into(self) -> Layout {
|
||||
unsafe { Layout::from_size_align_unchecked(self.size, self.alignment) }
|
||||
Layout::from_size_align(self.size, self.alignment).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ doctest = false
|
||||
bench = false
|
||||
|
||||
[features]
|
||||
default = ["rp235x", "defmt"]
|
||||
default = ["rp235x", "defmt", "pimoroni2w"]
|
||||
pimoroni2w = ["rp235x"]
|
||||
rp2040 = ["embassy-rp/rp2040"]
|
||||
rp235x = ["embassy-rp/rp235xb"]
|
||||
|
||||
@@ -3,7 +3,7 @@ use abi_sys::{
|
||||
PrintAbi, ReadFile, RngRequest, SleepMsAbi, keyboard::*,
|
||||
};
|
||||
use alloc::{string::ToString, vec::Vec};
|
||||
use core::{alloc::GlobalAlloc, sync::atomic::Ordering};
|
||||
use core::{alloc::GlobalAlloc, ops::DerefMut, sync::atomic::Ordering};
|
||||
use embassy_rp::clocks::{RoscRng, clk_sys_freq};
|
||||
use embassy_time::Instant;
|
||||
use embedded_graphics::draw_target::DrawTarget;
|
||||
@@ -11,8 +11,7 @@ use embedded_sdmmc::{DirEntry, LfnBuffer};
|
||||
use heapless::spsc::Queue;
|
||||
|
||||
use crate::{
|
||||
display::FRAMEBUFFER,
|
||||
framebuffer::FB_PAUSED,
|
||||
display::{FRAMEBUFFER, FRAMEBUFFER2, WRITE_FRAMEBUFFER2},
|
||||
storage::{Dir, File, SDCARD},
|
||||
};
|
||||
|
||||
@@ -80,9 +79,19 @@ pub extern "C" fn draw_iter(cpixels: *const CPixel, len: usize) {
|
||||
|
||||
let iter = cpixels.iter().copied().map(|c: CPixel| c.into());
|
||||
|
||||
FB_PAUSED.store(true, Ordering::Release);
|
||||
unsafe { FRAMEBUFFER.as_mut().unwrap().draw_iter(iter).unwrap() }
|
||||
FB_PAUSED.store(false, Ordering::Release);
|
||||
let fb = if cfg!(feature = "pimoroni2w") {
|
||||
if WRITE_FRAMEBUFFER2.load(Ordering::Acquire) {
|
||||
unsafe { FRAMEBUFFER2.deref_mut() }
|
||||
} else {
|
||||
unsafe { &mut FRAMEBUFFER }
|
||||
}
|
||||
} else {
|
||||
unsafe { &mut FRAMEBUFFER }
|
||||
};
|
||||
|
||||
fb.draw_iter(iter).unwrap();
|
||||
|
||||
WRITE_FRAMEBUFFER2.fetch_not(Ordering::AcqRel);
|
||||
}
|
||||
|
||||
pub static mut KEY_CACHE: Queue<KeyEvent, 32> = Queue::new();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use crate::framebuffer::{self, AtomicFrameBuffer, FB_PAUSED};
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use crate::framebuffer::{self, AtomicFrameBuffer};
|
||||
use alloc::vec;
|
||||
use core::alloc::GlobalAlloc;
|
||||
use core::alloc::Layout;
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
use core::sync::atomic::AtomicBool;
|
||||
use core::sync::atomic::Ordering;
|
||||
use embassy_rp::{
|
||||
Peri,
|
||||
@@ -8,11 +12,8 @@ use embassy_rp::{
|
||||
spi::{Async, Spi},
|
||||
};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embedded_graphics::{
|
||||
pixelcolor::Rgb565,
|
||||
prelude::{DrawTarget, RgbColor},
|
||||
};
|
||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||
use once_cell::unsync::Lazy;
|
||||
use st7365p_lcd::ST7365P;
|
||||
|
||||
type DISPLAY = ST7365P<
|
||||
@@ -25,24 +26,33 @@ type DISPLAY = ST7365P<
|
||||
pub const SCREEN_WIDTH: usize = 320;
|
||||
pub const SCREEN_HEIGHT: usize = 320;
|
||||
|
||||
pub static mut FRAMEBUFFER: Option<AtomicFrameBuffer> = None;
|
||||
// used to switch which fb is being used for read/write
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
pub static WRITE_FRAMEBUFFER2: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
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::<u16>(framebuffer::SIZE).unwrap())
|
||||
as *mut u16;
|
||||
let buf = core::slice::from_raw_parts_mut(slab, framebuffer::SIZE);
|
||||
// the default screen buffer - the only one on boards without extra ram or psram
|
||||
pub static mut FRAMEBUFFER: Lazy<AtomicFrameBuffer> = Lazy::new(|| {
|
||||
static mut BUF: [u16; framebuffer::SIZE] = [0; framebuffer::SIZE];
|
||||
AtomicFrameBuffer::new(unsafe { &mut BUF })
|
||||
});
|
||||
|
||||
let mut fb = AtomicFrameBuffer::new(buf);
|
||||
fb.clear(Rgb565::BLACK).unwrap();
|
||||
fb
|
||||
});
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
pub static mut FRAMEBUFFER2: Lazy<AtomicFrameBuffer> = Lazy::new(|| {
|
||||
use embedded_graphics::{
|
||||
pixelcolor::Rgb565,
|
||||
prelude::{DrawTarget, RgbColor},
|
||||
};
|
||||
|
||||
let buf = unsafe {
|
||||
let slab =
|
||||
crate::heap::HEAP.alloc(Layout::array::<u16>(framebuffer::SIZE).unwrap()) as *mut u16;
|
||||
core::slice::from_raw_parts_mut(slab, framebuffer::SIZE)
|
||||
};
|
||||
let mut fb = AtomicFrameBuffer::new(buf);
|
||||
fb.set_all_tiles(false);
|
||||
fb.clear(Rgb565::BLACK).unwrap();
|
||||
fb
|
||||
});
|
||||
|
||||
pub async fn init_display(
|
||||
spi: Spi<'static, SPI1, Async>,
|
||||
@@ -50,8 +60,6 @@ pub async fn init_display(
|
||||
data: Peri<'static, PIN_14>,
|
||||
reset: Peri<'static, PIN_15>,
|
||||
) -> DISPLAY {
|
||||
init_fb();
|
||||
|
||||
let spi_device = ExclusiveDevice::new(spi, Output::new(cs, Level::Low), Delay).unwrap();
|
||||
let mut display = ST7365P::new(
|
||||
spi_device,
|
||||
@@ -63,14 +71,7 @@ pub async fn init_display(
|
||||
);
|
||||
display.init().await.unwrap();
|
||||
display.set_custom_orientation(0x40).await.unwrap();
|
||||
unsafe {
|
||||
FRAMEBUFFER
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.draw(&mut display)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
unsafe { FRAMEBUFFER.draw(&mut display).await.unwrap() }
|
||||
display.set_on().await.unwrap();
|
||||
|
||||
display
|
||||
@@ -79,18 +80,18 @@ pub async fn init_display(
|
||||
#[embassy_executor::task]
|
||||
pub async fn display_handler(mut display: DISPLAY) {
|
||||
loop {
|
||||
if !FB_PAUSED.load(Ordering::Acquire) {
|
||||
unsafe {
|
||||
FRAMEBUFFER
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.partial_draw(&mut display)
|
||||
.await
|
||||
.unwrap()
|
||||
};
|
||||
}
|
||||
let fb = if cfg!(feature = "pimoroni2w") {
|
||||
if WRITE_FRAMEBUFFER2.load(Ordering::Acquire) {
|
||||
unsafe { &mut FRAMEBUFFER }
|
||||
} else {
|
||||
unsafe { &mut FRAMEBUFFER2 }
|
||||
}
|
||||
} else {
|
||||
unsafe { &mut FRAMEBUFFER }
|
||||
};
|
||||
fb.safe_draw(&mut display).await.unwrap();
|
||||
|
||||
// small yield to allow other tasks to run
|
||||
Timer::after_nanos(500).await;
|
||||
Timer::after_nanos(100).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::display::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use embassy_sync::lazy_lock::LazyLock;
|
||||
use embedded_graphics::{
|
||||
draw_target::DrawTarget,
|
||||
pixelcolor::{
|
||||
@@ -13,32 +14,37 @@ use embedded_hal_2::digital::OutputPin;
|
||||
use embedded_hal_async::{delay::DelayNs, spi::SpiDevice};
|
||||
use st7365p_lcd::ST7365P;
|
||||
|
||||
const TILE_SIZE: usize = 16; // 16x16 tile
|
||||
const TILE_COUNT: usize = (SCREEN_WIDTH / TILE_SIZE) * (SCREEN_HEIGHT / TILE_SIZE); // 400 tiles
|
||||
const NUM_TILE_ROWS: usize = SCREEN_WIDTH / TILE_SIZE;
|
||||
const NUM_TILE_COLS: usize = SCREEN_WIDTH / TILE_SIZE;
|
||||
pub const TILE_SIZE: usize = 16; // 16x16 tile
|
||||
pub const TILE_COUNT: usize = (SCREEN_WIDTH / TILE_SIZE) * (SCREEN_HEIGHT / TILE_SIZE); // 400 tiles
|
||||
|
||||
const MAX_BATCH_TILES: usize = (SCREEN_WIDTH / TILE_SIZE) * 2;
|
||||
type BatchTileBuf = [u16; MAX_BATCH_TILES * TILE_SIZE * TILE_SIZE];
|
||||
// Group of tiles for batching
|
||||
pub const MAX_META_TILES: usize = (SCREEN_WIDTH / TILE_SIZE) * 2; // max number of meta tiles in buffer
|
||||
type MetaTileVec = heapless::Vec<Rectangle, { TILE_COUNT / MAX_META_TILES }>;
|
||||
|
||||
pub const SIZE: usize = SCREEN_HEIGHT * SCREEN_WIDTH;
|
||||
|
||||
pub static FB_PAUSED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct AtomicFrameBuffer<'a> {
|
||||
fb: &'a mut [u16],
|
||||
dirty_tiles: [AtomicBool; TILE_COUNT],
|
||||
batch_tile_buf: BatchTileBuf,
|
||||
dirty_tiles: heapless::Vec<AtomicBool, TILE_COUNT>,
|
||||
}
|
||||
|
||||
impl<'a> AtomicFrameBuffer<'a> {
|
||||
pub fn new(buffer: &'a mut [u16]) -> Self {
|
||||
assert!(buffer.len() == SIZE);
|
||||
let mut dirty_tiles = heapless::Vec::new();
|
||||
for _ in 0..TILE_COUNT {
|
||||
dirty_tiles.push(AtomicBool::new(true)).unwrap()
|
||||
}
|
||||
Self {
|
||||
fb: buffer,
|
||||
dirty_tiles: core::array::from_fn(|_| AtomicBool::new(true)),
|
||||
batch_tile_buf: [0; MAX_BATCH_TILES * TILE_SIZE * TILE_SIZE],
|
||||
dirty_tiles,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_all_tiles(&mut self, set: bool) {
|
||||
for t in self.dirty_tiles.iter_mut() {
|
||||
t.store(set, Ordering::Release);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,17 +99,59 @@ impl<'a> AtomicFrameBuffer<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Checks if a full draw would be faster than individual tile batches
|
||||
fn should_full_draw(&self) -> bool {
|
||||
let threshold_pixels = SIZE * 80 / 100;
|
||||
let mut dirty_pixels = 0;
|
||||
// walk the dirty tiles and mark groups of tiles(meta-tiles) for batched updates
|
||||
fn find_meta_tiles(&mut self, tiles_x: usize, tiles_y: usize) -> MetaTileVec {
|
||||
let mut meta_tiles: MetaTileVec = heapless::Vec::new();
|
||||
|
||||
self.dirty_tiles.iter().any(|tile| {
|
||||
if tile.load(Ordering::Acquire) {
|
||||
dirty_pixels += TILE_SIZE * TILE_SIZE;
|
||||
for ty in 0..tiles_y {
|
||||
let mut tx = 0;
|
||||
while tx < tiles_x {
|
||||
let idx = ty * tiles_x + tx;
|
||||
if !self.dirty_tiles[idx].load(Ordering::Acquire) {
|
||||
tx += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Start meta-tile at this tile
|
||||
let mut width_tiles = 1;
|
||||
let height_tiles = 1;
|
||||
|
||||
// Grow horizontally, but keep under MAX_TILES_PER_METATILE
|
||||
while tx + width_tiles < tiles_x
|
||||
&& unsafe {
|
||||
self.dirty_tiles[ty * tiles_x + tx + width_tiles].load(Ordering::Acquire)
|
||||
}
|
||||
&& (width_tiles + height_tiles) <= MAX_META_TILES
|
||||
{
|
||||
width_tiles += 1;
|
||||
}
|
||||
|
||||
// TODO: for simplicity, skipped vertical growth
|
||||
|
||||
for x_off in 0..width_tiles {
|
||||
unsafe {
|
||||
self.dirty_tiles[ty * tiles_x + tx + x_off].store(false, Ordering::Release);
|
||||
};
|
||||
}
|
||||
|
||||
// new meta-tile pos
|
||||
let rect = Rectangle::new(
|
||||
Point::new((tx * TILE_SIZE) as i32, (ty * TILE_SIZE) as i32),
|
||||
Size::new(
|
||||
(width_tiles * TILE_SIZE) as u32,
|
||||
(height_tiles * TILE_SIZE) as u32,
|
||||
),
|
||||
);
|
||||
|
||||
if meta_tiles.push(rect).is_err() {
|
||||
return meta_tiles;
|
||||
};
|
||||
|
||||
tx += width_tiles;
|
||||
}
|
||||
dirty_pixels >= threshold_pixels
|
||||
})
|
||||
}
|
||||
|
||||
meta_tiles
|
||||
}
|
||||
|
||||
/// Sends the entire framebuffer to the display
|
||||
@@ -126,36 +174,68 @@ impl<'a> AtomicFrameBuffer<'a> {
|
||||
)
|
||||
.await?;
|
||||
|
||||
for tile in self.dirty_tiles.iter() {
|
||||
tile.store(false, Ordering::Release);
|
||||
unsafe {
|
||||
for tile in self.dirty_tiles.iter() {
|
||||
tile.store(false, Ordering::Release);
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn safe_draw<SPI, DC, RST, DELAY>(
|
||||
&mut self,
|
||||
display: &mut ST7365P<SPI, DC, RST, DELAY>,
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
SPI: SpiDevice,
|
||||
DC: OutputPin,
|
||||
RST: OutputPin,
|
||||
DELAY: DelayNs,
|
||||
{
|
||||
let tiles_x = SCREEN_WIDTH / TILE_SIZE;
|
||||
let _tiles_y = SCREEN_HEIGHT / TILE_SIZE;
|
||||
|
||||
let mut pixel_buffer: heapless::Vec<u16, { TILE_SIZE * TILE_SIZE }> = heapless::Vec::new();
|
||||
|
||||
for tile_idx in 0..TILE_COUNT {
|
||||
if self.dirty_tiles[tile_idx].swap(false, Ordering::AcqRel) {
|
||||
let tx = tile_idx % tiles_x;
|
||||
let ty = tile_idx / tiles_x;
|
||||
|
||||
let x_start = tx * TILE_SIZE;
|
||||
let y_start = ty * TILE_SIZE;
|
||||
|
||||
let x_end = (x_start + TILE_SIZE).min(SCREEN_WIDTH);
|
||||
let y_end = (y_start + TILE_SIZE).min(SCREEN_HEIGHT);
|
||||
|
||||
pixel_buffer.clear();
|
||||
|
||||
for y in y_start..y_end {
|
||||
let start = y * SCREEN_WIDTH + x_start;
|
||||
let end = y * SCREEN_WIDTH + x_end;
|
||||
pixel_buffer
|
||||
.extend_from_slice(&self.fb[start..end])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
display
|
||||
.set_pixels_buffered(
|
||||
x_start as u16,
|
||||
y_start as u16,
|
||||
(x_end - 1) as u16,
|
||||
(y_end - 1) as u16,
|
||||
&pixel_buffer,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// copy N tiles horizontally to the right into batch tile buf
|
||||
fn append_tiles_to_batch(
|
||||
&mut self,
|
||||
tile_x: u16,
|
||||
tile_y: u16,
|
||||
total_tiles: u16, // number of tiles being written to buf
|
||||
) {
|
||||
debug_assert!(total_tiles as usize <= NUM_TILE_COLS);
|
||||
for batch_row_num in 0..TILE_SIZE {
|
||||
let batch_row_offset = batch_row_num * total_tiles as usize * TILE_SIZE;
|
||||
let batch_row = &mut self.batch_tile_buf
|
||||
[batch_row_offset..batch_row_offset + (total_tiles as usize * TILE_SIZE)];
|
||||
|
||||
let fb_row_offset = (tile_y as usize * TILE_SIZE + batch_row_num) * SCREEN_WIDTH
|
||||
+ tile_x as usize * TILE_SIZE;
|
||||
let fb_row =
|
||||
&self.fb[fb_row_offset..fb_row_offset + (total_tiles as usize * TILE_SIZE)];
|
||||
|
||||
batch_row.copy_from_slice(fb_row);
|
||||
}
|
||||
}
|
||||
|
||||
// Pushes tiles to the display in batches to avoid full frame pushes (unless needed)
|
||||
/// Sends only dirty tiles (16x16px) in batches to the display
|
||||
pub async fn partial_draw<SPI, DC, RST, DELAY>(
|
||||
&mut self,
|
||||
display: &mut ST7365P<SPI, DC, RST, DELAY>,
|
||||
@@ -166,53 +246,57 @@ impl<'a> AtomicFrameBuffer<'a> {
|
||||
RST: OutputPin,
|
||||
DELAY: DelayNs,
|
||||
{
|
||||
if self.should_full_draw() {
|
||||
return self.draw(display).await;
|
||||
}
|
||||
if unsafe { self.dirty_tiles.iter().any(|p| p.load(Ordering::Acquire)) } {
|
||||
let tiles_x = (SCREEN_WIDTH + TILE_SIZE - 1) / TILE_SIZE;
|
||||
let tiles_y = (SCREEN_HEIGHT + TILE_SIZE - 1) / TILE_SIZE;
|
||||
|
||||
for tile_row in 0..NUM_TILE_ROWS {
|
||||
let row_start_idx = tile_row * NUM_TILE_COLS;
|
||||
let mut col = 0;
|
||||
let meta_tiles = self.find_meta_tiles(tiles_x, tiles_y);
|
||||
|
||||
while col < NUM_TILE_COLS {
|
||||
// Check for dirty tile
|
||||
if self.dirty_tiles[row_start_idx + col].swap(false, Ordering::Acquire) {
|
||||
let run_start = col;
|
||||
let mut run_len = 1;
|
||||
// buffer for copying meta tiles before sending to display
|
||||
let mut pixel_buffer: heapless::Vec<u16, { MAX_META_TILES * TILE_SIZE * TILE_SIZE }> =
|
||||
heapless::Vec::new();
|
||||
|
||||
// Extend run while contiguous dirty tiles and within MAX_BATCH_TILES
|
||||
while col + 1 < NUM_TILE_COLS
|
||||
&& self.dirty_tiles[row_start_idx + col + 1].load(Ordering::Acquire)
|
||||
&& run_len < MAX_BATCH_TILES
|
||||
{
|
||||
col += 1;
|
||||
run_len += 1;
|
||||
}
|
||||
for rect in meta_tiles {
|
||||
let rect_width = rect.size.width as usize;
|
||||
let rect_height = rect.size.height as usize;
|
||||
let rect_x = rect.top_left.x as usize;
|
||||
let rect_y = rect.top_left.y as usize;
|
||||
|
||||
// Copy the whole horizontal run into the batch buffer in one call
|
||||
let tile_x = run_start;
|
||||
let tile_y = tile_row;
|
||||
self.append_tiles_to_batch(tile_x as u16, tile_y as u16, run_len as u16);
|
||||
pixel_buffer.clear();
|
||||
|
||||
// Compute coordinates for display write
|
||||
let start_x = tile_x * TILE_SIZE;
|
||||
let end_x = start_x + run_len * TILE_SIZE - 1;
|
||||
let start_y = tile_y * TILE_SIZE;
|
||||
let end_y = start_y + TILE_SIZE - 1;
|
||||
for row in 0..rect_height {
|
||||
let y = rect_y + row;
|
||||
let start = y * SCREEN_WIDTH + rect_x;
|
||||
let end = start + rect_width;
|
||||
|
||||
// Send batch to display
|
||||
display
|
||||
.set_pixels_buffered(
|
||||
start_x as u16,
|
||||
start_y as u16,
|
||||
end_x as u16,
|
||||
end_y as u16,
|
||||
&self.batch_tile_buf[..run_len * TILE_SIZE * TILE_SIZE],
|
||||
)
|
||||
.await?;
|
||||
// Safe: we guarantee buffer will not exceed MAX_META_TILE_PIXELS
|
||||
pixel_buffer
|
||||
.extend_from_slice(&self.fb[start..end])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
col += 1;
|
||||
display
|
||||
.set_pixels_buffered(
|
||||
rect_x as u16,
|
||||
rect_y as u16,
|
||||
(rect_x + rect_width - 1) as u16,
|
||||
(rect_y + rect_height - 1) as u16,
|
||||
&pixel_buffer,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// walk the meta-tile and set as clean
|
||||
let start_tx = rect_x / TILE_SIZE;
|
||||
let start_ty = rect_y / TILE_SIZE;
|
||||
let end_tx = (rect_x + rect_width - 1) / TILE_SIZE;
|
||||
let end_ty = (rect_y + rect_height - 1) / TILE_SIZE;
|
||||
|
||||
for ty in start_ty..=end_ty {
|
||||
for tx in start_tx..=end_tx {
|
||||
let tile_idx = ty * tiles_x + tx;
|
||||
self.dirty_tiles[tile_idx].store(false, Ordering::Release);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,8 +317,8 @@ impl<'a> DrawTarget for AtomicFrameBuffer<'a> {
|
||||
|
||||
for Pixel(coord, color) in pixels {
|
||||
if coord.x >= 0 && coord.y >= 0 {
|
||||
let x = coord.x;
|
||||
let y = coord.y;
|
||||
let x = coord.x as i32;
|
||||
let y = coord.y as i32;
|
||||
|
||||
if (x as usize) < SCREEN_WIDTH && (y as usize) < SCREEN_HEIGHT {
|
||||
let idx = (y as usize) * SCREEN_WIDTH + (x as usize);
|
||||
|
||||
@@ -12,10 +12,8 @@ mod abi;
|
||||
mod display;
|
||||
mod elf;
|
||||
mod framebuffer;
|
||||
#[allow(unused)]
|
||||
mod heap;
|
||||
mod peripherals;
|
||||
#[allow(unused)]
|
||||
mod psram;
|
||||
mod scsi;
|
||||
mod storage;
|
||||
@@ -82,10 +80,7 @@ static mut CORE1_STACK: Stack<16384> = Stack::new();
|
||||
static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
|
||||
static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
|
||||
|
||||
#[cfg(not(feature = "pimoroni2w"))]
|
||||
static mut ARENA: [u8; 250 * 1024] = [0; 250 * 1024];
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
static mut ARENA: [u8; 400 * 1024] = [0; 400 * 1024];
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> =
|
||||
@@ -95,12 +90,11 @@ static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> =
|
||||
#[embassy_executor::task]
|
||||
async fn watchdog_task(mut watchdog: Watchdog) {
|
||||
if let Some(reason) = watchdog.reset_reason() {
|
||||
let _reason = match reason {
|
||||
let reason = match reason {
|
||||
ResetReason::Forced => "forced",
|
||||
ResetReason::TimedOut => "timed out",
|
||||
};
|
||||
#[cfg(feature = "debug")]
|
||||
defmt::error!("Watchdog reset reason: {}", _reason);
|
||||
defmt::error!("Watchdog reset reason: {}", reason);
|
||||
}
|
||||
|
||||
watchdog.start(Duration::from_secs(3));
|
||||
@@ -200,7 +194,7 @@ async fn userland_task() {
|
||||
{
|
||||
ENABLE_UI.store(true, Ordering::Release);
|
||||
UI_CHANGE.signal(());
|
||||
unsafe { FRAMEBUFFER.as_mut().unwrap().clear(Rgb565::BLACK).unwrap() };
|
||||
unsafe { FRAMEBUFFER.clear(Rgb565::BLACK).unwrap() };
|
||||
|
||||
let mut selections = SELECTIONS.lock().await;
|
||||
selections.set_changed(true);
|
||||
@@ -227,7 +221,6 @@ struct Sd {
|
||||
cs: Peri<'static, PIN_17>,
|
||||
det: Peri<'static, PIN_22>,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
struct Psram {
|
||||
pio: Peri<'static, PIO0>,
|
||||
sclk: Peri<'static, PIN_21>,
|
||||
@@ -253,7 +246,7 @@ async fn setup_mcu(mcu: Mcu) {
|
||||
|
||||
async fn setup_display(display: Display, spawner: Spawner) {
|
||||
let mut config = spi::Config::default();
|
||||
config.frequency = 64_000_000;
|
||||
config.frequency = 16_000_000;
|
||||
let spi = Spi::new(
|
||||
display.spi,
|
||||
display.clk,
|
||||
@@ -286,18 +279,20 @@ async fn setup_psram(psram: Psram) {
|
||||
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
async fn setup_qmi_psram() {
|
||||
let mut tries = 5;
|
||||
Timer::after_millis(250).await;
|
||||
let psram_qmi_size = init_psram_qmi(&embassy_rp::pac::QMI, &embassy_rp::pac::XIP_CTRL);
|
||||
#[cfg(feature = "debug")]
|
||||
defmt::info!("size: {}", psram_qmi_size);
|
||||
Timer::after_millis(100).await;
|
||||
|
||||
if psram_qmi_size > 0 {
|
||||
init_qmi_psram_heap(psram_qmi_size);
|
||||
return;
|
||||
} else {
|
||||
panic!("qmi psram not initialized");
|
||||
while tries > 1 {
|
||||
let psram_qmi_size = init_psram_qmi(&embassy_rp::pac::QMI, &embassy_rp::pac::XIP_CTRL);
|
||||
defmt::info!("size: {}", psram_qmi_size);
|
||||
Timer::after_millis(100).await;
|
||||
if psram_qmi_size > 0 {
|
||||
init_qmi_psram_heap(psram_qmi_size);
|
||||
return;
|
||||
}
|
||||
defmt::info!("failed to init qmi psram... trying again");
|
||||
tries -= 1;
|
||||
}
|
||||
panic!("qmi psram not initialized");
|
||||
}
|
||||
|
||||
async fn setup_sd(sd: Sd) {
|
||||
@@ -321,7 +316,7 @@ async fn kernel_task(
|
||||
watchdog: Peri<'static, WATCHDOG>,
|
||||
display: Display,
|
||||
sd: Sd,
|
||||
_psram: Psram,
|
||||
psram: Psram,
|
||||
mcu: Mcu,
|
||||
usb: Peri<'static, USB>,
|
||||
) {
|
||||
@@ -329,16 +324,11 @@ async fn kernel_task(
|
||||
.spawn(watchdog_task(Watchdog::new(watchdog)))
|
||||
.unwrap();
|
||||
|
||||
setup_mcu(mcu).await;
|
||||
|
||||
defmt::info!("setting up psram");
|
||||
Timer::after_millis(100).await;
|
||||
|
||||
// setup_psram(psram).await;
|
||||
#[cfg(feature = "pimoroni2w")]
|
||||
setup_qmi_psram().await;
|
||||
|
||||
Timer::after_millis(100).await;
|
||||
setup_mcu(mcu).await;
|
||||
setup_display(display, spawner).await;
|
||||
setup_sd(sd).await;
|
||||
|
||||
|
||||
@@ -526,7 +526,6 @@ pub fn init_psram_qmi(
|
||||
let psram_size = detect_psram_qmi(qmi);
|
||||
|
||||
if psram_size == 0 {
|
||||
#[cfg(feature = "debug")]
|
||||
defmt::error!("qmi psram size 0");
|
||||
return 0;
|
||||
}
|
||||
@@ -549,13 +548,13 @@ pub fn init_psram_qmi(
|
||||
let min_deselect: u32 = ((18 * 1_000_000 + (clock_period_fs - 1)) / clock_period_fs
|
||||
- u64::from(divisor + 1) / 2) as u32;
|
||||
|
||||
// #[cfg(feature = "defmt")]
|
||||
// defmt::info!(
|
||||
// "clock_period_fs={} max_select={} min_deselect={}",
|
||||
// clock_period_fs,
|
||||
// max_select,
|
||||
// min_deselect
|
||||
// );
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::info!(
|
||||
"clock_period_fs={} max_select={} min_deselect={}",
|
||||
clock_period_fs,
|
||||
max_select,
|
||||
min_deselect
|
||||
);
|
||||
|
||||
qmi.direct_csr().write(|w| {
|
||||
w.set_clkdiv(10);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
use crate::{
|
||||
BINARY_CH, display::FRAMEBUFFER, elf::load_binary, framebuffer::FB_PAUSED,
|
||||
peripherals::keyboard, storage::FileName,
|
||||
BINARY_CH,
|
||||
display::{FRAMEBUFFER, FRAMEBUFFER2, WRITE_FRAMEBUFFER2},
|
||||
elf::load_binary,
|
||||
peripherals::keyboard,
|
||||
storage::FileName,
|
||||
};
|
||||
use abi_sys::keyboard::{KeyCode, KeyState};
|
||||
use alloc::{str::FromStr, string::String, vec::Vec};
|
||||
use core::sync::atomic::Ordering;
|
||||
use core::{ops::DerefMut, sync::atomic::Ordering};
|
||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
|
||||
use embedded_graphics::{
|
||||
Drawable,
|
||||
@@ -68,7 +71,7 @@ pub async fn clear_selection() {
|
||||
if let Some(area) = sel.last_bounds {
|
||||
Rectangle::new(area.top_left, area.size)
|
||||
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
|
||||
.draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() })
|
||||
.draw(unsafe { &mut *FRAMEBUFFER })
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@@ -78,12 +81,20 @@ async fn draw_selection() {
|
||||
let file_names = &guard.selections.clone();
|
||||
|
||||
let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
||||
let display_area = unsafe { FRAMEBUFFER.as_mut().unwrap().bounding_box() };
|
||||
let display_area = unsafe { FRAMEBUFFER.bounding_box() };
|
||||
|
||||
const NO_BINS: &str = "No Programs found on SD Card. Ensure programs end with '.bin', and are located in the root directory";
|
||||
let no_bins = String::from_str(NO_BINS).unwrap();
|
||||
|
||||
FB_PAUSED.store(true, Ordering::Release); // ensure all elements show up at once
|
||||
let mut fb = if cfg!(feature = "pimoroni2w") {
|
||||
if WRITE_FRAMEBUFFER2.load(Ordering::Acquire) {
|
||||
unsafe { FRAMEBUFFER2.deref_mut() }
|
||||
} else {
|
||||
unsafe { &mut FRAMEBUFFER }
|
||||
}
|
||||
} else {
|
||||
unsafe { &mut FRAMEBUFFER }
|
||||
};
|
||||
|
||||
if file_names.is_empty() {
|
||||
TextBox::new(
|
||||
@@ -94,7 +105,7 @@ async fn draw_selection() {
|
||||
),
|
||||
text_style,
|
||||
)
|
||||
.draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() })
|
||||
.draw(fb.deref_mut())
|
||||
.unwrap();
|
||||
} else {
|
||||
let mut views: alloc::vec::Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new();
|
||||
@@ -119,18 +130,17 @@ async fn draw_selection() {
|
||||
.bounding_box();
|
||||
Rectangle::new(selected_bounds.top_left, selected_bounds.size)
|
||||
.into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1))
|
||||
.draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() })
|
||||
.draw(fb.deref_mut())
|
||||
.unwrap();
|
||||
|
||||
guard.last_bounds = Some(layout.bounds());
|
||||
|
||||
layout
|
||||
.draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() })
|
||||
.unwrap();
|
||||
layout.draw(fb.deref_mut()).unwrap();
|
||||
}
|
||||
|
||||
guard.changed = false;
|
||||
FB_PAUSED.store(false, Ordering::Release); // ensure all elements show up at once
|
||||
|
||||
WRITE_FRAMEBUFFER2.fetch_not(Ordering::AcqRel);
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
[package]
|
||||
name = "main_proc_macro"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
quote = "1.0.41"
|
||||
syn = "2.0.108"
|
||||
@@ -1,21 +0,0 @@
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{ItemFn, parse_macro_input};
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(item as ItemFn);
|
||||
let name = &input.sig.ident;
|
||||
|
||||
// ensure we emit _start in the same module as the fn
|
||||
let expanded = quote! {
|
||||
#input
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn _start() {
|
||||
#name();
|
||||
}
|
||||
};
|
||||
|
||||
expanded.into()
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use abi::{
|
||||
print,
|
||||
};
|
||||
use alloc::{format, string::String, vec, vec::Vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{
|
||||
Drawable,
|
||||
geometry::{Dimensions, Point},
|
||||
@@ -25,6 +26,12 @@ use embedded_layout::{
|
||||
prelude::Chain,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn _start() {
|
||||
main()
|
||||
|
||||
@@ -8,16 +8,27 @@ use abi::{
|
||||
fs::{list_dir, read_file},
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
main, print,
|
||||
print,
|
||||
};
|
||||
use alloc::{format, string::ToString, vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{
|
||||
Drawable, image::Image, mono_font::MonoTextStyle, mono_font::ascii::FONT_6X10,
|
||||
pixelcolor::Rgb565, prelude::*, text::Text,
|
||||
};
|
||||
use tinybmp::Bmp;
|
||||
|
||||
#[main]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
print!("user panic: {} @ {:?}", info.message(), info.location());
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn _start() {
|
||||
main()
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
print!("Starting Gallery app");
|
||||
let mut bmp_buf = vec![0_u8; 100_000];
|
||||
|
||||
@@ -6,4 +6,4 @@ edition = "2024"
|
||||
[dependencies]
|
||||
abi = { path = "../../abi" }
|
||||
embedded-graphics = "0.8.1"
|
||||
tinygif = { git = "https://github.com/LegitCamper/tinygif" }
|
||||
tinygif = "0.0.4"
|
||||
|
||||
@@ -7,15 +7,24 @@ use abi::{
|
||||
fs::{file_len, read_file},
|
||||
get_key, get_ms,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
main, print, sleep,
|
||||
};
|
||||
use alloc::{format, vec};
|
||||
use embedded_graphics::{
|
||||
image::ImageDrawable, pixelcolor::Rgb565, prelude::Point, transform::Transform,
|
||||
print, sleep,
|
||||
};
|
||||
use alloc::vec;
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{image::ImageDrawable, pixelcolor::Rgb565};
|
||||
use tinygif::Gif;
|
||||
|
||||
#[main]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn _start() {
|
||||
main()
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
print!("Starting Gif app");
|
||||
let mut display = Display;
|
||||
@@ -27,27 +36,20 @@ pub fn main() {
|
||||
assert!(read == size);
|
||||
|
||||
let gif = Gif::<Rgb565>::from_slice(&buf).unwrap();
|
||||
let height = gif.height();
|
||||
|
||||
let mut frame_num = 0;
|
||||
loop {
|
||||
for mut frame in gif.frames() {
|
||||
for frame in gif.frames() {
|
||||
let start = get_ms();
|
||||
|
||||
frame
|
||||
.translate_mut(Point::new(0, (320 - height as i32) / 2))
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
frame.draw(&mut display).unwrap();
|
||||
frame_num += 1;
|
||||
|
||||
if frame_num % 5 == 0 {
|
||||
if frame_num % 100 == 0 {
|
||||
let event = get_key();
|
||||
if event.state != KeyState::Idle {
|
||||
match event.key {
|
||||
KeyCode::Esc => {
|
||||
drop(buf);
|
||||
return;
|
||||
}
|
||||
KeyCode::Esc => return,
|
||||
_ => (),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,10 +9,16 @@ use abi::{
|
||||
keyboard::{KeyCode, KeyState},
|
||||
print, sleep,
|
||||
};
|
||||
use alloc::format;
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
|
||||
use embedded_snake::{Direction, SnakeGame};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "Rust" fn _start() {
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user