Revert ADC calibration removal, complete merge

This commit is contained in:
Lucian Copeland 2020-10-01 13:06:48 -04:00
parent c624c1e838
commit 0bbd067a17
3 changed files with 9 additions and 16 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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"