From a0498330ef7d035890ab1b3632d789ee3c9fccdf Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Sat, 5 Oct 2024 17:54:31 -0400 Subject: dummy fw bme bringup --- Cargo.lock | 11 ++++++++- Cargo.toml | 34 +++++++++++++++++++-------- common/Cargo.toml | 12 ++++++++++ common/src/lib.rs | 32 +++++++++++++++++++++++++ host/Cargo.toml | 8 +++++-- hw/ocularium.kicad_pro | 7 +++++- rust-toolchain.toml | 2 +- src/lib.rs | 15 ------------ src/main.rs | 63 +++++++++++++++++++++++++++++++++++++------------- src/usb.rs | 6 ++++- 10 files changed, 144 insertions(+), 46 deletions(-) create mode 100644 common/Cargo.toml create mode 100644 common/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 8ff026d..4cb5cd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2999,14 +2999,23 @@ dependencies = [ "lsm6dsm", "molybdos", "molybdos_build", + "ocularium_common", "pio", "serde", "veml7700_async", ] +[[package]] +name = "ocularium_common" +version = "0.1.0-alpha0" +dependencies = [ + "nalgebra", + "serde", +] + [[package]] name = "ocularium_host" -version = "0.1.0" +version = "0.1.0-alpha0" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 35a20f3..fd542ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,17 @@ [package] name = "ocularium" -version = "0.1.0-alpha0" -edition = "2021" description = "firmware for tiny kite-borne sensor node" -authors = [ - "Nathan Perry " -] -license = "MIT" -homepage = "https://blog.npry.dev/resenv/ocularium" -repository = "https://pub.npry.dev/ocularium" include = ["build.rs", "/src/", "Cargo.toml", "README.md", "LICENSE"] +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true [workspace] members = [ + "common", "host" ] @@ -20,19 +19,35 @@ exclude = [ "pio_i2s" ] +[workspace.package] +version = "0.1.0-alpha0" +edition = "2021" +authors = [ + "Nathan Perry " +] +license = "MIT" +homepage = "https://blog.npry.dev/resenv/ocularium" +repository = "https://pub.npry.dev/ocularium" + +[workspace.dependencies] +serde = { version = "1.0", default-features = false } + [features] disable_sd = [] +disable_i2s = [] [dependencies] veml7700_async = { git = "https://pub.npry.dev/veml7700_async" } drogue_bme680_async = { git = "https://pub.npry.dev/drogue_bme680_async" } lsm6dsm = { git = "https://pub.npry.dev/lsm6dsm" } -serde = { version = "1.0", default-features = false } +serde = { workspace = true, default-features = false, features = ["derive", "alloc"] } embassy-executor = { git = "https://github.com/embassy-rs/embassy", features = ["executor-interrupt", "executor-thread", "arch-cortex-m", "nightly"] } cortex-m-rt = { version = "0.7", default-features = false } +ocularium_common = { path = "common" } + pio = "0.2" [dependencies.molybdos] @@ -46,6 +61,7 @@ features = [ "postcard", "serde", "chrono", + "alloc", "impl_alloc", ] diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..bcde395 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "ocularium_common" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +serde = { workspace = true, default-features = false, features = ["derive", "alloc"] } +na = { package = "nalgebra", version = "0.32", default-features = false, features = ["serde-serialize-no-std"] } diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..5dde0b9 --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,32 @@ +#![no_std] + +extern crate alloc; + +use alloc::vec::Vec; + +#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] +pub enum Uplink { + Ping, +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] +pub enum Downlink { + Pong, + Sensor(Sensor), +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)] +pub enum Sensor { + Gas { + temp_c: f32, + pressure: f32, + }, + Lux { + lux: f32, + }, + IMU { + accel: na::Vector3, + gyro: na::Vector3, + }, + Pdm(Vec), +} diff --git a/host/Cargo.toml b/host/Cargo.toml index 886962c..2b8dd7f 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -1,7 +1,11 @@ [package] name = "ocularium_host" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true [dependencies] clap = { version = "4.5.18", features = ["derive"] } diff --git a/hw/ocularium.kicad_pro b/hw/ocularium.kicad_pro index 4146b0f..a52a28b 100644 --- a/hw/ocularium.kicad_pro +++ b/hw/ocularium.kicad_pro @@ -58,7 +58,12 @@ "width": 0.0 } ], - "drc_exclusions": [], + "drc_exclusions": [ + "hole_clearance|156580000|103750000|6f14d0af-8022-493d-a4d3-c126bf2f9f97|c128407a-cf54-4b89-aff0-40f83aae7c62", + "hole_clearance|156580000|103950000|6f14d0af-8022-493d-a4d3-c126bf2f9f97|947b690e-b6d1-4fe7-8732-54cc07ed7932", + "hole_clearance|156580000|98150000|7a8c08c0-35a0-43a8-88cd-4e02f2d31343|7aa07162-d5c2-477c-af87-497280f7e21e", + "hole_clearance|156580000|98350000|7a8c08c0-35a0-43a8-88cd-4e02f2d31343|6adbaddf-99f8-43c4-82f8-9e16309b9901" + ], "meta": { "version": 2 }, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 171a005..c5d350b 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-09-12" +channel = "nightly-2024-10-04" targets = ["thumbv6m-none-eabi"] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 6a9d858..0c9ac1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1 @@ #![no_std] - -#[derive( - Debug, Clone, PartialEq, PartialOrd, molybdos::serde::Serialize, molybdos::serde::Deserialize, -)] -pub enum Uplink { - Ping, -} - -#[derive( - Debug, Clone, PartialEq, PartialOrd, molybdos::serde::Serialize, molybdos::serde::Deserialize, -)] -pub enum Downlink { - Pong, - PDM(molybdos::heapless::Vec), -} diff --git a/src/main.rs b/src/main.rs index 6cf46be..454ed05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,8 @@ #![no_main] #![feature(impl_trait_in_assoc_type)] -use crate::usb::COBS_DOWNLINK; +extern crate alloc; + use molybdos::{ embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice, embassy_executor, @@ -33,6 +34,7 @@ use molybdos::{ pubsub, pubsub::PubSubBehavior, }, + embedded_hal_async, embedded_hal_async::spi::{ Operation, SpiDevice as _, @@ -46,7 +48,13 @@ use molybdos::{ heapless, pal::StaticOutput, }; -use ocularium::Downlink; + +use ocularium_common::{ + Downlink, + Sensor, +}; + +use crate::usb::COBS_DOWNLINK; mod bringup; mod usb; @@ -95,26 +103,31 @@ async fn main(spawner: embassy_executor::Spawner) { molybdos::lib::usb::start!(molybdos::pal::UsbDriver, acm, &usb::UPLINK, &usb::DOWNLINK); molybdos::lib::util::cobs::start!( - ocularium::Uplink, + ocularium_common::Uplink, &usb::UPLINK, &usb::COBS_UPLINK, - ocularium::Downlink, + ocularium_common::Downlink, &usb::DOWNLINK, &usb::COBS_DOWNLINK ); let mut spidev = SpiDevice::new(bme_spi, bme_cs); + manually_check_bme_id(&mut spidev).await; - let data = &mut [0u8]; + let config = drogue_bme680_async::Configuration::default(); - let result = spidev - .transaction(&mut [Operation::Write(&[0x50 | (1 << 7)]), Operation::Read(data)]) - .await; - if let Err(e) = result { - defmt::error!("reading spi dev: {}", defmt::Debug2Format(&e)); - } else { - defmt::info!("read chipid: {:x}", data[0]); - } + let bme = drogue_bme680_async::Sensor::new_spi(spidev).await.unwrap(); + let mut bme = drogue_bme680_async::Controller::new( + bme, + molybdos::embassy_time::Delay, + config, + drogue_bme680_async::StaticProvider(23), + ) + .await + .unwrap(); + + let meas = bme.measure_default().await.unwrap().unwrap(); + defmt::info!("got bme measurement: {}", defmt::Debug2Format(&meas)); #[cfg(not(feature = "disable_sd"))] { @@ -137,19 +150,37 @@ async fn main(spawner: embassy_executor::Spawner) { } } - spawner.must_spawn(drain_pipe()); - spawner.must_spawn(run_i2s(i2s, i2s_dma)); + #[cfg(not(feature = "disable_i2s"))] + { + spawner.must_spawn(drain_pipe()); + spawner.must_spawn(run_i2s(i2s, i2s_dma)); + } loop { molybdos::embassy_time::Timer::after(molybdos::embassy_time::Duration::from_secs(1)).await; } } +async fn manually_check_bme_id(spidev: &mut impl embedded_hal_async::spi::SpiDevice) { + let data = &mut [0u8]; + + let result = spidev + .transaction(&mut [Operation::Write(&[0x50 | (1 << 7)]), Operation::Read(data)]) + .await; + if let Err(e) = result { + defmt::error!("reading spi dev: {}", defmt::Debug2Format(&e)); + } else { + defmt::info!("read chipid: {:x}", data[0]); + } +} + +#[cfg(not(feature = "disable_i2s"))] #[::embassy_executor::task] async fn run_i2s(mut i2s: bringup::StaticI2S, dma: embassy_rp::peripherals::DMA_CH5) { i2s.run::<960>(dma, &I2S_PIPE).await } +#[cfg(not(feature = "disable_i2s"))] #[::embassy_executor::task] async fn drain_pipe() { let publ = COBS_DOWNLINK.publisher().expect("getting publisher"); @@ -159,7 +190,7 @@ async fn drain_pipe() { let n = I2S_PIPE.read(buf).await; for elem in (&buf[..n]).chunks(48) { - publ.publish_immediate(Downlink::PDM(heapless::Vec::from_slice(elem).unwrap())); + publ.publish_immediate(Downlink::Sensor(Sensor::Pdm(alloc::vec::Vec::from(elem)))); } } } diff --git a/src/usb.rs b/src/usb.rs index 7ec1aae..b50b085 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -1,2 +1,6 @@ molybdos::lib::usb_pipes!(pub); -molybdos::lib::cobs_pubsub!(pub, ocularium::Uplink => COBS_UPLINK, ocularium::Downlink => COBS_DOWNLINK); +molybdos::lib::cobs_pubsub!( + pub, + ocularium_common::Uplink => COBS_UPLINK, + ocularium_common::Downlink => COBS_DOWNLINK +); -- cgit v1.3.1