Skip to content

Bug fixes for analogbufio espressif implementation #7879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2023
Merged
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
10 changes: 7 additions & 3 deletions ports/espressif/common-hal/analogbufio/BufferedIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
#define NUM_SAMPLES_PER_INTERRUPT 256
#define NUM_ADC_CHANNELS 1
#define DMA_BUFFER_SIZE 1024
#define ATTENUATION ADC_ATTEN_DB_0
#define ATTENUATION ADC_ATTEN_DB_11
#define ADC_READ_TIMEOUT_MS 2000
#define ADC_PIN_MAX_VALUE 0xfff

#if defined(CONFIG_IDF_TARGET_ESP32)
#define ADC_RESULT_BYTE 2
Expand Down Expand Up @@ -239,6 +240,7 @@ uint32_t common_hal_analogbufio_bufferedin_readinto(analogbufio_bufferedin_obj_t
uint32_t captured_bytes = 0;
esp_err_t ret;
uint32_t ret_num = 0;
uint32_t adc_reading = 0;
adc_digi_convert_mode_t convert_mode = ADC_CONV_SINGLE_UNIT_2;
adc_digi_output_format_t output_format = ADC_DIGI_OUTPUT_FORMAT_TYPE1;

Expand All @@ -264,11 +266,13 @@ uint32_t common_hal_analogbufio_bufferedin_readinto(analogbufio_bufferedin_obj_t
uint16_t *pBuffer = (uint16_t *)(void *)&buffer[captured_bytes];
if (output_format == ADC_DIGI_OUTPUT_FORMAT_TYPE1) {
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
*pBuffer = pResult->type1.data;
adc_reading = pResult->type1.data;
#endif
} else {
*pBuffer = pResult->type2.data;
adc_reading = pResult->type2.data;
}
adc_reading = adc_reading * ((1 << 16) - 1) / ADC_PIN_MAX_VALUE;
*pBuffer = (uint16_t)adc_reading;
captured_bytes += sizeof(uint16_t);
captured_samples++;
} else {
Expand Down