ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
preferences.h
Go to the documentation of this file.
1#pragma once
2#ifdef USE_ESP32
3
5#include <soc/soc_caps.h>
6
7// RTC-backed preference storage is compiled in only when a config option actually selects it
8// (USE_ESP32_RTC_PREFERENCES, emitted during code generation) and the variant has RTC memory
9// (SOC_RTC_MEM_SUPPORTED; the ESP32-C2 and -C61 have none). Otherwise in_flash=false falls
10// back to NVS and no RTC memory is reserved.
11#if defined(USE_ESP32_RTC_PREFERENCES) && SOC_RTC_MEM_SUPPORTED
12#define USE_ESP32_RTC_PREFERENCES_STORAGE
13#endif
14
15namespace esphome::esp32 {
16
17struct NVSData;
18
19class ESP32Preferences final : public PreferencesMixin<ESP32Preferences> {
20 public:
22 void open();
24 // Two-argument form defaults to NVS (flash) storage, preserving historic ESP32 behavior.
26 bool sync();
27 bool reset();
28
30
31 protected:
32 bool is_changed_(uint32_t nvs_handle, const NVSData &to_save, const char *key_str);
33
34#ifdef USE_ESP32_RTC_PREFERENCES_STORAGE
35 // RTC-backed storage (in_flash=false).
37 // Next free word offset in the RTC storage region (bump allocated in make_preference order).
39#endif
40};
41
43
44} // namespace esphome::esp32
45
46DECLARE_PREFERENCE_ALIASES(esphome::esp32::ESP32Preferences)
47
48#endif // USE_ESP32
CRTP mixin providing type-safe template make_preference<T>() helpers.
bool is_changed_(uint32_t nvs_handle, const NVSData &to_save, const char *key_str)
ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)
ESPPreferenceObject make_rtc_preference_(size_t length, uint32_t type)
uint16_t type
void setup_preferences()
static void uint32_t
uint16_t length
Definition tt21100.cpp:0