Skip to content

Commit 21fd75c

Browse files
committed
drivers: adc: iadc_gecko: enables oversampling for the IADC
Enables the zephyr interpretation of oversampling for the IADC sequence, averaging the samples for up to 16 measurements. Signed-off-by: Paulo Santos <[email protected]>
1 parent 6e018bb commit 21fd75c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/adc/iadc_gecko.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct adc_gecko_channel_config {
3030
IADC_CfgReference_t reference;
3131
IADC_PosInput_t input_positive;
3232
IADC_NegInput_t input_negative;
33+
IADC_DigitalAveraging_t digital_averaging;
3334
bool initialized;
3435
};
3536

@@ -73,6 +74,9 @@ static void adc_gecko_set_config(const struct device *dev)
7374

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

77+
initAllConfigs.configs[0].digAvg = channel_config->digital_averaging;
78+
init.warmup = iadcWarmupKeepWarm;
79+
7680
IADC_init(iadc, &init, &initAllConfigs);
7781

7882
IADC_initSingle(iadc, &sInit, &initSingleInput);
@@ -125,8 +129,8 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
125129
return -EINVAL;
126130
}
127131

128-
if (sequence->oversampling) {
129-
LOG_ERR("Oversampling is not supported");
132+
if (sequence->oversampling > iadcDigitalAverage16) {
133+
LOG_ERR("Oversampling must be smaller");
130134
return -EINVAL;
131135
}
132136

@@ -140,7 +144,8 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
140144
channels = sequence->channels;
141145
channel_count = 0;
142146
while (channels) {
143-
/* Iterate through all channels and check if they are initialized */
147+
/* Iterate through all channels, check if they are initialized, and update the
148+
* digital averaging ratio */
144149
index = find_lsb_set(channels) - 1;
145150
if (index >= GECKO_CHANNEL_COUNT) {
146151
LOG_DBG("Requested channel index not available: %d", index);
@@ -153,6 +158,7 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
153158
}
154159
channel_count++;
155160
channels &= ~BIT(index);
161+
data->channel_config[index].digital_averaging = sequence->oversampling;
156162
}
157163

158164
/* Check buffer size */

0 commit comments

Comments
 (0)