Skip to content

Commit e8b9a27

Browse files
committed
drivers: adc: fix oversampling ranges
user api to configure adc sequence ranges from o to 8 and this needs to be translated into 2^N i.e 0 to 256. MSPM0 internal adc supports upto 128 sampling, to re-range it and get the input range from 0-8. Signed-off-by: Parthiban Nallathambi <[email protected]>
1 parent 43c46ed commit e8b9a27

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

drivers/adc/adc_mspm0_adc12.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,23 +529,17 @@ static int adc_mspm0_read_internal(const struct device *dev, const struct adc_se
529529

530530
data->buffer = sequence->buffer;
531531

532-
/* Validate oversampling */
533-
if ((sequence->oversampling != 0) && (sequence->oversampling != 2) &&
534-
(sequence->oversampling != 4) && (sequence->oversampling != 8) &&
535-
(sequence->oversampling != 16) && (sequence->oversampling != 32) &&
536-
(sequence->oversampling != 64) && (sequence->oversampling != 128)) {
537-
LOG_ERR("ADC oversampling %d not supported. Only 2/4/8/16/32/64/128.",
538-
sequence->oversampling);
532+
if(data->resolution == 14 && sequence->oversampling != 7){
533+
LOG_ERR("Oversampling has to be set to 7. 14-bit effective resolution can only be used with hardware averaging.");
539534
return -EINVAL;
540535
}
541536

542-
if(data->resolution == 14 && sequence->oversampling != 128){
543-
LOG_ERR("Oversampling has to be set to 128. 14-bit effective resolution can only be used with hardware averaging.");
537+
if (sequence->oversampling > 7) {
538+
LOG_ERR("Oversampling out of range");
544539
return -EINVAL;
545540
}
546541

547-
data->oversampling = sequence->oversampling;
548-
542+
data->oversampling = sequence->oversampling ? BIT(sequence->oversampling) : 0;
549543
if (sequence->calibrate) {
550544
LOG_ERR("Calibration not supported");
551545
return -ENOTSUP;

0 commit comments

Comments
 (0)