20template <
typename SettingStruct>
72 =
reinterpret_cast<SaveStruct *
>(qspi_.
GetData(address_offset_));
80 StoreSettingsIfChanged();
99 StoreSettingsIfChanged();
105 settings_ = default_settings_;
107 StoreSettingsIfChanged();
117 void StoreSettingsIfChanged()
120 s.storage_state = state_;
121 s.user_data = settings_;
123 void *data_ptr = qspi_.
GetData(address_offset_);
139 auto storage_data =
reinterpret_cast<SaveStruct *
>(data_ptr);
140 if(settings_ != storage_data->user_data)
142 qspi_.
Erase(address_offset_, address_offset_ +
sizeof(s));
143 qspi_.
Write(address_offset_,
sizeof(s), (uint8_t *)&s);
148 uint32_t address_offset_;
149 SettingStruct default_settings_;
150 SettingStruct settings_;
Definition leddriver.h:33
Non Volatile storage class for persistent settings on an external flash device.
Definition PersistentStorage.h:22
void Save()
Definition PersistentStorage.h:96
void Init(const SettingStruct &defaults, uint32_t address_offset=0)
Definition PersistentStorage.h:66
State GetState() const
Definition PersistentStorage.h:90
PersistentStorage(QSPIHandle &qspi)
Definition PersistentStorage.h:47
SettingStruct & GetSettings()
Definition PersistentStorage.h:93
State
Definition PersistentStorage.h:38
void RestoreDefaults()
Definition PersistentStorage.h:103
Result Erase(uint32_t start_addr, uint32_t end_addr)
void * GetData(uint32_t offset=0)
Result Write(uint32_t address, uint32_t size, uint8_t *buffer)
@ INTERNAL_FLASH
Definition system.h:64
static MemoryRegion GetProgramMemoryRegion()
void dsy_dma_invalidate_cache_for_buffer(uint8_t *buffer, size_t size)
Hardware defines and helpers for daisy field platform.
Definition index.h:2