1 /*
2  * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* This file is used to get `adc2_init_code_calibration` executed before the APP when the ADC2 is used by Wi-Fi or other drivers.
8 The linker will link constructor (adc2_init_code_calibration) only when any sections inside the same file (adc2_cal_include) is used.
9 Don't put any other code into this file. */
10 
11 #include "adc2_wifi_private.h"
12 #include "hal/adc_hal.h"
13 #include "esp_private/adc_cali.h"
14 
15 /**
16  * @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code.
17  *        This API be called in before `app_main()`.
18  */
adc2_init_code_calibration(void)19 static __attribute__((constructor)) void adc2_init_code_calibration(void)
20 {
21     const adc_ll_num_t adc_n = ADC_NUM_2;
22     const adc_atten_t atten = ADC_ATTEN_DB_11;
23     const adc_channel_t channel = 0;
24     adc_cal_offset(adc_n, channel, atten);
25 }
26 
27 /** Don't call `adc2_cal_include` in user code. */
adc2_cal_include(void)28 void adc2_cal_include(void)
29 {
30     /* When this empty function is called, the `adc2_init_code_calibration` constructor will be linked and executed before the app.*/
31 }
32