adc2_init_cal.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2016-2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /* 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.
  15. The linker will link constructor (adc2_init_code_calibration) only when any sections inside the same file (adc2_cal_include) is used.
  16. Don't put any other code into this file. */
  17. #include "adc2_wifi_private.h"
  18. #include "hal/adc_hal.h"
  19. #include "esp_private/adc_cali.h"
  20. /**
  21. * @brief Set initial code to ADC2 after calibration. ADC2 RTC and ADC2 PWDET controller share the initial code.
  22. * This API be called in before `app_main()`.
  23. */
  24. static __attribute__((constructor)) void adc2_init_code_calibration(void)
  25. {
  26. const adc_ll_num_t adc_n = ADC_NUM_2;
  27. const adc_atten_t atten = ADC_ATTEN_DB_11;
  28. const adc_channel_t channel = 0;
  29. adc_cal_offset(adc_n, channel, atten);
  30. }
  31. /** Don't call `adc2_cal_include` in user code. */
  32. void adc2_cal_include(void)
  33. {
  34. /* When this empty function is called, the `adc2_init_code_calibration` constructor will be linked and executed before the app.*/
  35. }