Skip to content

Commit d6c610d

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 d6c610d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/adc/iadc_gecko.c

Lines changed: 10 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,8 @@ 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+
7679
IADC_init(iadc, &init, &initAllConfigs);
7780

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

128-
if (sequence->oversampling) {
129-
LOG_ERR("Oversampling is not supported");
131+
if (sequence->oversampling > iadcDigitalAverage16) {
132+
LOG_ERR("Oversampling must be smaller");
130133
return -EINVAL;
131134
}
132135

@@ -140,7 +143,10 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
140143
channels = sequence->channels;
141144
channel_count = 0;
142145
while (channels) {
143-
/* Iterate through all channels and check if they are initialized */
146+
/*
147+
* Iterate through all channels, check if they are initialized, and update the
148+
* digital averaging ratio
149+
*/
144150
index = find_lsb_set(channels) - 1;
145151
if (index >= GECKO_CHANNEL_COUNT) {
146152
LOG_DBG("Requested channel index not available: %d", index);
@@ -153,6 +159,7 @@ static int start_read(const struct device *dev, const struct adc_sequence *seque
153159
}
154160
channel_count++;
155161
channels &= ~BIT(index);
162+
data->channel_config[index].digital_averaging = sequence->oversampling;
156163
}
157164

158165
/* Check buffer size */

0 commit comments

Comments
 (0)