29
29
#include "py/runtime.h"
30
30
#include "supervisor/shared/translate.h"
31
31
32
- #include "driver/adc .h"
33
- // TODO: Add when ESP-IDF is updated latest version
34
- // #include "esp-idf/ components/esp_adc_cal/include/esp_adc_cal.h"
32
+ #include "components/ driver/include/driver/adc_common .h"
33
+
34
+ #include "components/esp_adc_cal/include/esp_adc_cal.h"
35
35
36
36
#include "shared-bindings/microcontroller/Pin.h"
37
37
@@ -69,10 +69,9 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
69
69
adc2_config_channel_atten ((adc2_channel_t )self -> pin -> adc_channel , ATTENUATION );
70
70
}
71
71
72
- // TODO: esp_adc_cal is only available in the latest version of the esp-idf. Enable when we update.
73
72
// Automatically select calibration process depending on status of efuse
74
- // esp_adc_cal_characteristics_t *adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
75
- // esp_adc_cal_characterize(self->pin->adc_index, ATTENUATION, DATA_WIDTH, DEFAULT_VREF, adc_chars);
73
+ esp_adc_cal_characteristics_t * adc_chars = calloc (1 , sizeof (esp_adc_cal_characteristics_t ));
74
+ esp_adc_cal_characterize (self -> pin -> adc_index , ATTENUATION , DATA_WIDTH , DEFAULT_VREF , adc_chars );
76
75
77
76
uint32_t adc_reading = 0 ;
78
77
//Multisampling
@@ -91,11 +90,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
91
90
adc_reading /= NO_OF_SAMPLES ;
92
91
93
92
// This corrects non-linear regions of the ADC range with a LUT, so it's a better reading than raw
94
- // Enable when ESP-IDF is updated
95
- //uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, adc_chars);
96
- //return voltage * ((1 << 16) - 1)/3300;
97
-
98
- return adc_reading ;
93
+ uint32_t voltage = esp_adc_cal_raw_to_voltage (adc_reading , adc_chars );
94
+ return voltage * ((1 << 16 ) - 1 )/3300 ;
99
95
}
100
96
101
97
float common_hal_analogio_analogin_get_reference_voltage (analogio_analogin_obj_t * self ) {
0 commit comments