Browse Source

feat(battery)!: Add chosen node for battery

battery.c now uses the zmk,battery chosen node to select a battery
sensor. Using the node labeled "BATTERY" is maintained for backwards
compatibility but is now deprecated. Custom boards should switch to
using the chosen node.

# Conflicts:
#	app/boards/arm/bluemicro840/bluemicro840_v1.dts
#	app/boards/arm/nice60/nice60.dts
#	app/boards/arm/nrfmicro/nrfmicro_13.dts

# Conflicts:
#	app/boards/arm/bluemicro840/bluemicro840_v1.dts
xmkb
Joel Spadin 3 years ago committed by Pete Johanson
parent
commit
388e345c28
  1. 3
      app/boards/arm/bluemicro840/bluemicro840_v1.dts
  2. 3
      app/boards/arm/bt60/bt60.dtsi
  3. 3
      app/boards/arm/mikoto/mikoto_520.dts
  4. 3
      app/boards/arm/nice60/nice60.dts
  5. 6
      app/boards/arm/nice_nano/nice_nano.dts
  6. 6
      app/boards/arm/nice_nano/nice_nano_v2.dts
  7. 3
      app/boards/arm/nrfmicro/nrfmicro_13.dts
  8. 3
      app/boards/arm/s40nc/s40nc.dts
  9. 3
      app/boards/seeeduino_xiao_ble.overlay
  10. 19
      app/src/battery.c

3
app/boards/arm/bluemicro840/bluemicro840_v1.dts

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt;
};
leds {
@ -34,7 +35,7 @@ @@ -34,7 +35,7 @@
control-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 7>;

3
app/boards/arm/bt60/bt60.dtsi

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt;
zmk,kscan = &kscan0;
zmk,matrix_transform = &default_transform;
};
@ -46,7 +47,7 @@ @@ -46,7 +47,7 @@
};
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 2>;

3
app/boards/arm/mikoto/mikoto_520.dts

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt;
};
leds {
@ -34,7 +35,7 @@ @@ -34,7 +35,7 @@
init-delay-ms = <50>;
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 2>;

3
app/boards/arm/nice60/nice60.dts

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt;
zmk,kscan = &kscan0;
zmk,matrix_transform = &default_transform;
zmk,underglow = &led_strip;
@ -81,7 +82,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,5) R @@ -81,7 +82,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,5) R
control-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 2>;

6
app/boards/arm/nice_nano/nice_nano.dts

@ -8,13 +8,17 @@ @@ -8,13 +8,17 @@
#include "nice_nano.dtsi"
/ {
chosen {
zmk,battery = &vbatt;
};
ext-power {
compatible = "zmk,ext-power-generic";
label = "EXT_POWER";
control-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 2>;

6
app/boards/arm/nice_nano/nice_nano_v2.dts

@ -8,6 +8,10 @@ @@ -8,6 +8,10 @@
#include "nice_nano.dtsi"
/ {
chosen {
zmk,battery = &vbatt;
};
ext-power {
compatible = "zmk,ext-power-generic";
label = "EXT_POWER";
@ -15,7 +19,7 @@ @@ -15,7 +19,7 @@
init-delay-ms = <50>;
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-nrf-vddh";
label = "BATTERY";
};

3
app/boards/arm/nrfmicro/nrfmicro_13.dts

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt;
};
leds {
@ -33,7 +34,7 @@ @@ -33,7 +34,7 @@
control-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 2>;

3
app/boards/arm/s40nc/s40nc.dts

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt;
zmk,kscan = &kscan0;
zmk,matrix_transform = &default_transform;
};
@ -69,7 +70,7 @@ @@ -69,7 +70,7 @@
};
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 2>;

3
app/boards/seeeduino_xiao_ble.overlay

@ -8,9 +8,10 @@ @@ -8,9 +8,10 @@
/ {
chosen {
zephyr,console = &cdc_acm_uart;
zmk,battery = &vbatt;
};
vbatt {
vbatt: vbatt {
compatible = "zmk,battery-voltage-divider";
label = "BATTERY";
io-channels = <&adc 7>;

19
app/src/battery.c

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
*/
#include <device.h>
#include <devicetree.h>
#include <init.h>
#include <kernel.h>
#include <drivers/sensor.h>
@ -18,12 +19,16 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -18,12 +19,16 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/battery.h>
#include <zmk/events/battery_state_changed.h>
const struct device *battery;
static uint8_t last_state_of_charge = 0;
uint8_t zmk_battery_state_of_charge() { return last_state_of_charge; }
#if DT_HAS_CHOSEN(zmk_battery)
static const struct device *const battery = DEVICE_DT_GET(DT_CHOSEN(zmk_battery));
#else
static const struct device *battery;
#endif
static int zmk_battery_update(const struct device *battery) {
struct sensor_value state_of_charge;
@ -75,10 +80,18 @@ static void zmk_battery_timer(struct k_timer *timer) { k_work_submit(&battery_wo @@ -75,10 +80,18 @@ static void zmk_battery_timer(struct k_timer *timer) { k_work_submit(&battery_wo
K_TIMER_DEFINE(battery_timer, zmk_battery_timer, NULL);
static int zmk_battery_init(const struct device *_arg) {
#if !DT_HAS_CHOSEN(zmk_battery)
battery = device_get_binding("BATTERY");
if (battery == NULL) {
LOG_DBG("No battery device labelled BATTERY found.");
return -ENODEV;
}
LOG_WRN("Finding battery device labeled BATTERY is deprecated. Use zmk,battery chosen node.");
#endif
if (!device_is_ready(battery)) {
LOG_ERR("Battery device \"%s\" is not ready", battery->name);
return -ENODEV;
}

Loading…
Cancel
Save