summaryrefslogtreecommitdiff
path: root/docs/drivers
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2025-02-28 05:46:14 +0000
committerGitHub <noreply@github.com>2025-02-28 16:46:14 +1100
commit6ee806f376f2bb821c1eb724645444fbf4f5a18e (patch)
tree85aa6bca7797b7f49f4bcccc1d7aed09ac59bed0 /docs/drivers
parent312f42945daede5c46d72e58dfe44b86c7666eb1 (diff)
Implement battery level interface (#24666)
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'docs/drivers')
-rw-r--r--docs/drivers/battery.md51
1 files changed, 51 insertions, 0 deletions
diff --git a/docs/drivers/battery.md b/docs/drivers/battery.md
new file mode 100644
index 0000000000..b1f75c1156
--- /dev/null
+++ b/docs/drivers/battery.md
@@ -0,0 +1,51 @@
1# Battery Driver
2
3This driver provides support for sampling battery level.
4
5## Usage
6
7To use this driver, add the following to your `rules.mk`:
8
9```make
10BATTERY_DRIVER_REQUIRED = yes
11```
12
13## Basic Configuration {#basic-configuration}
14
15Add the following to your `config.h`:
16
17|Define |Default |Description |
18|--------------------------|--------|--------------------------------------------------|
19|`BATTERY_SAMPLE_INTERVAL` |`30000` |The time between battery samples in milliseconds. |
20
21## Driver Configuration {#driver-configuration}
22
23Driver selection can be configured in `rules.mk` as `BATTERY_DRIVER`. Valid values are `adc` (default), `vendor`, or `custom`. See below for information on individual drivers.
24
25### ADC Driver {#adc-driver}
26
27This is the default battery driver. The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider.
28
29```make
30BATTERY_DRIVER = adc
31```
32
33The following `#define`s apply only to the `adc` driver:
34
35|Define |Default |Description |
36|-----------------------------|--------------|--------------------------------------------------------------|
37|`BATTERY_PIN` |*Not defined* |The GPIO pin connected to the voltage divider. |
38|`BATTERY_REF_VOLTAGE_MV` |`3300` |The ADC reverence voltage, in millivolts. |
39|`BATTERY_VOLTAGE_DIVIDER_R1` |`100000` |The voltage divider resistance, in kOhm. Set to 0 to disable. |
40|`BATTERY_VOLTAGE_DIVIDER_R1` |`100000` |The voltage divider resistance, in kOhm. Set to 0 to disable. |
41|`BATTERY_ADC_RESOLUTION` |`10` |The ADC resolution configured for the ADC Driver. |
42
43## Functions
44
45### `uint8_t battery_get_percent(void)` {#api-battery-get-percent}
46
47Sample battery level.
48
49#### Return Value {#api-battery-get-percent-return}
50
51The battery percentage, in the range 0-100.