sensors: reconfig adc for channel

Some ADCs (e.g. SAM0) can only convert one channel at a time
    and therefore need to be reconfigured for every voltage
    divider prior to startin the conversion

Signed-off-by: Patrick Günzel <patrick.guenzel@kinexon.com>
This commit is contained in:
Patrick Günzel 2024-09-05 09:58:59 +02:00 committed by Henrik Brix Andersen
parent c46247b550
commit 2a999e14e8

View file

@ -40,6 +40,14 @@ static int fetch(const struct device *dev, enum sensor_channel chan)
/* Wait until sampling is valid */
k_sleep(data->earliest_sample);
/* configure the active channel to be converted */
ret = adc_channel_setup_dt(&config->voltage.port);
if (ret != 0) {
LOG_ERR("adc_setup failed: %d", ret);
return ret;
}
/* start conversion */
ret = adc_read(config->voltage.port.dev, &data->sequence);
if (ret != 0) {
LOG_ERR("adc_read: %d", ret);