mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-28 16:25:33 +00:00
Compare commits
1 Commits
selection-
...
macros
| Author | SHA1 | Date | |
|---|---|---|---|
| 97639138a1 |
66
Cargo.lock
generated
66
Cargo.lock
generated
@@ -18,6 +18,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"abi_sys",
|
"abi_sys",
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
|
"embedded-sdmmc",
|
||||||
|
"main_proc_macro",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rand_core 0.9.3",
|
"rand_core 0.9.3",
|
||||||
]
|
]
|
||||||
@@ -30,6 +32,7 @@ dependencies = [
|
|||||||
"cbindgen",
|
"cbindgen",
|
||||||
"defmt 0.3.100",
|
"defmt 0.3.100",
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
|
"embedded-sdmmc",
|
||||||
"strum",
|
"strum",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -348,7 +351,7 @@ checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -445,7 +448,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"strsim 0.11.1",
|
"strsim 0.11.1",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -456,7 +459,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core",
|
"darling_core",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -494,7 +497,7 @@ dependencies = [
|
|||||||
"proc-macro-error2",
|
"proc-macro-error2",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -643,7 +646,7 @@ dependencies = [
|
|||||||
"darling",
|
"darling",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1017,7 +1020,7 @@ checksum = "4f6e621fe4c7e05b695274b722dc0a60bacd1c8696b58191baa0154713d52400"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1210,7 +1213,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1287,7 +1290,6 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"abi",
|
"abi",
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
"selection_ui",
|
|
||||||
"tinygif",
|
"tinygif",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1647,6 +1649,14 @@ version = "0.4.27"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "main_proc_macro"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.108",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.7.5"
|
version = "2.7.5"
|
||||||
@@ -1727,7 +1737,7 @@ checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1919,7 +1929,7 @@ dependencies = [
|
|||||||
"proc-macro-error2",
|
"proc-macro-error2",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1986,7 +1996,7 @@ dependencies = [
|
|||||||
"proc-macro-error-attr2",
|
"proc-macro-error-attr2",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2000,9 +2010,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.40"
|
version = "1.0.41"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@@ -2190,16 +2200,6 @@ version = "0.13.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add"
|
checksum = "c1257cd4248b4132760d6524d6dda4e053bc648c9070b960929bf50cfb1e7add"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "selection_ui"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"abi",
|
|
||||||
"embedded-graphics",
|
|
||||||
"embedded-layout",
|
|
||||||
"embedded-text",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@@ -2242,7 +2242,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2409,7 +2409,7 @@ dependencies = [
|
|||||||
"heck 0.5.0",
|
"heck 0.5.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2438,9 +2438,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.104"
|
version = "2.0.108"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -2537,7 +2537,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2548,7 +2548,7 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2616,7 +2616,7 @@ dependencies = [
|
|||||||
"darling",
|
"darling",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2775,7 +2775,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2797,7 +2797,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
@@ -2947,5 +2947,5 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.104",
|
"syn 2.0.108",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ members = [
|
|||||||
"kernel",
|
"kernel",
|
||||||
"abi_sys",
|
"abi_sys",
|
||||||
"abi",
|
"abi",
|
||||||
"selection_ui",
|
|
||||||
"user-apps/calculator",
|
"user-apps/calculator",
|
||||||
"user-apps/snake",
|
"user-apps/snake",
|
||||||
"user-apps/gallery",
|
"user-apps/gallery",
|
||||||
"user-apps/gif",
|
"user-apps/gif",
|
||||||
|
"main_proc_macro",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
@@ -27,4 +27,4 @@ panic = "abort"
|
|||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
lto = true
|
lto = true
|
||||||
opt-level = "s"
|
opt-level = "z"
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
abi_sys = { path = "../abi_sys" }
|
abi_sys = { path = "../abi_sys" }
|
||||||
|
main_proc_macro = { path = "../main_proc_macro" }
|
||||||
|
embedded-sdmmc = { version = "0.9", default-features = false }
|
||||||
embedded-graphics = "0.8.1"
|
embedded-graphics = "0.8.1"
|
||||||
once_cell = { version = "1", default-features = false }
|
once_cell = { version = "1", default-features = false }
|
||||||
rand_core = "0.9.3"
|
rand_core = "0.9.3"
|
||||||
|
|||||||
101
abi/src/lib.rs
101
abi/src/lib.rs
@@ -5,10 +5,20 @@ extern crate alloc;
|
|||||||
|
|
||||||
pub use abi_sys::{self, keyboard};
|
pub use abi_sys::{self, keyboard};
|
||||||
use abi_sys::{RngRequest, alloc, dealloc, keyboard::KeyEvent};
|
use abi_sys::{RngRequest, alloc, dealloc, keyboard::KeyEvent};
|
||||||
pub use alloc::format;
|
use alloc::format;
|
||||||
use core::alloc::{GlobalAlloc, Layout};
|
use core::{
|
||||||
|
alloc::{GlobalAlloc, Layout},
|
||||||
|
panic::PanicInfo,
|
||||||
|
};
|
||||||
|
pub use main_proc_macro::main;
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOC: Alloc = Alloc;
|
static ALLOC: Alloc = Alloc;
|
||||||
|
|
||||||
@@ -27,7 +37,7 @@ unsafe impl GlobalAlloc for Alloc {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! print {
|
macro_rules! print {
|
||||||
($($arg:tt)*) => {{
|
($($arg:tt)*) => {{
|
||||||
let s = $crate::format!($($arg)*);
|
let s = format!($($arg)*);
|
||||||
$crate::abi_sys::print(s.as_ptr(), s.len());
|
$crate::abi_sys::print(s.as_ptr(), s.len());
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
@@ -140,9 +150,7 @@ impl RngCore for Rng {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod fs {
|
pub mod fs {
|
||||||
use core::fmt::Display;
|
use embedded_sdmmc::DirEntry;
|
||||||
|
|
||||||
use alloc::{format, vec::Vec};
|
|
||||||
|
|
||||||
pub fn read_file(file: &str, read_from: usize, buf: &mut [u8]) -> usize {
|
pub fn read_file(file: &str, read_from: usize, buf: &mut [u8]) -> usize {
|
||||||
abi_sys::read_file(
|
abi_sys::read_file(
|
||||||
@@ -154,85 +162,8 @@ pub mod fs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FileName<'a> {
|
pub fn list_dir(path: &str, files: &mut [Option<DirEntry>]) -> usize {
|
||||||
full: &'a str,
|
abi_sys::list_dir(path.as_ptr(), path.len(), files.as_mut_ptr(), files.len())
|
||||||
base: &'a str,
|
|
||||||
ext: Option<&'a str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> FileName<'a> {
|
|
||||||
pub fn full_name(&self) -> &str {
|
|
||||||
self.full
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn base(&self) -> &str {
|
|
||||||
self.base
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn extension(&self) -> Option<&str> {
|
|
||||||
self.ext
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Display for FileName<'a> {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
||||||
write!(f, "{}", self.full_name())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a str> for FileName<'a> {
|
|
||||||
fn from(s: &'a str) -> FileName<'a> {
|
|
||||||
let full = s;
|
|
||||||
|
|
||||||
// Split on last dot for extension
|
|
||||||
let (base, ext) = match s.rfind('.') {
|
|
||||||
Some(idx) => (&s[..idx], Some(&s[idx + 1..])),
|
|
||||||
None => (s, None),
|
|
||||||
};
|
|
||||||
|
|
||||||
FileName { full, base, ext }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const MAX_ENTRY_NAME_LEN: usize = 25;
|
|
||||||
const MAX_ENTRIES: usize = 25;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
|
||||||
pub struct Entries([[u8; MAX_ENTRY_NAME_LEN]; MAX_ENTRIES]);
|
|
||||||
|
|
||||||
impl Entries {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self([[0; MAX_ENTRY_NAME_LEN]; MAX_ENTRIES])
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get list of file names after listing
|
|
||||||
pub fn entries<'a>(&'a self) -> Vec<FileName<'a>> {
|
|
||||||
self.0
|
|
||||||
.iter()
|
|
||||||
.filter_map(|buf| {
|
|
||||||
let nul_pos = buf.iter().position(|&b| b == 0).unwrap_or(buf.len());
|
|
||||||
Some(core::str::from_utf8(&buf[..nul_pos]).ok()?.into())
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_ptrs(&mut self) -> [*mut u8; MAX_ENTRIES] {
|
|
||||||
let mut ptrs: [*mut u8; MAX_ENTRIES] = [core::ptr::null_mut(); MAX_ENTRIES];
|
|
||||||
for (i, buf) in self.0.iter_mut().enumerate() {
|
|
||||||
ptrs[i] = buf.as_mut_ptr();
|
|
||||||
}
|
|
||||||
ptrs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn list_dir(path: &str, entries: &mut Entries) -> usize {
|
|
||||||
abi_sys::list_dir(
|
|
||||||
path.as_ptr(),
|
|
||||||
path.len(),
|
|
||||||
entries.as_ptrs().as_mut_ptr(),
|
|
||||||
MAX_ENTRIES,
|
|
||||||
MAX_ENTRY_NAME_LEN,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_len(str: &str) -> usize {
|
pub fn file_len(str: &str) -> usize {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ defmt = ["dep:defmt"]
|
|||||||
strum = { version = "0.27.2", default-features = false, features = ["derive"] }
|
strum = { version = "0.27.2", default-features = false, features = ["derive"] }
|
||||||
bitflags = "2.9.4"
|
bitflags = "2.9.4"
|
||||||
embedded-graphics = "0.8.1"
|
embedded-graphics = "0.8.1"
|
||||||
|
embedded-sdmmc = { version = "0.9.0", default-features = false }
|
||||||
defmt = { version = "0.3", optional = true }
|
defmt = { version = "0.3", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use core::alloc::Layout;
|
use core::alloc::Layout;
|
||||||
|
|
||||||
use core::ffi::c_char;
|
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Pixel,
|
Pixel,
|
||||||
pixelcolor::{Rgb565, raw::RawU16},
|
pixelcolor::{Rgb565, raw::RawU16},
|
||||||
prelude::{IntoStorage, Point},
|
prelude::{IntoStorage, Point},
|
||||||
};
|
};
|
||||||
|
use embedded_sdmmc::DirEntry;
|
||||||
use strum::{EnumCount, EnumIter};
|
use strum::{EnumCount, EnumIter};
|
||||||
|
|
||||||
pub type EntryFn = fn();
|
pub type EntryFn = fn();
|
||||||
@@ -395,23 +396,21 @@ pub extern "C" fn gen_rand(req: &mut RngRequest) {
|
|||||||
pub type ListDir = extern "C" fn(
|
pub type ListDir = extern "C" fn(
|
||||||
str: *const u8,
|
str: *const u8,
|
||||||
len: usize,
|
len: usize,
|
||||||
entries: *mut *mut c_char,
|
files: *mut Option<DirEntry>,
|
||||||
file_len: usize,
|
file_len: usize,
|
||||||
max_entry_str_len: usize,
|
|
||||||
) -> usize;
|
) -> usize;
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn list_dir(
|
pub extern "C" fn list_dir(
|
||||||
str: *const u8,
|
str: *const u8,
|
||||||
len: usize,
|
len: usize,
|
||||||
entries: *mut *mut c_char,
|
files: *mut Option<DirEntry>,
|
||||||
entry_count: usize,
|
file_len: usize,
|
||||||
max_entry_str_len: usize,
|
|
||||||
) -> usize {
|
) -> usize {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = CALL_ABI_TABLE[CallTable::ListDir as usize];
|
let ptr = CALL_ABI_TABLE[CallTable::ListDir as usize];
|
||||||
let f: ListDir = core::mem::transmute(ptr);
|
let f: ListDir = core::mem::transmute(ptr);
|
||||||
f(str, len, entries, entry_count, max_entry_str_len)
|
f(str, len, files, file_len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ use abi_sys::{
|
|||||||
PrintAbi, ReadFile, RngRequest, SleepMsAbi, keyboard::*,
|
PrintAbi, ReadFile, RngRequest, SleepMsAbi, keyboard::*,
|
||||||
};
|
};
|
||||||
use alloc::{string::ToString, vec::Vec};
|
use alloc::{string::ToString, vec::Vec};
|
||||||
use core::{alloc::GlobalAlloc, ffi::c_char, ptr, sync::atomic::Ordering};
|
use core::{alloc::GlobalAlloc, sync::atomic::Ordering};
|
||||||
use embassy_rp::clocks::{RoscRng, clk_sys_freq};
|
use embassy_rp::clocks::{RoscRng, clk_sys_freq};
|
||||||
use embassy_time::Instant;
|
use embassy_time::Instant;
|
||||||
use embedded_graphics::draw_target::DrawTarget;
|
use embedded_graphics::draw_target::DrawTarget;
|
||||||
use embedded_sdmmc::LfnBuffer;
|
use embedded_sdmmc::{DirEntry, LfnBuffer};
|
||||||
use heapless::spsc::Queue;
|
use heapless::spsc::Queue;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -116,27 +116,11 @@ pub extern "C" fn gen_rand(req: &mut RngRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn copy_entry_to_user_buf(name: &[u8], dest: *mut c_char, max_str_len: usize) {
|
fn get_dir_entries(dir: &Dir, files: &mut [Option<DirEntry>]) -> usize {
|
||||||
if !dest.is_null() {
|
|
||||||
let len = name.len().min(max_str_len - 1);
|
|
||||||
unsafe {
|
|
||||||
ptr::copy_nonoverlapping(name.as_ptr(), dest as *mut u8, len);
|
|
||||||
*dest.add(len) = 0; // nul terminator
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn get_dir_entries(dir: &Dir, entries: &mut [*mut c_char], max_str_len: usize) -> usize {
|
|
||||||
let mut b = [0; 25];
|
|
||||||
let mut buf = LfnBuffer::new(&mut b);
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
dir.iterate_dir_lfn(&mut buf, |entry, lfn_name| {
|
dir.iterate_dir(|entry| {
|
||||||
if i < entries.len() {
|
if i < files.len() {
|
||||||
if let Some(name) = lfn_name {
|
files[i] = Some(entry.clone());
|
||||||
unsafe { copy_entry_to_user_buf(name.as_bytes(), entries[i], max_str_len) };
|
|
||||||
} else {
|
|
||||||
unsafe { copy_entry_to_user_buf(entry.name.base_name(), entries[i], max_str_len) };
|
|
||||||
}
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -144,30 +128,24 @@ unsafe fn get_dir_entries(dir: &Dir, entries: &mut [*mut c_char], max_str_len: u
|
|||||||
i
|
i
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn recurse_dir(
|
fn recurse_dir(dir: &Dir, dirs: &[&str], files: &mut [Option<DirEntry>]) -> usize {
|
||||||
dir: &Dir,
|
|
||||||
dirs: &[&str],
|
|
||||||
entries: &mut [*mut c_char],
|
|
||||||
max_str_len: usize,
|
|
||||||
) -> usize {
|
|
||||||
if dirs.is_empty() {
|
if dirs.is_empty() {
|
||||||
return unsafe { get_dir_entries(dir, entries, max_str_len) };
|
return get_dir_entries(dir, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
let dir = dir.open_dir(dirs[0]).unwrap();
|
let dir = dir.open_dir(dirs[0]).unwrap();
|
||||||
unsafe { recurse_dir(&dir, &dirs[1..], entries, max_str_len) }
|
recurse_dir(&dir, &dirs[1..], files)
|
||||||
}
|
}
|
||||||
|
|
||||||
const _: ListDir = list_dir;
|
const _: ListDir = list_dir;
|
||||||
pub extern "C" fn list_dir(
|
pub extern "C" fn list_dir(
|
||||||
dir: *const u8,
|
dir: *const u8,
|
||||||
len: usize,
|
len: usize,
|
||||||
entries: *mut *mut c_char,
|
files: *mut Option<DirEntry>,
|
||||||
files_len: usize,
|
files_len: usize,
|
||||||
max_entry_str_len: usize,
|
|
||||||
) -> usize {
|
) -> usize {
|
||||||
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
|
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
|
||||||
let files = unsafe { core::slice::from_raw_parts_mut(entries, files_len) };
|
let files = unsafe { core::slice::from_raw_parts_mut(files, files_len) };
|
||||||
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
|
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
|
||||||
let dir = unsafe { core::str::from_raw_parts(dir, len) };
|
let dir = unsafe { core::str::from_raw_parts(dir, len) };
|
||||||
let dirs: Vec<&str> = dir.split('/').collect();
|
let dirs: Vec<&str> = dir.split('/').collect();
|
||||||
@@ -178,12 +156,10 @@ pub extern "C" fn list_dir(
|
|||||||
let mut wrote = 0;
|
let mut wrote = 0;
|
||||||
sd.access_root_dir(|root| {
|
sd.access_root_dir(|root| {
|
||||||
if dirs[0] == "" && dirs.len() >= 2 {
|
if dirs[0] == "" && dirs.len() >= 2 {
|
||||||
unsafe {
|
if dir == "/" {
|
||||||
if dir == "/" {
|
wrote = get_dir_entries(&root, files);
|
||||||
wrote = get_dir_entries(&root, files, max_entry_str_len);
|
} else {
|
||||||
} else {
|
wrote = recurse_dir(&root, &dirs[1..], files);
|
||||||
wrote = recurse_dir(&root, &dirs[1..], files, max_entry_str_len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ use crate::{heap::init_qmi_psram_heap, psram::init_psram_qmi};
|
|||||||
use crate::{
|
use crate::{
|
||||||
abi::{KEY_CACHE, MS_SINCE_LAUNCH},
|
abi::{KEY_CACHE, MS_SINCE_LAUNCH},
|
||||||
display::{FRAMEBUFFER, display_handler, init_display},
|
display::{FRAMEBUFFER, display_handler, init_display},
|
||||||
heap::HEAP,
|
|
||||||
peripherals::{
|
peripherals::{
|
||||||
conf_peripherals,
|
conf_peripherals,
|
||||||
keyboard::{KeyState, read_keyboard_fifo},
|
keyboard::{KeyState, read_keyboard_fifo},
|
||||||
@@ -322,7 +321,7 @@ async fn kernel_task(
|
|||||||
watchdog: Peri<'static, WATCHDOG>,
|
watchdog: Peri<'static, WATCHDOG>,
|
||||||
display: Display,
|
display: Display,
|
||||||
sd: Sd,
|
sd: Sd,
|
||||||
psram: Psram,
|
_psram: Psram,
|
||||||
mcu: Mcu,
|
mcu: Mcu,
|
||||||
usb: Peri<'static, USB>,
|
usb: Peri<'static, USB>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
11
main_proc_macro/Cargo.toml
Normal file
11
main_proc_macro/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "main_proc_macro"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
quote = "1.0.41"
|
||||||
|
syn = "2.0.108"
|
||||||
21
main_proc_macro/src/lib.rs
Normal file
21
main_proc_macro/src/lib.rs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
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()
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "selection_ui"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
abi = { path = "../abi" }
|
|
||||||
embedded-graphics = "0.8.1"
|
|
||||||
embedded-layout = "0.4.2"
|
|
||||||
embedded-text = "0.7.3"
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
|
|
||||||
extern crate alloc;
|
|
||||||
|
|
||||||
use abi::{
|
|
||||||
display::Display,
|
|
||||||
get_key,
|
|
||||||
keyboard::{KeyCode, KeyState},
|
|
||||||
print, sleep,
|
|
||||||
};
|
|
||||||
use alloc::vec::Vec;
|
|
||||||
use embedded_graphics::{
|
|
||||||
Drawable,
|
|
||||||
mono_font::{MonoTextStyle, ascii::FONT_10X20},
|
|
||||||
pixelcolor::Rgb565,
|
|
||||||
prelude::{Dimensions, Point, Primitive, RgbColor, Size},
|
|
||||||
primitives::{PrimitiveStyle, Rectangle},
|
|
||||||
text::Text,
|
|
||||||
};
|
|
||||||
use embedded_layout::{
|
|
||||||
align::{horizontal, vertical},
|
|
||||||
layout::linear::{FixedMargin, LinearLayout},
|
|
||||||
prelude::*,
|
|
||||||
};
|
|
||||||
use embedded_text::TextBox;
|
|
||||||
|
|
||||||
pub struct SelectionUi<'a> {
|
|
||||||
selection: usize,
|
|
||||||
items: &'a [&'a str],
|
|
||||||
error: &'a str,
|
|
||||||
last_bounds: Option<Rectangle>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> SelectionUi<'a> {
|
|
||||||
pub fn new(items: &'a [&'a str], error: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
selection: 0,
|
|
||||||
items,
|
|
||||||
error,
|
|
||||||
last_bounds: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_selection_ui(&mut self, display: &mut Display) -> Result<Option<usize>, ()> {
|
|
||||||
self.draw(display)?;
|
|
||||||
let selection;
|
|
||||||
loop {
|
|
||||||
let key = get_key();
|
|
||||||
if key.state == KeyState::Pressed {
|
|
||||||
print!("Got Key press: {:?}", key.key);
|
|
||||||
if let Some(s) = self.update(display, key.key)? {
|
|
||||||
selection = Some(s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(selection)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// updates the display with a new keypress.
|
|
||||||
/// returns selection idx if selected
|
|
||||||
pub fn update(&mut self, display: &mut Display, key: KeyCode) -> Result<Option<usize>, ()> {
|
|
||||||
match key {
|
|
||||||
KeyCode::JoyUp => {
|
|
||||||
self.selection = self.selection.saturating_sub(1);
|
|
||||||
}
|
|
||||||
KeyCode::JoyDown => {
|
|
||||||
self.selection = self.selection.saturating_add(1);
|
|
||||||
}
|
|
||||||
KeyCode::Enter | KeyCode::JoyRight => return Ok(Some(self.selection)),
|
|
||||||
_ => return Ok(Some(self.selection)),
|
|
||||||
};
|
|
||||||
self.draw(display)?;
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, display: &mut Display) -> Result<(), ()> {
|
|
||||||
let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
|
||||||
let display_area = display.bounding_box();
|
|
||||||
|
|
||||||
if self.items.is_empty() {
|
|
||||||
TextBox::new(
|
|
||||||
&self.error,
|
|
||||||
Rectangle::new(
|
|
||||||
Point::new(25, 25),
|
|
||||||
Size::new(display_area.size.width - 50, display_area.size.width - 50),
|
|
||||||
),
|
|
||||||
text_style,
|
|
||||||
)
|
|
||||||
.draw(display)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut views: Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new();
|
|
||||||
|
|
||||||
for i in self.items {
|
|
||||||
views.push(Text::new(i, Point::zero(), text_style));
|
|
||||||
}
|
|
||||||
|
|
||||||
let views_group = Views::new(views.as_mut_slice());
|
|
||||||
|
|
||||||
let layout = LinearLayout::vertical(views_group)
|
|
||||||
.with_alignment(horizontal::Center)
|
|
||||||
.with_spacing(FixedMargin(5))
|
|
||||||
.arrange()
|
|
||||||
.align_to(&display_area, horizontal::Center, vertical::Center);
|
|
||||||
|
|
||||||
// draw selected box
|
|
||||||
let selected_bounds = layout.inner().get(self.selection).ok_or(())?.bounding_box();
|
|
||||||
Rectangle::new(selected_bounds.top_left, selected_bounds.size)
|
|
||||||
.into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1))
|
|
||||||
.draw(display)?;
|
|
||||||
|
|
||||||
self.last_bounds = Some(layout.bounds());
|
|
||||||
|
|
||||||
layout.draw(display)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,6 @@ use abi::{
|
|||||||
print,
|
print,
|
||||||
};
|
};
|
||||||
use alloc::{format, string::String, vec, vec::Vec};
|
use alloc::{format, string::String, vec, vec::Vec};
|
||||||
use core::panic::PanicInfo;
|
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Drawable,
|
Drawable,
|
||||||
geometry::{Dimensions, Point},
|
geometry::{Dimensions, Point},
|
||||||
@@ -26,12 +25,6 @@ use embedded_layout::{
|
|||||||
prelude::Chain,
|
prelude::Chain,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[panic_handler]
|
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "Rust" fn _start() {
|
pub extern "Rust" fn _start() {
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -5,35 +5,25 @@
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use abi::{
|
use abi::{
|
||||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||||
fs::{Entries, list_dir, read_file},
|
fs::{list_dir, read_file},
|
||||||
get_key,
|
get_key,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print,
|
main, print,
|
||||||
};
|
};
|
||||||
use alloc::{format, vec};
|
use alloc::{format, string::ToString, vec};
|
||||||
use core::panic::PanicInfo;
|
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
Drawable, image::Image, mono_font::MonoTextStyle, mono_font::ascii::FONT_6X10,
|
Drawable, image::Image, mono_font::MonoTextStyle, mono_font::ascii::FONT_6X10,
|
||||||
pixelcolor::Rgb565, prelude::*, text::Text,
|
pixelcolor::Rgb565, prelude::*, text::Text,
|
||||||
};
|
};
|
||||||
use tinybmp::Bmp;
|
use tinybmp::Bmp;
|
||||||
|
|
||||||
#[panic_handler]
|
#[main]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location());
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub extern "Rust" fn _start() {
|
|
||||||
main()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
print!("Starting Gallery app");
|
print!("Starting Gallery app");
|
||||||
let mut bmp_buf = vec![0_u8; 100_000];
|
let mut bmp_buf = vec![0_u8; 100_000];
|
||||||
let mut display = Display;
|
let mut display = Display;
|
||||||
|
|
||||||
|
// Grid parameters
|
||||||
let grid_cols = 3;
|
let grid_cols = 3;
|
||||||
let grid_rows = 3;
|
let grid_rows = 3;
|
||||||
let cell_width = SCREEN_WIDTH as i32 / grid_cols;
|
let cell_width = SCREEN_WIDTH as i32 / grid_cols;
|
||||||
@@ -41,44 +31,50 @@ pub fn main() {
|
|||||||
|
|
||||||
let mut images_drawn = 0;
|
let mut images_drawn = 0;
|
||||||
|
|
||||||
let mut entries = Entries::new();
|
let mut files = [const { None }; 18];
|
||||||
let files_num = list_dir("/images", &mut entries);
|
let files_num = list_dir("/images", &mut files);
|
||||||
|
|
||||||
for file in &entries.entries()[2..files_num] {
|
for file in &files[2..files_num] {
|
||||||
if images_drawn >= grid_cols * grid_rows {
|
if images_drawn >= grid_cols * grid_rows {
|
||||||
break; // only draw 3x3
|
break; // only draw 3x3
|
||||||
}
|
}
|
||||||
|
|
||||||
print!("file: {}", file);
|
if let Some(f) = file {
|
||||||
if file.extension().unwrap_or("") == "bmp" || file.extension().unwrap_or("") == "BMP" {
|
print!("file: {}", f.name);
|
||||||
let file_path = format!("/images/{}", file);
|
if f.name.extension() == b"bmp" || f.name.extension() == b"BMP" {
|
||||||
|
let file = format!("/images/{}", f.name);
|
||||||
|
|
||||||
let read = read_file(&file_path, 0, &mut &mut bmp_buf[..]);
|
let read = read_file(&file, 0, &mut &mut bmp_buf[..]);
|
||||||
if read > 0 {
|
if read > 0 {
|
||||||
let bmp = Bmp::from_slice(&bmp_buf).expect("failed to parse bmp");
|
let bmp = Bmp::from_slice(&bmp_buf).expect("failed to parse bmp");
|
||||||
|
|
||||||
let row = images_drawn / grid_cols;
|
let row = images_drawn / grid_cols;
|
||||||
let col = images_drawn % grid_cols;
|
let col = images_drawn % grid_cols;
|
||||||
let cell_x = col * cell_width;
|
let cell_x = col * cell_width;
|
||||||
let cell_y = row * cell_height;
|
let cell_y = row * cell_height;
|
||||||
|
|
||||||
// Center image inside cell
|
// Center image inside cell
|
||||||
let bmp_w = bmp.size().width as i32;
|
let bmp_w = bmp.size().width as i32;
|
||||||
let bmp_h = bmp.size().height as i32;
|
let bmp_h = bmp.size().height as i32;
|
||||||
let x = cell_x + (cell_width - bmp_w) / 2;
|
let x = cell_x + (cell_width - bmp_w) / 2;
|
||||||
let y = cell_y + 5; // 5px top margin
|
let y = cell_y + 5; // 5px top margin
|
||||||
|
|
||||||
Image::new(&bmp, Point::new(x, y))
|
Image::new(&bmp, Point::new(x, y))
|
||||||
|
.draw(&mut display)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
||||||
|
let text_y = y + bmp_h + 2; // 2px gap under image
|
||||||
|
Text::new(
|
||||||
|
f.name.to_string().as_str(),
|
||||||
|
Point::new(cell_x + 2, text_y),
|
||||||
|
text_style,
|
||||||
|
)
|
||||||
.draw(&mut display)
|
.draw(&mut display)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
images_drawn += 1;
|
||||||
let text_y = y + bmp_h + 2; // 2px gap under image
|
}
|
||||||
Text::new(&file.base(), Point::new(cell_x + 2, text_y), text_style)
|
|
||||||
.draw(&mut display)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
images_drawn += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,4 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
abi = { path = "../../abi" }
|
abi = { path = "../../abi" }
|
||||||
embedded-graphics = "0.8.1"
|
embedded-graphics = "0.8.1"
|
||||||
selection_ui = { path = "../../selection_ui" }
|
|
||||||
tinygif = { git = "https://github.com/LegitCamper/tinygif" }
|
tinygif = { git = "https://github.com/LegitCamper/tinygif" }
|
||||||
|
|||||||
@@ -4,55 +4,29 @@
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use abi::{
|
use abi::{
|
||||||
display::Display,
|
display::Display,
|
||||||
fs::{Entries, file_len, list_dir, read_file},
|
fs::{file_len, read_file},
|
||||||
get_key, get_ms,
|
get_key, get_ms,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print, sleep,
|
main, print, sleep,
|
||||||
};
|
};
|
||||||
use alloc::{format, vec, vec::Vec};
|
use alloc::{format, vec};
|
||||||
use core::panic::PanicInfo;
|
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
image::ImageDrawable, pixelcolor::Rgb565, prelude::Point, transform::Transform,
|
image::ImageDrawable, pixelcolor::Rgb565, prelude::Point, transform::Transform,
|
||||||
};
|
};
|
||||||
use selection_ui::SelectionUi;
|
|
||||||
use tinygif::Gif;
|
use tinygif::Gif;
|
||||||
|
|
||||||
#[panic_handler]
|
#[main]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
pub extern "Rust" fn _start() {
|
|
||||||
main()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
print!("Starting Gif app");
|
print!("Starting Gif app");
|
||||||
let mut display = Display;
|
let mut display = Display;
|
||||||
|
|
||||||
let mut entries = Entries::new();
|
let size = file_len("/gifs/bad_apple.gif");
|
||||||
list_dir("/gifs", &mut entries);
|
|
||||||
|
|
||||||
let mut files = entries.entries();
|
|
||||||
files.retain(|e| e.extension().unwrap_or("") == "gif");
|
|
||||||
let gifs = &files.iter().map(|e| e.full_name()).collect::<Vec<&str>>();
|
|
||||||
|
|
||||||
let mut selection_ui = SelectionUi::new(&gifs, "No Gif files found in /gifs");
|
|
||||||
let selection = selection_ui
|
|
||||||
.run_selection_ui(&mut display)
|
|
||||||
.expect("failed to draw")
|
|
||||||
.expect("Failed to get user selection");
|
|
||||||
|
|
||||||
let file_name = format!("/gifs/{}", gifs[selection]);
|
|
||||||
let size = file_len(&file_name);
|
|
||||||
let mut buf = vec![0_u8; size];
|
let mut buf = vec![0_u8; size];
|
||||||
let read = read_file(&file_name, 0, &mut buf);
|
let read = read_file("/gifs/bad_apple.gif", 0, &mut buf);
|
||||||
print!("read: {}, file size: {}", read, size);
|
print!("read: {}, file size: {}", read, size);
|
||||||
assert!(read == size);
|
assert!(read == size);
|
||||||
|
|
||||||
let gif = Gif::<Rgb565>::from_slice(&buf).expect("Failed to parse gif");
|
let gif = Gif::<Rgb565>::from_slice(&buf).unwrap();
|
||||||
let height = gif.height();
|
let height = gif.height();
|
||||||
|
|
||||||
let mut frame_num = 0;
|
let mut frame_num = 0;
|
||||||
|
|||||||
@@ -9,16 +9,10 @@ use abi::{
|
|||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print, sleep,
|
print, sleep,
|
||||||
};
|
};
|
||||||
use core::panic::PanicInfo;
|
use alloc::format;
|
||||||
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
|
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
|
||||||
use embedded_snake::{Direction, SnakeGame};
|
use embedded_snake::{Direction, SnakeGame};
|
||||||
|
|
||||||
#[panic_handler]
|
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "Rust" fn _start() {
|
pub extern "Rust" fn _start() {
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user