components/driver/esp32s2/adc.c
//NOTE: according to calibration version, different types of lock may be taken during the process:
//  1. Semaphore when reading efuse
//  2. Spinlock when actually doing ADC calibration
//This function shoudn't be called inside critical section or ISR
according to calibration version, different types of lock may be taken during the process:
1. Semaphore when reading efuse
2. Spinlock when actually doing ADC calibration
This function shoudn't be called inside critical section or ISR
according to calibration version different types of lock may be taken during the process : 1 . Semaphore when reading efuse 2 . Spinlock when actually doing ADC calibration This function shoudn ' t be called inside critical section or ISR
uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten)
{
#ifdef CONFIG_IDF_ENV_FPGA
    return 0;
#endif
    if (s_adc_cali_param[adc_n][atten]) {
        ESP_LOGV(ADC_TAG, "Use calibrated val ADC%d atten=%d: %04X", adc_n, atten, s_adc_cali_param[adc_n][atten]);
        return (uint32_t)s_adc_cali_param[adc_n][atten];
    }
    uint32_t dout = 0;
    int version = esp_efuse_rtc_table_read_calib_version();
    if (version == 2) {
        int tag = esp_efuse_rtc_table_get_tag(version, adc_n + 1, atten, RTCCALIB_V2_PARAM_VINIT);
        dout = esp_efuse_rtc_table_get_parsed_efuse_value(tag, false);
    } else {
        adc_power_acquire();
        ADC_ENTER_CRITICAL();
        const bool internal_gnd = true;
        dout = adc_hal_self_calibration(adc_n, channel, atten, internal_gnd);
        ADC_EXIT_CRITICAL();
        adc_power_release();
    }
    ESP_LOGD(ADC_TAG, "Calib(V%d) ADC%d atten=%d: %04X", version, adc_n, atten, dout);
    s_adc_cali_param[adc_n][atten] = (uint16_t)dout;
    return dout;
}
uint32_t adc_get_calibration_offset ( adc_ll_num_t adc_n , adc_channel_t channel , adc_atten_t atten ) { #ifdef CONFIG_IDF_ENV_FPGA return 0 ; #endif if ( s_adc_cali_param [ adc_n ] [ atten ] ) { ESP_LOGV ( ADC_TAG , " " , adc_n , atten , s_adc_cali_param [ adc_n ] [ atten ] ) ; return ( uint32_t ) s_adc_cali_param [ adc_n ] [ atten ] ; } uint32_t dout = 0 ; int version = esp_efuse_rtc_table_read_calib_version ( ) ; if ( version == 2 ) { int tag = esp_efuse_rtc_table_get_tag ( version , adc_n + 1 , atten , RTCCALIB_V2_PARAM_VINIT ) ; dout = esp_efuse_rtc_table_get_parsed_efuse_value ( tag , false ) ; } else { adc_power_acquire ( ) ; ADC_ENTER_CRITICAL ( ) ; const bool internal_gnd = true ; dout = adc_hal_self_calibration ( adc_n , channel , atten , internal_gnd ) ; ADC_EXIT_CRITICAL ( ) ; adc_power_release ( ) ; } ESP_LOGD ( ADC_TAG , " " , version , adc_n , atten , dout ) ; s_adc_cali_param [ adc_n ] [ atten ] = ( uint16_t ) dout ; return dout ; }
NOTE: according to calibration version, different types of lock may be taken during the process:
1.
NOTE : according to calibration version different types of lock may be taken during the process : 1 .
// check if we can fetch the values from eFuse.