esp_storage/
lib.rs

1#![cfg_attr(not(all(test, feature = "emulation")), no_std)]
2
3#[cfg(not(feature = "emulation"))]
4#[cfg_attr(feature = "esp32c2", path = "esp32c2.rs")]
5#[cfg_attr(feature = "esp32c3", path = "esp32c3.rs")]
6#[cfg_attr(feature = "esp32c6", path = "esp32c6.rs")]
7#[cfg_attr(feature = "esp32h2", path = "esp32h2.rs")]
8#[cfg_attr(feature = "esp32", path = "esp32.rs")]
9#[cfg_attr(feature = "esp32s2", path = "esp32s2.rs")]
10#[cfg_attr(feature = "esp32s3", path = "esp32s3.rs")]
11#[cfg_attr(
12    not(any(
13        feature = "esp32c2",
14        feature = "esp32c3",
15        feature = "esp32c6",
16        feature = "esp32",
17        feature = "esp32s2",
18        feature = "esp32s3",
19        feature = "esp32h2"
20    )),
21    path = "stub.rs"
22)]
23mod chip_specific;
24
25#[cfg(feature = "emulation")]
26#[path = "stub.rs"]
27mod chip_specific;
28
29#[cfg(any(feature = "storage", feature = "nor-flash"))]
30mod common;
31
32#[cfg(any(feature = "storage", feature = "nor-flash"))]
33use common::FlashSectorBuffer;
34#[cfg(any(feature = "storage", feature = "nor-flash"))]
35pub use common::{FlashStorage, FlashStorageError};
36
37#[cfg(feature = "storage")]
38mod storage;
39
40#[cfg(feature = "nor-flash")]
41mod nor_flash;
42
43#[cfg(feature = "low-level")]
44pub mod ll;
45
46#[cfg(not(feature = "emulation"))]
47#[inline(always)]
48#[link_section = ".rwtext"]
49fn maybe_with_critical_section<R>(f: impl FnOnce() -> R) -> R {
50    #[cfg(feature = "critical-section")]
51    return critical_section::with(|_| f());
52
53    #[cfg(not(feature = "critical-section"))]
54    f()
55}
56
57#[cfg(feature = "emulation")]
58fn maybe_with_critical_section<R>(f: impl FnOnce() -> R) -> R {
59    f()
60}
61
62#[doc(hidden)]
63#[macro_export]
64macro_rules! rom_fn {
65    ($(#[$attrs:meta])* fn $name:ident($($arg:tt: $ty:ty),*) $(-> $retval:ty)? = $addr:expr) => {
66        $(#[$attrs])*
67        #[allow(unused)]
68        #[inline(always)]
69        #[link_section = ".rwtext"]
70        fn $name($($arg:$ty),*) $(-> $retval)? {
71            unsafe {
72                let rom_fn: unsafe extern "C" fn($($arg: $ty),*) $(-> $retval)? =
73                    core::mem::transmute($addr as usize);
74                rom_fn($($arg),*)
75            }
76        }
77    };
78
79    ($($(#[$attrs:meta])* fn $name:ident($($arg:tt: $ty:ty),*) $(-> $retval:ty)? = $addr:expr;)+) => {
80        $(
81            $crate::rom_fn!(fn $name($($arg: $ty),*) $(-> $retval)? = $addr);
82        )+
83    };
84}