Implement battery level interface (#24666)

Co-authored-by: Nick Brassel <nick@tzarc.org>
This commit is contained in:
Joel Challis 2025-02-28 05:46:14 +00:00 committed by GitHub
parent 312f42945d
commit 6ee806f376
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 275 additions and 0 deletions

31
drivers/battery/battery.c Normal file
View file

@ -0,0 +1,31 @@
// Copyright 2025 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include "battery_driver.h"
#include "battery.h"
#include "timer.h"
#ifndef BATTERY_SAMPLE_INTERVAL
# define BATTERY_SAMPLE_INTERVAL 30000
#endif
static uint8_t last_bat_level = 100;
void battery_init(void) {
battery_driver_init();
last_bat_level = battery_driver_sample_percent();
}
void battery_task(void) {
static uint32_t bat_timer = 0;
if (timer_elapsed32(bat_timer) > BATTERY_SAMPLE_INTERVAL) {
last_bat_level = battery_driver_sample_percent();
bat_timer = timer_read32();
}
}
uint8_t battery_get_percent(void) {
return last_bat_level;
}