mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-27 04:10:28 +00:00
Remove lazy_static in favor of OnceLock (#2063)
* [esp-metadata] Remove lazy_static in favor of OnceLock * [esp-wifishark] Remove lazy_static in favor of normal initialisation * [ieee802154-sniffer] Shorten SelectorConfig initialisation * [ieee802154-sniffer] Remove lazy_static in favor of normal initialisation
This commit is contained in:
parent
0cf7abfc47
commit
49e14b7ccb
@ -2,7 +2,7 @@
|
||||
name = "esp-metadata"
|
||||
version = "0.3.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.60.0"
|
||||
rust-version = "1.70.0"
|
||||
description = "Metadata for Espressif devices"
|
||||
repository = "https://github.com/esp-rs/esp-hal"
|
||||
license = "MIT OR Apache-2.0"
|
||||
@ -11,6 +11,5 @@ license = "MIT OR Apache-2.0"
|
||||
anyhow = "1.0.86"
|
||||
clap = { version = "4.5.16", features = ["derive"], optional = true }
|
||||
basic-toml = "0.1.9"
|
||||
lazy_static = "1.5.0"
|
||||
serde = { version = "1.0.209", features = ["derive"] }
|
||||
strum = { version = "0.26.3", features = ["derive"] }
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
[](https://crates.io/crates/esp-metadata)
|
||||
[](https://docs.rs/esp-metadata)
|
||||

|
||||

|
||||

|
||||
[](https://matrix.to/#/#esp-rs:matrix.org)
|
||||
|
||||
@ -14,7 +14,7 @@ Metadata for Espressif devices, intended for use in [build scripts].
|
||||
|
||||
## Minimum Supported Rust Version (MSRV)
|
||||
|
||||
This crate is guaranteed to compile on stable Rust 1.60 and up. It _might_
|
||||
This crate is guaranteed to compile on stable Rust 1.70 and up. It _might_
|
||||
compile with older versions but that may change in any new patch release.
|
||||
|
||||
## License
|
||||
|
@ -1,24 +1,15 @@
|
||||
//! Metadata for Espressif devices, primarily intended for use in build scripts.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
const ESP32_TOML: &str = include_str!("../devices/esp32.toml");
|
||||
const ESP32C2_TOML: &str = include_str!("../devices/esp32c2.toml");
|
||||
const ESP32C3_TOML: &str = include_str!("../devices/esp32c3.toml");
|
||||
const ESP32C6_TOML: &str = include_str!("../devices/esp32c6.toml");
|
||||
const ESP32H2_TOML: &str = include_str!("../devices/esp32h2.toml");
|
||||
const ESP32S2_TOML: &str = include_str!("../devices/esp32s2.toml");
|
||||
const ESP32S3_TOML: &str = include_str!("../devices/esp32s3.toml");
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref ESP32_CFG: Config = basic_toml::from_str(ESP32_TOML).unwrap();
|
||||
static ref ESP32C2_CFG: Config = basic_toml::from_str(ESP32C2_TOML).unwrap();
|
||||
static ref ESP32C3_CFG: Config = basic_toml::from_str(ESP32C3_TOML).unwrap();
|
||||
static ref ESP32C6_CFG: Config = basic_toml::from_str(ESP32C6_TOML).unwrap();
|
||||
static ref ESP32H2_CFG: Config = basic_toml::from_str(ESP32H2_TOML).unwrap();
|
||||
static ref ESP32S2_CFG: Config = basic_toml::from_str(ESP32S2_TOML).unwrap();
|
||||
static ref ESP32S3_CFG: Config = basic_toml::from_str(ESP32S3_TOML).unwrap();
|
||||
macro_rules! include_toml {
|
||||
($type:ty, $file:expr) => {{
|
||||
static LOADED_TOML: OnceLock<$type> = OnceLock::new();
|
||||
LOADED_TOML.get_or_init(|| basic_toml::from_str(include_str!($file)).unwrap())
|
||||
}};
|
||||
}
|
||||
|
||||
/// Supported device architectures.
|
||||
@ -178,13 +169,13 @@ impl Config {
|
||||
/// The configuration for the specified chip.
|
||||
pub fn for_chip(chip: &Chip) -> &Self {
|
||||
match chip {
|
||||
Chip::Esp32 => &ESP32_CFG,
|
||||
Chip::Esp32c2 => &ESP32C2_CFG,
|
||||
Chip::Esp32c3 => &ESP32C3_CFG,
|
||||
Chip::Esp32c6 => &ESP32C6_CFG,
|
||||
Chip::Esp32h2 => &ESP32H2_CFG,
|
||||
Chip::Esp32s2 => &ESP32S2_CFG,
|
||||
Chip::Esp32s3 => &ESP32S3_CFG,
|
||||
Chip::Esp32 => include_toml!(Config, "../devices/esp32.toml"),
|
||||
Chip::Esp32c2 => include_toml!(Config, "../devices/esp32c2.toml"),
|
||||
Chip::Esp32c3 => include_toml!(Config, "../devices/esp32c3.toml"),
|
||||
Chip::Esp32c6 => include_toml!(Config, "../devices/esp32c6.toml"),
|
||||
Chip::Esp32h2 => include_toml!(Config, "../devices/esp32h2.toml"),
|
||||
Chip::Esp32s2 => include_toml!(Config, "../devices/esp32s2.toml"),
|
||||
Chip::Esp32s3 => include_toml!(Config, "../devices/esp32s3.toml"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,4 +8,3 @@ r-extcap = "0.2.4"
|
||||
pcap-file = "2.0.0"
|
||||
serialport = "4.2.1"
|
||||
clap = { version = "4.3.5", features = ["derive"] }
|
||||
lazy_static = "1.4.0"
|
||||
|
@ -4,7 +4,6 @@ use std::{
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use lazy_static::lazy_static;
|
||||
use pcap_file::{
|
||||
pcap::{PcapHeader, PcapPacket, PcapWriter},
|
||||
DataLink,
|
||||
@ -25,40 +24,6 @@ pub struct AppArgs {
|
||||
serialport: String,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref METADATA: Metadata = Metadata {
|
||||
help_url: "http://github.com/esp-rs/esp-wifi".into(),
|
||||
display_description: "esp-wifi".into(),
|
||||
..r_extcap::cargo_metadata!()
|
||||
};
|
||||
static ref WIFI_CAPTURE_INTERFACE: Interface = Interface {
|
||||
value: "wifi".into(),
|
||||
display: "esp-wifi Ethernet capture".into(),
|
||||
dlt: Dlt {
|
||||
data_link_type: DataLink::USER0,
|
||||
name: "USER0".into(),
|
||||
display: "Ethernet".into(),
|
||||
},
|
||||
};
|
||||
static ref BT_CAPTURE_INTERFACE: Interface = Interface {
|
||||
value: "bt".into(),
|
||||
display: "esp-wifi HCI capture".into(),
|
||||
dlt: Dlt {
|
||||
data_link_type: DataLink::USER1,
|
||||
name: "USER1".into(),
|
||||
display: "HCI".into(),
|
||||
},
|
||||
};
|
||||
static ref CONFIG_SERIALPORT: StringConfig = StringConfig::builder()
|
||||
.config_number(1)
|
||||
.call("serialport")
|
||||
.display("Serialport")
|
||||
.tooltip("Serialport to connect to")
|
||||
.required(false)
|
||||
.placeholder("")
|
||||
.build();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = AppArgs::parse();
|
||||
|
||||
@ -68,25 +33,62 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let wifi_capture_interface = Interface {
|
||||
value: "wifi".into(),
|
||||
display: "esp-wifi Ethernet capture".into(),
|
||||
dlt: Dlt {
|
||||
data_link_type: DataLink::USER0,
|
||||
name: "USER0".into(),
|
||||
display: "Ethernet".into(),
|
||||
},
|
||||
};
|
||||
|
||||
let bt_capture_interface = Interface {
|
||||
value: "bt".into(),
|
||||
display: "esp-wifi HCI capture".into(),
|
||||
dlt: Dlt {
|
||||
data_link_type: DataLink::USER1,
|
||||
name: "USER1".into(),
|
||||
display: "HCI".into(),
|
||||
},
|
||||
};
|
||||
|
||||
match args.extcap.run().unwrap() {
|
||||
ExtcapStep::Interfaces(interfaces_step) => {
|
||||
let metadata = Metadata {
|
||||
help_url: "http://github.com/esp-rs/esp-wifi".into(),
|
||||
display_description: "esp-wifi".into(),
|
||||
..r_extcap::cargo_metadata!()
|
||||
};
|
||||
|
||||
interfaces_step.list_interfaces(
|
||||
&METADATA,
|
||||
&[&*WIFI_CAPTURE_INTERFACE, &*BT_CAPTURE_INTERFACE],
|
||||
&metadata,
|
||||
&[&wifi_capture_interface, &bt_capture_interface],
|
||||
&[],
|
||||
);
|
||||
}
|
||||
ExtcapStep::Dlts(dlts_step) => {
|
||||
dlts_step
|
||||
.print_from_interfaces(&[&*WIFI_CAPTURE_INTERFACE, &*BT_CAPTURE_INTERFACE])
|
||||
.print_from_interfaces(&[&wifi_capture_interface, &bt_capture_interface])
|
||||
.unwrap();
|
||||
}
|
||||
ExtcapStep::Config(config_step) => config_step.list_configs(&[&*CONFIG_SERIALPORT]),
|
||||
ExtcapStep::Config(config_step) => {
|
||||
let config_serialport = StringConfig::builder()
|
||||
.config_number(1)
|
||||
.call("serialport")
|
||||
.display("Serialport")
|
||||
.tooltip("Serialport to connect to")
|
||||
.required(false)
|
||||
.placeholder("")
|
||||
.build();
|
||||
|
||||
config_step.list_configs(&[&config_serialport])
|
||||
}
|
||||
ExtcapStep::ReloadConfig(_reload_config_step) => {
|
||||
panic!("Unsupported operation");
|
||||
}
|
||||
ExtcapStep::Capture(capture_step) => {
|
||||
let (data_link, prefix) = if capture_step.interface == WIFI_CAPTURE_INTERFACE.value {
|
||||
let (data_link, prefix) = if capture_step.interface == wifi_capture_interface.value {
|
||||
(DataLink::ETHERNET, "@WIFIFRAME [")
|
||||
} else {
|
||||
(DataLink::BLUETOOTH_HCI_H4, "@HCIFRAME [")
|
||||
|
@ -8,4 +8,3 @@ r-extcap = "0.2.4"
|
||||
pcap-file = "2.0.0"
|
||||
serialport = "4.2.0"
|
||||
clap = { version = "4.1.7", features = ["derive"] }
|
||||
lazy_static = "1.4.0"
|
||||
|
@ -4,7 +4,6 @@ use std::{
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use lazy_static::lazy_static;
|
||||
use pcap_file::{
|
||||
pcap::{PcapHeader, PcapPacket, PcapWriter},
|
||||
DataLink,
|
||||
@ -28,102 +27,11 @@ pub struct AppArgs {
|
||||
channel: String,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref METADATA: Metadata = Metadata {
|
||||
help_url: "http://github.com/esp-rs".into(),
|
||||
display_description: "esp-ieee802154".into(),
|
||||
..r_extcap::cargo_metadata!()
|
||||
};
|
||||
static ref WIFI_CAPTURE_INTERFACE: Interface = Interface {
|
||||
value: "802.15.4".into(),
|
||||
display: "esp-ieee802154 Sniffer".into(),
|
||||
dlt: Dlt {
|
||||
data_link_type: DataLink::USER0,
|
||||
name: "USER0".into(),
|
||||
display: "IEEE802.15.4".into(),
|
||||
},
|
||||
};
|
||||
static ref CONFIG_SERIALPORT: StringConfig = StringConfig::builder()
|
||||
.config_number(1)
|
||||
.call("serialport")
|
||||
.display("Serialport")
|
||||
.tooltip("Serialport to connect to")
|
||||
.required(false)
|
||||
.placeholder("")
|
||||
.build();
|
||||
static ref CONFIG_CHANNEL: SelectorConfig = SelectorConfig::builder()
|
||||
.config_number(3)
|
||||
.call("channel")
|
||||
.display("Channel")
|
||||
.tooltip("Channel Selector")
|
||||
.default_options([
|
||||
ConfigOptionValue::builder()
|
||||
.value("11")
|
||||
.display("11")
|
||||
.default(true)
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("12")
|
||||
.display("12")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("13")
|
||||
.display("13")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("14")
|
||||
.display("14")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("15")
|
||||
.display("15")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("16")
|
||||
.display("16")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("17")
|
||||
.display("17")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("18")
|
||||
.display("18")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("19")
|
||||
.display("19")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("20")
|
||||
.display("20")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("21")
|
||||
.display("21")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("22")
|
||||
.display("22")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("23")
|
||||
.display("23")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("24")
|
||||
.display("24")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("25")
|
||||
.display("25")
|
||||
.build(),
|
||||
ConfigOptionValue::builder()
|
||||
.value("26")
|
||||
.display("26")
|
||||
.build(),
|
||||
])
|
||||
.build();
|
||||
fn config_option_value(value: &'static str) -> ConfigOptionValue {
|
||||
ConfigOptionValue::builder()
|
||||
.value(value)
|
||||
.display(value)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -135,17 +43,71 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
let wifi_capture_interface = Interface {
|
||||
value: "802.15.4".into(),
|
||||
display: "esp-ieee802154 Sniffer".into(),
|
||||
dlt: Dlt {
|
||||
data_link_type: DataLink::USER0,
|
||||
name: "USER0".into(),
|
||||
display: "IEEE802.15.4".into(),
|
||||
},
|
||||
};
|
||||
|
||||
match args.extcap.run().unwrap() {
|
||||
ExtcapStep::Interfaces(interfaces_step) => {
|
||||
interfaces_step.list_interfaces(&METADATA, &[&*WIFI_CAPTURE_INTERFACE], &[]);
|
||||
let metadata = Metadata {
|
||||
help_url: "http://github.com/esp-rs".into(),
|
||||
display_description: "esp-ieee802154".into(),
|
||||
..r_extcap::cargo_metadata!()
|
||||
};
|
||||
|
||||
interfaces_step.list_interfaces(&metadata, &[&wifi_capture_interface], &[]);
|
||||
}
|
||||
ExtcapStep::Dlts(dlts_step) => {
|
||||
dlts_step
|
||||
.print_from_interfaces(&[&*WIFI_CAPTURE_INTERFACE])
|
||||
.print_from_interfaces(&[&wifi_capture_interface])
|
||||
.unwrap();
|
||||
}
|
||||
ExtcapStep::Config(config_step) => {
|
||||
config_step.list_configs(&[&*CONFIG_SERIALPORT, &*CONFIG_CHANNEL])
|
||||
let config_serialport = StringConfig::builder()
|
||||
.config_number(1)
|
||||
.call("serialport")
|
||||
.display("Serialport")
|
||||
.tooltip("Serialport to connect to")
|
||||
.required(false)
|
||||
.placeholder("")
|
||||
.build();
|
||||
|
||||
let config_channel = SelectorConfig::builder()
|
||||
.config_number(3)
|
||||
.call("channel")
|
||||
.display("Channel")
|
||||
.tooltip("Channel Selector")
|
||||
.default_options([
|
||||
ConfigOptionValue::builder()
|
||||
.value("11")
|
||||
.display("11")
|
||||
.default(true)
|
||||
.build(),
|
||||
config_option_value("12"),
|
||||
config_option_value("13"),
|
||||
config_option_value("14"),
|
||||
config_option_value("15"),
|
||||
config_option_value("16"),
|
||||
config_option_value("17"),
|
||||
config_option_value("18"),
|
||||
config_option_value("19"),
|
||||
config_option_value("20"),
|
||||
config_option_value("21"),
|
||||
config_option_value("22"),
|
||||
config_option_value("23"),
|
||||
config_option_value("24"),
|
||||
config_option_value("25"),
|
||||
config_option_value("26"),
|
||||
])
|
||||
.build();
|
||||
|
||||
config_step.list_configs(&[&config_serialport, &config_channel])
|
||||
}
|
||||
ExtcapStep::ReloadConfig(_reload_config_step) => {
|
||||
panic!("Unsupported operation");
|
||||
|
Loading…
x
Reference in New Issue
Block a user