From 0bbd067a17eaf89ec5fdc87d18555edb4608f784 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Thu, 1 Oct 2020 13:06:48 -0400 Subject: [PATCH] Revert ADC calibration removal, complete merge --- ports/esp32s2/Makefile | 5 +---- ports/esp32s2/common-hal/analogio/AnalogIn.c | 18 +++++++----------- ports/esp32s2/common-hal/analogio/AnalogIn.h | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile index 1289835059..f19c960f43 100644 --- a/ports/esp32s2/Makefile +++ b/ports/esp32s2/Makefile @@ -77,6 +77,7 @@ INC += -I../../supervisor/shared/usb INC += -isystem esp-idf INC += -isystem esp-idf/components/driver/include INC += -isystem esp-idf/components/hal/esp32s2/include +INC += -isystem esp-idf/components/driver/esp32s2/include INC += -isystem esp-idf/components/hal/include INC += -isystem esp-idf/components/freertos/include/freertos @@ -97,10 +98,6 @@ INC += -isystem esp-idf/components/newlib/platform_include INC += -isystem esp-idf/components/lwip/lwip/src/include INC += -isystem esp-idf/components/lwip/port/esp32/include INC += -isystem esp-idf/components/lwip/include/apps/sntp -<<<<<<< HEAD -======= -INC += -isystem esp-idf/components/hal/include ->>>>>>> esp32-update-idf INC += -isystem esp-idf/components/soc/include INC += -isystem esp-idf/components/soc/src/esp32s2/include INC += -isystem esp-idf/components/soc/soc/include diff --git a/ports/esp32s2/common-hal/analogio/AnalogIn.c b/ports/esp32s2/common-hal/analogio/AnalogIn.c index 1a15fc77cd..d8acc5728c 100644 --- a/ports/esp32s2/common-hal/analogio/AnalogIn.c +++ b/ports/esp32s2/common-hal/analogio/AnalogIn.c @@ -29,9 +29,9 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -#include "driver/adc.h" -// TODO: Add when ESP-IDF is updated latest version -// #include "esp-idf/components/esp_adc_cal/include/esp_adc_cal.h" +#include "components/driver/include/driver/adc_common.h" + +#include "components/esp_adc_cal/include/esp_adc_cal.h" #include "shared-bindings/microcontroller/Pin.h" @@ -69,10 +69,9 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { adc2_config_channel_atten((adc2_channel_t)self->pin->adc_channel, ATTENUATION); } - // TODO: esp_adc_cal is only available in the latest version of the esp-idf. Enable when we update. // Automatically select calibration process depending on status of efuse - // esp_adc_cal_characteristics_t *adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t)); - // esp_adc_cal_characterize(self->pin->adc_index, ATTENUATION, DATA_WIDTH, DEFAULT_VREF, adc_chars); + esp_adc_cal_characteristics_t *adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t)); + esp_adc_cal_characterize(self->pin->adc_index, ATTENUATION, DATA_WIDTH, DEFAULT_VREF, adc_chars); uint32_t adc_reading = 0; //Multisampling @@ -91,11 +90,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { adc_reading /= NO_OF_SAMPLES; // This corrects non-linear regions of the ADC range with a LUT, so it's a better reading than raw - // Enable when ESP-IDF is updated - //uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars); - //return voltage * ((1 << 16) - 1)/3300; - - return adc_reading; + uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars); + return voltage * ((1 << 16) - 1)/3300; } float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { diff --git a/ports/esp32s2/common-hal/analogio/AnalogIn.h b/ports/esp32s2/common-hal/analogio/AnalogIn.h index 5ea4a913de..548cbb5cc0 100644 --- a/ports/esp32s2/common-hal/analogio/AnalogIn.h +++ b/ports/esp32s2/common-hal/analogio/AnalogIn.h @@ -29,7 +29,7 @@ #include "common-hal/microcontroller/Pin.h" -#include "esp-idf/components/soc/include/hal/adc_types.h" +#include "components/soc/include/hal/adc_types.h" #include "FreeRTOS.h" #include "freertos/semphr.h" #include "py/obj.h"