aboutsummaryrefslogtreecommitdiffstats
path: root/docs/drivers
diff options
context:
space:
mode:
authorJoel Challis2025-08-17 02:14:48 +0200
committerGitHub2025-08-17 02:14:48 +0200
commitcc696a2ae838a9639335ca8eb3cb3b794c06bc33 (patch)
tree901b54bda536acb5503c6cf924b0f30bca1a174e /docs/drivers
parentf29d8117bf877a4df1f88f40e0131f4465748540 (diff)
Refactor battery driver (#25550)
Diffstat (limited to 'docs/drivers')
-rw-r--r--docs/drivers/battery.md69
1 files changed, 24 insertions, 45 deletions
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 @@
# Battery Driver
-This driver provides support for sampling battery level.
+This driver provides support for directly sampling battery level.
## Usage
@@ -10,21 +10,17 @@ To use this driver, add the following to your `rules.mk`:
BATTERY_DRIVER_REQUIRED = yes
```
-## Basic Configuration {#basic-configuration}
-
-Add the following to your `config.h`:
-
-|Define |Default |Description |
-|--------------------------|--------|--------------------------------------------------|
-|`BATTERY_SAMPLE_INTERVAL` |`30000` |The time between battery samples in milliseconds. |
+::::info Note
+This is already configured for you if you are using the [Battery](../features/battery) feature.
+::::
## Driver Configuration {#driver-configuration}
-Driver 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.
+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}
-This is the default battery driver. The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider.
+The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider.
```make
BATTERY_DRIVER = adc
@@ -32,42 +28,25 @@ BATTERY_DRIVER = adc
The following `#define`s apply only to the `adc` driver:
-|Define |Default |Description |
-|-----------------------------|--------------|--------------------------------------------------------------|
-|`BATTERY_PIN` |*Not defined* |The GPIO pin connected to the voltage divider. |
-|`BATTERY_REF_VOLTAGE_MV` |`3300` |The ADC reverence voltage, in millivolts. |
-|`BATTERY_VOLTAGE_DIVIDER_R1` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. |
-|`BATTERY_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. |
-
-## Functions
-
-### `uint8_t battery_get_percent(void)` {#api-battery-get-percent}
-
-Sample battery level.
-
-#### Return Value {#api-battery-get-percent-return}
-
-The battery percentage, in the range 0-100.
+|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. |
-## Callbacks
+### Custom Driver {#custom-driver}
-### `void battery_percent_changed_user(uint8_t level)` {#api-battery-percent-changed-user}
+A custom driver is expected to implement the following interface:
-User hook called when battery level changed.
+```c
+void battery_driver_init(void) {
+ // Perform any initialisation here
+}
-### Arguments {#api-battery-percent-changed-user-arguments}
-
- - `uint8_t level`
- The battery percentage, in the range 0-100.
-
----
-
-### `void battery_percent_changed_kb(uint8_t level)` {#api-battery-percent-changed-kb}
-
-Keyboard hook called when battery level changed.
-
-### Arguments {#api-battery-percent-changed-kb-arguments}
-
- - `uint8_t level`
- The battery percentage, in the range 0-100.
+uint8_t battery_driver_sample_percent(void) {
+ // Read and return current state here
+ return value;
+}
+```