Skip to content

Commit

Permalink
[Firmware] Improve how net-* flags are handled (#200)
Browse files Browse the repository at this point in the history
* Removed anna from codeowners

* Unified wifi and ble feature flags to get nrf compiling
  • Loading branch information
TheButlah authored Apr 5, 2023
1 parent 60224d5 commit b177008
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 43 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
* @thebutlah
/autoupdater @TheDevMinerTV

# People need to be able to update these
/Cargo.lock
Expand Down
33 changes: 20 additions & 13 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
67 changes: 40 additions & 27 deletions firmware/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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.
Expand All @@ -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)]
Expand Down
6 changes: 5 additions & 1 deletion firmware/src/networking/ble/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions firmware/src/networking/ble/nrf52.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions firmware/src/networking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod protocol;

#[cfg(feature = "net-wifi")]
pub mod wifi;

Expand Down
2 changes: 1 addition & 1 deletion firmware/src/networking/wifi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "net-wifi")]
#[cfg(mcu_f_esp32)]
#[path = "esp.rs"]
pub mod;

Expand Down

0 comments on commit b177008

Please sign in to comment.