Lines Matching +full:divider +full:- +full:val
2 * Copyright (c) 2018-2019 Peter Bigot Consulting, LLC
3 * Copyright (c) 2019-2020 Nordic Semiconductor ASA
5 * SPDX-License-Identifier: Apache-2.0
27 /* This board uses a divider that reduces max voltage to
46 * the battery is measured through a voltage divider;
85 const struct io_channel_config *iocp = &cfg->io_channel; in divider_setup()
86 const struct gpio_dt_spec *gcp = &cfg->power_gpios; in divider_setup()
88 struct adc_sequence *asp = &ddp->adc_seq; in divider_setup()
89 struct adc_channel_cfg *accp = &ddp->adc_cfg; in divider_setup()
92 if (!device_is_ready(ddp->adc)) { in divider_setup()
93 LOG_ERR("ADC device is not ready %s", ddp->adc->name); in divider_setup()
94 return -ENOENT; in divider_setup()
97 if (gcp->port) { in divider_setup()
98 if (!device_is_ready(gcp->port)) { in divider_setup()
99 LOG_ERR("%s: device not ready", gcp->port->name); in divider_setup()
100 return -ENOENT; in divider_setup()
105 gcp->port->name, gcp->pin, rc); in divider_setup()
112 .buffer = &ddp->raw, in divider_setup()
113 .buffer_size = sizeof(ddp->raw), in divider_setup()
125 if (cfg->output_ohm != 0) { in divider_setup()
126 accp->input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 in divider_setup()
127 + iocp->channel; in divider_setup()
129 accp->input_positive = SAADC_CH_PSELP_PSELP_VDD; in divider_setup()
132 asp->resolution = 14; in divider_setup()
137 rc = adc_channel_setup(ddp->adc, accp); in divider_setup()
138 LOG_INF("Setup AIN%u got %d", iocp->channel, rc); in divider_setup()
158 int rc = -ENOENT; in battery_measure_enable()
164 if (gcp->port) { in battery_measure_enable()
173 int rc = -ENOENT; in battery_sample()
178 struct adc_sequence *sp = &ddp->adc_seq; in battery_sample()
180 rc = adc_read(ddp->adc, sp); in battery_sample()
181 sp->calibrate = false; in battery_sample()
183 int32_t val = ddp->raw; in battery_sample() local
185 adc_raw_to_millivolts(adc_ref_internal(ddp->adc), in battery_sample()
186 ddp->adc_cfg.gain, in battery_sample()
187 sp->resolution, in battery_sample()
188 &val); in battery_sample()
190 if (dcp->output_ohm != 0) { in battery_sample()
191 rc = val * (uint64_t)dcp->full_ohm in battery_sample()
192 / dcp->output_ohm; in battery_sample()
194 ddp->raw, val, rc); in battery_sample()
196 rc = val; in battery_sample()
197 LOG_INF("raw %u ~ %u mV\n", ddp->raw, val); in battery_sample()
210 if (batt_mV >= pb->lvl_mV) { in battery_level_pptt()
212 return pb->lvl_pptt; in battery_level_pptt()
215 while ((pb->lvl_pptt > 0) in battery_level_pptt()
216 && (batt_mV < pb->lvl_mV)) { in battery_level_pptt()
219 if (batt_mV < pb->lvl_mV) { in battery_level_pptt()
221 return pb->lvl_pptt; in battery_level_pptt()
225 const struct battery_level_point *pa = pb - 1; in battery_level_pptt()
227 return pb->lvl_pptt in battery_level_pptt()
228 + ((pa->lvl_pptt - pb->lvl_pptt) in battery_level_pptt()
229 * (batt_mV - pb->lvl_mV) in battery_level_pptt()
230 / (pa->lvl_mV - pb->lvl_mV)); in battery_level_pptt()