refactor: create util module with shared mk_static
- use crate::util::mk_static in network module - use crate::util::mk_static in mqtt module - use crate::util::mk_static in hal module - remove dead mk_static macro from esp module
This commit is contained in:
@@ -120,15 +120,6 @@ pub struct Esp<'a> {
|
|||||||
// CPU cores/threads, reconsider this.
|
// CPU cores/threads, reconsider this.
|
||||||
unsafe impl Send for Esp<'_> {}
|
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<'_> {
|
impl Esp<'_> {
|
||||||
pub fn get_time(&self) -> DateTime<Utc> {
|
pub fn get_time(&self) -> DateTime<Utc> {
|
||||||
DateTime::from_timestamp_micros(self.rtc.current_time_us() as i64)
|
DateTime::from_timestamp_micros(self.rtc.current_time_us() as i64)
|
||||||
|
|||||||
@@ -282,14 +282,7 @@ pub struct FreePeripherals<'a> {
|
|||||||
pub adc1: ADC1<'a>,
|
pub adc1: ADC1<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! mk_static {
|
use crate::util::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 PlantHal {
|
impl PlantHal {
|
||||||
pub async fn create() -> Result<Mutex<CriticalSectionRawMutex, HAL<'static>>, FatError> {
|
pub async fn create() -> Result<Mutex<CriticalSectionRawMutex, HAL<'static>>, FatError> {
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ mod mqtt;
|
|||||||
mod network;
|
mod network;
|
||||||
mod plant_state;
|
mod plant_state;
|
||||||
mod tank;
|
mod tank;
|
||||||
|
mod util;
|
||||||
mod webserver;
|
mod webserver;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|||||||
@@ -110,14 +110,7 @@ async fn publish_inner(subtopic: &str, message: &str) -> FatResult<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! mk_static {
|
use crate::util::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 mqtt_init(
|
pub async fn mqtt_init(
|
||||||
network_config: &'static NetworkConfig,
|
network_config: &'static NetworkConfig,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::config::NetworkConfig;
|
|||||||
use crate::fat_error::{ContextExt, FatError, FatResult};
|
use crate::fat_error::{ContextExt, FatError, FatResult};
|
||||||
use crate::hal::{PlantHal, HAL};
|
use crate::hal::{PlantHal, HAL};
|
||||||
use crate::mqtt;
|
use crate::mqtt;
|
||||||
|
use crate::util::mk_static;
|
||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use chrono::{DateTime, Utc};
|
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(
|
pub async fn wifi_ap(
|
||||||
ssid: String,
|
ssid: String,
|
||||||
interface_ap: Interface<'static>,
|
interface_ap: Interface<'static>,
|
||||||
|
|||||||
10
rust/src/util.rs
Normal file
10
rust/src/util.rs
Normal file
@@ -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;
|
||||||
Reference in New Issue
Block a user