figured out how to print text to the console
This commit is contained in:
parent
45affbb325
commit
d1b1bb1038
316
Cargo.lock
generated
316
Cargo.lock
generated
@ -14,6 +14,15 @@ dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "as-slice"
|
||||
version = "0.1.5"
|
||||
@ -83,6 +92,12 @@ dependencies = [
|
||||
"rustc_version 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "bitfield"
|
||||
version = "0.13.2"
|
||||
@ -119,12 +134,27 @@ version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "byterepr"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7eb1a05c2ec66850db33d8dd2119626aef815662a074656a74bbe47a562fdf4"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "const-default"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b396d1f76d455557e1218ec8066ae14bba60b4b36ecd55577ba979f5db7ecaa"
|
||||
|
||||
[[package]]
|
||||
name = "cortex-m"
|
||||
version = "0.7.7"
|
||||
@ -428,6 +458,7 @@ checksum = "f820157f198ada183ad62e0a66f554c610cdcd1a9f27d4b316358103ced7a1f8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"critical-section",
|
||||
"defmt",
|
||||
"document-features",
|
||||
"embassy-time-driver",
|
||||
"embedded-hal 0.2.7",
|
||||
@ -491,6 +522,18 @@ dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-alloc"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f2de9133f68db0d4627ad69db767726c99ff8585272716708227008d3f1bddd"
|
||||
dependencies = [
|
||||
"const-default",
|
||||
"critical-section",
|
||||
"linked_list_allocator",
|
||||
"rlsf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "0.2.7"
|
||||
@ -564,6 +607,16 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flatbuffers"
|
||||
version = "23.5.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dac53e22462d78c16d64a1cd22371b54cc3fe94aa15e7886a2fa6e5d1ab8640"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"rustc_version 0.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
@ -694,6 +747,24 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
|
||||
|
||||
[[package]]
|
||||
name = "linked_list_allocator"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286"
|
||||
|
||||
[[package]]
|
||||
name = "litrs"
|
||||
version = "0.4.1"
|
||||
@ -716,6 +787,83 @@ version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
||||
|
||||
[[package]]
|
||||
name = "matrixmultiply"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"rawpointer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "microflow"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"libm",
|
||||
"microflow-macros",
|
||||
"nalgebra 0.33.2",
|
||||
"simba 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "microflow-macros"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"byterepr",
|
||||
"flatbuffers",
|
||||
"nalgebra 0.32.6",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"simba 0.8.1",
|
||||
"structmeta",
|
||||
"syn 2.0.94",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nalgebra"
|
||||
version = "0.32.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b5c17de023a86f59ed79891b2e5d5a94c705dbe904a5b5c9c952ea6221b03e4"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"matrixmultiply",
|
||||
"nalgebra-macros",
|
||||
"num-complex",
|
||||
"num-rational",
|
||||
"num-traits",
|
||||
"simba 0.8.1",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nalgebra"
|
||||
version = "0.33.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26aecdf64b707efd1310e3544d709c5c0ac61c13756046aaaba41be5c4f66a3b"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"nalgebra-macros",
|
||||
"num-complex",
|
||||
"num-rational",
|
||||
"num-traits",
|
||||
"simba 0.9.0",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nalgebra-macros"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.94",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nb"
|
||||
version = "0.1.3"
|
||||
@ -741,6 +889,34 @@ dependencies = [
|
||||
"cortex-m-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
||||
dependencies = [
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@ -766,6 +942,12 @@ dependencies = [
|
||||
"defmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.16"
|
||||
@ -784,6 +966,30 @@ version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr2"
|
||||
version = "2.0.0"
|
||||
@ -830,6 +1036,24 @@ version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
|
||||
[[package]]
|
||||
name = "rawpointer"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
|
||||
|
||||
[[package]]
|
||||
name = "rlsf"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "222fb240c3286247ecdee6fa5341e7cdad0ffdf8e7e401d9937f2d58482a20bf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"const-default",
|
||||
"libc",
|
||||
"svgbobdoc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
@ -848,6 +1072,15 @@ dependencies = [
|
||||
"semver 1.0.24",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "safe_arch"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
@ -895,6 +1128,31 @@ dependencies = [
|
||||
"syn 2.0.94",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simba"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "061507c94fc6ab4ba1c9a0305018408e312e17c041eb63bef8aa726fa33aceae"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"num-complex",
|
||||
"num-traits",
|
||||
"paste",
|
||||
"wide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simba"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3a386a501cd104797982c15ae17aafe8b9261315b5d07e3ec803f2ea26be0fa"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"num-complex",
|
||||
"num-traits",
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
@ -935,6 +1193,42 @@ version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "structmeta"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e1575d8d40908d70f6fd05537266b90ae71b15dbbe7a8b7dffa2b759306d329"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"structmeta-derive",
|
||||
"syn 2.0.94",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structmeta-derive"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "152a0b65a590ff6c3da95cabe2353ee04e6167c896b28e3b14478c2636c922fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.94",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "svgbobdoc"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2c04b93fc15d79b39c63218f15e3fdffaa4c227830686e3b7c5f41244eb3e50"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
@ -973,11 +1267,17 @@ dependencies = [
|
||||
"embassy-futures",
|
||||
"embassy-nrf",
|
||||
"embassy-sync 0.6.1",
|
||||
"embassy-time",
|
||||
"embassy-usb",
|
||||
"embassy-usb-logger",
|
||||
"embedded-alloc",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"fixed",
|
||||
"heapless 0.8.0",
|
||||
"libm",
|
||||
"microflow",
|
||||
"nalgebra 0.33.2",
|
||||
"panic-probe",
|
||||
"static_cell",
|
||||
]
|
||||
@ -1014,6 +1314,12 @@ version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||
|
||||
[[package]]
|
||||
name = "usb-device"
|
||||
version = "0.3.2"
|
||||
@ -1088,6 +1394,16 @@ dependencies = [
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wide"
|
||||
version = "0.7.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41b5576b9a81633f3e8df296ce0063042a73507636cbe956c61133dd7034ab22"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"safe_arch",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.35"
|
||||
|
20
Cargo.toml
20
Cargo.toml
@ -17,7 +17,10 @@ members = ["tflite_demo"]
|
||||
# ]
|
||||
|
||||
[workspace.dependencies]
|
||||
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
|
||||
cortex-m = { version = "0.7.7", features = [
|
||||
"critical-section-single-core",
|
||||
"inline-asm",
|
||||
] }
|
||||
cortex-m-rt = "0.7.5"
|
||||
defmt = "0.3.10"
|
||||
defmt-rtt = "0.4.1"
|
||||
@ -54,15 +57,15 @@ panic-probe = { version = "0.3.2", features = ["print-defmt"] }
|
||||
# nrf52840-hal = "0.16.0"
|
||||
# usb-device = "0.3.2"
|
||||
# usbd-serial = "0.2.2"
|
||||
# microflow = { path = "../microflow-rs" }
|
||||
microflow = { path = "../microflow-rs" }
|
||||
# # microflow = "0.1.3"
|
||||
# nalgebra = { version = "0.33.2", default-features = false, features = [
|
||||
# "macros",
|
||||
# ] }
|
||||
# libm = "0.2"
|
||||
nalgebra = { version = "0.33.2", default-features = false, features = [
|
||||
"macros",
|
||||
] }
|
||||
libm = "0.2"
|
||||
# panic-halt = "1.0.0"
|
||||
# panic-probe = { version = "0.3.2", features = ["print-defmt"] }
|
||||
# heapless = "0.8.0"
|
||||
heapless = "0.8.0"
|
||||
# lsm6ds3tr = { path = "../lsm6ds3tr-rs" }
|
||||
|
||||
# embassy-sync = { version = "0.5.0" }
|
||||
@ -91,8 +94,9 @@ panic-probe = { version = "0.3.2", features = ["print-defmt"] }
|
||||
# embedded-storage = "0.3.0"
|
||||
embedded-hal = "1.0.0"
|
||||
embedded-hal-async = { version = "1.0.0" }
|
||||
embedded-alloc = "0.6.0"
|
||||
|
||||
# embedded-hal-bus = { version = "0.2.0", features = ["async"] }
|
||||
# embedded-alloc = "0.6.0"
|
||||
# nrf-softdevice = { version = "0.1.0", features = [
|
||||
# "defmt",
|
||||
# "ble-peripheral",
|
||||
|
@ -14,8 +14,9 @@ embassy-embedded-hal.workspace = true
|
||||
embassy-futures.workspace = true
|
||||
embassy-usb.workspace = true
|
||||
embassy-usb-logger.workspace = true
|
||||
embassy-time.workspace = true
|
||||
|
||||
# embedded-alloc.workspace = true
|
||||
embedded-alloc.workspace = true
|
||||
embedded-hal.workspace = true
|
||||
embedded-hal-async.workspace = true
|
||||
|
||||
@ -29,9 +30,9 @@ defmt-rtt.workspace = true
|
||||
# usb-device.workspace = true
|
||||
# usbd-serial.workspace = true
|
||||
|
||||
# microflow.workspace = true
|
||||
# libm.workspace = true
|
||||
# nalgebra.workspace = true
|
||||
microflow.workspace = true
|
||||
libm.workspace = true
|
||||
nalgebra.workspace = true
|
||||
|
||||
# heapless.workspace = true
|
||||
# lsm6ds3tr.workspace = true
|
||||
@ -39,6 +40,7 @@ defmt-rtt.workspace = true
|
||||
# nrf-softdevice-s140.workspace = true
|
||||
fixed.workspace = true
|
||||
atomic-pool.workspace = true
|
||||
heapless.workspace = true
|
||||
|
||||
panic-probe.workspace = true
|
||||
defmt-serial.workspace = true
|
||||
|
@ -3,25 +3,29 @@
|
||||
|
||||
mod lsm6ds3tr;
|
||||
|
||||
use defmt::{info, panic};
|
||||
use core::fmt::Write;
|
||||
use defmt::{info, panic, unwrap};
|
||||
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_nrf::peripherals::TWISPI0;
|
||||
use embassy_nrf::twim::Twim;
|
||||
use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect};
|
||||
use embassy_nrf::usb::{Driver, Instance};
|
||||
use embassy_nrf::usb::vbus_detect::HardwareVbusDetect;
|
||||
use embassy_nrf::usb::Driver;
|
||||
use embassy_nrf::{bind_interrupts, pac, peripherals, twim, usb};
|
||||
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
|
||||
use embassy_sync::mutex::Mutex;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
|
||||
use embassy_usb::driver::EndpointError;
|
||||
use embassy_usb::{Builder, Config};
|
||||
use embassy_usb::{Builder, Config, UsbDevice};
|
||||
use embedded_alloc::LlffHeap;
|
||||
|
||||
use lsm6ds3tr::interface::i2c::I2cInterface;
|
||||
// use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice;
|
||||
use static_cell::StaticCell;
|
||||
|
||||
use heapless::String;
|
||||
|
||||
use {defmt_serial as _, panic_probe as _};
|
||||
|
||||
static I2C_BUS: StaticCell<Mutex<NoopRawMutex, Twim<TWISPI0>>> = StaticCell::new();
|
||||
@ -31,8 +35,91 @@ bind_interrupts!(struct Irqs {
|
||||
CLOCK_POWER => usb::vbus_detect::InterruptHandler;
|
||||
});
|
||||
|
||||
type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
|
||||
|
||||
#[global_allocator]
|
||||
static HEAP: LlffHeap = LlffHeap::empty();
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn usb_task(mut device: UsbDevice<'static, MyDriver>) {
|
||||
device.run().await;
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn echo_task(mut class: CdcAcmClass<'static, MyDriver>) {
|
||||
loop {
|
||||
class.wait_connection().await;
|
||||
info!("Connected");
|
||||
let _ = echo(&mut class).await;
|
||||
info!("Disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
// async fn write_task(
|
||||
// mut class: CdcAcmClass<'static, MyDriver>,
|
||||
// mut imu: lsm6ds3tr::LSM6DS3TR<
|
||||
// I2cInterface<I2cDevice<'static, NoopRawMutex, Twim<'static, TWISPI0>>>,
|
||||
// >,
|
||||
// ) {
|
||||
// loop {
|
||||
// class.wait_connection().await;
|
||||
// info!("Connected");
|
||||
|
||||
// // Read accelerometer data from the IMU
|
||||
// let accel_data = imu.read_accel().await.unwrap();
|
||||
|
||||
// let mut data = String::<32>::new();
|
||||
// if write!(
|
||||
// data,
|
||||
// "Accel: x={}, y={}, z={}\r\n",
|
||||
// accel_data.x, accel_data.y, accel_data.z
|
||||
// )
|
||||
// .is_ok()
|
||||
// {
|
||||
// if let Err(e) = class.write_packet(data.as_bytes()).await {
|
||||
// info!("Failed to write to serial console: {:?}", e);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // // Format the accelerometer data
|
||||
// // let message = format!(
|
||||
// // "Accel: x={}, y={}, z={}\r\n",
|
||||
// // accel_data.x, accel_data.y, accel_data.z
|
||||
// // );
|
||||
// // if let Err(e) = class.write_packet(message.as_bytes()).await {
|
||||
// // info!("Failed to write to serial console: {:?}", e);
|
||||
// // }
|
||||
|
||||
// // Add a delay of 1 second
|
||||
// Timer::after(Duration::from_secs(1)).await;
|
||||
|
||||
// info!("Disconnected");
|
||||
// }
|
||||
// }
|
||||
async fn write_task(mut class: CdcAcmClass<'static, MyDriver>) {
|
||||
let mut count = 1;
|
||||
loop {
|
||||
class.wait_connection().await;
|
||||
info!("Connected");
|
||||
|
||||
let mut data = String::<32>::new();
|
||||
if write!(data, "Count: {}\r\n", count).is_ok() {
|
||||
if let Err(e) = class.write_packet(data.as_bytes()).await {
|
||||
info!("Failed to write to serial console: {:?}", e);
|
||||
}
|
||||
}
|
||||
count += 1;
|
||||
|
||||
// Add a delay of 1 second
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
|
||||
info!("Disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
|
||||
info!("Enabling ext hfosc...");
|
||||
@ -50,49 +137,30 @@ async fn main(_spawner: Spawner) {
|
||||
config.max_power = 100;
|
||||
config.max_packet_size_0 = 64;
|
||||
|
||||
static STATE: StaticCell<State> = StaticCell::new();
|
||||
let state = STATE.init(State::new());
|
||||
|
||||
// Create embassy-usb DeviceBuilder using the driver and config.
|
||||
// It needs some buffers for building the descriptors.
|
||||
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 mut state = State::new();
|
||||
|
||||
static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new();
|
||||
static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new();
|
||||
static MSOS_DESC: StaticCell<[u8; 128]> = StaticCell::new();
|
||||
static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new();
|
||||
let mut builder = Builder::new(
|
||||
driver,
|
||||
config,
|
||||
&mut config_descriptor,
|
||||
&mut bos_descriptor,
|
||||
&mut msos_descriptor,
|
||||
&mut control_buf,
|
||||
&mut CONFIG_DESC.init([0; 256])[..],
|
||||
&mut BOS_DESC.init([0; 256])[..],
|
||||
&mut MSOS_DESC.init([0; 128])[..],
|
||||
&mut CONTROL_BUF.init([0; 128])[..],
|
||||
);
|
||||
|
||||
// Create classes on the builder.
|
||||
let mut class = CdcAcmClass::new(&mut builder, &mut state, 64);
|
||||
let class = CdcAcmClass::new(&mut builder, state, 64);
|
||||
|
||||
// Build the builder.
|
||||
let mut usb = builder.build();
|
||||
let usb = builder.build();
|
||||
|
||||
// Run the USB device.
|
||||
let usb_fut = usb.run();
|
||||
|
||||
// Do stuff with the class!
|
||||
let echo_fut = async {
|
||||
loop {
|
||||
class.wait_connection().await;
|
||||
info!("Connected");
|
||||
let _ = echo(&mut class).await;
|
||||
info!("Disconnected");
|
||||
}
|
||||
};
|
||||
|
||||
// Run everything concurrently.
|
||||
// If we had made everything `'static` above instead, we could do this using separate tasks instead.
|
||||
join(usb_fut, echo_fut).await;
|
||||
|
||||
// let config = twim::Config::default();
|
||||
// let i2c = embassy_nrf::twim::Twim::new(p.TWISPI0, Irqs2, p.P0_07, p.P0_27, config);
|
||||
unwrap!(spawner.spawn(usb_task(usb)));
|
||||
|
||||
let i2c_bus = {
|
||||
use embassy_nrf::{
|
||||
@ -114,13 +182,13 @@ async fn main(_spawner: Spawner) {
|
||||
let i2c = I2cDevice::new(i2c_bus);
|
||||
|
||||
let interface = I2cInterface::new(i2c);
|
||||
let imu = lsm6ds3tr::LSM6DS3TR::new(interface);
|
||||
let mut imu = lsm6ds3tr::LSM6DS3TR::new(interface);
|
||||
|
||||
// let mut serial_port = usbd_serial::SerialPort::new(&usb);
|
||||
// imu.init().await.unwrap();
|
||||
|
||||
loop {
|
||||
info!("Hello, world!");
|
||||
}
|
||||
// imu.read_accel().await.unwrap();
|
||||
|
||||
unwrap!(spawner.spawn(write_task(class)));
|
||||
}
|
||||
|
||||
struct Disconnected {}
|
||||
@ -134,9 +202,7 @@ impl From<EndpointError> for Disconnected {
|
||||
}
|
||||
}
|
||||
|
||||
async fn echo<'d, T: Instance + 'd, P: VbusDetect + 'd>(
|
||||
class: &mut CdcAcmClass<'d, Driver<'d, T, P>>,
|
||||
) -> Result<(), Disconnected> {
|
||||
async fn echo(class: &mut CdcAcmClass<'static, MyDriver>) -> Result<(), Disconnected> {
|
||||
let mut buf = [0; 64];
|
||||
loop {
|
||||
let n = class.read_packet(&mut buf).await?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user