logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

battery.md (2560B)


  1. # Battery Driver
  2. This driver provides support for sampling battery level.
  3. ## Usage
  4. To use this driver, add the following to your `rules.mk`:
  5. ```make
  6. BATTERY_DRIVER_REQUIRED = yes
  7. ```
  8. ## Basic Configuration {#basic-configuration}
  9. Add the following to your `config.h`:
  10. |Define |Default |Description |
  11. |--------------------------|--------|--------------------------------------------------|
  12. |`BATTERY_SAMPLE_INTERVAL` |`30000` |The time between battery samples in milliseconds. |
  13. ## Driver Configuration {#driver-configuration}
  14. 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.
  15. ### ADC Driver {#adc-driver}
  16. This is the default battery driver. The default configuration assumes the battery is connected to a ADC capable pin through a voltage divider.
  17. ```make
  18. BATTERY_DRIVER = adc
  19. ```
  20. The following `#define`s apply only to the `adc` driver:
  21. |Define |Default |Description |
  22. |-----------------------------|--------------|--------------------------------------------------------------|
  23. |`BATTERY_PIN` |*Not defined* |The GPIO pin connected to the voltage divider. |
  24. |`BATTERY_REF_VOLTAGE_MV` |`3300` |The ADC reverence voltage, in millivolts. |
  25. |`BATTERY_VOLTAGE_DIVIDER_R1` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. |
  26. |`BATTERY_VOLTAGE_DIVIDER_R2` |`100` |The voltage divider resistance, in kOhm. Set to 0 to disable. |
  27. |`BATTERY_ADC_RESOLUTION` |`10` |The ADC resolution configured for the ADC Driver. |
  28. ## Functions
  29. ### `uint8_t battery_get_percent(void)` {#api-battery-get-percent}
  30. Sample battery level.
  31. #### Return Value {#api-battery-get-percent-return}
  32. The battery percentage, in the range 0-100.
  33. ## Callbacks
  34. ### `void battery_percent_changed_user(uint8_t level)` {#api-battery-percent-changed-user}
  35. User hook called when battery level changed.
  36. ### Arguments {#api-battery-percent-changed-user-arguments}
  37. - `uint8_t level`
  38. The battery percentage, in the range 0-100.
  39. ---
  40. ### `void battery_percent_changed_kb(uint8_t level)` {#api-battery-percent-changed-kb}
  41. Keyboard hook called when battery level changed.
  42. ### Arguments {#api-battery-percent-changed-kb-arguments}
  43. - `uint8_t level`
  44. The battery percentage, in the range 0-100.