daisy::PersistentStorage¶
Non Volatile storage class for persistent settings on an external flash device. More...
#include <PersistentStorage.h>
Public Types¶
Name | |
---|---|
enum class | State |
Public Functions¶
Name | |
---|---|
PersistentStorage(QSPIHandle & qspi) | |
void | Init(const SettingStruct & defaults, uint32_t address_offset =0) |
State | GetState() const |
SettingStruct & | GetSettings() |
void | Save() |
void | RestoreDefaults() |
Detailed Description¶
Non Volatile storage class for persistent settings on an external flash device.
Author: shensley
Todo:
-
Make Save() non-blocking
-
Add wear leveling
Storage occupied by the struct will be one word larger than the SettingStruct used. The extra word is used to store the state of the data, and whether it's been overwritten or not.
Public Types Documentation¶
enum State¶
Enumerator | Value | Description |
---|---|---|
UNKNOWN | 0 | |
FACTORY | 1 | |
USER | 2 |
State of the storage. When created, prior to initialiation, the state will be Unknown
During initialization, the state will be changed to either FACTORY, or USER.
If this is the first time these settings are being written to the target address, the defaults will be written to that location, and the state will be set to FACTORY.
Once the first user-trigger save has been made, the state will be updated to USER to indicate that the defaults have overwritten.
Public Functions Documentation¶
function PersistentStorage¶
Parameters:
- qspi reference to the hardware qspi peripheral.
Constructor for storage class
function Init¶
Parameters:
- defaults should be a setting structure containing the default values. this will be updated to contain the stored data.
- address_offset offset for location on the QSPI chip (offset to base address of device). This defaults to the first address on the chip, and will be masked to the nearest multiple of 256
Initialize Storage class
The values in this class will be stored as the default for restoration to 'factory' settings.
function GetState¶
Returns the state of the Persistent Data
function GetSettings¶
Returns a reference to the setting struct
function Save¶
Performs the save operation, storing the storage
function RestoreDefaults¶
Restores the settings stored in the QSPI
---¶
Updated on 2024-01-03 at 19:41:00 +0000