up
This commit is contained in:
258
Cargo.lock
generated
258
Cargo.lock
generated
@@ -33,15 +33,6 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@@ -108,7 +99,7 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
|
||||
dependencies = [
|
||||
"rustc_version 0.2.3",
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -153,15 +144,6 @@ version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "byterepr"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7eb1a05c2ec66850db33d8dd2119626aef815662a074656a74bbe47a562fdf4"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.3.0"
|
||||
@@ -639,16 +621,6 @@ 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"
|
||||
@@ -858,7 +830,6 @@ dependencies = [
|
||||
"heapless",
|
||||
"libm",
|
||||
"lsm6ds3tr",
|
||||
"nalgebra 0.33.2",
|
||||
"nrf-softdevice",
|
||||
"nrf-softdevice-s140",
|
||||
"nrf52840-hal",
|
||||
@@ -868,89 +839,12 @@ dependencies = [
|
||||
"usbd-serial",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matrixmultiply"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"rawpointer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[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"
|
||||
@@ -1073,34 +967,6 @@ dependencies = [
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[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"
|
||||
@@ -1146,12 +1012,6 @@ 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"
|
||||
@@ -1170,30 +1030,6 @@ 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"
|
||||
@@ -1240,12 +1076,6 @@ 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 = "regex"
|
||||
version = "1.11.1"
|
||||
@@ -1293,25 +1123,7 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
|
||||
dependencies = [
|
||||
"semver 1.0.24",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "safe_arch"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1323,12 +1135,6 @@ dependencies = [
|
||||
"semver-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba"
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
@@ -1355,31 +1161,6 @@ 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 = "ssmarshal"
|
||||
version = "1.0.0"
|
||||
@@ -1417,29 +1198,6 @@ 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"
|
||||
@@ -1499,8 +1257,6 @@ dependencies = [
|
||||
"heapless",
|
||||
"libm",
|
||||
"lsm6ds3tr",
|
||||
"microflow",
|
||||
"nalgebra 0.33.2",
|
||||
"nrf-softdevice",
|
||||
"nrf-softdevice-s140",
|
||||
"nrf52840-hal",
|
||||
@@ -1645,16 +1401,6 @@ dependencies = [
|
||||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wide"
|
||||
version = "0.7.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58e6db2670d2be78525979e9a5f9c69d296fd7d670549fe9ebf70f8708cb5019"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"safe_arch",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.35"
|
||||
|
||||
@@ -50,9 +50,9 @@ nrf52840-hal = "0.16.0"
|
||||
usb-device = "0.2.7"
|
||||
usbd-serial = "0.1.0"
|
||||
microflow = { path = "../microflow-rs" }
|
||||
nalgebra = { version = "0.33.2", default-features = false, features = [
|
||||
"macros",
|
||||
] }
|
||||
# nalgebra = { version = "0.33.2", default-features = false, features = [
|
||||
# "macros",
|
||||
# ] }
|
||||
libm = "0.2"
|
||||
panic-halt = "1.0.0"
|
||||
heapless = "0.8.0"
|
||||
|
||||
BIN
bluetooth_demo/.DS_Store
vendored
Normal file
BIN
bluetooth_demo/.DS_Store
vendored
Normal file
Binary file not shown.
36
bluetooth_demo/Cargo.toml
Normal file
36
bluetooth_demo/Cargo.toml
Normal file
@@ -0,0 +1,36 @@
|
||||
[package]
|
||||
name = "bluetooth_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cortex-m.workspace = true
|
||||
cortex-m-rt.workspace = true
|
||||
nrf52840-hal.workspace = true
|
||||
usb-device.workspace = true
|
||||
usbd-serial.workspace = true
|
||||
libm.workspace = true
|
||||
# nalgebra.workspace = true
|
||||
heapless.workspace = true
|
||||
lsm6ds3tr.workspace = true
|
||||
defmt.workspace = true
|
||||
defmt-rtt.workspace = true
|
||||
embedded-alloc.workspace = true
|
||||
embedded-hal.workspace = true
|
||||
embedded-hal-async.workspace = true
|
||||
nrf-softdevice.workspace = true
|
||||
nrf-softdevice-s140.workspace = true
|
||||
embassy-nrf.workspace = true
|
||||
embassy-time.workspace = true
|
||||
embassy-executor.workspace = true
|
||||
embassy-sync.workspace = true
|
||||
embassy-embedded-hal.workspace = true
|
||||
fixed.workspace = true
|
||||
atomic-pool.workspace = true
|
||||
static_cell.workspace = true
|
||||
embassy-usb.workspace = true
|
||||
embassy-futures.workspace = true
|
||||
panic-probe.workspace = true
|
||||
assign-resources.workspace = true
|
||||
4
bluetooth_demo/src/common.rs
Normal file
4
bluetooth_demo/src/common.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#![macro_use]
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use embassy_nrf as _; // time driver
|
||||
89
bluetooth_demo/src/main.rs
Normal file
89
bluetooth_demo/src/main.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use assign_resources::assign_resources;
|
||||
use core::fmt::Write;
|
||||
use defmt::{dbg, info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::usb::vbus_detect::HardwareVbusDetect;
|
||||
use embassy_nrf::usb::Driver;
|
||||
use embassy_nrf::{bind_interrupts, peripherals, twim, usb, Peripherals};
|
||||
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
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, UsbDevice};
|
||||
use heapless::String;
|
||||
use lsm6ds3tr::interface::I2cInterface;
|
||||
use lsm6ds3tr::{
|
||||
registers::{GyroSampleRate, GyroScale},
|
||||
AccelSampleRate, AccelScale, AccelSettings, GyroSettings, LsmSettings, LSM6DS3TR,
|
||||
};
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
mod usb_dfu;
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
USBD => usb::InterruptHandler<peripherals::USBD>;
|
||||
CLOCK_POWER => usb::vbus_detect::InterruptHandler;
|
||||
});
|
||||
|
||||
assign_resources! {
|
||||
imu: ImuResources {
|
||||
spi: SPI2,
|
||||
}
|
||||
}
|
||||
|
||||
bind_interrupts!(struct IrqsTest {
|
||||
// SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0 => twim::InterruptHandler<TWISPI0>;
|
||||
TWISPI0 => twim::InterruptHandler<peripherals::TWISPI0>;
|
||||
});
|
||||
|
||||
static I2C_BUS: StaticCell<Mutex<ThreadModeRawMutex, twim::Twim<peripherals::TWISPI0>>> =
|
||||
StaticCell::new();
|
||||
|
||||
type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
// let resources = split_resources!(p);
|
||||
|
||||
// Create the driver, from the HAL.
|
||||
let driver = Driver::new(p.USBD, Irqs, HardwareVbusDetect::new(Irqs));
|
||||
|
||||
let mut config = Config::new(0xc0de, 0xcafe);
|
||||
config.manufacturer = Some("Umbrella Corporation");
|
||||
config.product = Some("Secret Project");
|
||||
config.serial_number = Some("11880");
|
||||
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.
|
||||
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_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, state, 64);
|
||||
|
||||
// Build the builder.
|
||||
let usb = builder.build();
|
||||
|
||||
unwrap!(spawner.spawn(usb_task(usb)));
|
||||
}
|
||||
157
bluetooth_demo/src/usb_dfu.rs
Normal file
157
bluetooth_demo/src/usb_dfu.rs
Normal file
@@ -0,0 +1,157 @@
|
||||
use crate::Irqs;
|
||||
use core::fmt::Write;
|
||||
use defmt::{info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_nrf::peripherals::USBD;
|
||||
use embassy_nrf::usb::vbus_detect::{HardwareVbusDetect, VbusDetect};
|
||||
use embassy_nrf::usb::{Driver, Instance};
|
||||
use embassy_nrf::{pac, peripherals};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
|
||||
use embassy_usb::driver::EndpointError;
|
||||
use embassy_usb::{Builder, Config};
|
||||
use heapless::String;
|
||||
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const MAGIC_REBOOT_MESSAGE: &str = "bootloader";
|
||||
|
||||
type MyDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
|
||||
|
||||
/// Creates a usb serial device.
|
||||
/// Sending it [MAGIC_REBOOT_MESSAGE] will reboot the device
|
||||
/// into serial-only-dfu mode.
|
||||
pub fn setup_dfu_over_usb(spawner: &Spawner, usbd: USBD) {
|
||||
spawner.spawn(dfu_over_usb(usbd, *spawner)).unwrap();
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn dfu_over_usb(usbd: USBD, spawner: Spawner) {
|
||||
pac::CLOCK.tasks_hfclkstart().write_value(1);
|
||||
while pac::CLOCK.events_hfclkstarted().read() != 1 {}
|
||||
|
||||
// Create the driver, from the HAL.
|
||||
let driver = Driver::new(usbd, Irqs, HardwareVbusDetect::new(Irqs));
|
||||
|
||||
// Create embassy-usb Config
|
||||
let mut config = Config::new(0xc0de, 0xcafe);
|
||||
config.manufacturer = Some("Embassy");
|
||||
config.product = Some("USB-serial example");
|
||||
config.serial_number = Some("12345678");
|
||||
config.max_power = 100;
|
||||
config.max_packet_size_0 = 64;
|
||||
|
||||
// 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();
|
||||
|
||||
let mut builder = Builder::new(
|
||||
driver,
|
||||
config,
|
||||
&mut config_descriptor,
|
||||
&mut bos_descriptor,
|
||||
&mut msos_descriptor,
|
||||
&mut control_buf,
|
||||
);
|
||||
|
||||
// Create classes on the builder.
|
||||
let mut class = CdcAcmClass::new(&mut builder, &mut state, 64);
|
||||
|
||||
// Build the builder.
|
||||
let mut usb = builder.build();
|
||||
|
||||
// Run the USB device.
|
||||
let usb_fut = usb.run();
|
||||
|
||||
// Do stuff with the class!
|
||||
// let reboot_fut = async {
|
||||
// loop {
|
||||
// class.wait_connection().await;
|
||||
// let _ = reboot_on_magic_message(&mut class).await;
|
||||
// }
|
||||
// };
|
||||
|
||||
let print_fut = async {
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
join(usb_fut, print_fut).await;
|
||||
}
|
||||
|
||||
struct Disconnected {}
|
||||
|
||||
impl From<EndpointError> for Disconnected {
|
||||
fn from(val: EndpointError) -> Self {
|
||||
match val {
|
||||
EndpointError::BufferOverflow => panic!("Buffer overflow"),
|
||||
EndpointError::Disabled => Disconnected {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn reboot_on_magic_message<'d, T: Instance + 'd, P: VbusDetect + 'd>(
|
||||
class: &mut CdcAcmClass<'d, Driver<'d, T, P>>,
|
||||
) -> Result<(), Disconnected> {
|
||||
let mut buf = [0; 64];
|
||||
|
||||
loop {
|
||||
let n = class.read_packet(&mut buf).await?;
|
||||
let data = &buf[..n];
|
||||
|
||||
if data == MAGIC_REBOOT_MESSAGE.as_bytes() {
|
||||
// Reboot the controller in DFU mode.
|
||||
// The magic number has been taken from the arduino bootloader:
|
||||
// https://github.com/mike1808/PIO_SEEED_Adafruit_nRF52_Arduino/blob/master/cores/nRF5/wiring.c#L26
|
||||
let dfu_magic_serial_only_reset = 0x4E;
|
||||
pac::POWER
|
||||
.gpregret()
|
||||
.write(|w| w.0 = dfu_magic_serial_only_reset);
|
||||
cortex_m::peripheral::SCB::sys_reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
COM_PORT=/dev/cu.usbmodem2101
|
||||
COM_PORT=/dev/cu.usbmodem1101
|
||||
|
||||
echo -e "bootloader" > $COM_PORT
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ nrf52840-hal.workspace = true
|
||||
usb-device.workspace = true
|
||||
usbd-serial.workspace = true
|
||||
libm.workspace = true
|
||||
nalgebra.workspace = true
|
||||
# nalgebra.workspace = true
|
||||
heapless.workspace = true
|
||||
lsm6ds3tr.workspace = true
|
||||
defmt.workspace = true
|
||||
|
||||
@@ -22,6 +22,7 @@ use lsm6ds3tr::{
|
||||
AccelSampleRate, AccelScale, AccelSettings, GyroSettings, LsmSettings, LSM6DS3TR,
|
||||
};
|
||||
use static_cell::StaticCell;
|
||||
use usb_dfu::setup_dfu_over_usb;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
mod usb_dfu;
|
||||
|
||||
@@ -11,9 +11,9 @@ cortex-m-rt.workspace = true
|
||||
nrf52840-hal.workspace = true
|
||||
usb-device.workspace = true
|
||||
usbd-serial.workspace = true
|
||||
microflow.workspace = true
|
||||
# microflow.workspace = true
|
||||
libm.workspace = true
|
||||
nalgebra.workspace = true
|
||||
# nalgebra.workspace = true
|
||||
heapless.workspace = true
|
||||
lsm6ds3tr.workspace = true
|
||||
defmt.workspace = true
|
||||
|
||||
Reference in New Issue
Block a user