mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 20:21:04 +00:00
adc: support adc efuse-based calibration on esp32s3
This commit is contained in:

committed by
Armando (Dou Yiwen)

parent
c54caa457e
commit
c45c6f52f1
@@ -17,6 +17,7 @@
|
||||
#include "driver/adc.h"
|
||||
#include "soc/efuse_periph.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_check.h"
|
||||
#include "assert.h"
|
||||
#include "esp_adc_cal.h"
|
||||
|
||||
@@ -82,11 +83,7 @@
|
||||
#define LUT_HIGH_THRESH (LUT_LOW_THRESH + LUT_ADC_STEP_SIZE)
|
||||
#define ADC_12_BIT_RES 4096
|
||||
|
||||
#define ADC_CAL_CHECK(cond, ret) ({ \
|
||||
if(!(cond)){ \
|
||||
return ret; \
|
||||
} \
|
||||
})
|
||||
const static char LOG_TAG[] = "ADC_CALI";
|
||||
|
||||
/* ------------------------ Characterization Constants ---------------------- */
|
||||
static const uint32_t adc1_tp_atten_scale[4] = {65504, 86975, 120389, 224310};
|
||||
@@ -372,21 +369,20 @@ esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel,
|
||||
uint32_t *voltage)
|
||||
{
|
||||
//Check parameters
|
||||
ADC_CAL_CHECK(chars != NULL, ESP_ERR_INVALID_ARG);
|
||||
ADC_CAL_CHECK(voltage != NULL, ESP_ERR_INVALID_ARG);
|
||||
ESP_RETURN_ON_FALSE(chars != NULL, ESP_ERR_INVALID_ARG, LOG_TAG, "No characteristic input");
|
||||
ESP_RETURN_ON_FALSE(voltage != NULL, ESP_ERR_INVALID_ARG, LOG_TAG, "No output buffer");
|
||||
|
||||
esp_err_t ret = ESP_OK;
|
||||
int adc_reading;
|
||||
if (chars->adc_num == ADC_UNIT_1) {
|
||||
//Check channel is valid on ADC1
|
||||
ADC_CAL_CHECK((adc1_channel_t)channel < ADC1_CHANNEL_MAX, ESP_ERR_INVALID_ARG);
|
||||
ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(0), ESP_ERR_INVALID_ARG, LOG_TAG, "Invalid channel");
|
||||
adc_reading = adc1_get_raw(channel);
|
||||
} else {
|
||||
//Check channel is valid on ADC2
|
||||
ADC_CAL_CHECK((adc2_channel_t)channel < ADC2_CHANNEL_MAX, ESP_ERR_INVALID_ARG);
|
||||
if (adc2_get_raw(channel, chars->bit_width, &adc_reading) != ESP_OK) {
|
||||
return ESP_ERR_TIMEOUT; //Timed out waiting for ADC2
|
||||
}
|
||||
ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(1), ESP_ERR_INVALID_ARG, LOG_TAG, "Invalid channel");
|
||||
ret = adc2_get_raw(channel, chars->bit_width, &adc_reading);
|
||||
}
|
||||
*voltage = esp_adc_cal_raw_to_voltage((uint32_t)adc_reading, chars);
|
||||
return ESP_OK;
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user