10 Commits
Author SHA1 Message Date
sawyer b30ccc4485 trying proper scsi handling 2025-11-09 14:04:34 -07:00
sawyer 700e007c87 updates 2025-11-06 11:48:50 -07:00
sawyer 3f6ed9b5a7 fix display override 2025-11-06 09:27:33 -07:00
sawyer fe5b2a253e overlay 2025-11-05 20:22:26 -07:00
sawyer f1ec7d8523 better ui 2025-11-05 19:46:58 -07:00
sawyer 5cbee3715f scsi improvements 2025-11-05 14:15:20 -07:00
sawyer 8290ec40a7 scsi works again, but has bugs 2025-11-05 11:20:24 -07:00
sawyer 4ec5afbc65 init 2025-11-05 11:00:05 -07:00
sawyer 513042b561 works 2025-11-04 16:50:57 -07:00
sawyer 375b5d1d47 init 2025-11-04 13:43:48 -07:00
29 changed files with 944 additions and 1501 deletions

No files matched your search

-2
View File
@@ -2,5 +2,3 @@
*.uf2 *.uf2
abi_sys.h abi_sys.h
assets/gif/bad_apple.gif assets/gif/bad_apple.gif
picolibc
user-apps/gboy/Peanut-GB
-6
View File
@@ -1,6 +0,0 @@
[submodule "picolibc"]
path = picolibc
url = https://github.com/picolibc/picolibc
[submodule "user-apps/gboy/Peanut-GB"]
path = user-apps/gboy/Peanut-GB
url = https://github.com/deltabeard/Peanut-GB
Generated
+272 -168
View File
@@ -26,7 +26,7 @@ dependencies = [
name = "abi_sys" name = "abi_sys"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bitflags 2.10.0", "bitflags 2.9.4",
"cbindgen", "cbindgen",
"defmt 0.3.100", "defmt 0.3.100",
"embedded-graphics", "embedded-graphics",
@@ -47,9 +47,9 @@ dependencies = [
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "1.1.4" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@@ -75,7 +75,7 @@ version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef1e3e699d84ab1b0911a1010c5c106aa34ae89aeac103be5ce0c3859db1e891" checksum = "ef1e3e699d84ab1b0911a1010c5c106aa34ae89aeac103be5ce0c3859db1e891"
dependencies = [ dependencies = [
"term 1.2.0", "term 1.0.2",
] ]
[[package]] [[package]]
@@ -161,6 +161,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
[[package]]
name = "bit_field"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6"
[[package]] [[package]]
name = "bitfield" name = "bitfield"
version = "0.13.2" version = "0.13.2"
@@ -181,9 +187,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.10.0" version = "2.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
[[package]] [[package]]
name = "bitvec" name = "bitvec"
@@ -229,9 +235,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.24.0" version = "1.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4" checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@@ -269,9 +275,9 @@ dependencies = [
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.4" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
[[package]] [[package]]
name = "clap" name = "clap"
@@ -342,7 +348,7 @@ checksum = "e37549a379a9e0e6e576fd208ee60394ccb8be963889eebba3ffe0980364f472"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -439,7 +445,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim 0.11.1", "strsim 0.11.1",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -450,7 +456,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -488,7 +494,7 @@ dependencies = [
"proc-macro-error2", "proc-macro-error2",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -497,17 +503,17 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e"
dependencies = [ dependencies = [
"thiserror 2.0.17", "thiserror 2.0.12",
] ]
[[package]] [[package]]
name = "defmt-rtt" name = "defmt-rtt"
version = "1.1.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93d5a25c99d89c40f5676bec8cefe0614f17f0f40e916f98e345dae941807f9e" checksum = "c6eca0aae8aa2cf8333200ecbd236274697bc0a394765c858b3d9372eb1abcfa"
dependencies = [ dependencies = [
"critical-section", "critical-section",
"defmt 1.0.1", "defmt 0.3.100",
] ]
[[package]] [[package]]
@@ -549,9 +555,9 @@ dependencies = [
[[package]] [[package]]
name = "document-features" name = "document-features"
version = "0.2.12" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d"
dependencies = [ dependencies = [
"litrs", "litrs",
] ]
@@ -637,7 +643,7 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -709,7 +715,7 @@ dependencies = [
"embassy-hal-internal 0.2.0", "embassy-hal-internal 0.2.0",
"embassy-sync 0.6.2", "embassy-sync 0.6.2",
"embassy-time 0.4.0", "embassy-time 0.4.0",
"embassy-usb-driver 0.1.1", "embassy-usb-driver 0.1.0",
"embedded-hal 0.2.7", "embedded-hal 0.2.7",
"embedded-hal 1.0.0", "embedded-hal 1.0.0",
"embedded-hal-async", "embedded-hal-async",
@@ -869,12 +875,9 @@ dependencies = [
[[package]] [[package]]
name = "embassy-usb-driver" name = "embassy-usb-driver"
version = "0.1.1" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "340c5ce591ef58c6449e43f51d2c53efe1bf0bb6a40cbf80afa0d259c7d52c76" checksum = "4fc247028eae04174b6635104a35b1ed336aabef4654f5e87a8f32327d231970"
dependencies = [
"embedded-io-async",
]
[[package]] [[package]]
name = "embassy-usb-driver" name = "embassy-usb-driver"
@@ -898,14 +901,6 @@ dependencies = [
"rlsf", "rlsf",
] ]
[[package]]
name = "embedded-audio"
version = "0.1.0"
source = "git+https://github.com/LegitCamper/embedded-audio#087784644d810b94dd659a03dbed4795dfb0bd24"
dependencies = [
"heapless",
]
[[package]] [[package]]
name = "embedded-graphics" name = "embedded-graphics"
version = "0.8.1" version = "0.8.1"
@@ -977,6 +972,18 @@ dependencies = [
"nb 1.1.0", "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]] [[package]]
name = "embedded-io" name = "embedded-io"
version = "0.6.1" version = "0.6.1"
@@ -1010,7 +1017,7 @@ checksum = "4f6e621fe4c7e05b695274b722dc0a60bacd1c8696b58191baa0154713d52400"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -1137,6 +1144,12 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]] [[package]]
name = "funty" name = "funty"
version = "2.0.0" version = "2.0.0"
@@ -1197,7 +1210,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -1237,9 +1250,9 @@ dependencies = [
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.9" version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [ dependencies = [
"typenum", "typenum",
"version_check", "version_check",
@@ -1280,9 +1293,9 @@ dependencies = [
[[package]] [[package]]
name = "goblin" name = "goblin"
version = "0.10.3" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51876e3748c4a347fe65b906f2b1ae46a1e55a497b22c94c1f4f2c469ff7673a" checksum = "7be320f077239a0361c20d608b4768c62a1b77aa4946dd76395aa4cd502cba7d"
dependencies = [ dependencies = [
"plain", "plain",
"scroll", "scroll",
@@ -1290,13 +1303,12 @@ dependencies = [
[[package]] [[package]]
name = "half" name = "half"
version = "2.7.1" version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"crunchy", "crunchy",
"zerocopy",
] ]
[[package]] [[package]]
@@ -1325,9 +1337,9 @@ dependencies = [
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.16.0" version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
[[package]] [[package]]
name = "heapless" name = "heapless"
@@ -1336,6 +1348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
dependencies = [ dependencies = [
"hash32", "hash32",
"serde",
"stable_deref_trait", "stable_deref_trait",
] ]
@@ -1366,6 +1379,15 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
[[package]]
name = "home"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf"
dependencies = [
"windows-sys",
]
[[package]] [[package]]
name = "ident_case" name = "ident_case"
version = "1.0.1" version = "1.0.1"
@@ -1384,19 +1406,19 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.12.0" version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown 0.16.0", "hashbrown 0.15.4",
] ]
[[package]] [[package]]
name = "is-terminal" name = "is-terminal"
version = "0.4.17" version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
dependencies = [ dependencies = [
"hermit-abi 0.5.2", "hermit-abi 0.5.2",
"libc", "libc",
@@ -1429,9 +1451,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.82" version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@@ -1452,7 +1474,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"abi_sys", "abi_sys",
"assign-resources", "assign-resources",
"bitflags 2.10.0", "bitflags 2.9.4",
"bt-hci", "bt-hci",
"bumpalo", "bumpalo",
"cortex-m", "cortex-m",
@@ -1460,7 +1482,7 @@ dependencies = [
"critical-section", "critical-section",
"cyw43", "cyw43",
"cyw43-pio", "cyw43-pio",
"defmt 1.0.1", "defmt 0.3.100",
"defmt-rtt", "defmt-rtt",
"embassy-embedded-hal 0.3.2", "embassy-embedded-hal 0.3.2",
"embassy-executor", "embassy-executor",
@@ -1478,11 +1500,10 @@ dependencies = [
"embedded-layout", "embedded-layout",
"embedded-sdmmc", "embedded-sdmmc",
"embedded-text", "embedded-text",
"fixed",
"goblin", "goblin",
"heapless", "heapless",
"micromath", "kolibri-embedded-gui",
"num_enum 0.7.5", "num_enum 0.7.4",
"once_cell", "once_cell",
"panic-probe", "panic-probe",
"portable-atomic", "portable-atomic",
@@ -1495,6 +1516,18 @@ dependencies = [
"trouble-host", "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]] [[package]]
name = "lalrpop" name = "lalrpop"
version = "0.19.12" version = "0.19.12"
@@ -1531,10 +1564,10 @@ dependencies = [
"petgraph 0.7.1", "petgraph 0.7.1",
"pico-args", "pico-args",
"regex", "regex",
"regex-syntax 0.8.8", "regex-syntax 0.8.5",
"sha3", "sha3",
"string_cache", "string_cache",
"term 1.2.0", "term 1.0.2",
"unicode-xid", "unicode-xid",
"walkdir", "walkdir",
] ]
@@ -1566,17 +1599,17 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.177" version = "0.2.174"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
[[package]] [[package]]
name = "libredox" name = "libredox"
version = "0.1.10" version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" checksum = "1580801010e535496706ba011c15f8532df6b42297d2e471fec38ceadd8c0638"
dependencies = [ dependencies = [
"bitflags 2.10.0", "bitflags 2.9.4",
"libc", "libc",
] ]
@@ -1594,30 +1627,31 @@ checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
[[package]] [[package]]
name = "litrs" name = "litrs"
version = "1.0.0" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.14" version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765"
dependencies = [ dependencies = [
"autocfg",
"scopeguard", "scopeguard",
] ]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.28" 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 = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.6" version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]] [[package]]
name = "micromath" name = "micromath"
@@ -1666,11 +1700,11 @@ dependencies = [
[[package]] [[package]]
name = "num_enum" name = "num_enum"
version = "0.7.5" version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a"
dependencies = [ dependencies = [
"num_enum_derive 0.7.5", "num_enum_derive 0.7.4",
"rustversion", "rustversion",
] ]
@@ -1687,13 +1721,13 @@ dependencies = [
[[package]] [[package]]
name = "num_enum_derive" name = "num_enum_derive"
version = "0.7.5" version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -1726,9 +1760,9 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.5" version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13"
dependencies = [ dependencies = [
"lock_api", "lock_api",
"parking_lot_core", "parking_lot_core",
@@ -1736,15 +1770,15 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot_core" name = "parking_lot_core"
version = "0.9.12" version = "0.9.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
"windows-link", "windows-targets",
] ]
[[package]] [[package]]
@@ -1760,7 +1794,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db"
dependencies = [ dependencies = [
"fixedbitset 0.4.2", "fixedbitset 0.4.2",
"indexmap 2.12.0", "indexmap 2.9.0",
] ]
[[package]] [[package]]
@@ -1770,7 +1804,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772"
dependencies = [ dependencies = [
"fixedbitset 0.5.7", "fixedbitset 0.5.7",
"indexmap 2.12.0", "indexmap 2.9.0",
] ]
[[package]] [[package]]
@@ -1828,7 +1862,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61d90fddc3d67f21bbf93683bc461b05d6a29c708caf3ffb79947d7ff7095406" checksum = "61d90fddc3d67f21bbf93683bc461b05d6a29c708caf3ffb79947d7ff7095406"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"num_enum 0.7.5", "num_enum 0.7.4",
"paste", "paste",
] ]
@@ -1885,7 +1919,7 @@ dependencies = [
"proc-macro-error2", "proc-macro-error2",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -1952,23 +1986,23 @@ dependencies = [
"proc-macro-error-attr2", "proc-macro-error-attr2",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.103" version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.42" version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@@ -2008,11 +2042,11 @@ checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.5.18" version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
dependencies = [ dependencies = [
"bitflags 2.10.0", "bitflags 2.9.4",
] ]
[[package]] [[package]]
@@ -2028,25 +2062,25 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.12.2" version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-automata", "regex-automata",
"regex-syntax 0.8.8", "regex-syntax 0.8.5",
] ]
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.13" version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-syntax 0.8.8", "regex-syntax 0.8.5",
] ]
[[package]] [[package]]
@@ -2057,15 +2091,18 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.8" version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]] [[package]]
name = "rgb" name = "rgb"
version = "0.8.52" version = "0.8.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a"
dependencies = [
"bytemuck",
]
[[package]] [[package]]
name = "rlsf" name = "rlsf"
@@ -2113,7 +2150,7 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
dependencies = [ dependencies = [
"bitflags 2.10.0", "bitflags 2.9.4",
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
@@ -2122,9 +2159,9 @@ dependencies = [
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.22" version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
[[package]] [[package]]
name = "ryu" name = "ryu"
@@ -2205,7 +2242,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -2260,9 +2297,9 @@ dependencies = [
[[package]] [[package]]
name = "smart-leds-trait" name = "smart-leds-trait"
version = "0.3.2" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f4441a131924d58da6b83a7ad765c460e64630cce504376c3a87a2558c487f" checksum = "edeb89c73244414bb0568611690dd095b2358b3fda5bae65ad784806cca00157"
dependencies = [ dependencies = [
"rgb", "rgb",
] ]
@@ -2311,9 +2348,15 @@ dependencies = [
[[package]] [[package]]
name = "stable_deref_trait" name = "stable_deref_trait"
version = "1.2.1" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "static_cell" name = "static_cell"
@@ -2366,7 +2409,7 @@ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -2395,9 +2438,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.110" version = "2.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2445,10 +2488,11 @@ dependencies = [
[[package]] [[package]]
name = "term" name = "term"
version = "1.2.0" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2111ef44dae28680ae9752bb89409e7310ca33a8c621ebe7b106cf5c928b3ac0" checksum = "8a984c8d058c627faaf5e8e2ed493fa3c51771889196de1016cf9c1c6e90d750"
dependencies = [ dependencies = [
"home",
"windows-sys", "windows-sys",
] ]
@@ -2478,11 +2522,11 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.17" version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [ dependencies = [
"thiserror-impl 2.0.17", "thiserror-impl 2.0.12",
] ]
[[package]] [[package]]
@@ -2493,18 +2537,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.17" version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -2572,21 +2616,21 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
"uuid", "uuid",
] ]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.19.0" version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.22" version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
@@ -2649,9 +2693,9 @@ dependencies = [
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.18.1" version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@@ -2711,22 +2755,35 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
"rustversion", "rustversion",
"wasm-bindgen-macro", "wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn 2.0.104",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@@ -2734,37 +2791,26 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [ dependencies = [
"bumpalo",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
"wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.105" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "wav_player"
version = "0.1.0"
dependencies = [
"abi",
"embedded-audio",
"embedded-graphics",
"rand",
"selection_ui",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
@@ -2783,9 +2829,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]] [[package]]
name = "winapi-util" name = "winapi-util"
version = "0.1.11" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys", "windows-sys",
] ]
@@ -2797,20 +2843,78 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-link" name = "windows-sys"
version = "0.2.1" version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-targets"
version = "0.61.2" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [ dependencies = [
"windows-link", "windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
] ]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]] [[package]]
name = "wit-bindgen" name = "wit-bindgen"
version = "0.46.0" version = "0.46.0"
@@ -2828,20 +2932,20 @@ dependencies = [
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.8.27" version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
dependencies = [ dependencies = [
"zerocopy-derive", "zerocopy-derive",
] ]
[[package]] [[package]]
name = "zerocopy-derive" name = "zerocopy-derive"
version = "0.8.27" version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.110", "syn 2.0.104",
] ]
+1 -2
View File
@@ -9,7 +9,6 @@ members = [
"user-apps/snake", "user-apps/snake",
"user-apps/gallery", "user-apps/gallery",
"user-apps/gif", "user-apps/gif",
"user-apps/wav_player",
] ]
[profile.release] [profile.release]
@@ -24,7 +23,7 @@ codegen-units = 1
lto = true lto = true
debug = false debug = false
opt-level = "z" opt-level = "z"
panic = "unwind" panic = "abort"
[profile.dev] [profile.dev]
lto = true lto = true
+15 -51
View File
@@ -3,8 +3,8 @@
extern crate alloc; extern crate alloc;
use abi_sys::{RngRequest, keyboard::KeyEvent}; pub use abi_sys::{self, keyboard};
pub use abi_sys::{keyboard, print}; use abi_sys::{RngRequest, alloc, dealloc, keyboard::KeyEvent};
pub use alloc::format; pub use alloc::format;
use core::alloc::{GlobalAlloc, Layout}; use core::alloc::{GlobalAlloc, Layout};
use rand_core::RngCore; use rand_core::RngCore;
@@ -16,19 +16,19 @@ struct Alloc;
unsafe impl GlobalAlloc for Alloc { unsafe impl GlobalAlloc for Alloc {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
abi_sys::alloc(layout.into()) alloc(layout.into())
} }
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
abi_sys::dealloc(ptr, layout.into()); dealloc(ptr, layout.into());
} }
} }
#[macro_export] #[macro_export]
macro_rules! println { macro_rules! print {
($($arg:tt)*) => {{ ($($arg:tt)*) => {{
let s = $crate::format!($($arg)*); let s = $crate::format!($($arg)*);
$crate::print(s.as_ptr(), s.len()); $crate::abi_sys::print(s.as_ptr(), s.len());
}}; }};
} }
@@ -45,8 +45,6 @@ pub fn get_key() -> KeyEvent {
} }
pub mod display { pub mod display {
use core::sync::atomic::{AtomicBool, Ordering};
use abi_sys::CPixel; use abi_sys::CPixel;
use embedded_graphics::{ use embedded_graphics::{
Pixel, Pixel,
@@ -61,28 +59,12 @@ pub mod display {
pub type Pixel565 = Pixel<Rgb565>; pub type Pixel565 = Pixel<Rgb565>;
const BUF_SIZE: usize = 1024; const BUF_SIZE: usize = 15 * 1024; // tune this for performance
static mut BUF: [CPixel; BUF_SIZE] = [CPixel::new(); BUF_SIZE]; static mut BUF: [CPixel; BUF_SIZE] = [CPixel::new(); BUF_SIZE];
// const BUF_SIZE: usize = 250 * 1024; // tune this for performance
// static mut BUF: Lazy<Vec<CPixel>> = Lazy::new(|| vec![const { CPixel::new() }; BUF_SIZE]);
static DISPLAY_TAKEN: AtomicBool = AtomicBool::new(false); pub struct Display;
pub struct Display {
_private: (),
}
impl Display {
/// Only one instance of Display can be taken
pub fn take() -> Option<Display> {
if DISPLAY_TAKEN
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
.is_ok()
{
Some(Self { _private: () })
} else {
None
}
}
}
impl Dimensions for Display { impl Dimensions for Display {
fn bounding_box(&self) -> Rectangle { fn bounding_box(&self) -> Rectangle {
@@ -158,30 +140,20 @@ impl RngCore for Rng {
} }
pub mod fs { pub mod fs {
use alloc::vec::Vec;
use core::fmt::Display; use core::fmt::Display;
pub fn read_file(file: &str, start_from: usize, buf: &mut [u8]) -> usize { use alloc::{format, vec::Vec};
pub fn read_file(file: &str, read_from: usize, buf: &mut [u8]) -> usize {
abi_sys::read_file( abi_sys::read_file(
file.as_ptr(), file.as_ptr(),
file.len(), file.len(),
start_from, read_from,
buf.as_mut_ptr(), buf.as_mut_ptr(),
buf.len(), buf.len(),
) )
} }
pub fn write_file(file: &str, start_from: usize, buf: &[u8]) {
abi_sys::write_file(
file.as_ptr(),
file.len(),
start_from,
buf.as_ptr(),
buf.len(),
)
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct FileName<'a> { pub struct FileName<'a> {
full: &'a str, full: &'a str,
base: &'a str, base: &'a str,
@@ -225,7 +197,7 @@ pub mod fs {
const MAX_ENTRY_NAME_LEN: usize = 25; const MAX_ENTRY_NAME_LEN: usize = 25;
const MAX_ENTRIES: usize = 25; const MAX_ENTRIES: usize = 25;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy)]
pub struct Entries([[u8; MAX_ENTRY_NAME_LEN]; MAX_ENTRIES]); pub struct Entries([[u8; MAX_ENTRY_NAME_LEN]; MAX_ENTRIES]);
impl Entries { impl Entries {
@@ -267,11 +239,3 @@ pub mod fs {
abi_sys::file_len(str.as_ptr(), str.len()) abi_sys::file_len(str.as_ptr(), str.len())
} }
} }
pub mod audio {
pub use abi_sys::{AUDIO_BUFFER_LEN, AUDIO_BUFFER_SAMPLES, audio_buffer_ready};
pub fn send_audio_buffer(buf: &[u8]) {
abi_sys::send_audio_buffer(buf.as_ptr(), buf.len())
}
}
+2 -48
View File
@@ -12,7 +12,7 @@ use strum::{EnumCount, EnumIter};
pub type EntryFn = fn(); pub type EntryFn = fn();
pub const ABI_CALL_TABLE_COUNT: usize = 14; pub const ABI_CALL_TABLE_COUNT: usize = 11;
const _: () = assert!(ABI_CALL_TABLE_COUNT == CallTable::COUNT); const _: () = assert!(ABI_CALL_TABLE_COUNT == CallTable::COUNT);
#[derive(Clone, Copy, EnumIter, EnumCount)] #[derive(Clone, Copy, EnumIter, EnumCount)]
@@ -28,10 +28,7 @@ pub enum CallTable {
GenRand = 7, GenRand = 7,
ListDir = 8, ListDir = 8,
ReadFile = 9, ReadFile = 9,
WriteFile = 10, FileLen = 10,
FileLen = 11,
AudioBufferReady = 12,
SendAudioBuffer = 13,
} }
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
@@ -441,24 +438,6 @@ pub extern "C" fn read_file(
} }
} }
pub type WriteFile =
extern "C" fn(str: *const u8, len: usize, write_from: usize, buf: *const u8, buf_len: usize);
#[unsafe(no_mangle)]
pub extern "C" fn write_file(
str: *const u8,
len: usize,
write_from: usize,
buf: *const u8,
buf_len: usize,
) {
unsafe {
let ptr = CALL_ABI_TABLE[CallTable::WriteFile as usize];
let f: WriteFile = core::mem::transmute(ptr);
f(str, len, write_from, buf, buf_len)
}
}
pub type FileLen = extern "C" fn(str: *const u8, len: usize) -> usize; pub type FileLen = extern "C" fn(str: *const u8, len: usize) -> usize;
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
@@ -469,28 +448,3 @@ pub extern "C" fn file_len(str: *const u8, len: usize) -> usize {
f(str, len) f(str, len)
} }
} }
pub type AudioBufferReady = extern "C" fn() -> bool;
#[allow(unused)]
pub fn audio_buffer_ready() -> bool {
unsafe {
let ptr = CALL_ABI_TABLE[CallTable::AudioBufferReady as usize];
let f: AudioBufferReady = core::mem::transmute(ptr);
f()
}
}
pub const AUDIO_BUFFER_SAMPLES: usize = 1024;
pub const AUDIO_BUFFER_LEN: usize = AUDIO_BUFFER_SAMPLES * 2;
pub type SendAudioBuffer = extern "C" fn(ptr: *const u8, len: usize);
#[allow(unused)]
pub fn send_audio_buffer(buf: *const u8, len: usize) {
unsafe {
let ptr = CALL_ABI_TABLE[CallTable::SendAudioBuffer as usize];
let f: SendAudioBuffer = core::mem::transmute(ptr);
f(buf, len)
}
}
+1 -40
View File
@@ -1,7 +1,5 @@
kernel-dev board: kernel-dev board:
cargo run --bin kernel --features {{board}} --features fps cargo run --bin kernel --features {{board}}
kernel-release-probe board:
cargo run --bin kernel --profile release --features {{board}} --features fps
kernel-release board: kernel-release board:
cargo build --bin kernel --release --no-default-features --features {{board}} cargo build --bin kernel --release --no-default-features --features {{board}}
elf2uf2-rs -d target/thumbv8m.main-none-eabihf/release/kernel elf2uf2-rs -d target/thumbv8m.main-none-eabihf/release/kernel
@@ -11,26 +9,6 @@ binary-args := "RUSTFLAGS=\"-C link-arg=-pie -C relocation-model=pic\""
cbindgen: cbindgen:
cbindgen abi_sys --output abi_sys.h -q cbindgen abi_sys --output abi_sys.h -q
newlib:
#!/bin/bash
cd picolibc
mkdir build
cd build
CONFIG_PICOLIBC=true ../scripts/do-configure thumbv8m_main_fp-none-eabi \
--buildtype=minsize \
-Dtests=true \
-Dtinystdio=false \
-Dsingle-thread=true \
-Db_pie=true \
-Ddefault_library=static \
-Dtinystdio=false \
-Dnewlib-nano-malloc=true \
-Dmultilib=false \
-Dpicolib=true \
"$@"
DESTDIR=./install meson install
ninja
userapp app: userapp app:
{{binary-args}} cargo build --bin {{app}} --profile release-binary {{binary-args}} cargo build --bin {{app}} --profile release-binary
@@ -39,20 +17,3 @@ userapps: cbindgen
just userapp snake just userapp snake
just userapp gallery just userapp gallery
just userapp gif just userapp gif
just userapp wav_player
copy-userapp app:
cp ./target/thumbv8m.main-none-eabihf/release-binary/{{app}} /run/media/$(whoami)/PICOCALC/{{app}}.bin
copy-userapps:
#!/bin/bash
just userapps
just copy-userapp calculator
just copy-userapp snake
just copy-userapp gallery
just copy-userapp gif
just copy-userapp wav_player
DEV=$(lsblk -o LABEL,NAME -nr | awk -v L="PICOCALC" '$1==L {print "/dev/" $2}')
udisksctl unmount -b "$DEV"
udisksctl power-off -b "$DEV"
+6 -12
View File
@@ -12,13 +12,10 @@ bench = false
[features] [features]
default = ["rp235x", "defmt"] default = ["rp235x", "defmt"]
pimoroni2w = ["rp235x", "psram"] pimoroni2w = ["rp235x"]
# rp2040 = ["embassy-rp/rp2040"] # unsupported, ram too small for fb rp2040 = ["embassy-rp/rp2040"]
rp235x = ["embassy-rp/rp235xb"] rp235x = ["embassy-rp/rp235xb"]
trouble = ["dep:bt-hci", "dep:cyw43", "dep:cyw43-pio", "dep:trouble-host"] trouble = ["dep:bt-hci", "dep:cyw43", "dep:cyw43-pio", "dep:trouble-host"]
psram = ["dep:embedded-alloc"]
overclock = []
fps = []
defmt = [ defmt = [
"dep:defmt", "dep:defmt",
"panic-probe/print-defmt", "panic-probe/print-defmt",
@@ -73,17 +70,16 @@ panic-probe = "0.3"
portable-atomic = { version = "1.11", features = ["critical-section"] } portable-atomic = { version = "1.11", features = ["critical-section"] }
assign-resources = "0.5.0" assign-resources = "0.5.0"
defmt = { version = "1.0.1", optional = true } defmt = { version = "0.3", optional = true }
defmt-rtt = "1.1.0" defmt-rtt = "0.4.2"
embedded-sdmmc = { version = "0.9", default-features = false } embedded-sdmmc = { version = "0.9", default-features = false }
st7365p-lcd = { git = "https://github.com/legitcamper/st7365p-lcd-rs", rev = "a784b9e6df0769371dfc522528e770cf8fc6403a" } # async branch st7365p-lcd = { git = "https://github.com/legitcamper/st7365p-lcd-rs", rev = "a784b9e6df0769371dfc522528e770cf8fc6403a" } # async branch
embedded-graphics = { version = "0.8.1" } embedded-graphics = { version = "0.8.1" }
embedded-text = "0.7.2" embedded-text = "0.7.2"
embedded-layout = "0.4.2" embedded-layout = "0.4.2"
kolibri-embedded-gui = "0.1.0"
micromath = "2.1.0"
fixed = "1.29.0"
strum = { version = "0.27.2", default-features = false } strum = { version = "0.27.2", default-features = false }
rand = { version = "0.9.0", default-features = false } rand = { version = "0.9.0", default-features = false }
once_cell = { version = "1.21.3", default-features = false } once_cell = { version = "1.21.3", default-features = false }
@@ -94,9 +90,7 @@ spin = "0.10.0"
num_enum = { version = "0.7.4", default-features = false } num_enum = { version = "0.7.4", default-features = false }
goblin = { version = "0.10.1", default-features = false, features = ["elf32"] } goblin = { version = "0.10.1", default-features = false, features = ["elf32"] }
talc = "4.4.3" talc = "4.4.3"
embedded-alloc = { version = "0.6.0", features = [ embedded-alloc = { version = "0.6.0", features = ["allocator_api"] }
"allocator_api",
], optional = true }
bumpalo = "3.19.0" bumpalo = "3.19.0"
abi_sys = { path = "../abi_sys" } abi_sys = { path = "../abi_sys" }
+17 -104
View File
@@ -1,24 +1,16 @@
use abi_sys::{ use abi_sys::{
AUDIO_BUFFER_SAMPLES, AllocAbi, AudioBufferReady, CLayout, CPixel, DeallocAbi, DrawIterAbi, AllocAbi, CLayout, CPixel, DeallocAbi, DrawIterAbi, FileLen, GenRand, GetMsAbi, ListDir,
FileLen, GenRand, GetMsAbi, ListDir, PrintAbi, ReadFile, RngRequest, SendAudioBuffer, PrintAbi, ReadFile, RngRequest, SleepMsAbi, keyboard::*,
SleepMsAbi, WriteFile, keyboard::*,
}; };
use alloc::{string::ToString, vec::Vec}; use alloc::{string::ToString, vec::Vec};
use core::{ffi::c_char, ptr, sync::atomic::Ordering}; use core::{alloc::GlobalAlloc, ffi::c_char, ptr, 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::LfnBuffer;
use heapless::spsc::Queue; use heapless::spsc::Queue;
#[cfg(feature = "psram")]
use crate::heap::HEAP;
#[cfg(feature = "psram")]
use core::alloc::GlobalAlloc;
use crate::{ use crate::{
audio::{AUDIO_BUFFER, AUDIO_BUFFER_READY},
display::FRAMEBUFFER, display::FRAMEBUFFER,
framebuffer::FB_PAUSED, framebuffer::FB_PAUSED,
storage::{Dir, File, SDCARD}, storage::{Dir, File, SDCARD},
@@ -28,14 +20,10 @@ const _: AllocAbi = alloc;
pub extern "C" fn alloc(layout: CLayout) -> *mut u8 { pub extern "C" fn alloc(layout: CLayout) -> *mut u8 {
// SAFETY: caller guarantees layout is valid // SAFETY: caller guarantees layout is valid
unsafe { unsafe {
#[cfg(feature = "psram")] if cfg!(feature = "pimoroni2w") {
{ crate::heap::HEAP.alloc(layout.into())
return HEAP.alloc(layout.into()); } else {
} alloc::alloc::alloc(layout.into())
#[cfg(not(feature = "psram"))]
{
return alloc::alloc::alloc(layout.into());
} }
} }
} }
@@ -43,14 +31,12 @@ pub extern "C" fn alloc(layout: CLayout) -> *mut u8 {
const _: DeallocAbi = dealloc; const _: DeallocAbi = dealloc;
pub extern "C" fn dealloc(ptr: *mut u8, layout: CLayout) { pub extern "C" fn dealloc(ptr: *mut u8, layout: CLayout) {
// SAFETY: caller guarantees ptr and layout are valid // SAFETY: caller guarantees ptr and layout are valid
#[cfg(feature = "psram")] unsafe {
{ if cfg!(feature = "pimoroni2w") {
unsafe { HEAP.dealloc(ptr, layout.into()) } crate::heap::HEAP.dealloc(ptr, layout.into())
} else {
alloc::alloc::dealloc(ptr, layout.into())
} }
#[cfg(not(feature = "psram"))]
{
unsafe { alloc::alloc::dealloc(ptr, layout.into()) }
} }
} }
@@ -220,8 +206,7 @@ fn recurse_file<T>(
} }
} }
}) })
.expect("Failed to iterate dir"); .unwrap();
if let Some(name) = short_name { if let Some(name) = short_name {
let mut file = dir let mut file = dir
.open_file_in_dir(name, embedded_sdmmc::Mode::ReadWriteAppend) .open_file_in_dir(name, embedded_sdmmc::Mode::ReadWriteAppend)
@@ -245,17 +230,7 @@ pub extern "C" fn read_file(
) -> usize { ) -> usize {
// SAFETY: caller guarantees `ptr` is valid for `len` bytes // SAFETY: caller guarantees `ptr` is valid for `len` bytes
let file = unsafe { core::str::from_raw_parts(str, len) }; let file = unsafe { core::str::from_raw_parts(str, len) };
let file: Vec<&str> = file.split('/').collect();
let mut components: [&str; 8] = [""; 8];
let mut count = 0;
for part in file.split('/') {
if count >= components.len() {
break;
}
components[count] = part;
count += 1;
}
// SAFETY: caller guarantees `ptr` is valid for `len` bytes // SAFETY: caller guarantees `ptr` is valid for `len` bytes
let mut buf = unsafe { core::slice::from_raw_parts_mut(buf, buf_len) }; let mut buf = unsafe { core::slice::from_raw_parts_mut(buf, buf_len) };
@@ -265,8 +240,8 @@ pub extern "C" fn read_file(
let sd = guard.as_mut().unwrap(); let sd = guard.as_mut().unwrap();
if !file.is_empty() { if !file.is_empty() {
sd.access_root_dir(|root| { sd.access_root_dir(|root| {
if let Ok(result) = recurse_file(&root, &components[1..count], |file| { if let Ok(result) = recurse_file(&root, &file[1..], |file| {
file.seek_from_start(start_from as u32).unwrap_or(()); file.seek_from_start(start_from as u32).unwrap();
file.read(&mut buf).unwrap() file.read(&mut buf).unwrap()
}) { }) {
read = result read = result
@@ -276,46 +251,9 @@ pub extern "C" fn read_file(
read read
} }
const _: WriteFile = write_file;
pub extern "C" fn write_file(
str: *const u8,
len: usize,
start_from: usize,
buf: *const u8,
buf_len: usize,
) {
// SAFETY: caller guarantees str ptr is valid for `len` bytes
let file = unsafe { core::str::from_raw_parts(str, len) };
let mut components: [&str; 8] = [""; 8];
let mut count = 0;
for part in file.split('/') {
if count >= components.len() {
break;
}
components[count] = part;
count += 1;
}
// SAFETY: caller guarantees buf ptr is valid for `buf_len` bytes
let buf = unsafe { core::slice::from_raw_parts(buf, buf_len) };
let mut guard = SDCARD.get().try_lock().expect("Failed to get sdcard");
let sd = guard.as_mut().unwrap();
if !file.is_empty() {
sd.access_root_dir(|root| {
recurse_file(&root, &components[1..count], |file| {
file.seek_from_start(start_from as u32).unwrap();
file.write(&buf).unwrap()
})
.unwrap_or(())
});
};
}
const _: FileLen = file_len; const _: FileLen = file_len;
pub extern "C" fn file_len(str: *const u8, len: usize) -> usize { pub extern "C" fn file_len(str: *const u8, len: usize) -> usize {
// SAFETY: caller guarantees str ptr is valid for `len` bytes // SAFETY: caller guarantees `ptr` is valid for `len` bytes
let file = unsafe { core::str::from_raw_parts(str, len) }; let file = unsafe { core::str::from_raw_parts(str, len) };
let file: Vec<&str> = file.split('/').collect(); let file: Vec<&str> = file.split('/').collect();
@@ -332,28 +270,3 @@ pub extern "C" fn file_len(str: *const u8, len: usize) -> usize {
} }
len as usize len as usize
} }
const _: AudioBufferReady = audio_buffer_ready;
pub extern "C" fn audio_buffer_ready() -> bool {
AUDIO_BUFFER_READY.load(Ordering::Acquire)
}
const _: SendAudioBuffer = send_audio_buffer;
pub extern "C" fn send_audio_buffer(ptr: *const u8, len: usize) {
// SAFETY: caller guarantees `ptr` is valid for `len` bytes
let buf = unsafe { core::slice::from_raw_parts(ptr, len) };
while !AUDIO_BUFFER_READY.load(Ordering::Acquire) {}
if buf.len() == AUDIO_BUFFER_SAMPLES * 2 {
AUDIO_BUFFER_READY.store(false, Ordering::Release);
unsafe { AUDIO_BUFFER.copy_from_slice(buf) };
} else {
#[cfg(feature = "defmt")]
defmt::warn!(
"user audio stream was wrong size: {} should be {}",
buf.len(),
AUDIO_BUFFER_SAMPLES * 2
)
}
}
-149
View File
@@ -1,149 +0,0 @@
use crate::Audio;
use core::sync::atomic::{AtomicBool, Ordering};
use embassy_futures::join::join;
use embassy_rp::{
Peri,
clocks::clk_sys_freq,
dma::{AnyChannel, Channel},
gpio::Level,
pio::{
Common, Config, Direction, FifoJoin, Instance, LoadedProgram, PioPin, ShiftConfig,
StateMachine, program::pio_asm,
},
};
use fixed::traits::ToFixed;
pub const SAMPLE_RATE_HZ: u32 = 22_050;
const AUDIO_BUFFER_SAMPLES: usize = 1024;
const _: () = assert!(AUDIO_BUFFER_SAMPLES == abi_sys::AUDIO_BUFFER_SAMPLES);
// 8bit stereo interleaved PCM audio buffers
pub static mut AUDIO_BUFFER: [u8; AUDIO_BUFFER_SAMPLES * 2] = [0; AUDIO_BUFFER_SAMPLES * 2];
static mut AUDIO_BUFFER_1: [u8; AUDIO_BUFFER_SAMPLES * 2] = [0; AUDIO_BUFFER_SAMPLES * 2];
pub static AUDIO_BUFFER_READY: AtomicBool = AtomicBool::new(true);
#[embassy_executor::task]
pub async fn audio_handler(mut audio: Audio) {
const SILENCE_VALUE: u8 = u8::MAX / 2;
let prg = PioPwmAudioProgram8Bit::new(&mut audio.pio);
let mut pwm_pio_left =
PioPwmAudio::new(audio.dma0, &mut audio.pio, audio.sm0, audio.left, &prg);
let mut pwm_pio_right =
PioPwmAudio::new(audio.dma1, &mut audio.pio, audio.sm1, audio.right, &prg);
loop {
write_samples(&mut pwm_pio_left, &mut pwm_pio_right, unsafe {
&AUDIO_BUFFER_1
})
.await;
unsafe { &mut AUDIO_BUFFER_1 }.fill(SILENCE_VALUE);
unsafe { core::mem::swap(&mut AUDIO_BUFFER, &mut AUDIO_BUFFER_1) };
AUDIO_BUFFER_READY.store(true, Ordering::Release)
}
}
async fn write_samples<PIO: Instance>(
left: &mut PioPwmAudio<'static, PIO, 0>,
right: &mut PioPwmAudio<'static, PIO, 1>,
buf: &[u8],
) {
// pack two samples per word
let mut packed_buf_left: [u32; AUDIO_BUFFER_SAMPLES / 2] = [0; AUDIO_BUFFER_SAMPLES / 2];
let mut packed_buf_right: [u32; AUDIO_BUFFER_SAMPLES / 2] = [0; AUDIO_BUFFER_SAMPLES / 2];
for ((pl, pr), sample) in packed_buf_left
.iter_mut()
.zip(packed_buf_right.iter_mut())
.zip(buf.chunks(4))
{
*pl = pack_u8_samples(sample[0], sample[2]);
*pr = pack_u8_samples(sample[1], sample[3]);
}
let left_fut = left
.sm
.tx()
.dma_push(left.dma.reborrow(), &packed_buf_left, false);
let right_fut = right
.sm
.tx()
.dma_push(right.dma.reborrow(), &packed_buf_right, false);
join(left_fut, right_fut).await;
}
struct PioPwmAudioProgram8Bit<'d, PIO: Instance>(LoadedProgram<'d, PIO>);
/// Writes one sample to pwm as high and low time
impl<'d, PIO: Instance> PioPwmAudioProgram8Bit<'d, PIO> {
fn new(common: &mut Common<'d, PIO>) -> Self {
// only uses 16 bits top for high, bottom for low
// allows two samples per word
let prg = pio_asm!(
"out x, 8", // pwm high time
"out y, 8", // pwm low time
"loop_high:",
"set pins, 1", // keep pin high
"jmp x-- loop_high", // decrement X until 0
"loop_low:",
"set pins, 0", // keep pin low
"jmp y-- loop_low", // decrement Y until 0
);
let prg = common.load_program(&prg.program);
Self(prg)
}
}
struct PioPwmAudio<'d, PIO: Instance, const SM: usize> {
dma: Peri<'d, AnyChannel>,
sm: StateMachine<'d, PIO, SM>,
}
impl<'d, PIO: Instance, const SM: usize> PioPwmAudio<'d, PIO, SM> {
fn new(
dma: Peri<'d, impl Channel>,
pio: &mut Common<'d, PIO>,
mut sm: StateMachine<'d, PIO, SM>,
pin: Peri<'d, impl PioPin>,
prg: &PioPwmAudioProgram8Bit<'d, PIO>,
) -> Self {
let pin = pio.make_pio_pin(pin);
sm.set_pins(Level::High, &[&pin]);
sm.set_pin_dirs(Direction::Out, &[&pin]);
let mut cfg = Config::default();
cfg.set_set_pins(&[&pin]);
cfg.fifo_join = FifoJoin::TxOnly;
let mut shift_cfg = ShiftConfig::default();
shift_cfg.auto_fill = true;
cfg.shift_out = shift_cfg;
cfg.use_program(&prg.0, &[]);
sm.set_config(&cfg);
let target_clock = (u8::MAX as u32 + 1) * SAMPLE_RATE_HZ;
let divider = (clk_sys_freq() / (target_clock * 2)).to_fixed();
sm.set_clock_divider(divider);
sm.set_enable(true);
Self {
dma: dma.into(),
sm,
}
}
}
/// packs two u8 samples into 32bit word
fn pack_u8_samples(sample1: u8, sample2: u8) -> u32 {
(u8_pcm_to_pwm(sample1) as u32) << 16 | u8_pcm_to_pwm(sample2) as u32
}
fn u8_pcm_to_pwm(sample: u8) -> u16 {
((sample as u16) << 8) | ((u8::MAX - sample) as u16)
}
+17 -42
View File
@@ -1,24 +1,20 @@
use crate::framebuffer::{self, AtomicFrameBuffer, FB_PAUSED}; use crate::framebuffer::{self, AtomicFrameBuffer, FB_PAUSED};
use core::alloc::{GlobalAlloc, Layout}; use core::alloc::{GlobalAlloc, Layout};
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use embassy_futures::yield_now;
use embassy_rp::{ use embassy_rp::{
Peri, Peri,
gpio::{Level, Output}, gpio::{Level, Output},
peripherals::{PIN_13, PIN_14, PIN_15, SPI1}, peripherals::{PIN_13, PIN_14, PIN_15, SPI1},
spi::{Async, Spi}, spi::{Async, Spi},
}; };
use embassy_time::Delay; use embassy_time::{Delay, Timer};
use embedded_graphics::{draw_target::DrawTarget, pixelcolor::Rgb565, prelude::RgbColor}; use embedded_graphics::{
pixelcolor::Rgb565,
prelude::{DrawTarget, RgbColor},
};
use embedded_hal_bus::spi::ExclusiveDevice; use embedded_hal_bus::spi::ExclusiveDevice;
use st7365p_lcd::ST7365P; use st7365p_lcd::ST7365P;
#[cfg(feature = "psram")]
use crate::heap::HEAP;
#[cfg(feature = "fps")]
pub use framebuffer::fps::{FPS_CANVAS, FPS_COUNTER};
type DISPLAY = ST7365P< type DISPLAY = ST7365P<
ExclusiveDevice<Spi<'static, SPI1, Async>, Output<'static>, Delay>, ExclusiveDevice<Spi<'static, SPI1, Async>, Output<'static>, Delay>,
Output<'static>, Output<'static>,
@@ -33,21 +29,18 @@ pub static mut FRAMEBUFFER: Option<AtomicFrameBuffer> = None;
fn init_fb() { fn init_fb() {
unsafe { unsafe {
#[cfg(feature = "psram")] FRAMEBUFFER = Some(if cfg!(not(feature = "pimoroni2w")) {
{ static mut BUF: [u16; framebuffer::SIZE] = [0; framebuffer::SIZE];
let slab = HEAP.alloc(Layout::array::<u16>(framebuffer::SIZE).unwrap()) as *mut u16; 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); let buf = core::slice::from_raw_parts_mut(slab, framebuffer::SIZE);
let mut fb = AtomicFrameBuffer::new(buf); let mut fb = AtomicFrameBuffer::new(buf);
fb.clear(Rgb565::BLACK).unwrap(); fb.clear(Rgb565::BLACK).unwrap();
FRAMEBUFFER = Some(fb); fb
} });
#[cfg(not(feature = "psram"))]
{
static mut BUF: [u16; framebuffer::SIZE] = [0; framebuffer::SIZE];
FRAMEBUFFER = Some(AtomicFrameBuffer::new(&mut BUF));
}
} }
} }
@@ -85,21 +78,7 @@ pub async fn init_display(
#[embassy_executor::task] #[embassy_executor::task]
pub async fn display_handler(mut display: DISPLAY) { pub async fn display_handler(mut display: DISPLAY) {
use embassy_time::{Instant, Timer};
// Target ~60 Hz refresh (≈16.67 ms per frame)
const FRAME_TIME_MS: u64 = 1000 / 60;
loop { loop {
let start = Instant::now();
#[cfg(feature = "fps")]
unsafe {
if FPS_COUNTER.should_draw() {
FPS_CANVAS.draw_fps().await;
}
}
if !FB_PAUSED.load(Ordering::Acquire) { if !FB_PAUSED.load(Ordering::Acquire) {
unsafe { unsafe {
FRAMEBUFFER FRAMEBUFFER
@@ -107,15 +86,11 @@ pub async fn display_handler(mut display: DISPLAY) {
.unwrap() .unwrap()
.partial_draw(&mut display) .partial_draw(&mut display)
.await .await
.unwrap(); .unwrap()
} };
} }
let elapsed = start.elapsed().as_millis() as u64; // small yield to allow other tasks to run
if elapsed < FRAME_TIME_MS { Timer::after_nanos(500).await;
Timer::after_millis(FRAME_TIME_MS - elapsed).await;
} else {
yield_now().await;
}
} }
} }
+2 -4
View File
@@ -2,7 +2,8 @@ use crate::{
abi, abi,
storage::{File, SDCARD}, storage::{File, SDCARD},
}; };
use abi_sys::{CallTable, EntryFn}; use abi_sys::CallTable;
use abi_sys::EntryFn;
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use bumpalo::Bump; use bumpalo::Bump;
use core::ptr; use core::ptr;
@@ -205,10 +206,7 @@ fn patch_abi(
CallTable::GenRand => abi::gen_rand as usize, CallTable::GenRand => abi::gen_rand as usize,
CallTable::ListDir => abi::list_dir as usize, CallTable::ListDir => abi::list_dir as usize,
CallTable::ReadFile => abi::read_file as usize, CallTable::ReadFile => abi::read_file as usize,
CallTable::WriteFile => abi::write_file as usize,
CallTable::FileLen => abi::file_len as usize, CallTable::FileLen => abi::file_len as usize,
CallTable::AudioBufferReady => abi::audio_buffer_ready as usize,
CallTable::SendAudioBuffer => abi::send_audio_buffer as usize,
}; };
unsafe { unsafe {
table_base.add(idx as usize).write(ptr); table_base.add(idx as usize).write(ptr);
-231
View File
@@ -13,9 +13,6 @@ use embedded_hal_2::digital::OutputPin;
use embedded_hal_async::{delay::DelayNs, spi::SpiDevice}; use embedded_hal_async::{delay::DelayNs, spi::SpiDevice};
use st7365p_lcd::ST7365P; use st7365p_lcd::ST7365P;
#[cfg(feature = "fps")]
use fps::{FPS_CANVAS, FPS_CANVAS_HEIGHT, FPS_CANVAS_WIDTH, FPS_CANVAS_X, FPS_CANVAS_Y};
const TILE_SIZE: usize = 16; // 16x16 tile const TILE_SIZE: usize = 16; // 16x16 tile
const TILE_COUNT: usize = (SCREEN_WIDTH / TILE_SIZE) * (SCREEN_HEIGHT / TILE_SIZE); // 400 tiles 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_ROWS: usize = SCREEN_WIDTH / TILE_SIZE;
@@ -133,34 +130,9 @@ impl<'a> AtomicFrameBuffer<'a> {
tile.store(false, Ordering::Release); tile.store(false, Ordering::Release);
} }
#[cfg(feature = "fps")]
unsafe {
crate::display::FPS_COUNTER.measure()
}
Ok(()) Ok(())
} }
// used when doing a full screen refresh fps must be drawn into fb
// unfortunately it is not garenteed to not be drawn over before
// being pushed to the display
#[cfg(feature = "fps")]
pub fn draw_fps_into_fb(&mut self) {
unsafe {
let canvas = &FPS_CANVAS.canvas;
for y in 0..FPS_CANVAS_HEIGHT {
let fb_y = FPS_CANVAS_Y + y;
let fb_row_start = fb_y * SCREEN_WIDTH + FPS_CANVAS_X;
let canvas_row_start = y * FPS_CANVAS_WIDTH;
self.fb[fb_row_start..fb_row_start + FPS_CANVAS_WIDTH].copy_from_slice(
&canvas[canvas_row_start..canvas_row_start + FPS_CANVAS_WIDTH],
);
}
}
}
// copy N tiles horizontally to the right into batch tile buf // copy N tiles horizontally to the right into batch tile buf
fn append_tiles_to_batch( fn append_tiles_to_batch(
&mut self, &mut self,
@@ -180,45 +152,6 @@ impl<'a> AtomicFrameBuffer<'a> {
&self.fb[fb_row_offset..fb_row_offset + (total_tiles as usize * TILE_SIZE)]; &self.fb[fb_row_offset..fb_row_offset + (total_tiles as usize * TILE_SIZE)];
batch_row.copy_from_slice(fb_row); batch_row.copy_from_slice(fb_row);
// override fps pixel region with fps
// avoids writing to fps, and having it overridden before draw
#[cfg(feature = "fps")]
{
let global_y = tile_y as usize * TILE_SIZE + batch_row_num;
if global_y >= FPS_CANVAS_Y && global_y < FPS_CANVAS_Y + FPS_CANVAS_HEIGHT {
let start_x = tile_x as usize * TILE_SIZE;
let end_x = start_x + (total_tiles as usize * TILE_SIZE);
// horizontal overlap check
let fps_x0 = FPS_CANVAS_X;
let fps_x1 = FPS_CANVAS_X + FPS_CANVAS_WIDTH;
let x0 = start_x.max(fps_x0);
let x1 = end_x.min(fps_x1);
if x1 > x0 {
let row_in_fps = global_y - FPS_CANVAS_Y;
let fps_off = row_in_fps
.checked_mul(FPS_CANVAS_WIDTH)
.and_then(|v| v.checked_add(x0 - fps_x0));
let batch_off = x0 - start_x;
let len = x1 - x0;
if let Some(fps_off) = fps_off {
let fps_len_ok = fps_off + len <= unsafe { FPS_CANVAS.canvas.len() };
let batch_len_ok = batch_off + len <= batch_row.len();
if fps_len_ok && batch_len_ok {
batch_row[batch_off..batch_off + len].copy_from_slice(unsafe {
&FPS_CANVAS.canvas[fps_off..fps_off + len]
});
}
}
}
}
}
} }
} }
@@ -234,25 +167,9 @@ impl<'a> AtomicFrameBuffer<'a> {
DELAY: DelayNs, DELAY: DelayNs,
{ {
if self.should_full_draw() { if self.should_full_draw() {
#[cfg(feature = "fps")]
self.draw_fps_into_fb();
return self.draw(display).await; return self.draw(display).await;
} }
#[cfg(feature = "fps")]
{
let fps_tile_x = FPS_CANVAS_X / TILE_SIZE;
let fps_tile_y = FPS_CANVAS_Y / TILE_SIZE;
let fps_tile_w = (FPS_CANVAS_WIDTH + TILE_SIZE - 1) / TILE_SIZE;
let fps_tile_h = (FPS_CANVAS_HEIGHT + TILE_SIZE - 1) / TILE_SIZE;
for ty in fps_tile_y..fps_tile_y + fps_tile_h {
for tx in fps_tile_x..fps_tile_x + fps_tile_w {
self.dirty_tiles[ty * NUM_TILE_COLS + tx].store(true, Ordering::Release);
}
}
}
for tile_row in 0..NUM_TILE_ROWS { for tile_row in 0..NUM_TILE_ROWS {
let row_start_idx = tile_row * NUM_TILE_COLS; let row_start_idx = tile_row * NUM_TILE_COLS;
let mut col = 0; let mut col = 0;
@@ -299,11 +216,6 @@ impl<'a> AtomicFrameBuffer<'a> {
} }
} }
#[cfg(feature = "fps")]
unsafe {
crate::display::FPS_COUNTER.measure()
}
Ok(()) Ok(())
} }
} }
@@ -429,146 +341,3 @@ impl<'a> OriginDimensions for AtomicFrameBuffer<'a> {
Size::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32) Size::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32)
} }
} }
#[cfg(feature = "fps")]
pub mod fps {
use crate::display::SCREEN_WIDTH;
use core::fmt::Write;
use embassy_time::{Duration, Instant};
use embedded_graphics::{
Drawable, Pixel,
draw_target::DrawTarget,
geometry::Point,
mono_font::{MonoTextStyle, ascii::FONT_8X13},
pixelcolor::Rgb565,
prelude::{IntoStorage, OriginDimensions, RgbColor, Size},
text::{Alignment, Text},
};
pub static mut FPS_COUNTER: FpsCounter = FpsCounter::new();
pub static mut FPS_CANVAS: FpsCanvas = FpsCanvas::new();
// "FPS: 120" = 8 len
const FPS_LEN: usize = 8;
pub const FPS_CANVAS_WIDTH: usize = (FONT_8X13.character_size.width + 4) as usize * FPS_LEN;
pub const FPS_CANVAS_HEIGHT: usize = FONT_8X13.character_size.height as usize;
// puts canvas in the top right of the display
// top left point of canvas
pub const FPS_CANVAS_X: usize = SCREEN_WIDTH - FPS_CANVAS_WIDTH;
pub const FPS_CANVAS_Y: usize = 0;
pub struct FpsCanvas {
pub canvas: [u16; FPS_CANVAS_HEIGHT * FPS_CANVAS_WIDTH],
}
impl FpsCanvas {
const fn new() -> Self {
Self {
canvas: [0; FPS_CANVAS_HEIGHT * FPS_CANVAS_WIDTH],
}
}
fn clear(&mut self) {
for p in &mut self.canvas {
*p = 0;
}
}
pub async fn draw_fps(&mut self) {
let mut buf: heapless::String<FPS_LEN> = heapless::String::new();
let fps = unsafe { FPS_COUNTER.smoothed };
let _ = write!(buf, "FPS: {}", fps as u8);
self.clear();
let text_style = MonoTextStyle::new(&FONT_8X13, Rgb565::WHITE);
Text::with_alignment(
buf.as_str(),
Point::new(
FPS_CANVAS_WIDTH as i32 / 2,
(FPS_CANVAS_HEIGHT as i32 + 8) / 2,
),
text_style,
Alignment::Center,
)
.draw(self)
.unwrap();
}
}
impl DrawTarget for FpsCanvas {
type Error = ();
type Color = Rgb565;
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where
I: IntoIterator<Item = Pixel<Self::Color>>,
{
for Pixel(point, color) in pixels {
if point.x < 0
|| point.x >= FPS_CANVAS_WIDTH as i32
|| point.y < 0
|| point.y >= FPS_CANVAS_HEIGHT as i32
{
continue;
}
let index = (point.y as usize) * FPS_CANVAS_WIDTH + point.x as usize;
self.canvas[index] = color.into_storage();
}
Ok(())
}
}
impl OriginDimensions for FpsCanvas {
fn size(&self) -> Size {
Size::new(FPS_CANVAS_WIDTH as u32, FPS_CANVAS_HEIGHT as u32)
}
}
pub struct FpsCounter {
last_frame: Option<Instant>,
smoothed: f32,
last_draw: Option<Instant>,
}
impl FpsCounter {
pub const fn new() -> Self {
Self {
last_frame: None,
smoothed: 0.0,
last_draw: None,
}
}
// Is called once per frame or partial frame to update FPS
pub fn measure(&mut self) {
let now = Instant::now();
if let Some(last) = self.last_frame {
let dt_us = (now - last).as_micros() as f32;
if dt_us > 0.0 {
let current = 1_000_000.0 / dt_us;
self.smoothed = if self.smoothed == 0.0 {
current
} else {
0.9 * self.smoothed + 0.1 * current
};
}
}
self.last_frame = Some(now);
}
pub fn should_draw(&mut self) -> bool {
let now = Instant::now();
match self.last_draw {
Some(last) if now - last < Duration::from_millis(200) => false,
_ => {
self.last_draw = Some(now);
true
}
}
}
}
}
+62 -138
View File
@@ -9,57 +9,48 @@
extern crate alloc; extern crate alloc;
mod abi; mod abi;
mod audio;
mod display; mod display;
mod elf; mod elf;
mod framebuffer; mod framebuffer;
#[allow(unused)]
mod heap;
mod peripherals; mod peripherals;
#[allow(unused)]
mod psram;
mod scsi; mod scsi;
mod storage; mod storage;
mod ui; mod ui;
mod usb; mod usb;
mod utils; mod utils;
#[cfg(feature = "psram")] #[cfg(feature = "pimoroni2w")]
#[allow(unused)] use crate::{heap::HEAP, heap::init_qmi_psram_heap, psram::init_psram_qmi};
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::{ use crate::{
abi::{KEY_CACHE, MS_SINCE_LAUNCH}, abi::{KEY_CACHE, MS_SINCE_LAUNCH},
audio::audio_handler, display::{display_handler, init_display},
display::{FRAMEBUFFER, display_handler, init_display}, elf::load_binary,
peripherals::{ peripherals::{
conf_peripherals, conf_peripherals,
keyboard::{KeyState, read_keyboard_fifo}, keyboard::{KeyState, read_keyboard_fifo},
}, },
scsi::MSC_SHUTDOWN, psram::init_psram,
storage::{SDCARD, SdCard}, storage::{SDCARD, SdCard},
ui::{SELECTIONS, clear_selection, ui_handler}, ui::{clear_screen, ui_handler},
usb::usb_handler,
}; };
use abi_sys::EntryFn;
use bumpalo::Bump;
use core::sync::atomic::{AtomicBool, Ordering};
use embassy_executor::{Executor, Spawner}; use embassy_executor::{Executor, Spawner};
use embassy_futures::{join::join, select::select};
use embassy_rp::{ use embassy_rp::{
Peri, Peri,
clocks::ClockConfig,
config::Config,
gpio::{Input, Level, Output, Pull}, gpio::{Input, Level, Output, Pull},
i2c::{self, I2c}, i2c::{self, I2c},
multicore::{Stack, spawn_core1}, multicore::{Stack, spawn_core1},
peripherals::{ peripherals::{
DMA_CH0, DMA_CH1, DMA_CH3, DMA_CH4, I2C1, PIN_2, PIN_3, PIN_6, PIN_7, PIN_10, PIN_11, DMA_CH0, DMA_CH1, DMA_CH3, DMA_CH4, I2C1, PIN_2, PIN_3, PIN_6, PIN_7, PIN_10, PIN_11,
PIN_12, PIN_13, PIN_14, PIN_15, PIN_16, PIN_17, PIN_18, PIN_19, PIN_20, PIN_21, PIN_22, PIN_12, PIN_13, PIN_14, PIN_15, PIN_16, PIN_17, PIN_18, PIN_19, PIN_20, PIN_21, PIN_22,
PIN_26, PIN_27, PIO0, SPI0, SPI1, USB, WATCHDOG, PIO0, SPI0, SPI1, USB, WATCHDOG,
}, },
pio::{self, Common, Pio, StateMachine}, pio,
spi::{self, Spi}, spi::{self, Spi},
usb as embassy_rp_usb, usb as embassy_rp_usb,
watchdog::{ResetReason, Watchdog}, watchdog::{ResetReason, Watchdog},
@@ -68,12 +59,8 @@ use embassy_sync::{
blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel, signal::Signal, blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel, signal::Signal,
}; };
use embassy_time::{Delay, Duration, Instant, Ticker, Timer}; use embassy_time::{Delay, Duration, Instant, Ticker, Timer};
use embedded_graphics::{
pixelcolor::Rgb565,
prelude::{DrawTarget, RgbColor},
};
use embedded_hal_bus::spi::ExclusiveDevice; use embedded_hal_bus::spi::ExclusiveDevice;
use embedded_sdmmc::SdCard as SdmmcSdCard; use embedded_sdmmc::{SdCard as SdmmcSdCard, ShortFileName};
use static_cell::StaticCell; use static_cell::StaticCell;
use talc::*; use talc::*;
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
@@ -118,20 +105,9 @@ async fn watchdog_task(mut watchdog: Watchdog) {
} }
} }
static ENABLE_UI: AtomicBool = AtomicBool::new(true);
static UI_CHANGE: Signal<CriticalSectionRawMutex, ()> = Signal::new();
const OVERCLOCK: u32 = 300_000_000;
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = if cfg!(feature = "overclock") { let p = embassy_rp::init(Default::default());
let clocks = ClockConfig::system_freq(OVERCLOCK).unwrap();
let config = Config::new(clocks);
embassy_rp::init(config)
} else {
embassy_rp::init(Default::default())
};
spawn_core1( spawn_core1(
p.CORE1, p.CORE1,
@@ -153,19 +129,6 @@ async fn main(_spawner: Spawner) {
data: p.PIN_14, data: p.PIN_14,
reset: p.PIN_15, reset: p.PIN_15,
}; };
let Pio {
common, sm0, sm1, ..
} = Pio::new(p.PIO0, Irqs);
let audio = Audio {
pio: common,
sm0,
dma0: p.DMA_CH3,
left: p.PIN_26,
sm1,
dma1: p.DMA_CH4,
right: p.PIN_27,
};
let sd = Sd { let sd = Sd {
spi: p.SPI0, spi: p.SPI0,
clk: p.PIN_18, clk: p.PIN_18,
@@ -174,15 +137,15 @@ async fn main(_spawner: Spawner) {
cs: p.PIN_17, cs: p.PIN_17,
det: p.PIN_22, det: p.PIN_22,
}; };
// let psram = Psram { let psram = Psram {
// pio: p.PIO0, pio: p.PIO0,
// sclk: p.PIN_21, sclk: p.PIN_21,
// mosi: p.PIN_2, mosi: p.PIN_2,
// miso: p.PIN_3, miso: p.PIN_3,
// cs: p.PIN_20, cs: p.PIN_20,
// dma1: p.DMA_CH3, dma1: p.DMA_CH3,
// dma2: p.DMA_CH4, dma2: p.DMA_CH4,
// }; };
let mcu = Mcu { let mcu = Mcu {
i2c: p.I2C1, i2c: p.I2C1,
clk: p.PIN_7, clk: p.PIN_7,
@@ -192,46 +155,32 @@ async fn main(_spawner: Spawner) {
executor0.run(|spawner| { executor0.run(|spawner| {
spawner spawner
.spawn(kernel_task( .spawn(kernel_task(
spawner, p.WATCHDOG, display, audio, sd, mcu, p.USB, spawner, p.WATCHDOG, display, sd, psram, mcu, p.USB,
)) ))
.unwrap() .unwrap()
}); });
} }
// One-slot channel to pass EntryFn from core1 // One-slot channel to pass EntryFn from core1
static BINARY_CH: Channel<CriticalSectionRawMutex, (EntryFn, Bump), 1> = Channel::new(); static BINARY_CH: Channel<CriticalSectionRawMutex, ShortFileName, 1> = Channel::new();
// runs dynamically loaded elf files // runs dynamically loaded elf files
#[embassy_executor::task] #[embassy_executor::task]
async fn userland_task() { async fn userland_task() {
let recv = BINARY_CH.receiver(); let recv = BINARY_CH.receiver();
loop { loop {
let (entry, _bump) = recv.receive().await; let name = recv.receive().await;
let (entry, _bump) = unsafe { load_binary(&name).await.expect("unable to load binary") };
// disable kernel ui clear_screen().await;
{
ENABLE_UI.store(false, Ordering::Release);
UI_CHANGE.signal(());
clear_selection().await;
MSC_SHUTDOWN.signal(());
}
unsafe { MS_SINCE_LAUNCH = Some(Instant::now()) }; unsafe { MS_SINCE_LAUNCH = Some(Instant::now()) };
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
defmt::info!("Executing Binary"); defmt::info!("Executing Binary");
entry(); entry();
// enable kernel ui STOP_KEY_HANDLER.signal(());
{ clear_screen().await;
ENABLE_UI.store(true, Ordering::Release);
UI_CHANGE.signal(());
unsafe { FRAMEBUFFER.as_mut().unwrap().clear(Rgb565::BLACK).unwrap() };
let mut selections = SELECTIONS.lock().await;
selections.set_changed(true);
}
} }
} }
@@ -246,15 +195,6 @@ struct Display {
data: Peri<'static, PIN_14>, data: Peri<'static, PIN_14>,
reset: Peri<'static, PIN_15>, reset: Peri<'static, PIN_15>,
} }
struct Audio {
pio: Common<'static, PIO0>,
dma0: Peri<'static, DMA_CH3>,
sm0: StateMachine<'static, PIO0, 0>,
left: Peri<'static, PIN_26>,
dma1: Peri<'static, DMA_CH4>,
sm1: StateMachine<'static, PIO0, 1>,
right: Peri<'static, PIN_27>,
}
struct Sd { struct Sd {
spi: Peri<'static, SPI0>, spi: Peri<'static, SPI0>,
clk: Peri<'static, PIN_18>, clk: Peri<'static, PIN_18>,
@@ -289,7 +229,7 @@ async fn setup_mcu(mcu: Mcu) {
async fn setup_display(display: Display, spawner: Spawner) { async fn setup_display(display: Display, spawner: Spawner) {
let mut config = spi::Config::default(); let mut config = spi::Config::default();
config.frequency = 192_000_000; config.frequency = 64_000_000;
let spi = Spi::new( let spi = Spi::new(
display.spi, display.spi,
display.clk, display.clk,
@@ -305,22 +245,23 @@ async fn setup_display(display: Display, spawner: Spawner) {
// psram is kind of useless on the pico calc // psram is kind of useless on the pico calc
// ive opted to use the pimoroni with on onboard xip psram instead // ive opted to use the pimoroni with on onboard xip psram instead
// async fn setup_psram(psram: Psram) { #[allow(unused)]
// let psram = init_psram( async fn setup_psram(psram: Psram) {
// psram.pio, psram.sclk, psram.mosi, psram.miso, psram.cs, psram.dma1, psram.dma2, let psram = init_psram(
// ) psram.pio, psram.sclk, psram.mosi, psram.miso, psram.cs, psram.dma1, psram.dma2,
// .await; )
.await;
// #[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
// defmt::info!("psram size: {}", psram.size); defmt::info!("psram size: {}", psram.size);
// if psram.size == 0 { if psram.size == 0 {
// #[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
// defmt::info!("\u{1b}[1mExternal PSRAM was NOT found!\u{1b}[0m"); defmt::info!("\u{1b}[1mExternal PSRAM was NOT found!\u{1b}[0m");
// } }
// } }
#[cfg(feature = "psram")] #[cfg(feature = "pimoroni2w")]
async fn setup_qmi_psram() { async fn setup_qmi_psram() {
Timer::after_millis(250).await; Timer::after_millis(250).await;
let psram_qmi_size = init_psram_qmi(&embassy_rp::pac::QMI, &embassy_rp::pac::XIP_CTRL); let psram_qmi_size = init_psram_qmi(&embassy_rp::pac::QMI, &embassy_rp::pac::XIP_CTRL);
@@ -346,7 +287,7 @@ async fn setup_sd(sd: Sd) {
let device = ExclusiveDevice::new(spi, cs, Delay).unwrap(); let device = ExclusiveDevice::new(spi, cs, Delay).unwrap();
let sdcard = SdmmcSdCard::new(device, Delay); let sdcard = SdmmcSdCard::new(device, Delay);
config.frequency = 32_000_000; config.frequency = 64_000_000;
sdcard.spi(|dev| dev.bus_mut().set_config(&config)); sdcard.spi(|dev| dev.bus_mut().set_config(&config));
SDCARD.get().lock().await.replace(SdCard::new(sdcard, det)); SDCARD.get().lock().await.replace(SdCard::new(sdcard, det));
} }
@@ -356,9 +297,8 @@ async fn kernel_task(
spawner: Spawner, spawner: Spawner,
watchdog: Peri<'static, WATCHDOG>, watchdog: Peri<'static, WATCHDOG>,
display: Display, display: Display,
audio: Audio,
sd: Sd, sd: Sd,
// _psram: Psram, _psram: Psram,
mcu: Mcu, mcu: Mcu,
usb: Peri<'static, USB>, usb: Peri<'static, USB>,
) { ) {
@@ -366,64 +306,48 @@ async fn kernel_task(
.spawn(watchdog_task(Watchdog::new(watchdog))) .spawn(watchdog_task(Watchdog::new(watchdog)))
.unwrap(); .unwrap();
#[cfg(feature = "debug")]
defmt::info!("Clock: {}", embassy_rp::clocks::clk_sys_freq());
setup_mcu(mcu).await; setup_mcu(mcu).await;
#[cfg(feature = "defmt")]
defmt::info!("setting up psram"); defmt::info!("setting up psram");
Timer::after_millis(100).await; Timer::after_millis(100).await;
// setup_psram(psram).await; // setup_psram(psram).await;
#[cfg(feature = "psram")] #[cfg(feature = "pimoroni2w")]
setup_qmi_psram().await; setup_qmi_psram().await;
Timer::after_millis(100).await; Timer::after_millis(100).await;
setup_display(display, spawner).await; setup_display(display, spawner).await;
setup_sd(sd).await; setup_sd(sd).await;
spawner.spawn(audio_handler(audio)).unwrap(); let usb_driver = embassy_rp_usb::Driver::new(usb, Irqs);
spawner.spawn(usb_handler(usb_driver)).unwrap();
let _usb = embassy_rp_usb::Driver::new(usb, Irqs);
// spawner.spawn(usb_handler(usb)).unwrap();
let mut ui_enabled = true;
loop { loop {
let ui_enabled = ENABLE_UI.load(Ordering::Relaxed);
if ui_enabled { if ui_enabled {
select(join(ui_handler(), prog_search_handler()), UI_CHANGE.wait()).await; ui_handler().await;
} else { } else {
select(key_handler(), UI_CHANGE.wait()).await; key_handler().await;
} }
ui_enabled ^= true // flip bool
} }
} }
async fn prog_search_handler() { static STOP_KEY_HANDLER: Signal<CriticalSectionRawMutex, ()> = Signal::new();
loop {
{
let mut guard = SDCARD.get().lock().await;
let sd = guard.as_mut().unwrap();
let mut files = sd.list_files_by_extension(".bin").unwrap();
files.sort();
let mut select = SELECTIONS.lock().await;
if *select.selections() != files {
select.update_selections(files);
select.reset();
}
}
Timer::after_secs(5).await;
}
}
async fn key_handler() { async fn key_handler() {
loop { loop {
if STOP_KEY_HANDLER.try_take().is_some() {
break;
}
if let Some(event) = read_keyboard_fifo().await { if let Some(event) = read_keyboard_fifo().await {
if let KeyState::Pressed = event.state {
unsafe { unsafe {
let _ = KEY_CACHE.enqueue(event); let _ = KEY_CACHE.enqueue(event);
} }
} }
}
Timer::after_millis(50).await; Timer::after_millis(50).await;
} }
} }
+100
View File
@@ -0,0 +1,100 @@
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Clone, Copy, Debug)]
pub struct ScsiSense {
pub key: u8,
pub asc: u8,
pub ascq: u8,
}
impl ScsiSense {
pub const fn new(key: u8, asc: u8, ascq: u8) -> Self {
Self { key, asc, ascq }
}
// --- Sense Key constants ---
pub const KEY_NO_SENSE: u8 = 0x00;
pub const KEY_RECOVERED_ERROR: u8 = 0x01;
pub const KEY_NOT_READY: u8 = 0x02;
pub const KEY_MEDIUM_ERROR: u8 = 0x03;
pub const KEY_HARDWARE_ERROR: u8 = 0x04;
pub const KEY_ILLEGAL_REQUEST: u8 = 0x05;
pub const KEY_UNIT_ATTENTION: u8 = 0x06;
pub const KEY_DATA_PROTECT: u8 = 0x07;
pub const KEY_BLANK_CHECK: u8 = 0x08;
pub const KEY_VENDOR_SPECIFIC: u8 = 0x09;
pub const KEY_COPY_ABORTED: u8 = 0x0A;
pub const KEY_ABORTED_COMMAND: u8 = 0x0B;
pub const KEY_VOLUME_OVERFLOW: u8 = 0x0D;
pub const KEY_MISCOMPARE: u8 = 0x0E;
// --- Common ASC/ASCQ pairs (subset of most-used codes) ---
pub const ASC_NO_ADDITIONAL_SENSE: u8 = 0x00;
// Medium errors
pub const ASC_UNRECOVERED_READ_ERROR: u8 = 0x11;
pub const ASCQ_UNRECOVERED_READ_ERROR: u8 = 0x00;
pub const ASC_UNRECOVERED_WRITE_ERROR: u8 = 0x03;
pub const ASCQ_UNRECOVERED_WRITE_ERROR: u8 = 0x01;
pub const ASC_WRITE_FAULT: u8 = 0x03;
pub const ASC_ID_CRC_ERROR: u8 = 0x10;
// Illegal requests
pub const ASC_INVALID_COMMAND_OPERATION_CODE: u8 = 0x20;
pub const ASC_LBA_OUT_OF_RANGE: u8 = 0x21;
pub const ASC_INVALID_FIELD_IN_CDB: u8 = 0x24;
// Not ready
pub const ASC_LOGICAL_UNIT_NOT_READY: u8 = 0x04;
pub const ASC_MEDIUM_NOT_PRESENT: u8 = 0x3A;
// Unit attention
pub const ASC_POWER_ON_RESET_OCCURRED: u8 = 0x29;
pub const ASC_MEDIUM_CHANGED: u8 = 0x28;
// Data protect
pub const ASC_WRITE_PROTECTED: u8 = 0x27;
// Aborted command
pub const ASC_COMMAND_ABORTED: u8 = 0x47;
// --- Helpers for common conditions ---
pub const fn no_sense() -> Self {
Self::new(Self::KEY_NO_SENSE, Self::ASC_NO_ADDITIONAL_SENSE, 0x00)
}
pub const fn invalid_cdb() -> Self {
Self::new(
Self::KEY_ILLEGAL_REQUEST,
Self::ASC_INVALID_FIELD_IN_CDB,
0x00,
)
}
pub const fn lba_out_of_range() -> Self {
Self::new(Self::KEY_ILLEGAL_REQUEST, Self::ASC_LBA_OUT_OF_RANGE, 0x00)
}
pub const fn medium_not_present() -> Self {
Self::new(Self::KEY_NOT_READY, Self::ASC_MEDIUM_NOT_PRESENT, 0x00)
}
pub const fn unrecovered_read_error() -> Self {
Self::new(
Self::KEY_MEDIUM_ERROR,
Self::ASC_UNRECOVERED_READ_ERROR,
Self::ASCQ_UNRECOVERED_READ_ERROR,
)
}
pub const fn unrecovered_write_error() -> Self {
Self::new(
Self::KEY_MEDIUM_ERROR,
Self::ASC_UNRECOVERED_WRITE_ERROR,
Self::ASCQ_UNRECOVERED_WRITE_ERROR,
)
}
pub const fn write_protected() -> Self {
Self::new(Self::KEY_DATA_PROTECT, Self::ASC_WRITE_PROTECTED, 0x00)
}
}
+189 -84
View File
@@ -1,7 +1,6 @@
use embassy_futures::select::select; use crate::storage::{SDCARD, SdCard};
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use core::sync::atomic::{AtomicBool, Ordering};
use embassy_sync::lazy_lock::LazyLock; use embassy_time::Timer;
use embassy_sync::signal::Signal;
use embassy_usb::Builder; use embassy_usb::Builder;
use embassy_usb::driver::{Driver, EndpointIn, EndpointOut}; use embassy_usb::driver::{Driver, EndpointIn, EndpointOut};
use embedded_sdmmc::{Block, BlockIdx}; use embedded_sdmmc::{Block, BlockIdx};
@@ -9,29 +8,32 @@ use heapless::Vec;
mod scsi_types; mod scsi_types;
use scsi_types::*; use scsi_types::*;
#[allow(unused)]
use crate::storage::{SDCARD, SdCard}; mod error;
use error::ScsiSense;
const BULK_ENDPOINT_PACKET_SIZE: usize = 64; const BULK_ENDPOINT_PACKET_SIZE: usize = 64;
pub static MSC_SHUTDOWN: Signal<CriticalSectionRawMutex, ()> = Signal::new(); // indicates that a scsi transaction is occurring and is
// NOT safe to disable usb, or acquire sdcard
pub static SCSI_BUSY: AtomicBool = AtomicBool::new(false);
// number of blocks to read from sd at once // stop scsi and return sdcard when safe to do so
// higher is better, but is larger. Size is BLOCKS * 512 bytes pub static SCSI_HALT: AtomicBool = AtomicBool::new(false);
const BLOCKS: usize = 32;
static mut BLOCK_BUF: LazyLock<[Block; BLOCKS]> = pub static SCSI_EJECTED: AtomicBool = AtomicBool::new(false);
LazyLock::new(|| core::array::from_fn(|_| Block::new()));
pub struct MassStorageClass<'d, D: Driver<'d>> { pub struct MassStorageClass<'d, D: Driver<'d>> {
temp_sd: Option<SdCard>, // temporary owns sdcard when scsi is running temp_sd: Option<SdCard>, // temporary owns sdcard when scsi is running
ejected: bool,
pending_eject: bool,
bulk_out: D::EndpointOut, bulk_out: D::EndpointOut,
bulk_in: D::EndpointIn, bulk_in: D::EndpointIn,
last_sense: ScsiSense,
prevent_removal: bool,
pending_eject: bool,
} }
impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> { impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
pub fn new(builder: &mut Builder<'d, D>, temp_sd: Option<SdCard>) -> Self { pub fn new(builder: &mut Builder<'d, D>) -> Self {
let mut function = builder.function(0x08, SUBCLASS_SCSI, 0x50); // Mass Storage class let mut function = builder.function(0x08, SUBCLASS_SCSI, 0x50); // Mass Storage class
let mut interface = function.interface(); let mut interface = function.interface();
let mut alt = interface.alt_setting(0x08, SUBCLASS_SCSI, 0x50, None); let mut alt = interface.alt_setting(0x08, SUBCLASS_SCSI, 0x50, None);
@@ -40,32 +42,56 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
let bulk_in = alt.endpoint_bulk_in(None, BULK_ENDPOINT_PACKET_SIZE as u16); let bulk_in = alt.endpoint_bulk_in(None, BULK_ENDPOINT_PACKET_SIZE as u16);
Self { Self {
temp_sd, temp_sd: None,
pending_eject: false,
ejected: false,
bulk_out, bulk_out,
bulk_in, bulk_in,
last_sense: ScsiSense::no_sense(),
prevent_removal: false,
pending_eject: false,
}
}
// Take sdcard to increase speed
pub async fn take_sdcard(&mut self) {
if self.temp_sd.is_none() {
let mut guard = SDCARD.get().lock().await;
if let Some(sd) = guard.take() {
self.temp_sd = Some(sd);
} else {
panic!("Tried to take SDCARD but it was already taken");
}
}
}
// return sdcard to global, so other tasks can use it
pub async fn return_sdcard(&mut self) {
if let Some(card) = self.temp_sd.take() {
let mut guard = SDCARD.get().lock().await;
*guard = Some(card);
} }
} }
pub async fn poll(&mut self) { pub async fn poll(&mut self) {
loop { loop {
if !self.ejected { if !self.prevent_removal && (SCSI_HALT.load(Ordering::Acquire) || self.pending_eject) {
select(self.handle_cbw(), MSC_SHUTDOWN.wait()).await;
if MSC_SHUTDOWN.signaled() {
#[cfg(feature = "defmt")]
defmt::info!("MSC shutting down");
if self.temp_sd.is_some() { if self.temp_sd.is_some() {
let mut guard = SDCARD.get().lock().await; self.return_sdcard().await;
guard.replace(self.temp_sd.take().unwrap()).unwrap(); SCSI_BUSY.store(false, Ordering::Release);
self.pending_eject = false;
}
} else {
self.handle_cbw().await;
} }
self.ejected = true; if SCSI_EJECTED.load(Ordering::Acquire) {
Timer::after_millis(100).await;
return; continue;
} }
if SCSI_BUSY.load(Ordering::Relaxed) {
Timer::after_millis(1).await;
} else {
Timer::after_millis(100).await;
} }
} }
} }
@@ -75,31 +101,19 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
if let Ok(n) = self.bulk_out.read(&mut cbw_buf).await { if let Ok(n) = self.bulk_out.read(&mut cbw_buf).await {
if n == 31 { if n == 31 {
if let Some(cbw) = CommandBlockWrapper::parse(&cbw_buf[..n]) { if let Some(cbw) = CommandBlockWrapper::parse(&cbw_buf[..n]) {
// Take sdcard to increase speed
if self.temp_sd.is_none() {
let mut guard = SDCARD.get().lock().await;
if let Some(sd) = guard.take() {
self.temp_sd = Some(sd);
} else {
#[cfg(feature = "defmt")]
defmt::warn!("Tried to take SDCARD but it was already taken");
return;
}
}
let command = parse_cb(&cbw.CBWCB); let command = parse_cb(&cbw.CBWCB);
if self.handle_command(command).await.is_ok() { if self.handle_command(command).await.is_ok() {
self.send_csw_success(cbw.dCBWTag).await self.send_csw_success(cbw.dCBWTag).await
} else { } else {
self.send_csw_fail(cbw.dCBWTag).await self.send_csw_fail(cbw.dCBWTag).await
} }
} else {
if self.pending_eject { self.last_sense = ScsiSense::invalid_cdb();
if let ScsiCommand::Write { lba: _, len: _ } = command { self.send_csw_fail(0).await;
MSC_SHUTDOWN.signal(());
}
}
} }
} else {
self.last_sense = ScsiSense::invalid_cdb();
self.send_csw_fail(0).await;
} }
} }
} }
@@ -107,6 +121,12 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
async fn handle_command(&mut self, command: ScsiCommand) -> Result<(), ()> { async fn handle_command(&mut self, command: ScsiCommand) -> Result<(), ()> {
let mut response: Vec<u8, BULK_ENDPOINT_PACKET_SIZE> = Vec::new(); let mut response: Vec<u8, BULK_ENDPOINT_PACKET_SIZE> = Vec::new();
const BLOCK_SIZE: usize = 512;
// number of blocks to read from sd at once
// higher is better, but is larger. Size is BLOCKS * 512 bytes
const BLOCKS: usize = 10;
let mut block_buf: [Block; BLOCKS] = core::array::from_fn(|_| Block::new());
match command { match command {
ScsiCommand::Unknown => Err(()), ScsiCommand::Unknown => Err(()),
ScsiCommand::Inquiry { ScsiCommand::Inquiry {
@@ -186,16 +206,41 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
self.bulk_in.write(&response[..len]).await.map_err(|_| ()) self.bulk_in.write(&response[..len]).await.map_err(|_| ())
} }
ScsiCommand::TestUnitReady => { ScsiCommand::TestUnitReady => {
if self.temp_sd.as_ref().unwrap().is_attached() { if !SCSI_EJECTED.load(Ordering::Acquire) && self.temp_sd.is_none() {
SCSI_BUSY.store(true, Ordering::Release);
self.take_sdcard().await;
}
match &self.temp_sd {
Some(sd) => {
if sd.is_attached() {
Ok(()) Ok(())
} else { } else {
self.last_sense = ScsiSense::medium_not_present();
Err(()) Err(())
} }
} }
ScsiCommand::RequestSense { None => {
desc: _, self.last_sense = ScsiSense::medium_not_present();
alloc_len: _, Err(())
} => Ok(()), }
}
}
ScsiCommand::RequestSense { desc: _, alloc_len } => {
// Prepare the buffer
let mut buf = [0u8; 18];
// Fixed format sense data
buf[0] = 0x70; // Response code, current errors
buf[2] = self.last_sense.key; // Sense Key
buf[7] = 0x0A; // Additional sense length (n-8)
buf[12] = self.last_sense.asc; // Additional Sense Code
buf[13] = self.last_sense.ascq; // Additional Sense Code Qualifier
let len = core::cmp::min(buf.len(), alloc_len as usize);
self.last_sense = ScsiSense::no_sense();
self.bulk_in.write(&buf[..len]).await.map_err(|_| ())
}
ScsiCommand::ModeSense6 { ScsiCommand::ModeSense6 {
dbd: _, dbd: _,
page_control: _, page_control: _,
@@ -234,55 +279,74 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
self.bulk_in.write(&response[..len]).await.map_err(|_| ()) self.bulk_in.write(&response[..len]).await.map_err(|_| ())
} }
ScsiCommand::ReadCapacity10 => { ScsiCommand::ReadCapacity10 => match self.temp_sd.as_ref() {
let block_size = SdCard::BLOCK_SIZE as u64; Some(sd) => {
let total_blocks = self.temp_sd.as_ref().unwrap().size() / block_size; let total_blocks = sd.size() / BLOCK_SIZE as u64;
let last_lba = total_blocks.checked_sub(1).unwrap_or(0); let last_lba = total_blocks.checked_sub(1).unwrap_or(0);
response.extend_from_slice(&(last_lba as u32).to_be_bytes())?; response.extend_from_slice(&(last_lba as u32).to_be_bytes())?;
response.extend_from_slice(&(block_size as u32).to_be_bytes())?; response.extend_from_slice(&(BLOCK_SIZE as u32).to_be_bytes())?;
self.bulk_in.write(&response).await.map_err(|_| ()) self.bulk_in.write(&response).await.map_err(|_| ())
} }
ScsiCommand::ReadCapacity16 { alloc_len } => { None => {
let block_size = SdCard::BLOCK_SIZE as u64; self.last_sense = ScsiSense::medium_not_present();
let total_blocks = self.temp_sd.as_ref().unwrap().size() / block_size; Err(())
}
},
ScsiCommand::ReadCapacity16 { alloc_len } => match self.temp_sd.as_ref() {
Some(sd) => {
let total_blocks = sd.size() / BLOCK_SIZE as u64;
let last_lba = total_blocks.checked_sub(1).unwrap_or(0); let last_lba = total_blocks.checked_sub(1).unwrap_or(0);
response.extend_from_slice(&last_lba.to_be_bytes())?; // 8 bytes last LBA response.extend_from_slice(&last_lba.to_be_bytes())?; // 8 bytes last LBA
response.extend_from_slice(&(block_size as u32).to_be_bytes())?; // 4 bytes block length response.extend_from_slice(&(BLOCK_SIZE as u32).to_be_bytes())?; // 4 bytes block length
response.extend_from_slice(&[0u8; 20])?; // 20 reserved bytes zeroed response.extend_from_slice(&[0u8; 20])?; // 20 reserved bytes zeroed
let len = alloc_len.min(response.len() as u32) as usize; let len = alloc_len.min(response.len() as u32) as usize;
self.bulk_in.write(&response[..len]).await.map_err(|_| ()) self.bulk_in.write(&response[..len]).await.map_err(|_| ())
} }
ScsiCommand::Read { lba, len } => { None => {
let sdcard = self.temp_sd.as_ref().unwrap(); self.last_sense = ScsiSense::medium_not_present();
let block_buf = unsafe { &mut *BLOCK_BUF.get_mut() }; Err(())
}
},
ScsiCommand::Read { lba, len } => match self.temp_sd.as_ref() {
Some(sd) => {
let mut blocks = len; let mut blocks = len;
let mut idx = lba; let mut idx = lba;
let mut error_occurred = false;
while blocks > 0 { while blocks > 0 {
if blocks >= block_buf.len() as u64 { if blocks >= block_buf.len() as u64 {
sdcard.read_blocks(block_buf, BlockIdx(idx as u32))?; sd.read_blocks(&mut block_buf, BlockIdx(idx as u32))?;
for block in &mut *block_buf { for block in &mut block_buf {
for chunk in block.contents.chunks(BULK_ENDPOINT_PACKET_SIZE.into()) { for chunk in block.contents.chunks(BULK_ENDPOINT_PACKET_SIZE.into())
self.bulk_in.write(chunk).await.map_err(|_| ())?; {
if self.bulk_in.write(chunk).await.map_err(|_| ()).is_err() {
error_occurred = true
}
} }
} }
blocks -= block_buf.len() as u64; blocks -= block_buf.len() as u64;
idx += block_buf.len() as u64; idx += block_buf.len() as u64;
} else { } else {
sdcard sd.read_blocks(
.read_blocks(&mut block_buf[..blocks as usize], BlockIdx(idx as u32))?; &mut block_buf[..blocks as usize],
BlockIdx(idx as u32),
)?;
for block in &block_buf[..blocks as usize] { for block in &block_buf[..blocks as usize] {
for chunk in block.contents.chunks(BULK_ENDPOINT_PACKET_SIZE.into()) { for chunk in block.contents.chunks(BULK_ENDPOINT_PACKET_SIZE.into())
self.bulk_in.write(chunk).await.map_err(|_| ())?; {
if self.bulk_in.write(chunk).await.map_err(|_| ()).is_err() {
error_occurred = true
}
} }
} }
@@ -290,36 +354,54 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
blocks = 0; blocks = 0;
} }
} }
if error_occurred {
self.last_sense = ScsiSense::unrecovered_read_error();
return Err(());
}
Ok(()) Ok(())
} }
ScsiCommand::Write { lba, len } => { None => {
let sdcard = self.temp_sd.as_ref().unwrap(); self.last_sense = ScsiSense::medium_not_present();
let block_buf = unsafe { &mut *BLOCK_BUF.get_mut() }; Err(())
}
},
ScsiCommand::Write { lba, len } => match self.temp_sd.as_ref() {
Some(sd) => {
let mut blocks = len; let mut blocks = len;
let mut idx = lba; let mut idx = lba;
let mut error_occurred = false;
while blocks > 0 { while blocks > 0 {
if blocks >= block_buf.len() as u64 { if blocks >= block_buf.len() as u64 {
for block in block_buf.as_mut() { for block in block_buf.as_mut() {
for chunk in block.contents.chunks_mut(BULK_ENDPOINT_PACKET_SIZE.into()) for chunk in
block.contents.chunks_mut(BULK_ENDPOINT_PACKET_SIZE.into())
{ {
self.bulk_out.read(chunk).await.map_err(|_| ())?; if self.bulk_out.read(chunk).await.map_err(|_| ()).is_err() {
error_occurred = true
}
} }
} }
sdcard.read_blocks(block_buf, BlockIdx(idx as u32))?; sd.read_blocks(&mut block_buf, BlockIdx(idx as u32))?;
blocks -= block_buf.len() as u64; blocks -= block_buf.len() as u64;
idx += block_buf.len() as u64; idx += block_buf.len() as u64;
} else { } else {
for block in block_buf[..blocks as usize].as_mut() { for block in block_buf[..blocks as usize].as_mut() {
for chunk in block.contents.chunks_mut(BULK_ENDPOINT_PACKET_SIZE.into()) for chunk in
block.contents.chunks_mut(BULK_ENDPOINT_PACKET_SIZE.into())
{ {
self.bulk_out.read(chunk).await.map_err(|_| ())?; if self.bulk_out.read(chunk).await.map_err(|_| ()).is_err() {
error_occurred = true
}
} }
} }
sdcard.write_blocks( sd.write_blocks(
&mut block_buf[..blocks as usize], &mut block_buf[..blocks as usize],
BlockIdx(idx as u32), BlockIdx(idx as u32),
)?; )?;
@@ -328,11 +410,23 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
blocks = 0; blocks = 0;
} }
} }
if error_occurred {
self.last_sense = ScsiSense::unrecovered_write_error();
return Err(());
}
Ok(()) Ok(())
} }
ScsiCommand::ReadFormatCapacities { alloc_len } => { None => {
self.last_sense = ScsiSense::medium_not_present();
Err(())
}
},
ScsiCommand::ReadFormatCapacities { alloc_len } => match self.temp_sd.as_ref() {
Some(sd) => {
let block_size = SdCard::BLOCK_SIZE as u32; let block_size = SdCard::BLOCK_SIZE as u32;
let num_blocks = (self.temp_sd.as_ref().unwrap().size() / block_size as u64) as u32; let num_blocks = (sd.size() / block_size as u64) as u32;
let mut response = [0u8; 12]; let mut response = [0u8; 12];
@@ -350,9 +444,18 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
.await .await
.map_err(|_| ()) .map_err(|_| ())
} }
ScsiCommand::PreventAllowMediumRemoval { prevent: _prevent } => Ok(()), None => {
self.last_sense = ScsiSense::medium_not_present();
Err(())
}
},
ScsiCommand::PreventAllowMediumRemoval { prevent } => {
self.prevent_removal = prevent;
Ok(())
}
ScsiCommand::StartStopUnit { start, load_eject } => { ScsiCommand::StartStopUnit { start, load_eject } => {
if !start && load_eject { if !start && load_eject {
SCSI_EJECTED.store(true, Ordering::Release);
self.pending_eject = true; self.pending_eject = true;
} }
Ok(()) Ok(())
@@ -366,7 +469,9 @@ impl<'d, 's, D: Driver<'d>> MassStorageClass<'d, D> {
pub async fn send_csw_fail(&mut self, tag: u32) { pub async fn send_csw_fail(&mut self, tag: u32) {
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
if tag != 0 {
defmt::error!("Command Failed: {}", tag); defmt::error!("Command Failed: {}", tag);
}
self.send_csw(tag, 0x01, 0).await; // 0x01 = Command Failed self.send_csw(tag, 0x01, 0).await; // 0x01 = Command Failed
} }
+1 -13
View File
@@ -35,24 +35,12 @@ impl TimeSource for DummyTimeSource {
} }
} }
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq)]
pub struct FileName { pub struct FileName {
pub long_name: String, pub long_name: String,
pub short_name: ShortFileName, pub short_name: ShortFileName,
} }
impl PartialOrd for FileName {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.long_name.cmp(&other.long_name))
}
}
impl Ord for FileName {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.long_name.cmp(&other.long_name)
}
}
pub struct SdCard { pub struct SdCard {
det: Input<'static>, det: Input<'static>,
volume_mgr: VolMgr, volume_mgr: VolMgr,
+181 -100
View File
@@ -1,18 +1,26 @@
use crate::{ use crate::{
BINARY_CH, display::FRAMEBUFFER, elf::load_binary, framebuffer::FB_PAUSED, BINARY_CH,
peripherals::keyboard, storage::FileName, display::FRAMEBUFFER,
framebuffer::FB_PAUSED,
peripherals::keyboard,
scsi::SCSI_BUSY,
storage::{FileName, SDCARD},
}; };
use abi_sys::keyboard::{KeyCode, KeyState}; use abi_sys::keyboard::{KeyCode, KeyState};
use alloc::{str::FromStr, string::String, vec::Vec}; use alloc::{str::FromStr, string::String, vec::Vec};
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex}; use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
use embassy_time::Timer;
use embedded_graphics::{ use embedded_graphics::{
Drawable, Drawable,
mono_font::{MonoTextStyle, ascii::FONT_10X20}, mono_font::{
MonoTextStyle,
ascii::{FONT_4X6, FONT_10X20},
},
pixelcolor::Rgb565, pixelcolor::Rgb565,
prelude::{Dimensions, Point, Primitive, RgbColor, Size}, prelude::{Dimensions, Point, Primitive, RgbColor, Size},
primitives::{PrimitiveStyle, Rectangle}, primitives::{PrimitiveStyle, Rectangle},
text::Text, text::{Alignment, Text},
}; };
use embedded_layout::{ use embedded_layout::{
align::{horizontal, vertical}, align::{horizontal, vertical},
@@ -21,61 +29,130 @@ use embedded_layout::{
}; };
use embedded_text::TextBox; use embedded_text::TextBox;
pub static SELECTIONS: Mutex<CriticalSectionRawMutex, SelectionList> =
Mutex::new(SelectionList::new());
pub async fn ui_handler() { pub async fn ui_handler() {
loop { let mut ui = UiState { page: UiPage::Menu };
if let Some(event) = keyboard::read_keyboard_fifo().await { let mut menu = MenuPage {
if let KeyState::Pressed = event.state { last_bounds: None,
match event.key { selection: 0,
KeyCode::Up => { changed: true,
let mut selections = SELECTIONS.lock().await;
selections.up();
}
KeyCode::Down => {
let mut selections = SELECTIONS.lock().await;
selections.down();
}
KeyCode::Enter | KeyCode::Right => {
let selections = SELECTIONS.lock().await;
let selection =
selections.selections[selections.current_selection as usize].clone();
let entry = unsafe {
load_binary(&selection.short_name)
.await
.expect("unable to load binary")
}; };
BINARY_CH.send(entry).await; let mut scsi = ScsiPage { last_bounds: None };
} update_selections().await;
_ => (),
} loop {
} // reset page, if usb was disabled internally
if ui.page == UiPage::Scsi && !SCSI_BUSY.load(Ordering::Acquire) {
scsi.clear().await;
ui.page = UiPage::Menu;
} else if ui.page == UiPage::Menu && SCSI_BUSY.load(Ordering::Acquire) {
menu.clear().await;
ui.page = UiPage::Scsi;
} }
let changed = SELECTIONS.lock().await.changed; if input_handler(&mut ui, &mut menu, &mut scsi).await {
if changed { return;
clear_selection().await;
draw_selection().await;
} }
match ui.page {
UiPage::Menu => menu.draw().await,
UiPage::Scsi => scsi.draw().await,
}
Timer::after_millis(5).await;
} }
} }
pub async fn clear_selection() { async fn input_handler(ui: &mut UiState, menu: &mut MenuPage, scsi: &mut ScsiPage) -> bool {
let sel = SELECTIONS.lock().await; if let Some(event) = keyboard::read_keyboard_fifo().await {
if event.state == KeyState::Pressed {
match (&mut ui.page, event.key) {
(UiPage::Menu, _) => return menu.handle_input(event.key).await,
(UiPage::Scsi, _) => return scsi.handle_input(event.key).await,
}
}
}
false
}
if let Some(area) = sel.last_bounds { #[derive(PartialEq)]
Rectangle::new(area.top_left, area.size) enum UiPage {
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK)) Menu,
.draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() }) Scsi,
.unwrap(); }
struct UiState {
page: UiPage,
}
trait Page {
async fn draw(&mut self);
async fn handle_input(&mut self, key: KeyCode) -> bool;
async fn clear(&mut self);
}
struct ScsiPage {
last_bounds: Option<Rectangle>,
}
impl Page for ScsiPage {
async fn draw(&mut self) {
let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
let fb = unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() };
let bounds = fb.bounding_box();
let text = Text::with_alignment(
"Usb Mass storage enabled",
bounds.center(),
text_style,
Alignment::Center,
);
self.last_bounds = Some(text.bounds());
text.draw(fb).unwrap();
}
async fn handle_input(&mut self, _key: KeyCode) -> bool {
false
}
async fn clear(&mut self) {
if let Some(rect) = self.last_bounds {
clear_rect(rect).await;
}
self.last_bounds = None;
} }
} }
async fn draw_selection() { static SELECTIONS: Mutex<CriticalSectionRawMutex, Vec<FileName>> = Mutex::new(Vec::new());
let mut guard = SELECTIONS.lock().await; static mut SELECTIONS_CHANGED: bool = true;
let file_names = guard.selections.clone();
async fn update_selections() {
while SCSI_BUSY.load(Ordering::Acquire) {
Timer::after_millis(100).await;
}
let mut guard = SDCARD.get().lock().await;
let sd = guard.as_mut().unwrap();
let files = sd.list_files_by_extension(".bin").unwrap();
let mut selections = SELECTIONS.lock().await;
if *selections != files {
*selections = files;
unsafe { SELECTIONS_CHANGED = true }
}
}
struct MenuPage {
last_bounds: Option<Rectangle>,
selection: usize,
changed: bool,
}
impl Page for MenuPage {
async fn draw(&mut self) {
if self.changed {
self.clear().await;
}
let guard = SELECTIONS.lock().await;
let file_names = &guard.clone();
let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE); let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
let display_area = unsafe { FRAMEBUFFER.as_mut().unwrap().bounding_box() }; let display_area = unsafe { FRAMEBUFFER.as_mut().unwrap().bounding_box() };
@@ -99,7 +176,7 @@ async fn draw_selection() {
} else { } else {
let mut views: alloc::vec::Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new(); let mut views: alloc::vec::Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new();
for i in &file_names { for i in file_names {
views.push(Text::new(&i.long_name, Point::zero(), text_style)); views.push(Text::new(&i.long_name, Point::zero(), text_style));
} }
@@ -114,7 +191,7 @@ async fn draw_selection() {
// draw selected box // draw selected box
let selected_bounds = layout let selected_bounds = layout
.inner() .inner()
.get(guard.current_selection as usize) .get(self.selection)
.expect("Selected binary missing") .expect("Selected binary missing")
.bounding_box(); .bounding_box();
Rectangle::new(selected_bounds.top_left, selected_bounds.size) Rectangle::new(selected_bounds.top_left, selected_bounds.size)
@@ -122,66 +199,70 @@ async fn draw_selection() {
.draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() }) .draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() })
.unwrap(); .unwrap();
guard.last_bounds = Some(layout.bounds()); self.last_bounds = Some(layout.bounds());
layout layout
.draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() }) .draw(unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() })
.unwrap(); .unwrap();
} }
guard.changed = false; self.changed = false;
FB_PAUSED.store(false, Ordering::Release); // ensure all elements show up at once FB_PAUSED.store(false, Ordering::Release); // ensure all elements show up at once
}
async fn handle_input(&mut self, key: KeyCode) -> bool {
match key {
KeyCode::Enter | KeyCode::Right => {
let selections = SELECTIONS.lock().await;
let selection = selections[self.selection].clone();
self.clear().await;
BINARY_CH.send(selection.short_name).await;
return true;
}
KeyCode::Up => {
if self.selection > 0 {
self.selection -= 1;
} else {
let len = SELECTIONS.lock().await.len();
if len > 0 {
self.selection = len - 1;
}
}
}
KeyCode::Down => {
if self.selection + 1 < SELECTIONS.lock().await.len() {
self.selection += 1;
} else {
self.selection = 0; // wrap to top
}
}
_ => (),
}
self.changed = true;
false
}
async fn clear(&mut self) {
if let Some(rect) = self.last_bounds {
clear_rect(rect).await;
}
self.last_bounds = None;
}
} }
#[derive(Clone)] pub async fn clear_screen() {
pub struct SelectionList { clear_rect(Rectangle {
// allows easy clearing of selection ui, top_left: Point::zero(),
// based on previous bounds size: Size::new(320, 320),
last_bounds: Option<Rectangle>, })
current_selection: u16, .await
selections: Vec<FileName>,
changed: bool,
} }
impl SelectionList { async fn clear_rect(rect: Rectangle) {
pub const fn new() -> Self { let fb = unsafe { &mut *FRAMEBUFFER.as_mut().unwrap() };
Self { Rectangle::new(rect.top_left, rect.size)
last_bounds: None, .into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
selections: Vec::new(), .draw(fb)
current_selection: 0, .unwrap();
changed: false,
}
}
pub fn set_changed(&mut self, changed: bool) {
self.changed = changed
}
pub fn update_selections(&mut self, selections: Vec<FileName>) {
self.selections = selections;
self.changed = true;
}
pub fn selections(&self) -> &Vec<FileName> {
&self.selections
}
pub fn reset(&mut self) {
self.current_selection = 0;
self.changed = true;
}
fn up(&mut self) {
if self.current_selection > 0 {
self.current_selection -= 1;
self.changed = true;
}
}
fn down(&mut self) {
if self.current_selection + 1 < self.selections.len() as u16 {
self.current_selection += 1;
self.changed = true;
}
}
} }
+13 -15
View File
@@ -1,10 +1,8 @@
use crate::{scsi::MassStorageClass, storage::SdCard}; use crate::scsi::{MassStorageClass, SCSI_EJECTED};
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::Ordering;
use embassy_futures::select::select; use embassy_futures::join::join;
use embassy_rp::{peripherals::USB, usb::Driver}; use embassy_rp::{peripherals::USB, usb::Driver};
use embassy_usb::{Builder, Config, UsbDevice}; use embassy_usb::{Builder, Config};
pub static USB_ACTIVE: AtomicBool = AtomicBool::new(false);
#[embassy_executor::task] #[embassy_executor::task]
pub async fn usb_handler(driver: Driver<'static, USB>) { pub async fn usb_handler(driver: Driver<'static, USB>) {
@@ -28,18 +26,18 @@ pub async fn usb_handler(driver: Driver<'static, USB>) {
&mut control_buf, &mut control_buf,
); );
let temp_sd: Option<SdCard> = None; let mut scsi = MassStorageClass::new(&mut builder);
let mut scsi = MassStorageClass::new(&mut builder, temp_sd); let mut usb = builder.build();
let usb = builder.build();
select(run(usb), scsi.poll()).await; join(
} async {
async fn run<'d>(mut usb: UsbDevice<'d, Driver<'d, USB>>) -> ! {
loop { loop {
usb.wait_resume().await; usb.wait_resume().await;
USB_ACTIVE.store(true, Ordering::Release); SCSI_EJECTED.store(false, Ordering::Release);
usb.run_until_suspend().await; usb.run_until_suspend().await;
USB_ACTIVE.store(false, Ordering::Release);
} }
},
scsi.poll(),
)
.await;
} }
Submodule picolibc deleted from d664643068.
+30 -59
View File
@@ -6,57 +6,50 @@ use abi::{
display::Display, display::Display,
get_key, get_key,
keyboard::{KeyCode, KeyState}, keyboard::{KeyCode, KeyState},
print, sleep,
}; };
use alloc::vec::Vec; use alloc::vec::Vec;
use embedded_graphics::{ use embedded_graphics::{
Drawable, Drawable,
mono_font::{MonoTextStyle, ascii::FONT_10X20}, mono_font::{MonoTextStyle, ascii::FONT_10X20},
pixelcolor::Rgb565, pixelcolor::Rgb565,
prelude::{Dimensions, DrawTarget, Point, Primitive, RgbColor}, prelude::{Dimensions, Point, Primitive, RgbColor, Size},
primitives::{PrimitiveStyle, Rectangle}, primitives::{PrimitiveStyle, Rectangle},
text::{Alignment, Text, renderer::TextRenderer}, text::Text,
}; };
use embedded_layout::{ use embedded_layout::{
align::{horizontal, vertical}, align::{horizontal, vertical},
layout::linear::{FixedMargin, LinearLayout}, layout::linear::{FixedMargin, LinearLayout},
prelude::*, prelude::*,
}; };
use embedded_text::TextBox;
#[derive(Debug)]
pub enum SelectionUiError<DisplayError> {
SelectionListEmpty,
DisplayError(DisplayError),
}
pub struct SelectionUi<'a> { pub struct SelectionUi<'a> {
selection: usize, selection: usize,
items: &'a [&'a str], items: &'a [&'a str],
error: &'a str,
last_bounds: Option<Rectangle>, last_bounds: Option<Rectangle>,
} }
impl<'a> SelectionUi<'a> { impl<'a> SelectionUi<'a> {
pub fn new(items: &'a [&'a str]) -> Self { pub fn new(items: &'a [&'a str], error: &'a str) -> Self {
Self { Self {
selection: 0, selection: 0,
items, items,
error,
last_bounds: None, last_bounds: None,
} }
} }
pub fn run_selection_ui( pub fn run_selection_ui(&mut self, display: &mut Display) -> Result<Option<usize>, ()> {
&mut self,
display: &mut Display,
) -> Result<Option<usize>, SelectionUiError<<Display as DrawTarget>::Error>> {
self.draw(display)?; self.draw(display)?;
let selection; let selection;
loop { loop {
let key = get_key(); let key = get_key();
if key.state == KeyState::Pressed { if key.state == KeyState::Pressed {
print!("Got Key press: {:?}", key.key);
if let Some(s) = self.update(display, key.key)? { if let Some(s) = self.update(display, key.key)? {
selection = Some(s); selection = Some(s);
display
.clear(Rgb565::BLACK)
.map_err(|e| SelectionUiError::DisplayError(e))?;
break; break;
} }
} }
@@ -66,41 +59,36 @@ impl<'a> SelectionUi<'a> {
/// updates the display with a new keypress. /// updates the display with a new keypress.
/// returns selection idx if selected /// returns selection idx if selected
pub fn update( pub fn update(&mut self, display: &mut Display, key: KeyCode) -> Result<Option<usize>, ()> {
&mut self,
display: &mut Display,
key: KeyCode,
) -> Result<Option<usize>, SelectionUiError<<Display as DrawTarget>::Error>> {
match key { match key {
KeyCode::Down => { KeyCode::JoyUp => {
self.selection = (self.selection + 1).min(self.items.len() - 1);
}
KeyCode::Up => {
self.selection = self.selection.saturating_sub(1); self.selection = self.selection.saturating_sub(1);
} }
KeyCode::Enter | KeyCode::Right => return Ok(Some(self.selection)), KeyCode::JoyDown => {
_ => return Ok(None), self.selection = self.selection.saturating_add(1);
}
KeyCode::Enter | KeyCode::JoyRight => return Ok(Some(self.selection)),
_ => return Ok(Some(self.selection)),
}; };
self.draw(display)?; self.draw(display)?;
Ok(None) Ok(None)
} }
fn draw( fn draw(&mut self, display: &mut Display) -> Result<(), ()> {
&mut self,
display: &mut Display,
) -> Result<(), SelectionUiError<<Display as DrawTarget>::Error>> {
let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE); let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
let display_area = display.bounding_box(); let display_area = display.bounding_box();
if self.items.is_empty() { if self.items.is_empty() {
return Err(SelectionUiError::SelectionListEmpty); TextBox::new(
} &self.error,
Rectangle::new(
if let Some(bounds) = self.last_bounds { Point::new(25, 25),
Rectangle::new(bounds.top_left, bounds.size) Size::new(display_area.size.width - 50, display_area.size.width - 50),
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK)) ),
text_style,
)
.draw(display) .draw(display)
.map_err(|e| SelectionUiError::DisplayError(e))?; .unwrap();
} }
let mut views: Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new(); let mut views: Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new();
@@ -117,32 +105,15 @@ impl<'a> SelectionUi<'a> {
.arrange() .arrange()
.align_to(&display_area, horizontal::Center, vertical::Center); .align_to(&display_area, horizontal::Center, vertical::Center);
layout
.draw(display)
.map_err(|e| SelectionUiError::DisplayError(e))?;
// draw selected box // draw selected box
if let Some(selected_bounds) = layout.inner().get(self.selection) { let selected_bounds = layout.inner().get(self.selection).ok_or(())?.bounding_box();
let selected_bounds = selected_bounds.bounding_box();
Rectangle::new(selected_bounds.top_left, selected_bounds.size) Rectangle::new(selected_bounds.top_left, selected_bounds.size)
.into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1)) .into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1))
.draw(display) .draw(display)?;
.map_err(|e| SelectionUiError::DisplayError(e))?;
self.last_bounds = Some(selected_bounds); self.last_bounds = Some(layout.bounds());
}
layout.draw(display)?;
Ok(()) Ok(())
} }
} }
pub fn draw_text_center<'a, S>(
display: &mut Display,
text: &'a str,
style: S,
) -> Result<Point, <Display as DrawTarget>::Error>
where
S: TextRenderer<Color = <Display as DrawTarget>::Color>,
{
Text::with_alignment(text, Point::zero(), style, Alignment::Center).draw(display)
}
+5 -5
View File
@@ -6,7 +6,7 @@ use abi::{
display::Display, display::Display,
get_key, get_key,
keyboard::{KeyCode, KeyState}, keyboard::{KeyCode, KeyState},
println, print,
}; };
use alloc::{format, string::String, vec, vec::Vec}; use alloc::{format, string::String, vec, vec::Vec};
use core::panic::PanicInfo; use core::panic::PanicInfo;
@@ -28,7 +28,7 @@ use embedded_layout::{
#[panic_handler] #[panic_handler]
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
println!("user panic: {} @ {:?}", info.message(), info.location(),); print!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {} loop {}
} }
@@ -38,8 +38,8 @@ pub extern "Rust" fn _start() {
} }
pub fn main() { pub fn main() {
println!("Starting Calculator app"); print!("Starting Calculator app");
let mut display = Display::take().unwrap(); let mut display = Display;
let mut input = vec!['e', 'x', 'p', 'r', ':', ' ']; let mut input = vec!['e', 'x', 'p', 'r', ':', ' '];
let input_min = input.len(); let input_min = input.len();
@@ -104,7 +104,7 @@ pub fn main() {
} }
let event = get_key(); let event = get_key();
if event.state == KeyState::Released { if event.state != KeyState::Idle {
match event.key { match event.key {
KeyCode::Char(ch) => { KeyCode::Char(ch) => {
input.push(ch); input.push(ch);
+5 -5
View File
@@ -8,7 +8,7 @@ use abi::{
fs::{Entries, list_dir, read_file}, fs::{Entries, list_dir, read_file},
get_key, get_key,
keyboard::{KeyCode, KeyState}, keyboard::{KeyCode, KeyState},
println, print,
}; };
use alloc::{format, vec}; use alloc::{format, vec};
use core::panic::PanicInfo; use core::panic::PanicInfo;
@@ -20,7 +20,7 @@ use tinybmp::Bmp;
#[panic_handler] #[panic_handler]
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
println!("user panic: {} @ {:?}", info.message(), info.location()); print!("user panic: {} @ {:?}", info.message(), info.location());
loop {} loop {}
} }
@@ -30,9 +30,9 @@ pub extern "Rust" fn _start() {
} }
pub fn main() { pub fn main() {
println!("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::take().unwrap(); let mut display = Display;
let grid_cols = 3; let grid_cols = 3;
let grid_rows = 3; let grid_rows = 3;
@@ -49,7 +49,7 @@ pub fn main() {
break; // only draw 3x3 break; // only draw 3x3
} }
println!("file: {}", file); print!("file: {}", file);
if file.extension().unwrap_or("") == "bmp" || file.extension().unwrap_or("") == "BMP" { if file.extension().unwrap_or("") == "bmp" || file.extension().unwrap_or("") == "BMP" {
let file_path = format!("/images/{}", file); let file_path = format!("/images/{}", file);
+1 -1
View File
@@ -5,6 +5,6 @@ edition = "2024"
[dependencies] [dependencies]
abi = { path = "../../abi" } abi = { path = "../../abi" }
selection_ui = { path = "../../selection_ui" }
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" }
+20 -39
View File
@@ -3,27 +3,23 @@
extern crate alloc; extern crate alloc;
use abi::{ use abi::{
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH}, display::Display,
fs::{Entries, file_len, list_dir, read_file}, fs::{Entries, file_len, list_dir, read_file},
get_key, get_ms, get_key, get_ms,
keyboard::{KeyCode, KeyState}, keyboard::{KeyCode, KeyState},
println, sleep, print, sleep,
}; };
use alloc::{format, vec, vec::Vec}; use alloc::{format, vec, vec::Vec};
use core::panic::PanicInfo; use core::panic::PanicInfo;
use embedded_graphics::{ use embedded_graphics::{
image::ImageDrawable, image::ImageDrawable, pixelcolor::Rgb565, prelude::Point, transform::Transform,
mono_font::{MonoTextStyle, ascii::FONT_6X10},
pixelcolor::Rgb565,
prelude::{Point, RgbColor},
transform::Transform,
}; };
use selection_ui::{SelectionUi, SelectionUiError, draw_text_center}; use selection_ui::SelectionUi;
use tinygif::Gif; use tinygif::Gif;
#[panic_handler] #[panic_handler]
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
println!("user panic: {} @ {:?}", info.message(), info.location(),); print!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {} loop {}
} }
@@ -33,56 +29,41 @@ pub extern "Rust" fn _start() {
} }
pub fn main() { pub fn main() {
println!("Starting Gif app"); print!("Starting Gif app");
let mut display = Display::take().unwrap(); let mut display = Display;
let mut entries = Entries::new(); let mut entries = Entries::new();
list_dir("/gifs", &mut entries); list_dir("/gifs", &mut entries);
let mut files = entries.entries(); let mut files = entries.entries();
files.retain(|e| e.extension().unwrap_or("") == "gif"); files.retain(|e| e.extension().unwrap_or("") == "gif");
let mut gifs = files.iter().map(|e| e.full_name()).collect::<Vec<&str>>(); let gifs = &files.iter().map(|e| e.full_name()).collect::<Vec<&str>>();
gifs.sort();
let mut selection_ui = SelectionUi::new(&mut gifs); let mut selection_ui = SelectionUi::new(&gifs, "No Gif files found in /gifs");
let selection = match selection_ui.run_selection_ui(&mut display) { let selection = selection_ui
Ok(maybe_sel) => maybe_sel, .run_selection_ui(&mut display)
Err(e) => match e { .expect("failed to draw")
SelectionUiError::SelectionListEmpty => { .expect("Failed to get user selection");
draw_text_center(
&mut display,
"No Gifs were found in /gifs",
MonoTextStyle::new(&FONT_6X10, Rgb565::RED),
)
.expect("Display Error");
None
}
SelectionUiError::DisplayError(_) => panic!("Display Error"),
},
};
assert!(selection.is_some()); let file_name = format!("/gifs/{}", gifs[selection]);
let file_name = format!("/gifs/{}", gifs[selection.unwrap()]);
let size = file_len(&file_name); 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(&file_name, 0, &mut buf);
println!("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).expect("Failed to parse gif");
let height = gif.height();
let translation = Point::new(
(SCREEN_WIDTH as i32 - gif.width() as i32) / 2,
(SCREEN_HEIGHT as i32 - gif.height() as i32) / 2,
);
let mut frame_num = 0; let mut frame_num = 0;
loop { loop {
for mut frame in gif.frames() { for mut frame in gif.frames() {
let start = get_ms(); let start = get_ms();
frame.translate_mut(translation).draw(&mut display).unwrap(); frame
.translate_mut(Point::new(0, (320 - height as i32) / 2))
.draw(&mut display)
.unwrap();
frame_num += 1; frame_num += 1;
if frame_num % 5 == 0 { if frame_num % 5 == 0 {
+4 -4
View File
@@ -7,7 +7,7 @@ use abi::{
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH}, display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
get_key, get_key,
keyboard::{KeyCode, KeyState}, keyboard::{KeyCode, KeyState},
println, sleep, print, sleep,
}; };
use core::panic::PanicInfo; use core::panic::PanicInfo;
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor}; use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
@@ -15,7 +15,7 @@ use embedded_snake::{Direction, SnakeGame};
#[panic_handler] #[panic_handler]
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
println!("user panic: {} @ {:?}", info.message(), info.location(),); print!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {} loop {}
} }
@@ -27,8 +27,8 @@ pub extern "Rust" fn _start() {
const CELL_SIZE: usize = 8; const CELL_SIZE: usize = 8;
pub fn main() { pub fn main() {
println!("Starting Snake app"); print!("Starting Snake app");
let mut display = Display::take().unwrap(); let mut display = Display;
let mut game = SnakeGame::<100, Rgb565, Rng>::new( let mut game = SnakeGame::<100, Rgb565, Rng>::new(
SCREEN_WIDTH as u16, SCREEN_WIDTH as u16,
-11
View File
@@ -1,11 +0,0 @@
[package]
name = "wav_player"
version = "0.1.0"
edition = "2024"
[dependencies]
abi = { path = "../../abi" }
selection_ui = { path = "../../selection_ui" }
embedded-graphics = "0.8.1"
rand = { version = "0.9.0", default-features = false }
embedded-audio = { git = "https://github.com/LegitCamper/embedded-audio" }
-28
View File
@@ -1,28 +0,0 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("../memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rustc-link-arg-bins=-Tmemory.x");
}
-139
View File
@@ -1,139 +0,0 @@
#![no_std]
#![no_main]
extern crate alloc;
use abi::{
audio::{AUDIO_BUFFER_LEN, audio_buffer_ready, send_audio_buffer},
display::Display,
format,
fs::{Entries, file_len, list_dir, read_file},
get_key,
keyboard::{KeyCode, KeyState},
println,
};
use alloc::{string::String, vec::Vec};
use core::panic::PanicInfo;
use embedded_audio::{AudioFile, PlatformFile, PlatformFileError, wav::Wav};
use embedded_graphics::{
mono_font::{MonoTextStyle, ascii::FONT_6X10},
pixelcolor::Rgb565,
prelude::RgbColor,
};
use selection_ui::{SelectionUi, SelectionUiError, draw_text_center};
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {}
}
#[unsafe(no_mangle)]
pub extern "Rust" fn _start() {
main()
}
pub fn main() {
println!("Starting Wav player app");
let mut display = Display::take().unwrap();
loop {
let mut entries = Entries::new();
list_dir("/music", &mut entries);
let mut files = entries.entries();
files.retain(|e| e.extension().unwrap_or("") == "wav");
let mut wavs = files.iter().map(|e| e.full_name()).collect::<Vec<&str>>();
wavs.sort();
let mut selection_ui = SelectionUi::new(&mut wavs);
let selection = match selection_ui.run_selection_ui(&mut display) {
Ok(maybe_sel) => maybe_sel,
Err(e) => match e {
SelectionUiError::SelectionListEmpty => {
draw_text_center(
&mut display,
"No Wavs were found in /gifs",
MonoTextStyle::new(&FONT_6X10, Rgb565::RED),
)
.expect("Display Error");
None
}
SelectionUiError::DisplayError(_) => panic!("Display Error"),
},
};
assert!(selection.is_some());
let file_name = format!("/music/{}", wavs[selection.unwrap()]);
let file = File::new(String::from(file_name));
let mut wav = Wav::new(file).unwrap();
println!("sample rate: {}", wav.sample_rate());
println!("channels: {:?}", wav.channels() as u8);
let mut buf = [0_u8; AUDIO_BUFFER_LEN];
loop {
if audio_buffer_ready() {
if wav.is_eof() {
break;
}
let _read = wav.read(&mut buf).unwrap();
send_audio_buffer(&buf);
}
let event = get_key();
if event.state == KeyState::Released {
match event.key {
KeyCode::Esc => return,
_ => (),
}
}
}
}
}
struct File {
current_pos: usize,
file: String,
}
impl File {
fn new(file: String) -> Self {
Self {
current_pos: 0,
file,
}
}
}
impl PlatformFile for File {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, PlatformFileError> {
let read = read_file(&self.file, self.current_pos, buf);
self.current_pos += read;
Ok(read)
}
fn seek_from_current(&mut self, offset: i64) -> Result<(), PlatformFileError> {
if offset.is_positive() {
self.current_pos += offset as usize;
} else {
self.current_pos -= offset as usize;
}
Ok(())
}
fn seek_from_start(&mut self, offset: usize) -> Result<(), PlatformFileError> {
self.current_pos = offset;
Ok(())
}
fn seek_from_end(&mut self, offset: usize) -> Result<(), PlatformFileError> {
self.current_pos = self.length() - offset;
Ok(())
}
fn length(&mut self) -> usize {
file_len(&self.file)
}
}