2025-08-17 01:14:48 +01:00

1.8 KiB

Battery Driver

This driver provides support for directly sampling battery level.

Usage

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

BATTERY_DRIVER_REQUIRED = yes

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

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

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

BATTERY_DRIVER = adc

The following #defines apply only to the adc driver:

Define Default Description
BATTERY_ADC_PIN Not defined The GPIO pin connected to the voltage divider.
BATTERY_ADC_REF_VOLTAGE_MV 3300 The ADC reverence voltage, in millivolts.
BATTERY_ADC_VOLTAGE_DIVIDER_R1 100 The voltage divider resistance, in kOhm. Set to 0 to disable.
BATTERY_ADC_VOLTAGE_DIVIDER_R2 100 The voltage divider resistance, in kOhm. Set to 0 to disable.
BATTERY_ADC_RESOLUTION 10 The ADC resolution configured for the ADC Driver.

Custom Driver

A custom driver is expected to implement the following interface:

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

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