Back to Qmk Firmware

Battery Driver

docs/drivers/battery.md

4.01.8 KB
Original Source

Battery Driver

This driver provides support for directly sampling battery level.

Usage

To use this driver, add the following to your rules.mk:

make
BATTERY_DRIVER_REQUIRED = yes

::::info Note This is already configured for you if you are using the Battery feature. ::::

Driver Configuration {#driver-configuration}

Driver selection can be configured in rules.mk as BATTERY_DRIVER. Valid values are adc, vendor, or custom. See below for information on individual drivers.

ADC Driver {#adc-driver}

The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider.

make
BATTERY_DRIVER = adc

The following #defines apply only to the adc driver:

DefineDefaultDescription
BATTERY_ADC_PINNot definedThe GPIO pin connected to the voltage divider.
BATTERY_ADC_REF_VOLTAGE_MV3300The ADC reverence voltage, in millivolts.
BATTERY_ADC_VOLTAGE_DIVIDER_R1100The voltage divider resistance, in kOhm. Set to 0 to disable.
BATTERY_ADC_VOLTAGE_DIVIDER_R2100The voltage divider resistance, in kOhm. Set to 0 to disable.
BATTERY_ADC_RESOLUTION10The ADC resolution configured for the ADC Driver.

Custom Driver {#custom-driver}

A custom driver is expected to implement the following interface:

c
void battery_driver_init(void) {
    // Perform any initialisation here
}

uint8_t battery_driver_sample_percent(void) {
    // Read and return current state here
    return value;
}