Skip to content
Open
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
13 changes: 10 additions & 3 deletions drivers/adc/iadc_gecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct adc_gecko_channel_config {
IADC_CfgReference_t reference;
IADC_PosInput_t input_positive;
IADC_NegInput_t input_negative;
IADC_DigitalAveraging_t digital_averaging;
bool initialized;
};

Expand Down Expand Up @@ -73,6 +74,8 @@ static void adc_gecko_set_config(const struct device *dev)

initAllConfigs.configs[0].reference = channel_config->reference;

initAllConfigs.configs[0].digAvg = channel_config->digital_averaging;

IADC_init(iadc, &init, &initAllConfigs);

IADC_initSingle(iadc, &sInit, &initSingleInput);
Expand Down Expand Up @@ -125,8 +128,8 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
return -EINVAL;
}

if (sequence->oversampling) {
LOG_ERR("Oversampling is not supported");
if (sequence->oversampling > iadcDigitalAverage16) {
LOG_ERR("Oversampling must be smaller");
return -EINVAL;
}

Expand All @@ -140,7 +143,10 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
channels = sequence->channels;
channel_count = 0;
while (channels) {
/* Iterate through all channels and check if they are initialized */
/*
* Iterate through all channels, check if they are initialized, and update the
* digital averaging ratio
*/
index = find_lsb_set(channels) - 1;
if (index >= GECKO_CHANNEL_COUNT) {
LOG_DBG("Requested channel index not available: %d", index);
Expand All @@ -153,6 +159,7 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
}
channel_count++;
channels &= ~BIT(index);
data->channel_config[index].digital_averaging = sequence->oversampling;
}

/* Check buffer size */
Expand Down