From b177008b12192cb62325872b855193633152c5b4 Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Tue, 4 Apr 2023 22:06:49 -0400 Subject: [PATCH] [Firmware] Improve how net-* flags are handled (#200) * Removed anna from codeowners * Unified wifi and ble feature flags to get nrf compiling --- .github/CODEOWNERS | 1 - firmware/Cargo.toml | 33 ++++++++------ firmware/build.rs | 67 +++++++++++++++++----------- firmware/src/networking/ble/mod.rs | 6 ++- firmware/src/networking/ble/nrf52.rs | 9 ++++ firmware/src/networking/mod.rs | 1 + firmware/src/networking/wifi/mod.rs | 2 +- 7 files changed, 76 insertions(+), 43 deletions(-) create mode 100644 firmware/src/networking/ble/nrf52.rs diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 332b31b1..3352f9b0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,4 @@ * @thebutlah -/autoupdater @TheDevMinerTV # People need to be able to update these /Cargo.lock diff --git a/firmware/Cargo.toml b/firmware/Cargo.toml index 1f5fe1b8..83e2d931 100644 --- a/firmware/Cargo.toml +++ b/firmware/Cargo.toml @@ -33,40 +33,38 @@ default = [ # Supported microcontrollers mcu-esp32 = [ + "_mcu-f-esp32", "dep:esp32-hal", "defmt_esp_println/esp32", "esp-backtrace/esp32", "xtensa-lx/esp32", - "dep:esp-alloc", - "dep:embedded-svc", - "esp-wifi?/esp32", + "esp-wifi/esp32", ] mcu-esp32c3 = [ + "_mcu-f-esp32", "dep:esp32c3-hal", "defmt_esp_println/esp32c3", "esp-backtrace/esp32c3", "dep:riscv", - "dep:esp-alloc", - "dep:embedded-svc", - "esp-wifi?/esp32c3", + "esp-wifi/esp32c3", ] mcu-nrf52840 = [ + "_mcu-f-nrf52", "embassy-nrf/nrf52840", "dep:embassy-usb", - "nrf-softdevice?/nrf52840", - "_mcu-f-nrf52", + "nrf-softdevice/nrf52840", "dep:nrf52840-pac", ] mcu-nrf52832 = [ - "embassy-nrf/nrf52832", - "nrf-softdevice?/nrf52832", "_mcu-f-nrf52", + "embassy-nrf/nrf52832", + "nrf-softdevice/nrf52832", "dep:nrf52832-pac", ] # Wi-fi dependencies -net-wifi = ["esp-wifi/wifi", "dep:embassy-net", "dep:smoltcp"] # use wifi -net-ble = ["esp-wifi/ble", "dep:bleps", "dep:bleps-macros"] +net-wifi = ["esp-wifi?/wifi"] # use wifi +net-ble = ["esp-wifi?/ble"] net-stubbed = [] # Stubs out network # Supported IMUs @@ -101,7 +99,16 @@ _mcu-f-nrf52 = [ "dep:alloc-cortex-m", "embassy-nrf/time-driver-rtc1", "embassy-executor/integrated-timers", - "defmt-bbq", + "dep:defmt-bbq", +] + +_mcu-f-esp32 = [ + "dep:esp-alloc", + "dep:embedded-svc", + "dep:embassy-net", + "dep:smoltcp", + "dep:bleps", + "dep:bleps-macros", ] [dependencies] diff --git a/firmware/build.rs b/firmware/build.rs index 1b44152b..d0624fd9 100644 --- a/firmware/build.rs +++ b/firmware/build.rs @@ -7,20 +7,6 @@ use std::{ path::{self, Path, PathBuf}, }; -mandatory_and_unique!("mcu-esp32", "mcu-esp32c3", "mcu-nrf52832", "mcu-nrf52840"); -mandatory_and_unique!("imu-stubbed", "imu-mpu6050", "imu-bmi160"); -mandatory_and_unique!("log-rtt", "log-usb-serial", "log-uart"); -mandatory_and_unique!("net-wifi", "net-ble", "net-stubbed"); -mandatory_and_unique!("fusion-stubbed", "fusion-dcm"); - -#[cfg(any(feature = "mcu-nrf52840", feature = "mcu-nrf52832"))] -mandatory_and_unique!( - "nrf-boot-none", - "nrf-boot-mbr", - "nrf-boot-s132", - "nrf-boot-s140" -); - /// Use memory.x.feature file as memory map macro_rules! memory_x { ($mcu:literal) => { @@ -40,12 +26,26 @@ fn main() -> Result<()> { println!("cargo:rerun-if-changed=linker_scripts/"); println!("cargo:rerun-if-changed=boards/"); println!("cargo:rerun-if-changed=.env"); - - // Any relevant env vars for the build script are listed here. println!("cargo:rerun-if-env-changed=BOARD"); + + load_env_and_aliases(); + check_features_compatible(); + + // Link into Espressif's radio driver blobs + #[cfg(all(feature = "esp-wifi"))] + println!("cargo:rustc-link-arg=-Trom_functions.x"); + + memory_x!("mcu-nrf52832"); + memory_x!("mcu-nrf52840"); + + let board_cfg = BoardConfig::from_file(&BoardConfig::get_path()?)?; + board_cfg.apply_to_env(); + + Ok(()) +} + +fn load_env_and_aliases() { let _ = dotenvy::dotenv(); - #[cfg(all(feature = "mcu-nrf52832", feature = "log-usb-serial"))] - compile_error!("the nrf52832 doesn't support USB!"); // NOTE: Can't use the `cfg_aliases` in the build script itself, only applies to // rest of codebase. @@ -60,18 +60,31 @@ fn main() -> Result<()> { xtensa: { any(feature = "mcu-esp32") }, riscv: { any(feature = "mcu-esp32c3") }, } +} - // Link into Espressif's radio driver blobs - #[cfg(all(feature = "esp-wifi"))] - println!("cargo:rustc-link-arg=-Trom_functions.x"); - - memory_x!("mcu-nrf52832"); - memory_x!("mcu-nrf52840"); +fn check_features_compatible() { + mandatory_and_unique!("mcu-esp32", "mcu-esp32c3", "mcu-nrf52832", "mcu-nrf52840"); + mandatory_and_unique!("imu-stubbed", "imu-mpu6050", "imu-bmi160"); + mandatory_and_unique!("log-rtt", "log-usb-serial", "log-uart"); + mandatory_and_unique!("net-wifi", "net-ble", "net-stubbed"); + mandatory_and_unique!("fusion-stubbed", "fusion-dcm"); + + #[cfg(any(feature = "mcu-nrf52840", feature = "mcu-nrf52832"))] + mandatory_and_unique!( + "nrf-boot-none", + "nrf-boot-mbr", + "nrf-boot-s132", + "nrf-boot-s140" + ); - let board_cfg = BoardConfig::from_file(&BoardConfig::get_path()?)?; - board_cfg.apply_to_env(); + #[cfg(all( + feature = "net-wifi", + any(feature = "mcu-nrf52840", feature = "mcu-nrf52832") + ))] + compile_error!("nrf52 mcu family doesn't support wifi!"); - Ok(()) + #[cfg(all(feature = "mcu-nrf52832", feature = "log-usb-serial"))] + compile_error!("the nrf52832 doesn't support USB!"); } #[allow(dead_code)] diff --git a/firmware/src/networking/ble/mod.rs b/firmware/src/networking/ble/mod.rs index 06b77699..b63846f0 100644 --- a/firmware/src/networking/ble/mod.rs +++ b/firmware/src/networking/ble/mod.rs @@ -1,3 +1,7 @@ -#[cfg(feature = "net-ble")] +#[cfg(mcu_f_esp32)] #[path = "esp.rs"] pub mod ඞ; + +#[cfg(mcu_f_nrf52)] +#[path = "nrf52.rs"] +pub mod ඞ; diff --git a/firmware/src/networking/ble/nrf52.rs b/firmware/src/networking/ble/nrf52.rs new file mode 100644 index 00000000..e7fb62f6 --- /dev/null +++ b/firmware/src/networking/ble/nrf52.rs @@ -0,0 +1,9 @@ +use embassy_time::{Duration, Timer}; + +use crate::{aliases::ඞ::NetConcrete, networking::protocol::Packets}; + +pub async fn network_task(_packets: &Packets, _net: NetConcrete) -> ! { + loop { + Timer::after(Duration::from_millis(10_000)).await + } +} diff --git a/firmware/src/networking/mod.rs b/firmware/src/networking/mod.rs index a091a19c..7b4e607b 100644 --- a/firmware/src/networking/mod.rs +++ b/firmware/src/networking/mod.rs @@ -1,4 +1,5 @@ pub mod protocol; + #[cfg(feature = "net-wifi")] pub mod wifi; diff --git a/firmware/src/networking/wifi/mod.rs b/firmware/src/networking/wifi/mod.rs index 6264ff1d..f09409a7 100644 --- a/firmware/src/networking/wifi/mod.rs +++ b/firmware/src/networking/wifi/mod.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "net-wifi")] +#[cfg(mcu_f_esp32)] #[path = "esp.rs"] pub mod ඞ;