Skip to content

Commit dc21efe

Browse files
committed
espressif: Validate sample rate
The reported code used an invalid sample rate. This improves the error message so that it is not a generic IDFError. The new error message says: ``` ValueError: sample_rate must be 20000-2000000 ``` I verified at a sample rate of 20000 that I could read both 0 and 65535 using a jumper wire to another GPIO pin configured as a digital output. Closes #9504
1 parent 396aaef commit dc21efe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ports/espressif/common-hal/analogbufio/BufferedIn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ void common_hal_analogbufio_bufferedin_construct(analogbufio_bufferedin_obj_t *s
7171
}
7272
#endif
7373

74+
mp_arg_validate_int_range(sample_rate, SOC_ADC_SAMPLE_FREQ_THRES_LOW, SOC_ADC_SAMPLE_FREQ_THRES_HIGH, MP_QSTR_sample_rate);
75+
7476
common_hal_mcu_pin_claim(pin);
7577
}
7678

@@ -109,7 +111,7 @@ static void start_dma(analogbufio_bufferedin_obj_t *self, adc_digi_convert_mode_
109111
};
110112

111113
#if defined(DEBUG_ANALOGBUFIO)
112-
mp_printf(&mp_plat_print, "pin:%d, ADC channel:%d, ADC index:%d, adc1_chan_mask:0x%x, adc2_chan_mask:0x%x\n", pin->number, pin->adc_channel, pin->adc_index, adc1_chan_mask, adc2_chan_mask);
114+
mp_printf(&mp_plat_print, "pin:%d, ADC channel:%d, ADC index:%d\n", pin->number, pin->adc_channel, pin->adc_index);
113115
#endif // DEBUG_ANALOGBUFIO
114116
esp_err_t err = adc_continuous_new_handle(&adc_dma_config, &self->handle);
115117
if (ESP_OK != err) {

0 commit comments

Comments
 (0)