8000 fix(battery) : Fix for the conflict between the battery_voltage_divider and AIN0, and modification to allow changing the oversampling value by yoshikik1991 · Pull Request #2964 · zmkfirmware/zmk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(battery) : Fix for the conflict between the battery_voltage_divider and AIN0, and modification to allow changing the oversampling value #2964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/module/drivers/sensor/battery/battery_voltage_divider.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -110,6 +111,7 @@ static const struct sensor_driver_api bvd_api = {
static int bvd_init(const struct device *dev) {
struct bvd_data *drv_data = dev->data;
const struct bvd_config *drv_cfg = dev->config;
uint32_t ch_mask = 0;

if (drv_data->adc == NULL) {
LOG_ERR("ADC failed to retrieve ADC driver");
Expand All @@ -130,11 +132,12 @@ static int bvd_init(const struct device *dev) {
}
#endif // DT_INST_NODE_HAS_PROP(0, power_gpios)

ch_mask |= BIT(drv_cfg->io_channel.channel);
drv_data->as = (struct adc_sequence){
.channels = BIT(0),
.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,
};

Expand All @@ -143,6 +146,7 @@ static int bvd_init(const struct device *dev) {
.gain = ADC_GAIN_1_6,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40),
.channel_id = drv_cfg->io_channel.channel,
.input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + drv_cfg->io_channel.channel,
};

Expand All @@ -169,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
0