From 76355b72ce6a540eea81a9241ef0e97cd196f06a Mon Sep 17 00:00:00 2001 From: Naxdy Date: Tue, 12 Mar 2024 00:08:34 +0100 Subject: [PATCH] refactor (WORKING) using embassy --- Cargo.lock | 1433 ++++++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 46 +- build.rs | 15 + flake.nix | 22 +- memory.x | 22 +- src/gcc_hid.rs | 315 +++++------ src/input.rs | 90 +-- src/main.rs | 201 ++----- 8 files changed, 1537 insertions(+), 607 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6671b51..146524f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,75 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "arrayvec" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + [[package]] name = "bare-metal" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" dependencies = [ - "rustc_version", + "rustc_version 0.2.3", ] +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitfield" version = "0.13.2" @@ -29,6 +83,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + [[package]] name = "bitvec" version = "1.0.1" @@ -42,10 +102,32 @@ dependencies = [ ] [[package]] -name = "byteorder" -version = "1.5.0" +name = "bytemuck" +version = "1.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] [[package]] name = "cortex-m" @@ -55,7 +137,7 @@ checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" dependencies = [ "bare-metal", "bitfield", - "embedded-hal", + "embedded-hal 0.2.7", "volatile-register", ] @@ -94,6 +176,47 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "darling" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.52", +] + +[[package]] +name = "darling_macro" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.52", +] + [[package]] name = "debug-helper" version = "0.3.13" @@ -106,7 +229,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3939552907426de152b3c2c6f51ed53f98f448babd26f28694c95f5906194595" dependencies = [ - "bitflags", + "bitflags 1.3.2", "defmt-macros", ] @@ -142,6 +265,42 @@ dependencies = [ "defmt", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "document-features" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95" +dependencies = [ + "litrs", +] + [[package]] name = "either" version = "1.10.0" @@ -149,12 +308,206 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] -name = "embedded-dma" +name = "embassy-embedded-hal" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eca4a9380d03e61063067b8239f67d2fa9f108ede7c46b4273804f6b79e59a1d" +dependencies = [ + "defmt", + "embassy-futures", + "embassy-sync 0.5.0", + "embassy-time", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "embedded-storage", + "embedded-storage-async", + "nb 1.1.0", +] + +[[package]] +name = "embassy-executor" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec648daedd2143466eff4b3e8002024f9f6c1de4ab7666bb679688752624c925" +dependencies = [ + "cortex-m", + "critical-section", + "defmt", + "document-features", + "embassy-executor-macros", + "embassy-time-driver", + "embassy-time-queue-driver", +] + +[[package]] +name = "embassy-executor-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad454accf80050e9cf7a51e994132ba0e56286b31f9317b68703897c328c59b5" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "embassy-futures" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" + +[[package]] +name = "embassy-hal-internal" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0ec47cf8bab914018d4bd2b4f0aaeb46e4f52ab1e7985df88aeef2c6eda5aed" +dependencies = [ + "cortex-m", + "critical-section", + "defmt", + "num-traits", +] + +[[package]] +name = "embassy-net-driver" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "994f7e5b5cb23521c22304927195f236813053eb9c065dd2226a32ba64695446" +checksum = "524eb3c489760508f71360112bca70f6e53173e6fe48fc5f0efd0f5ab217751d" + +[[package]] +name = "embassy-net-driver-channel" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "584ab4da7e5612efaa7d55ee76161d9549adf788eab48d49362eddbf322f9933" dependencies = [ - "stable_deref_trait", + "embassy-futures", + "embassy-net-driver", + "embassy-sync 0.3.0", +] + +[[package]] +name = "embassy-rp" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "438f170cbd97d4a870e8d57e1738ee815255028ad31dd409d891e2bf797dc531" +dependencies = [ + "atomic-polyfill", + "cfg-if", + "cortex-m", + "cortex-m-rt", + "critical-section", + "defmt", + "document-features", + "embassy-embedded-hal", + "embassy-futures", + "embassy-hal-internal", + "embassy-sync 0.5.0", + "embassy-time", + "embassy-time-driver", + "embassy-usb-driver", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "embedded-hal-nb", + "embedded-io", + "embedded-io-async", + "embedded-storage", + "embedded-storage-async", + "fixed", + "futures", + "nb 1.1.0", + "pio", + "pio-proc", + "rand_core", + "rp-pac", + "rp2040-boot2", +] + +[[package]] +name = "embassy-sync" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0525b466ca3ace30b57f2db868a35215dfaecd038d8668cb2db03feb7c069a0" +dependencies = [ + "cfg-if", + "critical-section", + "futures-util", + "heapless 0.7.17", +] + +[[package]] +name = "embassy-sync" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd938f25c0798db4280fcd8026bf4c2f48789aebf8f77b6e5cf8a7693ba114ec" +dependencies = [ + "cfg-if", + "critical-section", + "defmt", + "embedded-io-async", + "futures-util", + "heapless 0.8.0", +] + +[[package]] +name = "embassy-time" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c844070d9f80dc66ee739299183312baee2e1cdeb6e90b4ea2af44f4676da5" +dependencies = [ + "cfg-if", + "critical-section", + "defmt", + "document-features", + "embassy-time-driver", + "embassy-time-queue-driver", + "embedded-hal 0.2.7", + "embedded-hal 1.0.0", + "embedded-hal-async", + "futures-util", + "heapless 0.8.0", +] + +[[package]] +name = "embassy-time-driver" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e0c214077aaa9206958b16411c157961fb7990d4ea628120a78d1a5a28aed24" +dependencies = [ + "document-features", +] + +[[package]] +name = "embassy-time-queue-driver" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1177859559ebf42cd24ae7ba8fe6ee707489b01d0bf471f8827b7b12dcb0bc0" + +[[package]] +name = "embassy-usb" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1587e58ed8f7e0215246e6bb8d7ef4837db682e209e5ef7410a81c500dc949e5" +dependencies = [ + "defmt", + "embassy-futures", + "embassy-net-driver-channel", + "embassy-sync 0.5.0", + "embassy-usb-driver", + "heapless 0.8.0", + "ssmarshal", + "usbd-hid", +] + +[[package]] +name = "embassy-usb-driver" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fc247028eae04174b6635104a35b1ed336aabef4654f5e87a8f32327d231970" +dependencies = [ + "defmt", ] [[package]] @@ -167,60 +520,147 @@ dependencies = [ "void", ] +[[package]] +name = "embedded-hal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" + +[[package]] +name = "embedded-hal-async" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884" +dependencies = [ + "embedded-hal 1.0.0", +] + +[[package]] +name = "embedded-hal-nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605" +dependencies = [ + "embedded-hal 1.0.0", + "nb 1.1.0", +] + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + +[[package]] +name = "embedded-io-async" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff09972d4073aa8c299395be75161d582e7629cd663171d62af73c8d50dba3f" +dependencies = [ + "embedded-io", +] + +[[package]] +name = "embedded-storage" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032" + +[[package]] +name = "embedded-storage-async" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1763775e2323b7d5f0aa6090657f5e21cfa02ede71f5dc40eead06d64dcd15cc" +dependencies = [ + "embedded-storage", +] + +[[package]] +name = "ena" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1" +dependencies = [ + "log", +] + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fixed" +version = "1.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4810bcba5534219e7c160473f3a59167e2c98bd7516bc0eec5185848bcd38963" +dependencies = [ + "az", + "bytemuck", + "half", + "typenum", +] + +[[package]] +name = "fixed-macro" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0c48af8cb14e02868f449f8a2187bd78af7a08da201fdc78d518ecb1675bc" +dependencies = [ + "fixed", + "fixed-macro-impl", + "fixed-macro-types", +] + +[[package]] +name = "fixed-macro-impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c93086f471c0a1b9c5e300ea92f5cd990ac6d3f8edf27616ef624b8fa6402d4b" +dependencies = [ + "fixed", + "paste", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "fixed-macro-types" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "044a61b034a2264a7f65aa0c3cd112a01b4d4ee58baace51fead3f21b993c7e4" +dependencies = [ + "fixed", + "fixed-macro-impl", +] + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "format_no_std" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d8ca877c98f19024674b6959301d81d3708c417823fa050692b45b54d74fe7d" -[[package]] -name = "frunk" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a351b59e12f97b4176ee78497dff72e4276fb1ceb13e19056aca7fa0206287" -dependencies = [ - "frunk_core", - "frunk_derives", -] - -[[package]] -name = "frunk_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af2469fab0bd07e64ccf0ad57a1438f63160c69b2e57f04a439653d68eb558d6" - -[[package]] -name = "frunk_derives" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fa992f1656e1707946bbba340ad244f0814009ef8c0118eb7b658395f19a2e" -dependencies = [ - "frunk_proc_macro_helpers", - "quote", - "syn 2.0.52", -] - -[[package]] -name = "frunk_proc_macro_helpers" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35b54add839292b743aeda6ebedbd8b11e93404f902c56223e51b9ec18a13d2c" -dependencies = [ - "frunk_core", - "proc-macro2", - "quote", - "syn 2.0.52", -] - -[[package]] -name = "fugit" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17186ad64927d5ac8f02c1e77ccefa08ccd9eaa314d5a4772278aa204a22f7e7" -dependencies = [ - "gcd", -] - [[package]] name = "funty" version = "2.0.0" @@ -228,10 +668,107 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] -name = "gcd" -version = "2.3.0" +name = "futures" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d758ba1b47b00caf47f24925c0074ecb20d6dfcffe7f6d53395c0465674841a" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "half" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5eceaaeec696539ddaf7b333340f1af35a5aa87ae3e4f3ead0532f72affab2e" +dependencies = [ + "cfg-if", + "crunchy", +] + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] [[package]] name = "hash32" @@ -242,16 +779,68 @@ dependencies = [ "byteorder", ] +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32 0.2.1", + "rustc_version 0.4.0", + "spin", + "stable_deref_trait", +] + [[package]] name = "heapless" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ - "hash32", + "hash32 0.3.1", "stable_deref_trait", ] +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "2.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + [[package]] name = "itertools" version = "0.10.5" @@ -261,6 +850,82 @@ dependencies = [ "either", ] +[[package]] +name = "lalrpop" +version = "0.19.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" +dependencies = [ + "ascii-canvas", + "bit-set", + "diff", + "ena", + "is-terminal", + "itertools", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax 0.6.29", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", +] + +[[package]] +name = "lalrpop-util" +version = "0.19.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" +dependencies = [ + "regex", +] + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall", +] + +[[package]] +name = "litrs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + [[package]] name = "naxgcc-fw" version = "0.1.0" @@ -269,17 +934,20 @@ dependencies = [ "cortex-m-rt", "defmt", "defmt-rtt", - "embedded-hal", + "embassy-embedded-hal", + "embassy-executor", + "embassy-futures", + "embassy-rp", + "embassy-sync 0.5.0", + "embassy-time", + "embassy-usb", + "fixed", + "fixed-macro", "format_no_std", - "fugit", "packed_struct", - "panic-halt", "panic-probe", - "rp2040-boot2", - "rp2040-flash", - "rp2040-hal", - "usb-device", - "usbd-human-interface-device", + "portable-atomic", + "static_cell", ] [[package]] @@ -297,22 +965,28 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + [[package]] name = "num_enum" version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" dependencies = [ - "num_enum_derive 0.5.11", -] - -[[package]] -name = "num_enum" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" -dependencies = [ - "num_enum_derive 0.7.2", + "num_enum_derive", ] [[package]] @@ -327,21 +1001,10 @@ dependencies = [ ] [[package]] -name = "num_enum_derive" -version = "0.7.2" +name = "once_cell" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.52", -] - -[[package]] -name = "option-block" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f2c5d345596a14d7c8b032a68f437955f0059f2eb9a5972371c84f7eef3227" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "packed_struct" @@ -364,12 +1027,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "panic-halt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" - [[package]] name = "panic-probe" version = "0.3.1" @@ -377,6 +1034,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa6fa5645ef5a760cd340eaa92af9c1ce131c8c09e7f8926d8a24b59d26652b9" dependencies = [ "cortex-m", + "defmt", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", ] [[package]] @@ -385,6 +1066,37 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "petgraph" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pio" version = "0.2.1" @@ -392,10 +1104,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76e09694b50f89f302ed531c1f2a7569f0be5867aee4ab4f8f729bbeec0078e3" dependencies = [ "arrayvec", - "num_enum 0.5.11", + "num_enum", "paste", ] +[[package]] +name = "pio-parser" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77532c2b8279aef98dfc7207ef15298a5a3d6b6cc76ccc8b65913d69f3a8dd6b" +dependencies = [ + "lalrpop", + "lalrpop-util", + "pio", + "regex-syntax 0.6.29", +] + +[[package]] +name = "pio-proc" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b04dc870fb3a4fd8b3e4ca8c61b53bc8ac4eb78b66805d2b3c2e5c4829e0d7a" +dependencies = [ + "codespan-reporting", + "lalrpop-util", + "pio", + "pio-parser", + "proc-macro-error", + "proc-macro2", + "quote", + "regex-syntax 0.6.29", + "syn 1.0.109", +] + +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +dependencies = [ + "critical-section", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -450,6 +1206,71 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rp-pac" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30f6c4c846269293db805e9c77864ff7b923395b480550df44f0868e3765337" +dependencies = [ + "cortex-m", + "cortex-m-rt", +] + [[package]] name = "rp2040-boot2" version = "0.3.0" @@ -459,72 +1280,36 @@ dependencies = [ "crc-any", ] -[[package]] -name = "rp2040-flash" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2007f9701924b88cbffc172cdf09e01b9c03ecd0b2f59bc6eea5283982855438" -dependencies = [ - "rp2040-hal", -] - -[[package]] -name = "rp2040-hal" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff2b9ae7e6dd6720fd9f64250c9087260e50fe98b6b032ccca65be3581167ca" -dependencies = [ - "cortex-m", - "critical-section", - "embedded-dma", - "embedded-hal", - "frunk", - "fugit", - "itertools", - "nb 1.1.0", - "paste", - "pio", - "rand_core", - "rp2040-hal-macros", - "rp2040-pac", - "usb-device", - "vcell", - "void", -] - -[[package]] -name = "rp2040-hal-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86479063e497efe1ae81995ef9071f54fd1c7427e04d6c5b84cde545ff672a5e" -dependencies = [ - "cortex-m-rt", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "rp2040-pac" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12d9d8375815f543f54835d01160d4e47f9e2cae75f17ff8f1ec19ce1da96e4c" -dependencies = [ - "cortex-m", - "cortex-m-rt", - "critical-section", - "vcell", -] - [[package]] name = "rustc_version" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.22", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "semver" version = "0.9.0" @@ -534,18 +1319,103 @@ dependencies = [ "semver-parser", ] +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "ssmarshal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3e6ad23b128192ed337dfa4f1b8099ced0c2bf30d61e551b65fda5916dbb850" +dependencies = [ + "encode_unicode", + "serde", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "static_cell" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa6ba4cf83bf80d3eb25f098ea5e790a0a1fcb5e357442259b231e412c2d3ca0" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.109" @@ -574,6 +1444,26 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.57" @@ -594,35 +1484,78 @@ dependencies = [ "syn 2.0.52", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "usb-device" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" + +[[package]] +name = "usbd-hid" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "975bd411f4a939986751ea09992a24fa47c4d25c6ed108d04b4c2999a4fd0132" dependencies = [ - "defmt", + "serde", + "ssmarshal", + "usb-device", + "usbd-hid-macros", ] [[package]] -name = "usbd-human-interface-device" -version = "0.4.5" +name = "usbd-hid-descriptors" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d69710303c06f23a1259d086bfb241212ae1ccfb5d582ebd596bb042d662ed73" +checksum = "dcbee8c6735e90894fba04770bc41e11fd3c5256018856e15dc4dd1e6c8a3dd1" dependencies = [ - "defmt", - "frunk", - "fugit", - "heapless", - "num_enum 0.7.2", - "option-block", - "packed_struct", - "usb-device", + "bitfield", +] + +[[package]] +name = "usbd-hid-macros" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261079a9ada015fa1acac7cc73c98559f3a92585e15f508034beccf6a2ab75a2" +dependencies = [ + "byteorder", + "proc-macro2", + "quote", + "serde", + "syn 1.0.109", + "usbd-hid-descriptors", ] [[package]] @@ -652,6 +1585,166 @@ dependencies = [ "vcell", ] +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 21acbd5..1720616 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,20 +6,40 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rp2040-hal = { version = "0.9.2", features = ["rt", "critical-section-impl"] } -rp2040-flash = "0.4.0" -usbd-human-interface-device = { version = "0.4.5", features = ["defmt"] } -usb-device = "0.2" -cortex-m = "0.7.7" -cortex-m-rt = "0.7.3" -embedded-hal = { version = "0.2.7", features = ["unproven"] } -panic-probe = "0.3.1" -defmt = "0.3.6" -defmt-rtt = "0.4.0" -rp2040-boot2 = "0.3.0" -fugit = "0.3.7" +embassy-time = { version = "0.3.0", features = [ + "defmt", + "defmt-timestamp-uptime", +] } +embassy-embedded-hal = { version = "0.1.0", features = ["defmt"] } +embassy-sync = { version = "0.5.0", features = ["defmt"] } +embassy-executor = { version = "0.5.0", features = [ + "task-arena-size-32768", + "arch-cortex-m", + "executor-thread", + "executor-interrupt", + "defmt", + "integrated-timers", +] } +embassy-rp = { version = "0.1.0", features = [ + "defmt", + "unstable-pac", + "time-driver", + "critical-section-impl", +] } +embassy-usb = { version = "0.1.0", features = ["defmt"] } +embassy-futures = { version = "0.1.0" } +defmt = "0.3" +defmt-rtt = "0.4" +fixed = "1.23.1" +fixed-macro = "1.2" +static_cell = "2" +portable-atomic = { version = "1.5", features = ["critical-section"] } + +#cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } +cortex-m = { version = "0.7.6", features = ["inline-asm"] } +cortex-m-rt = "0.7.0" +panic-probe = { version = "0.3", features = ["print-defmt"] } packed_struct = { version = "0.10.1", default_features = false } -panic-halt = "0.2.0" format_no_std = "1.0.2" # cargo build/run diff --git a/build.rs b/build.rs index 555cdf6..3f915f9 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,13 @@ +//! 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; @@ -18,4 +28,9 @@ fn main() { // here, we ensure the build script is only re-run when // `memory.x` is changed. println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); } diff --git a/flake.nix b/flake.nix index d815d63..b900aff 100644 --- a/flake.nix +++ b/flake.nix @@ -46,14 +46,14 @@ CARGO_BUILD_TARGET = "thumbv6m-none-eabi"; - RUSTFLAGS = [ - "-Clinker=flip-link" - "-Clink-arg=--nmagic" - "-Clink-arg=-Tlink.x" - "-Clink-arg=-Tdefmt.x" - "-Cinline-threshold=5" - "-Cno-vectorize-loops" - ]; + # RUSTFLAGS = [ + # "-Clinker=flip-link" + # "-Clink-arg=--nmagic" + # "-Clink-arg=-Tlink.x" + # "-Clink-arg=-Tdefmt.x" + # "-Cinline-threshold=5" + # "-Cno-vectorize-loops" + # ]; in { packages.default = self.packages.${system}.naxgcc-fw-uf2; @@ -77,7 +77,7 @@ "--target=${CARGO_BUILD_TARGET}" ]; - inherit RUSTFLAGS; + # inherit RUSTFLAGS; }; devShells.default = pkgs.mkShell { @@ -87,9 +87,9 @@ }; CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER = "probe-rs run --chip RP2040 --protocol swd"; - DEFMT_LOG = "trace"; + DEFMT_LOG = "debug"; - inherit RUSTFLAGS CARGO_BUILD_TARGET; + inherit CARGO_BUILD_TARGET; }; })); } diff --git a/memory.x b/memory.x index 070eac7..771b8fa 100644 --- a/memory.x +++ b/memory.x @@ -1,15 +1,17 @@ MEMORY { BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 - RAM : ORIGIN = 0x20000000, LENGTH = 256K -} -EXTERN(BOOT2_FIRMWARE) + /* Pick one of the two options for RAM layout */ -SECTIONS { - /* ### Boot loader */ - .boot2 ORIGIN(BOOT2) : - { - KEEP(*(.boot2)); - } > BOOT2 -} INSERT BEFORE .text; \ No newline at end of file + /* OPTION A: Use all RAM banks as one big block */ + /* Reasonable, unless you are doing something */ + /* really particular with DMA or other concurrent */ + /* access that would benefit from striping */ + RAM : ORIGIN = 0x20000000, LENGTH = 264K + + /* OPTION B: Keep the unstriped sections separate */ + /* RAM: ORIGIN = 0x20000000, LENGTH = 256K */ + /* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */ + /* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */ +} \ No newline at end of file diff --git a/src/gcc_hid.rs b/src/gcc_hid.rs index 8293845..1aec104 100644 --- a/src/gcc_hid.rs +++ b/src/gcc_hid.rs @@ -1,27 +1,23 @@ use core::default::Default; -use defmt::{error, info, unwrap, Debug2Format, Format}; -use embedded_hal::timer::CountDown as _; -use fugit::ExtU32; +use defmt::{debug, error, info, trace, unwrap, warn, Debug2Format, Format}; +use embassy_futures::{ + join::join, + select::{self, select, Either}, +}; +use embassy_rp::{peripherals::USB, usb::Driver}; +use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; +use embassy_sync::signal::Signal; +use embassy_time::Duration; +use embassy_usb::{ + class::hid::{HidReaderWriter, ReportId, RequestHandler, State}, + control::OutResponse, + Builder, Handler, +}; use packed_struct::{derive::PackedStruct, PackedStruct}; -use rp2040_flash::flash::flash_unique_id; -use rp2040_hal::timer::CountDown; -use usb_device::{ - bus::{UsbBus, UsbBusAllocator}, - device::{UsbDeviceBuilder, UsbVidPid}, -}; -use usbd_human_interface_device::{ - descriptor::InterfaceProtocol, - device::DeviceClass, - interface::{ - InBytes64, Interface, InterfaceBuilder, InterfaceConfig, OutBytes64, ReportSingle, - UsbAllocatable, - }, - usb_class::UsbHidClassBuilder, - UsbHidError, -}; +use portable_atomic::Ordering; -use crate::{input::GCC_STATE, CORE_LOCK, LOCKED}; +use crate::input::GCC_STATE; #[rustfmt::skip] pub const GCC_REPORT_DESCRIPTOR: &[u8] = &[ @@ -148,76 +144,27 @@ impl Default for RawConsoleReport { Self { packet: [0u8; 64] } } } -pub struct GcConfig<'a> { - interface: InterfaceConfig<'a, InBytes64, OutBytes64, ReportSingle>, -} -impl<'a> GcConfig<'a> { - #[must_use] - pub fn new(interface: InterfaceConfig<'a, InBytes64, OutBytes64, ReportSingle>) -> Self { - Self { interface } - } -} +struct GccRequestHandler {} -impl<'a> Default for GcConfig<'a> { - #[must_use] - fn default() -> Self { - let i = unwrap!( - unwrap!(unwrap!(InterfaceBuilder::new(GCC_REPORT_DESCRIPTOR)) - .boot_device(InterfaceProtocol::None) - .description("NaxGCC") - .in_endpoint(1.millis())) - .with_out_endpoint(1.millis()) - ); - - Self::new(i.build()) - } -} - -impl<'a, B: UsbBus + 'a> UsbAllocatable<'a, B> for GcConfig<'a> { - type Allocated = GcController<'a, B>; - - fn allocate(self, usb_alloc: &'a UsbBusAllocator) -> Self::Allocated { - Self::Allocated { - interface: Interface::new(usb_alloc, self.interface), - } - } -} - -pub struct GcController<'a, B: UsbBus> { - interface: Interface<'a, B, InBytes64, OutBytes64, ReportSingle>, -} - -impl<'a, B: UsbBus> GcController<'a, B> { - pub fn write_report(&mut self, report: &GcReport) -> Result<(), UsbHidError> { - let report = get_gcinput_hid_report(report); - - self.interface - .write_report(&report) - .map(|_| ()) - .map_err(|e| UsbHidError::from(e)) +impl RequestHandler for GccRequestHandler { + fn get_report(&self, id: ReportId, _buf: &mut [u8]) -> Option { + info!("Get report for {:?}", id); + None } - pub fn read_report(&mut self) -> Result { - let mut report = RawConsoleReport::default(); - match self.interface.read_report(&mut report.packet) { - Err(e) => Err(UsbHidError::from(e)), - Ok(_) => Ok(report), - } - } -} - -impl<'a, B: UsbBus> DeviceClass<'a> for GcController<'a, B> { - type I = Interface<'a, B, InBytes64, OutBytes64, ReportSingle>; - - fn interface(&mut self) -> &mut Self::I { - &mut self.interface + fn set_report(&self, id: ReportId, data: &[u8]) -> OutResponse { + info!("Set report for {:?}: {=[u8]}", id, data); + OutResponse::Accepted } - fn reset(&mut self) {} + fn set_idle_ms(&self, id: Option, dur: u32) { + info!("Set idle rate for {:?} to {:?}", id, dur); + } - fn tick(&mut self) -> Result<(), UsbHidError> { - Ok(()) + fn get_idle_ms(&self, id: Option) -> Option { + info!("Get idle rate for {:?}", id); + None } } @@ -245,80 +192,142 @@ fn get_gcinput_hid_report(input_state: &GcReport) -> [u8; 37] { buffer } -pub fn usb_transfer_loop<'a, T: UsbBus>( - usb_bus: UsbBusAllocator, - mut poll_timer: CountDown<'a>, -) -> ! { - // let mut serial_buffer = [0u8; 64]; +struct MyDeviceHandler { + configured: bool, +} - // let serial = unsafe { - // let mut id = [0u8; 8]; +impl MyDeviceHandler { + fn new() -> Self { + MyDeviceHandler { configured: false } + } +} - // flash_unique_id(&mut id, true); - - // let s = format_no_std::show( - // &mut serial_buffer, - // format_args!( - // "{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", - // id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] - // ), - // ) - // .unwrap(); - - // info!("Detected flash with unique serial number {}", s); - - // s - // }; - - let mut gcc = UsbHidClassBuilder::new() - .add_device(GcConfig::default()) - .build(&usb_bus); - - let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x057e, 0x0337)) - .manufacturer("Naxdy") - .product("NaxGCC") - .serial_number("flarn") - .device_class(0) - .device_protocol(0) - .device_sub_class(0) - .self_powered(false) - .max_power(500) - .max_packet_size_0(64) - .build(); - - poll_timer.start(1.millis()); - - info!("Got here"); - - loop { - if unsafe { LOCKED } { - continue; +impl Handler for MyDeviceHandler { + fn enabled(&mut self, enabled: bool) { + self.configured = true; + if enabled { + info!("Device enabled"); + } else { + info!("Device disabled"); } + } - if poll_timer.wait().is_ok() { - match gcc.device().write_report(&(unsafe { GCC_STATE })) { - Err(UsbHidError::WouldBlock) => {} - Ok(_) => {} - Err(e) => { - error!("Error: {:?}", Debug2Format(&e)); - panic!(); - } - } - } - if usb_dev.poll(&mut [&mut gcc]) { - match gcc.device().read_report() { - Err(UsbHidError::WouldBlock) => {} - Err(e) => { - error!("Failed to read report: {:?}", Debug2Format(&e)); - } - Ok(report) => { - info!("Received report: {:08x}", report.packet); - // rumble packet - if report.packet[0] == 0x11 { - info!("Received rumble info: Controller1 ({:08x}) Controller2 ({:08x}) Controller3 ({:08x}) Controller4 ({:08x})", report.packet[1], report.packet[2], report.packet[3], report.packet[4]); - } - } - } + fn reset(&mut self) { + self.configured = false; + info!("Bus reset, the Vbus current limit is 100mA"); + } + + fn addressed(&mut self, addr: u8) { + self.configured = false; + info!("USB address set to: {}", addr); + } + + fn configured(&mut self, configured: bool) { + self.configured = configured; + if configured { + info!( + "Device configured, it may now draw up to the configured current limit from Vbus." + ) + } else { + info!("Device is no longer configured, the Vbus current limit is 100mA."); } } } + +#[embassy_executor::task] +pub async fn usb_transfer_loop(driver: Driver<'static, USB>) { + debug!("Start of config"); + let mut usb_config = embassy_usb::Config::new(0x057e, 0x0337); + usb_config.manufacturer = Some("Naxdy"); + usb_config.product = Some("NaxGCC"); + usb_config.serial_number = Some("Fleeb"); + usb_config.max_power = 100; + usb_config.max_packet_size_0 = 64; + usb_config.device_class = 0; + usb_config.device_protocol = 0; + usb_config.self_powered = false; + usb_config.device_sub_class = 0; + usb_config.supports_remote_wakeup = false; + + let mut device_descriptor = [0; 256]; + let mut config_descriptor = [0; 256]; + let mut bos_descriptor = [0; 256]; + let mut msos_descriptor = [0; 256]; + let mut control_buf = [0; 64]; + + let request_handler = GccRequestHandler {}; + let mut device_handler = MyDeviceHandler::new(); + + let mut state = State::new(); + + let mut builder = Builder::new( + driver, + usb_config, + &mut device_descriptor, + &mut config_descriptor, + &mut bos_descriptor, + &mut msos_descriptor, + &mut control_buf, + ); + + builder.handler(&mut device_handler); + + let hid_config = embassy_usb::class::hid::Config { + report_descriptor: GCC_REPORT_DESCRIPTOR, + request_handler: Some(&request_handler), + poll_ms: 1, + max_packet_size: 64, + }; + let hid = HidReaderWriter::<_, 5, 37>::new(&mut builder, &mut state, hid_config); + + let mut usb = builder.build(); + + let usb_fut = async { + loop { + usb.run_until_suspend().await; + debug!("Suspended"); + usb.wait_resume().await; + debug!("RESUMED!"); + } + }; + + let (mut reader, mut writer) = hid.split(); + debug!("In here"); + + let mut timer = embassy_time::Ticker::every(Duration::from_millis(1)); + + let in_fut = async { + loop { + let state = unsafe { GCC_STATE.clone() }; + let report = get_gcinput_hid_report(&state); + match writer.write(&report).await { + Ok(()) => { + trace!("Report Written: {:08b}", report); + } + Err(e) => warn!("Failed to send report: {:?}", e), + } + } + }; + + let out_fut = async { + loop { + debug!("Readery loop"); + let mut buf = [0u8; 5]; + match reader.read(&mut buf).await { + Ok(e) => { + debug!("READ SOMETHIN: {:08b}", buf) + } + Err(e) => { + warn!("Failed to read: {:?}", e); + } + } + } + }; + + let usb_fut_wrapped = async { + usb_fut.await; + debug!("USB FUT DED"); + }; + + join(usb_fut_wrapped, join(in_fut, out_fut)).await; +} diff --git a/src/input.rs b/src/input.rs index 3c02b40..94d5d22 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,5 +1,5 @@ -use defmt::info; -use embedded_hal::digital::v2::InputPin; +use defmt::{debug, info}; +use embassy_rp::{gpio::Input, peripherals::PIN_15, Peripherals}; use crate::gcc_hid::{Buttons1, Buttons2, GcReport}; @@ -29,87 +29,11 @@ pub static mut GCC_STATE: GcReport = GcReport { trigger_r: 0, }; -macro_rules! pin_inputs { - ($x:tt {$($f:tt: $g:tt),*}) => { - pub struct $x<$($g,)*> - where - $( - $g: InputPin, - )* - { - $( - pub $f: $g, - )* - } - }; -} - -macro_rules! assign_pins { - ($gcc:expr, $inputs:tt, {$($p:tt.$c:tt),*}) => { - $( - $gcc.$p.$c = $inputs.$c.is_low().map_err(|_| "").unwrap(); - )* - }; -} - -pin_inputs!(BasicInputs { - button_a: A, - button_b: B, - button_x: X, - button_y: Y, - dpad_left: Dl, - dpad_right: Dr, - dpad_down: Dd, - dpad_up: Du, - button_start: S, - button_z: Z, - button_r: R, - button_l: L -}); - -pub fn input_loop< - A: InputPin, - B: InputPin, - X: InputPin, - Y: InputPin, - Dl: InputPin, - Dr: InputPin, - Dd: InputPin, - Du: InputPin, - S: InputPin, - Z: InputPin, - R: InputPin, - L: InputPin, ->( - basic_inputs: BasicInputs, -) -> ! { - info!("Input loop started."); - - let update_gcc_state = || unsafe { - // simple booleans - assign_pins!(GCC_STATE, basic_inputs, { - buttons_1.button_a, - buttons_1.button_b, - buttons_1.button_x, - buttons_1.button_y, - buttons_1.dpad_left, - buttons_1.dpad_right, - buttons_1.dpad_down, - buttons_1.dpad_up, - buttons_2.button_start, - buttons_2.button_z, - buttons_2.button_r, - buttons_2.button_l - }); - - // TODO: sticks - GCC_STATE.cstick_x = 127; - GCC_STATE.cstick_y = 127; - GCC_STATE.stick_x = 127; - GCC_STATE.stick_y = 127; - }; - +#[embassy_executor::task] +pub async fn input_loop(btn_z: Input<'static, PIN_15>) -> ! { loop { - update_gcc_state(); + unsafe { + GCC_STATE.buttons_2.button_z = btn_z.is_low(); + } } } diff --git a/src/main.rs b/src/main.rs index 6c83554..33d4a5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,186 +1,53 @@ -//! # GPIO 'Blinky' Example +//! This example test the RP Pico on board LED. //! -//! This application demonstrates how to control a GPIO pin on the RP2040. -//! -//! It may need to be adapted to your particular board layout and/or pin assignment. -//! -//! See the `Cargo.toml` file for Copyright and license details. +//! It does not work with the RP Pico W board. See wifi_blinky.rs. #![no_std] #![no_main] -mod flash_mem; mod gcc_hid; mod input; -use cortex_m::interrupt::Mutex; -use defmt::{error, info}; - -use fugit::{ExtU32, RateExtU32}; - -// Ensure we halt the program on panic (if we don't mention this crate it won't -// be linked) -use defmt_rtt as _; -use panic_probe as _; - -use rp2040_flash::flash::flash_unique_id; -// Alias for our HAL crate -use rp2040_hal as hal; - -// A shorter alias for the Peripheral Access Crate, which provides low-level -// register access -use hal::{ - gpio::FunctionSpi, - multicore::{self, Multicore, Stack}, - pac, Spi, -}; - -// Some traits we need -use embedded_hal::{ - blocking::{delay::DelayMs, spi::Transfer}, - digital::v2::OutputPin, - spi::MODE_0, - timer::CountDown, -}; - -use usb_device::bus::UsbBusAllocator; - -use crate::{ - flash_mem::{read_from_flash, write_to_flash}, - gcc_hid::usb_transfer_loop, - input::{input_loop, BasicInputs}, +use defmt::info; +use embassy_executor::{Executor, Spawner}; +use embassy_rp::{ + bind_interrupts, + gpio::{self, Input}, + multicore::{spawn_core1, Stack}, + peripherals::USB, + usb::{Driver, InterruptHandler}, }; +use embassy_time::Timer; +use gcc_hid::usb_transfer_loop; +use gpio::{Level, Output}; +use input::input_loop; +use static_cell::StaticCell; +use {defmt_rtt as _, panic_probe as _}; static mut CORE1_STACK: Stack<4096> = Stack::new(); +static EXECUTOR0: StaticCell = StaticCell::new(); +static EXECUTOR1: StaticCell = StaticCell::new(); -pub static mut LOCKED: bool = false; +bind_interrupts!(struct Irqs { + USBCTRL_IRQ => InterruptHandler; +}); -pub static CORE_LOCK: Mutex<()> = Mutex::new(()); - -/// The linker will place this boot block at the start of our program image. We -/// need this to help the ROM bootloader get our code up and running. -/// Note: This boot block is not necessary when using a rp-hal based BSP -/// as the BSPs already perform this step. -#[link_section = ".boot2"] -#[used] -pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H; - -/// External high-speed crystal on the Raspberry Pi Pico board is 12 MHz. Adjust -/// if your board has a different frequency -const XTAL_FREQ_HZ: u32 = 12_000_000u32; - -/// Entry point to our bare-metal application. -/// -/// The `#[rp2040_hal::entry]` macro ensures the Cortex-M start-up code calls this function -/// as soon as all global variables and the spinlock are initialised. -/// -/// The function configures the RP2040 peripherals, then toggles a GPIO pin in -/// an infinite loop. If there is an LED connected to that pin, it will blink. -#[rp2040_hal::entry] +#[cortex_m_rt::entry] fn main() -> ! { - // Grab our singleton objects - let mut pac = pac::Peripherals::take().unwrap(); + let p = embassy_rp::init(Default::default()); - // Set up the watchdog driver - needed by the clock setup code - let mut watchdog = hal::Watchdog::new(pac.WATCHDOG); + let driver = Driver::new(p.USB, Irqs); - // Configure the clocks - let clocks = hal::clocks::init_clocks_and_plls( - XTAL_FREQ_HZ, - pac.XOSC, - pac.CLOCKS, - pac.PLL_SYS, - pac.PLL_USB, - &mut pac.RESETS, - &mut watchdog, - ) - .ok() - .unwrap(); + info!("Initializing"); - let mut timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks); + spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || { + let executor1 = EXECUTOR1.init(Executor::new()); + executor1.run(|spawner| spawner.spawn(usb_transfer_loop(driver)).unwrap()); + }); - // The single-cycle I/O block controls our GPIO pins - let mut sio = hal::Sio::new(pac.SIO); - - // Set the pins to their default state - let pins = hal::gpio::Pins::new( - pac.IO_BANK0, - pac.PADS_BANK0, - sio.gpio_bank0, - &mut pac.RESETS, - ); - - // usb parts - let usb_bus = UsbBusAllocator::new(hal::usb::UsbBus::new( - pac.USBCTRL_REGS, - pac.USBCTRL_DPRAM, - clocks.usb_clock, - true, - &mut pac.RESETS, - )); - - let mut mc = Multicore::new(&mut pac.PSM, &mut pac.PPB, &mut sio.fifo); - let cores = mc.cores(); - let core1 = &mut cores[1]; - - let _transfer_loop = core1 - .spawn(unsafe { &mut CORE1_STACK.mem }, move || { - let mut poll_timer = timer.count_down(); - poll_timer.start(1.millis()); - - usb_transfer_loop(usb_bus, poll_timer) - }) - .unwrap(); - - info!("Initialized"); - - let mut ccs = pins.gpio23.into_push_pull_output(); - let mut acs = pins.gpio24.into_push_pull_output(); - - ccs.set_high().unwrap(); - acs.set_high().unwrap(); - - let spi_device = pac.SPI0; - - let clk = pins.gpio6.into_function::(); - let tx = pins.gpio7.into_function::(); - let rx = pins.gpio4.into_function::(); - - let spi_pin_layout = (tx, rx, clk); - - let mut spi = Spi::<_, _, _, 8>::new(spi_device, spi_pin_layout).init( - &mut pac.RESETS, - 3_000_000u32.Hz(), - 3_000_000u32.Hz(), - MODE_0, - ); - - let mut w = [0b11010000u8; 3]; - - info!("W is {}", w); - - let r = spi.transfer(&mut w); - - match r { - Ok(t) => { - info!("T is {}", t) - } - Err(e) => { - error!("SPI transfer failed: {}", e); - } - } - - input_loop(BasicInputs { - button_a: pins.gpio17.into_pull_up_input(), - button_b: pins.gpio16.into_pull_up_input(), - button_x: pins.gpio18.into_pull_up_input(), - button_y: pins.gpio19.into_pull_up_input(), - button_z: pins.gpio20.into_pull_up_input(), - button_r: pins.gpio21.into_pull_up_input(), - button_l: pins.gpio22.into_pull_up_input(), - dpad_left: pins.gpio8.into_pull_up_input(), - dpad_up: pins.gpio9.into_pull_up_input(), - dpad_down: pins.gpio10.into_pull_up_input(), - dpad_right: pins.gpio11.into_pull_up_input(), - button_start: pins.gpio5.into_pull_up_input(), + let executor0 = EXECUTOR0.init(Executor::new()); + executor0.run(|spawner| { + spawner + .spawn(input_loop(Input::new(p.PIN_15, gpio::Pull::Up))) + .unwrap() }); }