summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2025-08-17 01:14:48 +0100
committerGitHub <noreply@github.com>2025-08-17 01:14:48 +0100
commitcc696a2ae838a9639335ca8eb3cb3b794c06bc33 (patch)
tree901b54bda536acb5503c6cf924b0f30bca1a174e /docs
parentf29d8117bf877a4df1f88f40e0131f4465748540 (diff)
Refactor battery driver (#25550)
Diffstat (limited to 'docs')
-rw-r--r--docs/_sidebar.json1
-rw-r--r--docs/drivers/battery.md69
-rw-r--r--docs/features/battery.md55
-rw-r--r--docs/reference_info_json.md26
4 files changed, 106 insertions, 45 deletions
diff --git a/docs/_sidebar.json b/docs/_sidebar.json
index ee4709a650..eec345b788 100644
--- a/docs/_sidebar.json
+++ b/docs/_sidebar.json
@@ -175,6 +175,7 @@
175 ] 175 ]
176 }, 176 },
177 { "text": "Audio", "link": "/features/audio" }, 177 { "text": "Audio", "link": "/features/audio" },
178 { "text": "Battery", "link": "/features/battery" },
178 { "text": "Bootmagic", "link": "/features/bootmagic" }, 179 { "text": "Bootmagic", "link": "/features/bootmagic" },
179 { "text": "Converters", "link": "/feature_converters" }, 180 { "text": "Converters", "link": "/feature_converters" },
180 { "text": "Custom Matrix", "link": "/custom_matrix" }, 181 { "text": "Custom Matrix", "link": "/custom_matrix" },
diff --git a/docs/drivers/battery.md b/docs/drivers/battery.md
index e482ffc8b6..ae07668cc0 100644
--- a/docs/drivers/battery.md
+++ b/docs/drivers/battery.md
@@ -1,6 +1,6 @@
1# Battery Driver 1# Battery Driver
2 2
3This driver provides support for sampling battery level. 3This driver provides support for directly sampling battery level.
4 4
5## Usage 5## Usage
6 6
@@ -10,21 +10,17 @@ To use this driver, add the following to your `rules.mk`:
10BATTERY_DRIVER_REQUIRED = yes 10BATTERY_DRIVER_REQUIRED = yes
11``` 11```
12 12
13## Basic Configuration {#basic-configuration} 13::::info Note
14 14This is already configured for you if you are using the [Battery](../features/battery) feature.
15Add the following to your `config.h`: 15::::
16
17|Define |Default |Description |
18|--------------------------|--------|--------------------------------------------------|
19|`BATTERY_SAMPLE_INTERVAL` |`30000` |The time between battery samples in milliseconds. |
20 16
21## Driver Configuration {#driver-configuration} 17## Driver Configuration {#driver-configuration}
22 18
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. 19Driver selection can be configured in `rules.mk` as `BATTERY_DRIVER`. Valid values are `adc`, `vendor`, or `custom`. See below for information on individual drivers.
24 20
25### ADC Driver {#adc-driver} 21### ADC Driver {#adc-driver}
26 22
27This is the default battery driver. The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider. 23The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider.
28 24
29```make 25```make
30BATTERY_DRIVER = adc 26BATTERY_DRIVER = adc
@@ -32,42 +28,25 @@ BATTERY_DRIVER = adc
32 28
33The following `#define`s apply only to the `adc` driver: 29The following `#define`s apply only to the `adc` driver:
34 30
35|Define |Default |Description | 31|Define |Default |Description |
36|-----------------------------|--------------|--------------------------------------------------------------| 32|---------------------------------|--------------|--------------------------------------------------------------|
37|`BATTERY_PIN` |*Not defined* |The GPIO pin connected to the voltage divider. | 33|`BATTERY_ADC_PIN` |*Not defined* |The GPIO pin connected to the voltage divider. |
38|`BATTERY_REF_VOLTAGE_MV` |`3300` |The ADC reverence voltage, in millivolts. | 34|`BATTERY_ADC_REF_VOLTAGE_MV` |`3300` |The ADC reverence voltage, in millivolts. |
39|`BATTERY_VOLTAGE_DIVIDER_R1` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. | 35|`BATTERY_ADC_VOLTAGE_DIVIDER_R1` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. |
40|`BATTERY_VOLTAGE_DIVIDER_R2` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. | 36|`BATTERY_ADC_VOLTAGE_DIVIDER_R2` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. |
41|`BATTERY_ADC_RESOLUTION` |`10` |The ADC resolution configured for the ADC Driver. | 37|`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.
52 38
53## Callbacks 39### Custom Driver {#custom-driver}
54 40
55### `void battery_percent_changed_user(uint8_t level)` {#api-battery-percent-changed-user} 41A custom driver is expected to implement the following interface:
56 42
57User hook called when battery level changed. 43```c
44void battery_driver_init(void) {
45 // Perform any initialisation here
46}
58 47
59### Arguments {#api-battery-percent-changed-user-arguments} 48uint8_t battery_driver_sample_percent(void) {
60 49 // Read and return current state here
61 - `uint8_t level` 50 return value;
62 The battery percentage, in the range 0-100. 51}
63 52```
64---
65
66### `void battery_percent_changed_kb(uint8_t level)` {#api-battery-percent-changed-kb}
67
68Keyboard hook called when battery level changed.
69
70### Arguments {#api-battery-percent-changed-kb-arguments}
71
72 - `uint8_t level`
73 The battery percentage, in the range 0-100.
diff --git a/docs/features/battery.md b/docs/features/battery.md
new file mode 100644
index 0000000000..f5c725efb9
--- /dev/null
+++ b/docs/features/battery.md
@@ -0,0 +1,55 @@
1# Battery
2
3This feature provides the high level abstraction for sampling battery level.
4
5## Usage
6
7To use this driver, add the following to your `rules.mk`:
8
9```make
10BATTERY_ENABLE = 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
23See the [Battery Driver](../drivers/battery) documentation for more information.
24
25## Functions
26
27### `uint8_t battery_get_percent(void)` {#api-battery-get-percent}
28
29Sample battery level.
30
31#### Return Value {#api-battery-get-percent-return}
32
33The battery percentage, in the range 0-100.
34
35## Callbacks
36
37### `void battery_percent_changed_user(uint8_t level)` {#api-battery-percent-changed-user}
38
39User hook called when battery level changed.
40
41### Arguments {#api-battery-percent-changed-user-arguments}
42
43 - `uint8_t level`
44 The battery percentage, in the range 0-100.
45
46---
47
48### `void battery_percent_changed_kb(uint8_t level)` {#api-battery-percent-changed-kb}
49
50Keyboard hook called when battery level changed.
51
52### Arguments {#api-battery-percent-changed-kb-arguments}
53
54 - `uint8_t level`
55 The battery percentage, in the range 0-100.
diff --git a/docs/reference_info_json.md b/docs/reference_info_json.md
index cf22317613..84377ef36c 100644
--- a/docs/reference_info_json.md
+++ b/docs/reference_info_json.md
@@ -179,6 +179,32 @@ Configures the [Backlight](features/backlight) feature.
179 * `pins` <Badge type="info">Array: Pin</Badge> 179 * `pins` <Badge type="info">Array: Pin</Badge>
180 * A list of GPIO pins connected to the backlight LEDs (`software` and `timer` drivers only). 180 * A list of GPIO pins connected to the backlight LEDs (`software` and `timer` drivers only).
181 181
182## Battery
183
184Configures the [Battery](features/battery) feature.
185
186* `battery`
187 * `adc`
188 * `pin` <Badge type="info">Pin</Badge> <Badge>Required</Badge>
189 * The GPIO pin connected to the voltage divider.
190 * `reference_voltage` <Badge type="info">Number</Badge>
191 * The ADC reverence voltage, in millivolts.
192 * Default: `3300`
193 * `divider_r1` <Badge type="info">Number</Badge>
194 * The voltage divider resistance, in kOhm. Set to 0 to disable.
195 * Default: `100`
196 * `divider_r2` <Badge type="info">Number</Badge>
197 * The voltage divider resistance, in kOhm. Set to 0 to disable.
198 * Default: `100`
199 * `resolution` <Badge type="info">Number</Badge>
200 * The ADC resolution configured for the ADC Driver.
201 * Default: `10`
202 * `driver` <Badge type="info">String</Badge> <Badge>Required</Badge>
203 * The driver to use. Must be one of `adc`, `custom`, `vendor`.
204 * `sample_interval` <Badge type="info">Number</Badge>
205 * The delay between sampling the battery in milliseconds.
206 * Default: `30000` (30 s)
207
182## Wireless/Bluetooth {#bluetooth} 208## Wireless/Bluetooth {#bluetooth}
183 209
184Configures the [Wireless](features/wireless) feature. 210Configures the [Wireless](features/wireless) feature.