diff --git a/esp-metadata/Cargo.toml b/esp-metadata/Cargo.toml index 754cf512711..9feba3208e0 100644 --- a/esp-metadata/Cargo.toml +++ b/esp-metadata/Cargo.toml @@ -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"] } basic-toml = "0.1.9" -lazy_static = "1.5.0" serde = { version = "1.0.209", features = ["derive"] } strum = { version = "0.26.3", features = ["derive"] } diff --git a/esp-metadata/README.md b/esp-metadata/README.md index dc2b1ae9d0e..6a54fede611 100644 --- a/esp-metadata/README.md +++ b/esp-metadata/README.md @@ -2,7 +2,7 @@ [![Crates.io](https://img.shields.io/crates/v/esp-metadata?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp-metadata) [![docs.rs](https://img.shields.io/docsrs/esp-metadata?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp-metadata) -![MSRV](https://img.shields.io/badge/MSRV-1.60-blue?labelColor=1C2C2E&style=flat-square) +![MSRV](https://img.shields.io/badge/MSRV-1.70-blue?labelColor=1C2C2E&style=flat-square) ![Crates.io](https://img.shields.io/crates/l/esp-metadata?labelColor=1C2C2E&style=flat-square) [![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](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 diff --git a/esp-metadata/src/lib.rs b/esp-metadata/src/lib.rs index 785ee502ce6..3c442464c83 100644 --- a/esp-metadata/src/lib.rs +++ b/esp-metadata/src/lib.rs @@ -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"), } } diff --git a/extras/esp-wifishark/Cargo.toml b/extras/esp-wifishark/Cargo.toml index af5aae771b5..8414d6e37da 100644 --- a/extras/esp-wifishark/Cargo.toml +++ b/extras/esp-wifishark/Cargo.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" diff --git a/extras/esp-wifishark/src/main.rs b/extras/esp-wifishark/src/main.rs index 6d541c8f484..b6863599670 100644 --- a/extras/esp-wifishark/src/main.rs +++ b/extras/esp-wifishark/src/main.rs @@ -4,7 +4,6 @@ use std::{ }; use clap::Parser; -use lazy_static::lazy_static; use pcap_file::{ pcap::{PcapHeader, PcapPacket, PcapWriter}, DataLink, @@ -25,13 +24,16 @@ 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 { +fn main() { + let args = AppArgs::parse(); + + if !args.extcap.capture { + if let Some(_filter) = args.extcap.extcap_capture_filter { + std::process::exit(0); + } + } + + let wifi_capture_interface = Interface { value: "wifi".into(), display: "esp-wifi Ethernet capture".into(), dlt: Dlt { @@ -40,7 +42,8 @@ lazy_static! { display: "Ethernet".into(), }, }; - static ref BT_CAPTURE_INTERFACE: Interface = Interface { + + let bt_capture_interface = Interface { value: "bt".into(), display: "esp-wifi HCI capture".into(), dlt: Dlt { @@ -49,44 +52,43 @@ lazy_static! { 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(); - - if !args.extcap.capture { - if let Some(_filter) = args.extcap.extcap_capture_filter { - std::process::exit(0); - } - } 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 [") diff --git a/extras/ieee802154-sniffer/Cargo.toml b/extras/ieee802154-sniffer/Cargo.toml index a15f339ea4d..c590be02960 100644 --- a/extras/ieee802154-sniffer/Cargo.toml +++ b/extras/ieee802154-sniffer/Cargo.toml @@ -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" diff --git a/extras/ieee802154-sniffer/src/main.rs b/extras/ieee802154-sniffer/src/main.rs index 8e1e7d2d1bb..097ad184302 100644 --- a/extras/ieee802154-sniffer/src/main.rs +++ b/extras/ieee802154-sniffer/src/main.rs @@ -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");