Skip to content

Commit 74343ba

Browse files
committed
Unified wifi and ble feature flags to get nrf compiling
1 parent 49d6343 commit 74343ba

File tree

6 files changed

+76
-42
lines changed

6 files changed

+76
-42
lines changed

‎firmware/Cargo.toml‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,38 @@ default = [
3333

3434
# Supported microcontrollers
3535
mcu-esp32 = [
36+
"_mcu-f-esp32",
3637
"dep:esp32-hal",
3738
"defmt_esp_println/esp32",
3839
"esp-backtrace/esp32",
3940
"xtensa-lx/esp32",
40-
"dep:esp-alloc",
41-
"dep:embedded-svc",
42-
"esp-wifi?/esp32",
41+
"esp-wifi/esp32",
4342
]
4443
mcu-esp32c3 = [
44+
"_mcu-f-esp32",
4545
"dep:esp32c3-hal",
4646
"defmt_esp_println/esp32c3",
4747
"esp-backtrace/esp32c3",
4848
"dep:riscv",
49-
"dep:esp-alloc",
50-
"dep:embedded-svc",
51-
"esp-wifi?/esp32c3",
49+
"esp-wifi/esp32c3",
5250
]
5351
mcu-nrf52840 = [
52+
"_mcu-f-nrf52",
5453
"embassy-nrf/nrf52840",
5554
"dep:embassy-usb",
56-
"nrf-softdevice?/nrf52840",
57-
"_mcu-f-nrf52",
55+
"nrf-softdevice/nrf52840",
5856
"dep:nrf52840-pac",
5957
]
6058
mcu-nrf52832 = [
61-
"embassy-nrf/nrf52832",
62-
"nrf-softdevice?/nrf52832",
6359
"_mcu-f-nrf52",
60+
"embassy-nrf/nrf52832",
61+
"nrf-softdevice/nrf52832",
6462
"dep:nrf52832-pac",
6563
]
6664

6765
# Wi-fi dependencies
68-
net-wifi = ["esp-wifi/wifi", "dep:embassy-net", "dep:smoltcp"] # use wifi
69-
net-ble = ["esp-wifi/ble", "dep:bleps", "dep:bleps-macros"]
66+
net-wifi = ["esp-wifi?/wifi"] # use wifi
67+
net-ble = ["esp-wifi?/ble"]
7068
net-stubbed = [] # Stubs out network
7169

7270
# Supported IMUs
@@ -101,7 +99,16 @@ _mcu-f-nrf52 = [
10199
"dep:alloc-cortex-m",
102100
"embassy-nrf/time-driver-rtc1",
103101
"embassy-executor/integrated-timers",
104-
"defmt-bbq",
102+
"dep:defmt-bbq",
103+
]
104+
105+
_mcu-f-esp32 = [
106+
"dep:esp-alloc",
107+
"dep:embedded-svc",
108+
"dep:embassy-net",
109+
"dep:smoltcp",
110+
"dep:bleps",
111+
"dep:bleps-macros",
105112
]
106113

107114
[dependencies]

‎firmware/build.rs‎

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@ use std::{
77
path::{self, Path, PathBuf},
88
};
99

10-
mandatory_and_unique!("mcu-esp32", "mcu-esp32c3", "mcu-nrf52832", "mcu-nrf52840");
11-
mandatory_and_unique!("imu-stubbed", "imu-mpu6050", "imu-bmi160");
12-
mandatory_and_unique!("log-rtt", "log-usb-serial", "log-uart");
13-
mandatory_and_unique!("net-wifi", "net-ble", "net-stubbed");
14-
mandatory_and_unique!("fusion-stubbed", "fusion-dcm");
15-
16-
#[cfg(any(feature = "mcu-nrf52840", feature = "mcu-nrf52832"))]
17-
mandatory_and_unique!(
18-
"nrf-boot-none",
19-
"nrf-boot-mbr",
20-
"nrf-boot-s132",
21-
"nrf-boot-s140"
22-
);
23-
2410
/// Use memory.x.feature file as memory map
2511
macro_rules! memory_x {
2612
($mcu:literal) => {
@@ -40,12 +26,26 @@ fn main() -> Result<()> {
4026
println!("cargo:rerun-if-changed=linker_scripts/");
4127
println!("cargo:rerun-if-changed=boards/");
4228
println!("cargo:rerun-if-changed=.env");
43-
44-
// Any relevant env vars for the build script are listed here.
4529
println!("cargo:rerun-if-env-changed=BOARD");
30+
31+
load_env_and_aliases();
32+
check_features_compatible();
33+
34+
// Link into Espressif's radio driver blobs
35+
#[cfg(all(feature = "esp-wifi"))]
36+
println!("cargo:rustc-link-arg=-Trom_functions.x");
37+
38+
memory_x!("mcu-nrf52832");
39+
memory_x!("mcu-nrf52840");
40+
41+
let board_cfg = BoardConfig::from_file(&BoardConfig::get_path()?)?;
42+
board_cfg.apply_to_env();
43+
44+
Ok(())
45+
}
46+
47+
fn load_env_and_aliases() {
4648
let _ = dotenvy::dotenv();
47-
#[cfg(all(feature = "mcu-nrf52832", feature = "log-usb-serial"))]
48-
compile_error!("the nrf52832 doesn't support USB!");
4949

5050
// NOTE: Can't use the `cfg_aliases` in the build script itself, only applies to
5151
// rest of codebase.
@@ -60,18 +60,31 @@ fn main() -> Result<()> {
6060
xtensa: { any(feature = "mcu-esp32") },
6161
riscv: { any(feature = "mcu-esp32c3") },
6262
}
63+
}
6364

64-
// Link into Espressif's radio driver blobs
65-
#[cfg(all(feature = "esp-wifi"))]
66-
println!("cargo:rustc-link-arg=-Trom_functions.x");
67-
68-
memory_x!("mcu-nrf52832");
69-
memory_x!("mcu-nrf52840");
65+
fn check_features_compatible() {
66+
mandatory_and_unique!("mcu-esp32", "mcu-esp32c3", "mcu-nrf52832", "mcu-nrf52840");
67+
mandatory_and_unique!("imu-stubbed", "imu-mpu6050", "imu-bmi160");
68+
mandatory_and_unique!("log-rtt", "log-usb-serial", "log-uart");
69+
mandatory_and_unique!("net-wifi", "net-ble", "net-stubbed");
70+
mandatory_and_unique!("fusion-stubbed", "fusion-dcm");
71+
72+
#[cfg(any(feature = "mcu-nrf52840", feature = "mcu-nrf52832"))]
73+
mandatory_and_unique!(
74+
"nrf-boot-none",
75+
"nrf-boot-mbr",
76+
"nrf-boot-s132",
77+
"nrf-boot-s140"
78+
);
7079

71-
let board_cfg = BoardConfig::from_file(&BoardConfig::get_path()?)?;
72-
board_cfg.apply_to_env();
80+
#[cfg(all(
81+
feature = "net-wifi",
82+
any(feature = "mcu-nrf52840", feature = "mcu-nrf52832")
83+
))]
84+
compile_error!("nrf52 mcu family doesn't support wifi!");
7385

74-
Ok(())
86+
#[cfg(all(feature = "mcu-nrf52832", feature = "log-usb-serial"))]
87+
compile_error!("the nrf52832 doesn't support USB!");
7588
}
7689

7790
#[allow(dead_code)]
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
#[cfg(feature = "net-ble")]
1+
#[cfg(mcu_f_esp32)]
22
#[path = "esp.rs"]
33
pub mod à¶ž;
4+
5+
#[cfg(mcu_f_nrf52)]
6+
#[path = "nrf52.rs"]
7+
pub mod à¶ž;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use embassy_time::{Duration, Timer};
2+
3+
use crate::{aliases::à¶ž::NetConcrete, networking::protocol::Packets};
4+
5+
pub async fn network_task(_packets: &Packets, _net: NetConcrete) -> ! {
6+
loop {
7+
Timer::after(Duration::from_millis(10_000)).await
8+
}
9+
}

‎firmware/src/networking/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod protocol;
2+
23
#[cfg(feature = "net-wifi")]
34
pub mod wifi;
45

‎firmware/src/networking/wifi/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(feature = "net-wifi")]
1+
#[cfg(mcu_f_esp32)]
22
#[path = "esp.rs"]
33
pub mod à¶ž;
44

0 commit comments

Comments
 (0)