Skip to main content

wifi_caddy/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3#![warn(missing_docs)]
4#![allow(async_fn_in_trait)]
5#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))]
6
7extern crate alloc;
8
9mod fmt;
10
11pub mod config_storage;
12
13#[cfg(feature = "portal")]
14pub mod portal;
15#[cfg(feature = "portal")]
16mod run_http;
17
18#[cfg(all(feature = "portal", feature = "debug-server"))]
19pub use run_http::run_http_debug_loop;
20#[cfg(feature = "portal")]
21pub use run_http::{ConfigUiOptions, run_http_config_loop};
22
23/// Parameters for config storage mount/format. Only the values are configurable;
24/// key IDs are fixed to match wifi-caddy-proc.
25#[doc(hidden)]
26#[derive(Clone, Copy, Debug)]
27pub struct ConfigStorageParams {
28    /// Magic value stored at the magic key (format identifier).
29    pub magic: u32,
30    /// Format version stored at the format version key.
31    pub format_version: u32,
32}
33
34/// Handle returned by the platform-specific init macro (e.g. `esp_wifi_caddy::wifi_init!`).
35/// Use [`.config()`](ConfigHandle::config) to get the shared config mutex to pass into
36/// application tasks.
37pub struct ConfigHandle<C: 'static> {
38    config: &'static embassy_sync::mutex::Mutex<
39        embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
40        C,
41    >,
42}
43
44impl<C: 'static> ConfigHandle<C> {
45    /// Create a new `ConfigHandle` wrapping the given config mutex.
46    pub fn new(
47        config: &'static embassy_sync::mutex::Mutex<
48            embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
49            C,
50        >,
51    ) -> Self {
52        Self { config }
53    }
54
55    /// Returns the shared config mutex (`'static`), for use in tasks or elsewhere.
56    pub fn config(
57        &self,
58    ) -> &'static embassy_sync::mutex::Mutex<
59        embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
60        C,
61    > {
62        self.config
63    }
64}