qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

battery.md (1853B)


      1 # Battery Driver
      2 
      3 This driver provides support for directly sampling battery level.
      4 
      5 ## Usage
      6 
      7 To use this driver, add the following to your `rules.mk`:
      8 
      9 ```make
     10 BATTERY_DRIVER_REQUIRED = yes
     11 ```
     12 
     13 ::::info Note
     14 This is already configured for you if you are using the [Battery](../features/battery) feature.
     15 ::::
     16 
     17 ## Driver Configuration {#driver-configuration}
     18 
     19 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.
     20 
     21 ### ADC Driver {#adc-driver}
     22 
     23 The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider.
     24 
     25 ```make
     26 BATTERY_DRIVER = adc
     27 ```
     28 
     29 The following `#define`s apply only to the `adc` driver:
     30 
     31 |Define                           |Default       |Description                                                   |
     32 |---------------------------------|--------------|--------------------------------------------------------------|
     33 |`BATTERY_ADC_PIN`                |*Not defined* |The GPIO pin connected to the voltage divider.                |
     34 |`BATTERY_ADC_REF_VOLTAGE_MV`     |`3300`        |The ADC reverence voltage, in millivolts.                     |
     35 |`BATTERY_ADC_VOLTAGE_DIVIDER_R1` |`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. |
     37 |`BATTERY_ADC_RESOLUTION`         |`10`          |The ADC resolution configured for the ADC Driver.             |
     38 
     39 ### Custom Driver {#custom-driver}
     40 
     41 A custom driver is expected to implement the following interface:
     42 
     43 ```c
     44 void battery_driver_init(void) {
     45     // Perform any initialisation here
     46 }
     47 
     48 uint8_t battery_driver_sample_percent(void) {
     49     // Read and return current state here
     50     return value;
     51 }
     52 ```