I've been trying to integrate the Battery Voltage example (v2.0.0\zephyr\samples\boards\nrf\battery) into my existing code. I can get the example to work stand alone on my hardware, but when I try and incorporate battery.c and battery.h into my own code, I get a bunch of build errors.
C:\Nordic\v2.0.0\zephyr\include\zephyr\device.h:96:39: error: '__device_dts_ord_DT_N_S_vbatt_P_io_channels_IDX_0_PH_ORD' undeclared here (not in a function)
96 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
| ^~~~~~~~~
C:\Nordic\v2.0.0\zephyr\include\zephyr\device.h:291:37: note: in expansion of macro 'DEVICE_NAME_GET'
291 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_NAME(node_id))
| ^~~~~~~~~~~~~~~
C:\Nordic\v2.0.0\zephyr\include\zephyr\device.h:311:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
311 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
c:\Nordic\Development\LSR-MAX\LSR-MAX_V0_09\src\battery.c:69:9: note: in expansion of macro 'DEVICE_DT_GET'
69 | .adc = DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(VBATT)),
| ^~~~~~~~~~~~~
The errors seem to be associated with these sections of the example code (note that I have modified these slightly from the example, as I have defined the vbatt node in my overlay file)
static const struct divider_config divider_config = {
.io_channel = {
DT_IO_CHANNELS_INPUT(VBATT),
},
.power_gpios = {
DT_GPIO_LABEL(VBATT, power_gpios),
DT_GPIO_PIN(VBATT, power_gpios),
DT_GPIO_FLAGS(VBATT, power_gpios),
},
.output_ohm = DT_PROP(VBATT, output_ohms),
.full_ohm = DT_PROP(VBATT, full_ohms),
};
static struct divider_data divider_data = {
.adc = DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(VBATT)),
};
For some reason, the following aren't being recognised: