3
3
#include <board/flash.h>
4
4
#include <board/options.h>
5
5
#include <common/debug.h>
6
+ #include <common/macro.h>
6
7
7
8
uint8_t __xdata OPTIONS [NUM_OPTIONS ];
8
9
@@ -17,6 +18,8 @@ uint8_t DEFAULT_OPTIONS[NUM_OPTIONS] = {
17
18
};
18
19
// clang-format on
19
20
21
+ #define SAVE_IMMEDIATELY BIT(OPT_POWER_ON_AC)
22
+
20
23
// Config is in the second to last sector of flash
21
24
const uint32_t OPTIONS_ADDR = 0x1F800 ;
22
25
// Signature is the size of the config
@@ -91,7 +94,7 @@ bool options_save_config(void) {
91
94
// TODO error handling
92
95
uint8_t options_get (uint16_t index ) {
93
96
if (index < NUM_OPTIONS ) {
94
- TRACE ("OPTION %x READ %x\n" , index , OPTIONS [index ]);
97
+ DEBUG ("OPTION %x READ %x\n" , index , OPTIONS [index ]);
95
98
return OPTIONS [index ];
96
99
} else {
97
100
return 0 ;
@@ -100,8 +103,10 @@ uint8_t options_get(uint16_t index) {
100
103
101
104
bool options_set (uint16_t index , uint8_t value ) {
102
105
if (index < NUM_OPTIONS ) {
106
+ DEBUG ("OPTION %x WRITE %x\n" , index , value );
103
107
OPTIONS [index ] = value ;
104
- TRACE ("OPTION %x WRITE %x\n" , index , value );
108
+ if (SAVE_IMMEDIATELY & BIT (index ))
109
+ return options_save_config ();
105
110
return true;
106
111
} else {
107
112
return false;
0 commit comments