1 /*
2  * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include "hal/adc_types.h"
10 #include "hal/adc_types_private.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 
17 /**
18  * This header file is only for hardware abstract concepts and APIs
19  * used by both ADC RTC controller and Digital controller
20  */
21 
22 /**
23  * ADC work mode
24  */
25 typedef enum adc_hal_work_mode_t {
26     ADC_HAL_SINGLE_READ_MODE,
27     ADC_HAL_CONTINUOUS_READ_MODE,
28     ADC_HAL_PWDET_MODE,
29     ADC_HAL_ULP_FSM_MODE,
30 } adc_hal_work_mode_t;
31 
32 /**
33  * Set ADC work mode
34  *
35  * @param unit       ADC unit
36  * @param work_mode  see `adc_hal_work_mode_t`
37  */
38 void adc_hal_set_controller(adc_unit_t unit, adc_hal_work_mode_t work_mode);
39 
40 #if SOC_ADC_ARBITER_SUPPORTED
41 //No ADC2 controller arbiter on ESP32
42 /**
43  * Config ADC2 module arbiter.
44  * The arbiter is to improve the use efficiency of ADC2. After the control right is robbed by the high priority,
45  * the low priority controller will read the invalid ADC2 data, and the validity of the data can be judged by the flag bit in the data.
46  *
47  * @note Only ADC2 support arbiter.
48  * @note The arbiter's working clock is APB_CLK. When the APB_CLK clock drops below 8 MHz, the arbiter must be in shield mode.
49  * @note Default priority: Wi-Fi > RTC > Digital;
50  *
51  * @param config Refer to ``adc_arbiter_t``.
52  */
53 void adc_hal_arbiter_config(adc_arbiter_t *config);
54 #endif  //#if SOC_ADC_ARBITER_SUPPORTED
55 
56 /*---------------------------------------------------------------
57                     ADC calibration setting
58 ---------------------------------------------------------------*/
59 #if SOC_ADC_CALIBRATION_V1_SUPPORTED
60 
61 /**
62  * @brief Initialize default parameter for the calibration block.
63  *
64  * @param adc_n ADC index numer
65  */
66 void adc_hal_calibration_init(adc_unit_t adc_n);
67 
68 /**
69  * Set the calibration result (initial data) to ADC.
70  *
71  * @note  Different ADC units and different attenuation options use different calibration data (initial data).
72  *
73  * @param adc_n ADC index number.
74  * @param param the calibration parameter to configure
75  */
76 void adc_hal_set_calibration_param(adc_unit_t adc_n, uint32_t param);
77 
78 /**
79  * Calibrate the ADC using internal connections.
80  *
81  * @note  Different ADC units and different attenuation options use different calibration data (initial data).
82  *
83  * @param adc_n ADC index number.
84  * @param atten ADC attenuation
85  * @param internal_gnd true:  Disconnect from the IO port and use the internal GND as the calibration voltage.
86  *                     false: Use IO external voltage as calibration voltage.
87  *
88  * @return
89  *      - The calibration result (initial data) to ADC, use `adc_hal_set_calibration_param` to set.
90  */
91 uint32_t adc_hal_self_calibration(adc_unit_t adc_n, adc_atten_t atten, bool internal_gnd);
92 
93 #endif //SOC_ADC_CALIBRATION_V1_SUPPORTED
94 
95 
96 #ifdef __cplusplus
97 }
98 #endif
99