Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default battery start threshold to 90% #401

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/board/system76/common/battery.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only

#include <board/battery.h>
#include <board/gpio.h>
#include <board/smbus.h>
#include <common/debug.h>

Expand Down Expand Up @@ -55,10 +56,13 @@ bool battery_set_end_threshold(uint8_t value) {
*/
int16_t battery_charger_configure(void) {
static bool should_charge = true;
bool ac_present = !gpio_get(&ACIN_N);

if (battery_get_end_threshold() == BATTERY_END_DEFAULT) {
// Stop threshold not configured: Always charge on AC.
should_charge = true;
if (!ac_present || (battery_info.status & BATTERY_FULLY_CHARGED)) {
// Always disable charger if:
// - AC is not plugged in, or
// - Battery is fully charged
should_charge = false;
} else if (battery_info.charge > battery_get_end_threshold()) {
// Stop threshold configured: Stop charging at threshold.
should_charge = false;
Expand Down
2 changes: 1 addition & 1 deletion src/board/system76/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ INCLUDE += $(SYSTEM76_COMMON_DIR)/common.mk
CFLAGS+=-I$(SYSTEM76_COMMON_DIR)/include

# Set battery charging thresholds
BATTERY_START_THRESHOLD?=0
BATTERY_START_THRESHOLD?=90
BATTERY_END_THRESHOLD?=100

CFLAGS+=\
Expand Down
3 changes: 3 additions & 0 deletions src/board/system76/common/include/board/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#define CHARGER_ADDRESS 0x09
#endif

#define BATTERY_FULLY_DISCHARGED BIT(4)
#define BATTERY_FULLY_CHARGED BIT(5)
#define BATTERY_DISCHARGING BIT(6)
#define BATTERY_INITIALIZED BIT(7)

struct battery_info {
Expand Down