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// Load configuration
2twr_config_init(0x12345678, &config, sizeof(config), NULL);
Code Example¶
1#include <application.h>
2
3// Example structure that save configuration of PIR detector
4typedef struct config_t
5{
6 uint16_t report_interval;
7 uint8_t pir_sensitivity;
8 uint16_t pir_deadtime;
9
10} config_t;
11
12config_t config;
13
14void application_init()
15{
16 // Load configuration
17 twr_config_init(0x12345678, &config, sizeof(config), NULL);
18
19 // Change parameter
20 config.report_interval = 500;
21
22 // Save config to EEPROM
23 twr_config_save();
24
25 // Reset configuration
26 twr_config_reset();
27}