mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-30 22:01:11 +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"
|
name = "esp-metadata"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.60.0"
|
rust-version = "1.70.0"
|
||||||
description = "Metadata for Espressif devices"
|
description = "Metadata for Espressif devices"
|
||||||
repository = "https://github.com/esp-rs/esp-hal"
|
repository = "https://github.com/esp-rs/esp-hal"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
@ -11,6 +11,5 @@ license = "MIT OR Apache-2.0"
|
|||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
clap = { version = "4.5.16", features = ["derive"], optional = true }
|
clap = { version = "4.5.16", features = ["derive"], optional = true }
|
||||||
basic-toml = "0.1.9"
|
basic-toml = "0.1.9"
|
||||||
lazy_static = "1.5.0"
|
|
||||||
serde = { version = "1.0.209", features = ["derive"] }
|
serde = { version = "1.0.209", features = ["derive"] }
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://crates.io/crates/esp-metadata)
|
[](https://crates.io/crates/esp-metadata)
|
||||||
[](https://docs.rs/esp-metadata)
|
[](https://docs.rs/esp-metadata)
|
||||||

|

|
||||||

|

|
||||||
[](https://matrix.to/#/#esp-rs:matrix.org)
|
[](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)
|
## 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.
|
compile with older versions but that may change in any new patch release.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
@ -1,24 +1,15 @@
|
|||||||
//! Metadata for Espressif devices, primarily intended for use in build scripts.
|
//! Metadata for Espressif devices, primarily intended for use in build scripts.
|
||||||
|
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
const ESP32_TOML: &str = include_str!("../devices/esp32.toml");
|
macro_rules! include_toml {
|
||||||
const ESP32C2_TOML: &str = include_str!("../devices/esp32c2.toml");
|
($type:ty, $file:expr) => {{
|
||||||
const ESP32C3_TOML: &str = include_str!("../devices/esp32c3.toml");
|
static LOADED_TOML: OnceLock<$type> = OnceLock::new();
|
||||||
const ESP32C6_TOML: &str = include_str!("../devices/esp32c6.toml");
|
LOADED_TOML.get_or_init(|| basic_toml::from_str(include_str!($file)).unwrap())
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Supported device architectures.
|
/// Supported device architectures.
|
||||||
@ -178,13 +169,13 @@ impl Config {
|
|||||||
/// The configuration for the specified chip.
|
/// The configuration for the specified chip.
|
||||||
pub fn for_chip(chip: &Chip) -> &Self {
|
pub fn for_chip(chip: &Chip) -> &Self {
|
||||||
match chip {
|
match chip {
|
||||||
Chip::Esp32 => &ESP32_CFG,
|
Chip::Esp32 => include_toml!(Config, "../devices/esp32.toml"),
|
||||||
Chip::Esp32c2 => &ESP32C2_CFG,
|
Chip::Esp32c2 => include_toml!(Config, "../devices/esp32c2.toml"),
|
||||||
Chip::Esp32c3 => &ESP32C3_CFG,
|
Chip::Esp32c3 => include_toml!(Config, "../devices/esp32c3.toml"),
|
||||||
Chip::Esp32c6 => &ESP32C6_CFG,
|
Chip::Esp32c6 => include_toml!(Config, "../devices/esp32c6.toml"),
|
||||||
Chip::Esp32h2 => &ESP32H2_CFG,
|
Chip::Esp32h2 => include_toml!(Config, "../devices/esp32h2.toml"),
|
||||||
Chip::Esp32s2 => &ESP32S2_CFG,
|
Chip::Esp32s2 => include_toml!(Config, "../devices/esp32s2.toml"),
|
||||||
Chip::Esp32s3 => &ESP32S3_CFG,
|
Chip::Esp32s3 => include_toml!(Config, "../devices/esp32s3.toml"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,4 +8,3 @@ r-extcap = "0.2.4"
|
|||||||
pcap-file = "2.0.0"
|
pcap-file = "2.0.0"
|
||||||
serialport = "4.2.1"
|
serialport = "4.2.1"
|
||||||
clap = { version = "4.3.5", features = ["derive"] }
|
clap = { version = "4.3.5", features = ["derive"] }
|
||||||
lazy_static = "1.4.0"
|
|
||||||
|
@ -4,7 +4,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use pcap_file::{
|
use pcap_file::{
|
||||||
pcap::{PcapHeader, PcapPacket, PcapWriter},
|
pcap::{PcapHeader, PcapPacket, PcapWriter},
|
||||||
DataLink,
|
DataLink,
|
||||||
@ -25,40 +24,6 @@ pub struct AppArgs {
|
|||||||
serialport: String,
|
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() {
|
fn main() {
|
||||||
let args = AppArgs::parse();
|
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() {
|
match args.extcap.run().unwrap() {
|
||||||
ExtcapStep::Interfaces(interfaces_step) => {
|
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(
|
interfaces_step.list_interfaces(
|
||||||
&METADATA,
|
&metadata,
|
||||||
&[&*WIFI_CAPTURE_INTERFACE, &*BT_CAPTURE_INTERFACE],
|
&[&wifi_capture_interface, &bt_capture_interface],
|
||||||
&[],
|
&[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ExtcapStep::Dlts(dlts_step) => {
|
ExtcapStep::Dlts(dlts_step) => {
|
||||||
dlts_step
|
dlts_step
|
||||||
.print_from_interfaces(&[&*WIFI_CAPTURE_INTERFACE, &*BT_CAPTURE_INTERFACE])
|
.print_from_interfaces(&[&wifi_capture_interface, &bt_capture_interface])
|
||||||
.unwrap();
|
.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) => {
|
ExtcapStep::ReloadConfig(_reload_config_step) => {
|
||||||
panic!("Unsupported operation");
|
panic!("Unsupported operation");
|
||||||
}
|
}
|
||||||
ExtcapStep::Capture(capture_step) => {
|
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 [")
|
(DataLink::ETHERNET, "@WIFIFRAME [")
|
||||||
} else {
|
} else {
|
||||||
(DataLink::BLUETOOTH_HCI_H4, "@HCIFRAME [")
|
(DataLink::BLUETOOTH_HCI_H4, "@HCIFRAME [")
|
||||||
|
@ -8,4 +8,3 @@ r-extcap = "0.2.4"
|
|||||||
pcap-file = "2.0.0"
|
pcap-file = "2.0.0"
|
||||||
serialport = "4.2.0"
|
serialport = "4.2.0"
|
||||||
clap = { version = "4.1.7", features = ["derive"] }
|
clap = { version = "4.1.7", features = ["derive"] }
|
||||||
lazy_static = "1.4.0"
|
|
||||||
|
@ -4,7 +4,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use pcap_file::{
|
use pcap_file::{
|
||||||
pcap::{PcapHeader, PcapPacket, PcapWriter},
|
pcap::{PcapHeader, PcapPacket, PcapWriter},
|
||||||
DataLink,
|
DataLink,
|
||||||
@ -28,102 +27,11 @@ pub struct AppArgs {
|
|||||||
channel: String,
|
channel: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
fn config_option_value(value: &'static str) -> ConfigOptionValue {
|
||||||
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()
|
ConfigOptionValue::builder()
|
||||||
.value("11")
|
.value(value)
|
||||||
.display("11")
|
.display(value)
|
||||||
.default(true)
|
.build()
|
||||||
.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 main() {
|
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() {
|
match args.extcap.run().unwrap() {
|
||||||
ExtcapStep::Interfaces(interfaces_step) => {
|
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) => {
|
ExtcapStep::Dlts(dlts_step) => {
|
||||||
dlts_step
|
dlts_step
|
||||||
.print_from_interfaces(&[&*WIFI_CAPTURE_INTERFACE])
|
.print_from_interfaces(&[&wifi_capture_interface])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
ExtcapStep::Config(config_step) => {
|
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) => {
|
ExtcapStep::ReloadConfig(_reload_config_step) => {
|
||||||
panic!("Unsupported operation");
|
panic!("Unsupported operation");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user