diff --git a/src/board/system76/common/battery.c b/src/board/system76/common/battery.c index 961a2eaa6..d8cd25da0 100644 --- a/src/board/system76/common/battery.c +++ b/src/board/system76/common/battery.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include +#include #include #include @@ -13,41 +14,31 @@ uint16_t battery_charger_input_voltage = BATTERY_CHARGER_VOLTAGE_AC; #define BATTERY_START_DEFAULT 0 #define BATTERY_END_DEFAULT 100 -// Represents a battery percentage level, below which charging will begin. -// Valid values are [0, 100] -// A value of 0 turns off the start threshold control. -static uint8_t battery_start_threshold = BATTERY_START_THRESHOLD; - -// Represents a battery percentage level, above which charging will stop. -// Valid values are [0, 100] -// A value of 100 turns off the stop threshold control. -static uint8_t battery_end_threshold = BATTERY_END_THRESHOLD; - uint8_t battery_get_start_threshold(void) { - if (battery_start_threshold > 100) + if (options_get(OPT_BAT_THRESHOLD_START) > 100) return BATTERY_START_DEFAULT; - return battery_start_threshold; + return options_get(OPT_BAT_THRESHOLD_START); } bool battery_set_start_threshold(uint8_t value) { - if (value > 100 || value >= battery_end_threshold) + if (value > 100 || value >= options_get(OPT_BAT_THRESHOLD_STOP)) return false; - battery_start_threshold = value; + options_set(OPT_BAT_THRESHOLD_START, value); return true; } uint8_t battery_get_end_threshold(void) { - if (battery_end_threshold > 100) + if (options_get(OPT_BAT_THRESHOLD_STOP) > 100) return BATTERY_END_DEFAULT; - return battery_end_threshold; + return options_get(OPT_BAT_THRESHOLD_STOP); } bool battery_set_end_threshold(uint8_t value) { - if (value > 100 || value <= battery_start_threshold) + if (value > 100 || value <= options_get(OPT_BAT_THRESHOLD_START)) return false; - battery_end_threshold = value; + options_set(OPT_BAT_THRESHOLD_STOP, value); return true; } @@ -98,8 +89,3 @@ void battery_event(void) { battery_charger_event(); } - -void battery_reset(void) { - battery_start_threshold = BATTERY_START_THRESHOLD; - battery_end_threshold = BATTERY_END_THRESHOLD; -} diff --git a/src/board/system76/common/common.mk b/src/board/system76/common/common.mk index d43c07866..84d6a8a22 100644 --- a/src/board/system76/common/common.mk +++ b/src/board/system76/common/common.mk @@ -65,14 +65,6 @@ SYSTEM76_COMMON_DIR=src/board/system76/common INCLUDE += $(SYSTEM76_COMMON_DIR)/common.mk CFLAGS+=-I$(SYSTEM76_COMMON_DIR)/include -# Set battery charging thresholds -BATTERY_START_THRESHOLD?=95 -BATTERY_END_THRESHOLD?=98 - -CFLAGS+=\ - -DBATTERY_START_THRESHOLD=$(BATTERY_START_THRESHOLD) \ - -DBATTERY_END_THRESHOLD=$(BATTERY_END_THRESHOLD) - # Add charger CHARGER?=bq24780s board-common-y += charger/$(CHARGER).c diff --git a/src/board/system76/common/config.c b/src/board/system76/common/config.c index 399d133ed..609ba8437 100644 --- a/src/board/system76/common/config.c +++ b/src/board/system76/common/config.c @@ -5,6 +5,7 @@ #include #include #include +#include #include /** @@ -19,7 +20,7 @@ bool config_should_reset(void) { */ void config_reset(void) { INFO("Reset configuration\n"); - battery_reset(); + options_reset(); keymap_erase_config(); keymap_load_default(); } diff --git a/src/board/system76/common/include/board/battery.h b/src/board/system76/common/include/board/battery.h index ad882ad74..b8d713f27 100644 --- a/src/board/system76/common/include/board/battery.h +++ b/src/board/system76/common/include/board/battery.h @@ -46,7 +46,6 @@ bool battery_set_end_threshold(uint8_t value); int16_t battery_charger_configure(void); void battery_event(void); -void battery_reset(void); // Defined by charger/*.c int16_t battery_charger_disable(void); diff --git a/src/board/system76/common/include/board/options.h b/src/board/system76/common/include/board/options.h index 74121fa2f..c8234110f 100644 --- a/src/board/system76/common/include/board/options.h +++ b/src/board/system76/common/include/board/options.h @@ -8,6 +8,8 @@ // Initialize the options void options_init(void); +// Restore defaults +void options_reset(void); // Save options to flash bool options_save_config(void); // Get an option diff --git a/src/board/system76/common/options.c b/src/board/system76/common/options.c index 4fce1621e..284ccc9e9 100644 --- a/src/board/system76/common/options.c +++ b/src/board/system76/common/options.c @@ -22,7 +22,7 @@ const uint32_t OPTIONS_ADDR = 0x1F800; // Signature is the size of the config const uint16_t OPTIONS_SIGNATURE = sizeof(OPTIONS); -static void options_load_default() { +void options_reset() { for (uint8_t opt = 0; opt < NUM_OPTIONS; opt++) { OPTIONS[opt] = DEFAULT_OPTIONS[opt]; } @@ -48,7 +48,7 @@ static bool options_erase_config(void) { void options_init(void) { if (!options_load_config()) { - options_load_default(); + options_reset(); } }