Skip to content

Commit

Permalink
options: save power on AC immediately on set()
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Kopeć <[email protected]>
  • Loading branch information
mkopec committed Jun 27, 2024
1 parent d51e946 commit 2dc97b4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/board/system76/common/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <board/flash.h>
#include <board/options.h>
#include <common/debug.h>
#include <common/macro.h>

uint8_t __xdata OPTIONS[NUM_OPTIONS];

Expand All @@ -17,6 +18,8 @@ uint8_t DEFAULT_OPTIONS[NUM_OPTIONS] = {
};
// clang-format on

#define SAVE_IMMEDIATELY BIT(OPT_POWER_ON_AC)

// Config is in the second to last sector of flash
const uint32_t OPTIONS_ADDR = 0x1F800;
// Signature is the size of the config
Expand Down Expand Up @@ -91,7 +94,7 @@ bool options_save_config(void) {
// TODO error handling
uint8_t options_get(uint16_t index) {
if (index < NUM_OPTIONS) {
TRACE("OPTION %x READ %x\n", index, OPTIONS[index]);
DEBUG("OPTION %x READ %x\n", index, OPTIONS[index]);
return OPTIONS[index];
} else {
return 0;
Expand All @@ -100,8 +103,10 @@ uint8_t options_get(uint16_t index) {

bool options_set(uint16_t index, uint8_t value) {
if (index < NUM_OPTIONS) {
DEBUG("OPTION %x WRITE %x\n", index, value);
OPTIONS[index] = value;
TRACE("OPTION %x WRITE %x\n", index, value);
if (SAVE_IMMEDIATELY & BIT(index))
return options_save_config();
return true;
} else {
return false;
Expand Down

0 comments on commit 2dc97b4

Please sign in to comment.