diff --git a/Software/MainBoard/rust/src/hal/esp.rs b/Software/MainBoard/rust/src/hal/esp.rs index 2e6c35f..f4dfcb7 100644 --- a/Software/MainBoard/rust/src/hal/esp.rs +++ b/Software/MainBoard/rust/src/hal/esp.rs @@ -101,15 +101,6 @@ pub struct Esp<'a> { // CPU cores/threads, reconsider this. unsafe impl Send for Esp<'_> {} -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write($val); - x - }}; -} - impl Esp<'_> { pub fn get_time(&self) -> DateTime { DateTime::from_timestamp_micros(self.rtc.current_time_us() as i64) diff --git a/Software/MainBoard/rust/src/hal/mod.rs b/Software/MainBoard/rust/src/hal/mod.rs index 405b9a8..4aa3ec6 100644 --- a/Software/MainBoard/rust/src/hal/mod.rs +++ b/Software/MainBoard/rust/src/hal/mod.rs @@ -241,14 +241,7 @@ pub struct FreePeripherals<'a> { pub adc1: ADC1<'a>, } -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write($val); - x - }}; -} +use crate::util::mk_static; impl PlantHal { pub async fn create() -> Result>, FatError> { diff --git a/Software/MainBoard/rust/src/main.rs b/Software/MainBoard/rust/src/main.rs index 6bde80d..0764326 100644 --- a/Software/MainBoard/rust/src/main.rs +++ b/Software/MainBoard/rust/src/main.rs @@ -71,6 +71,7 @@ mod mqtt; mod network; mod plant_state; mod tank; +mod util; mod webserver; extern crate alloc; diff --git a/Software/MainBoard/rust/src/mqtt.rs b/Software/MainBoard/rust/src/mqtt.rs index 3828790..fcbedd4 100644 --- a/Software/MainBoard/rust/src/mqtt.rs +++ b/Software/MainBoard/rust/src/mqtt.rs @@ -114,14 +114,7 @@ async fn publish_inner(subtopic: &str, message: &str) -> FatResult<()> { } } -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} +use crate::util::mk_static; pub async fn mqtt_init( network_config: &'static NetworkConfig, diff --git a/Software/MainBoard/rust/src/network.rs b/Software/MainBoard/rust/src/network.rs index dfe545e..4c459cc 100644 --- a/Software/MainBoard/rust/src/network.rs +++ b/Software/MainBoard/rust/src/network.rs @@ -3,6 +3,7 @@ use crate::config::NetworkConfig; use crate::fat_error::{ContextExt, FatError, FatResult}; use crate::hal::{PlantHal, HAL}; use crate::mqtt; +use crate::util::mk_static; use alloc::string::{String, ToString}; use alloc::sync::Arc; use chrono::{DateTime, Utc}; @@ -196,15 +197,6 @@ pub(crate) async fn run_dhcp(stack: Stack<'static>, ip: Ipv4Addr) { } } -macro_rules! mk_static { - ($t:ty,$val:expr) => {{ - static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); - #[deny(unused_attributes)] - let x = STATIC_CELL.uninit().write(($val)); - x - }}; -} - pub async fn wifi_ap( ssid: String, interface_ap: Interface<'static>, diff --git a/Software/MainBoard/rust/src/util.rs b/Software/MainBoard/rust/src/util.rs new file mode 100644 index 0000000..9241868 --- /dev/null +++ b/Software/MainBoard/rust/src/util.rs @@ -0,0 +1,10 @@ +macro_rules! mk_static { + ($t:ty,$val:expr) => {{ + static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new(); + #[deny(unused_attributes)] + let x = STATIC_CELL.uninit().write(($val)); + x + }}; +} + +pub(crate) use mk_static;