14#elif defined(USE_ESP8266)
18#elif defined(USE_LIBRETINY)
20#elif defined(USE_HOST)
22#elif defined(USE_ZEPHYR) && defined(CONFIG_SETTINGS)
40 { backend.save(
src,
len) } -> std::same_as<bool>;
41 { backend.load(dest,
len) } -> std::same_as<bool>;
44#if !defined(USE_ESP32) && !defined(USE_ESP8266) && !defined(USE_RP2) && !defined(USE_LIBRETINY) && \
45 !defined(USE_HOST) && !(defined(USE_ZEPHYR) && defined(CONFIG_SETTINGS))
48 bool save(
const uint8_t *,
size_t) {
return false; }
49 bool load(uint8_t *,
size_t) {
return false; }
55 "The platform's preference backend is missing part of the PreferenceBackend surface");
62 template<
typename T>
bool save(
const T *
src) {
return this->
save(
reinterpret_cast<const uint8_t *
>(
src),
sizeof(T)); }
64 template<
typename T>
bool load(T *dest) {
return this->
load(
reinterpret_cast<uint8_t *
>(dest),
sizeof(T)); }
99 { prefs.make_preference(
len,
type, in_flash) } -> std::same_as<ESPPreferenceObject>;
100 { prefs.make_preference(
len,
type) } -> std::same_as<ESPPreferenceObject>;
101 { prefs.template make_preference<uint32_t>(
type, in_flash) } -> std::same_as<ESPPreferenceObject>;
102 { prefs.template make_preference<uint32_t>(
type) } -> std::same_as<ESPPreferenceObject>;
103 { prefs.sync() } -> std::same_as<bool>;
104 { prefs.reset() } -> std::same_as<bool>;
113 { prefs.load_from_key(
type, data,
len) } -> std::same_as<bool>;
120 template<typename T, enable_if_t<is_trivially_copyable<T>::value,
bool> =
true>
125 template<typename T, enable_if_t<is_trivially_copyable<T>::value,
bool> =
true>
137#define DECLARE_PREFERENCE_ALIASES(platform_class) \
138 namespace esphome { \
139 using Preferences = platform_class; \
140 using ESPPreferences = Preferences; \
141 extern ESPPreferences *global_preferences; \
PreferenceBackend * backend_
ESPPreferenceObject(PreferenceBackend *backend)
bool save(const uint8_t *src, size_t len)
Raw save with explicit length, for callers that only know the size at runtime.
ESPPreferenceObject()=default
bool load(uint8_t *dest, size_t len)
Raw load with explicit length, for callers that only know the size at runtime.
CRTP mixin providing type-safe template make_preference<T>() helpers.
ESPPreferenceObject make_preference(uint32_t type)
ESPPreferenceObject make_preference(uint32_t type, bool in_flash)
esp32::ESP32PreferenceBackend PreferenceBackend
bool save(const uint8_t *, size_t)
bool load(uint8_t *, size_t)