Support configurable ADC oversampling via device tree in battery_voltage_divider.c

- Add 'oversampling' property to bvd_config and use it in adc_sequence.
- Read oversampling value from device tree, defaulting to 4 if not set.
This commit is contained in:
yoshikik1991 2025-06-13 14:18:49 +00:00
parent 1076efc1b1
commit 53ea8a192e
2 changed files with 9 additions and 1 deletions

View File

@ -26,6 +26,7 @@ struct bvd_config {
struct gpio_dt_spec power;
uint32_t output_ohm;
uint32_t full_ohm;
uint8_t oversampling;
};
struct bvd_data {
@ -136,7 +137,7 @@ static int bvd_init(const struct device *dev) {
.channels = ch_mask,
.buffer = &drv_data->value.adc_raw,
.buffer_size = sizeof(drv_data->value.adc_raw),
.oversampling = 4,
.oversampling = drv_cfg->oversampling,
.calibrate = true,
};
@ -172,6 +173,7 @@ static const struct bvd_config bvd_cfg = {
#endif
.output_ohm = DT_INST_PROP(0, output_ohms),
.full_ohm = DT_INST_PROP(0, full_ohms),
.oversampling = DT_INST_PROP_OR(0, oversampling, 4),
};
DEVICE_DT_INST_DEFINE(0, &bvd_init, NULL, &bvd_data, &bvd_cfg, POST_KERNEL,

View File

@ -6,3 +6,9 @@ description: Battery SoC monitoring using voltage divider
compatible: "zmk,battery-voltage-divider"
include: voltage-divider.yaml
properties:
oversampling:
type: int
required: false
description: Oversampling value for ADC