mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
adc_oneshot: move power acquire back to adc_oneshot_new_unit
Revert and fix of d197c59eaa5107c7c2981d308363c7d643e16774 in !23575 adc_cali: fix the condition of ocode calibration
This commit is contained in:
parent
e90a2d50c4
commit
6f673e95c9
@ -19,10 +19,8 @@
|
||||
|
||||
int esp_efuse_rtc_calib_get_ver(void)
|
||||
{
|
||||
uint32_t blk_ver = efuse_hal_blk_version();
|
||||
|
||||
uint32_t cali_version = 0;
|
||||
if (blk_ver > 0) {
|
||||
if (efuse_hal_blk_version() >= 1) {
|
||||
cali_version = ESP_EFUSE_ADC_CALIB_VER;
|
||||
} else {
|
||||
ESP_LOGW("eFuse", "calibration efuse version does not match, set default version to 0");
|
||||
|
@ -122,6 +122,10 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a
|
||||
_lock_release(&s_ctx.mutex);
|
||||
#endif
|
||||
|
||||
if (init_config->ulp_mode == ADC_ULP_MODE_DISABLE) {
|
||||
sar_periph_ctrl_adc_oneshot_power_acquire();
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "new adc unit%"PRId32" is created", unit->unit_id);
|
||||
*ret_unit = unit;
|
||||
return ESP_OK;
|
||||
@ -167,7 +171,6 @@ esp_err_t adc_oneshot_read(adc_oneshot_unit_handle_t handle, adc_channel_t chan,
|
||||
}
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
|
||||
sar_periph_ctrl_adc_oneshot_power_acquire();
|
||||
adc_oneshot_hal_setup(&(handle->hal), chan);
|
||||
#if SOC_ADC_CALIBRATION_V1_SUPPORTED
|
||||
adc_atten_t atten = adc_ll_get_atten(handle->unit_id, chan);
|
||||
@ -176,7 +179,6 @@ esp_err_t adc_oneshot_read(adc_oneshot_unit_handle_t handle, adc_channel_t chan,
|
||||
#endif // SOC_ADC_CALIBRATION_V1_SUPPORTED
|
||||
bool valid = false;
|
||||
valid = adc_oneshot_hal_convert(&(handle->hal), out_raw);
|
||||
sar_periph_ctrl_adc_oneshot_power_release();
|
||||
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
adc_lock_release(handle->unit_id);
|
||||
@ -192,7 +194,6 @@ esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t c
|
||||
|
||||
portENTER_CRITICAL_SAFE(&rtc_spinlock);
|
||||
|
||||
sar_periph_ctrl_adc_oneshot_power_acquire();
|
||||
adc_oneshot_hal_setup(&(handle->hal), chan);
|
||||
#if SOC_ADC_CALIBRATION_V1_SUPPORTED
|
||||
adc_atten_t atten = adc_ll_get_atten(handle->unit_id, chan);
|
||||
@ -200,7 +201,6 @@ esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t c
|
||||
adc_set_hw_calibration_code(handle->unit_id, atten);
|
||||
#endif
|
||||
adc_oneshot_hal_convert(&(handle->hal), out_raw);
|
||||
sar_periph_ctrl_adc_oneshot_power_release();
|
||||
|
||||
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
|
||||
|
||||
@ -210,6 +210,7 @@ esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t c
|
||||
esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
adc_ulp_mode_t ulp_mode = handle->ulp_mode;
|
||||
bool success_free = s_adc_unit_free(handle->unit_id);
|
||||
ESP_RETURN_ON_FALSE(success_free, ESP_ERR_NOT_FOUND, TAG, "adc%"PRId32" isn't in use", handle->unit_id + 1);
|
||||
|
||||
@ -220,6 +221,10 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle)
|
||||
ESP_LOGD(TAG, "adc unit%"PRId32" is deleted", handle->unit_id);
|
||||
free(handle);
|
||||
|
||||
if (ulp_mode == ADC_ULP_MODE_DISABLE) {
|
||||
sar_periph_ctrl_adc_oneshot_power_release();
|
||||
}
|
||||
|
||||
#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
|
||||
//To free the APB_SARADC periph if needed
|
||||
_lock_acquire(&s_ctx.mutex);
|
||||
|
@ -78,20 +78,8 @@ static void calibrate_ocode(void)
|
||||
|
||||
void esp_ocode_calib_init(void)
|
||||
{
|
||||
bool ignore_major = efuse_ll_get_disable_blk_version_major();
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
|
||||
uint8_t ocode_scheme_ver = 0;
|
||||
if(blk_version == 0 && !ignore_major) {
|
||||
ESP_HW_LOGE(TAG, "Invalid blk_version\n");
|
||||
abort();
|
||||
}
|
||||
if(blk_version > 0) {
|
||||
ocode_scheme_ver = 1;
|
||||
}
|
||||
|
||||
if (ocode_scheme_ver == 1) {
|
||||
set_ocode_by_efuse(ocode_scheme_ver);
|
||||
if (efuse_hal_blk_version() >= 1) {
|
||||
set_ocode_by_efuse(1);
|
||||
} else {
|
||||
calibrate_ocode();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user