Non Volatile storage class for persistent settings on an external flash device. More...
Non Volatile storage class for persistent settings on an external flash device.
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.
#include <PersistentStorage.h>
Public Types | |
enum class | State { UNKNOWN = 0 , FACTORY = 1 , USER = 2 } |
Public Member Functions | |
PersistentStorage (QSPIHandle &qspi) | |
void | Init (const SettingStruct &defaults, uint32_t address_offset=0) |
State | GetState () const |
SettingStruct & | GetSettings () |
void | Save () |
void | RestoreDefaults () |
|
strong |
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.
Enumerator | |
---|---|
UNKNOWN | |
FACTORY | |
USER |
|
inline |
Constructor for storage class
qspi | reference to the hardware qspi peripheral. |
|
inline |
Returns a reference to the setting struct
|
inline |
Returns the state of the Persistent Data
|
inline |
Initialize Storage class
The values in this class will be stored as the default for restoration to 'factory' settings.
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 |
|
inline |
Restores the settings stored in the QSPI
|
inline |
Performs the save operation, storing the storage