libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::PersistentStorage< SettingStruct > Class Template Reference

Non Volatile storage class for persistent settings on an external flash device. More...

Detailed Description

template<typename SettingStruct>
class daisy::PersistentStorage< SettingStruct >

Non Volatile storage class for persistent settings on an external flash device.

Author
shensley

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.

Todo:

- Add wear leveling

#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
 
SettingStructGetSettings ()
 
void Save ()
 
void RestoreDefaults ()
 

Member Enumeration Documentation

◆ State

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 

Constructor & Destructor Documentation

◆ PersistentStorage()

template<typename SettingStruct >
daisy::PersistentStorage< SettingStruct >::PersistentStorage ( QSPIHandle qspi)
inline

Constructor for storage class

Parameters
qspireference to the hardware qspi peripheral.

Member Function Documentation

◆ GetSettings()

Returns a reference to the setting struct

◆ GetState()

template<typename SettingStruct >
State daisy::PersistentStorage< SettingStruct >::GetState ( ) const
inline

Returns the state of the Persistent Data

◆ Init()

template<typename SettingStruct >
void daisy::PersistentStorage< SettingStruct >::Init ( const SettingStruct defaults,
uint32_t  address_offset = 0 
)
inline

Initialize Storage class

The values in this class will be stored as the default for restoration to 'factory' settings.

Parameters
defaultsshould be a setting structure containing the default values. this will be updated to contain the stored data.
address_offsetoffset 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

◆ RestoreDefaults()

template<typename SettingStruct >
void daisy::PersistentStorage< SettingStruct >::RestoreDefaults ( )
inline

Restores the settings stored in the QSPI

◆ Save()

Performs the save operation, storing the storage


The documentation for this class was generated from the following file: