How to: EEPROM twr_config¶
twr_config
functions helps you to easily create a variable or structure of variables that are saved in internal EEPROM memory.
Library will automatically initialize your configuration when:
It runs first time
If the signature parameter is different
If the new configuration structure has different length
If the EEPROM is corrupted
Tip
Initialization¶
The first parameter, signature
, is unique number for your firmware.
This way if you load a different firmware to the Core Module that is using configuration structure with the same length,
the library will see that and initialize the configuration properly again.
The last parameter init_config can be:
NULL
- the config structure is zeroed when initializedPointer to structure - the
init_config
is copied to theconfig
structure when initialized
1 2 | // Load configuration
twr_config_init(0x12345678, &config, sizeof(config), NULL);
|
Code Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <application.h>
// Example structure that save configuration of PIR detector
typedef struct config_t
{
uint16_t report_interval;
uint8_t pir_sensitivity;
uint16_t pir_deadtime;
} config_t;
config_t config;
void application_init()
{
// Load configuration
twr_config_init(0x12345678, &config, sizeof(config), NULL);
// Change parameter
config.report_interval = 500;
// Save config to EEPROM
twr_config_save();
// Reset configuration
twr_config_reset();
}
|