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