1 /*
2  * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 
14 #if SOC_ADC_ARBITER_SUPPORTED
15 /*---------------------------------------------------------------
16                     Arbiter
17 ---------------------------------------------------------------*/
18 /**
19  * @brief ADC arbiter work mode option.
20  */
21 typedef enum {
22     ADC_ARB_MODE_SHIELD,    ///< Force shield arbiter, Select the highest priority controller to work
23     ADC_ARB_MODE_FIX,       ///< Fixed priority switch controller mode
24     ADC_ARB_MODE_LOOP,      ///< Loop priority switch controller mode. Each controller has the same priority, and the arbiter will switch to the next controller after the measurement is completed
25 } adc_arbiter_mode_t;
26 
27 /**
28  * @brief ADC arbiter work mode and priority setting.
29  *
30  * @note Only ADC2 support arbiter.
31  */
32 typedef struct {
33     adc_arbiter_mode_t mode;    ///< Refer to ``adc_arbiter_mode_t``
34     uint8_t rtc_pri;            ///< RTC controller priority. Range: 0 ~ 2
35     uint8_t dig_pri;            ///< Digital controller priority. Range: 0 ~ 2
36     uint8_t pwdet_pri;          ///< Wi-Fi controller priority. Range: 0 ~ 2
37 } adc_arbiter_t;
38 
39 /**
40  * @brief ADC arbiter default configuration.
41  */
42 #define ADC_ARBITER_CONFIG_DEFAULT() { \
43     .mode = ADC_ARB_MODE_FIX, \
44     .rtc_pri = 1, \
45     .dig_pri = 0, \
46     .pwdet_pri = 2, \
47 }
48 #endif  //#if SOC_ADC_ARBITER_SUPPORTED
49 
50 #if SOC_ADC_MONITOR_SUPPORTED
51 /*---------------------------------------------------------------
52                     Monitor
53 ---------------------------------------------------------------*/
54 /**
55  * @brief ADC digital controller (DMA mode) monitor index options.
56  *
57  * @note  For ESP32-S2, The monitor object of the ADC is fixed.
58  */
59 typedef enum {
60     ADC_DIGI_MONITOR_IDX0 = 0, /*!<The monitor index 0.
61                                   For ESP32-S2, It can only be used to monitor all enabled channels of ADC1 unit at the same time. */
62     ADC_DIGI_MONITOR_IDX1,     /*!<The monitor index 1.
63                                   For ESP32-S2, It can only be used to monitor all enabled channels of ADC2 unit at the same time. */
64     ADC_DIGI_MONITOR_IDX_MAX
65 } adc_digi_monitor_idx_t;
66 
67 /**
68  * @brief Set monitor mode of adc digital controller.
69  *        MONITOR_HIGH:If ADC_OUT >  threshold, Generates monitor interrupt.
70  *        MONITOR_LOW: If ADC_OUT <  threshold, Generates monitor interrupt.
71  */
72 typedef enum {
73 #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2
74     ADC_DIGI_MONITOR_DIS = 0,  /*!<Disable monitor. */
75     ADC_DIGI_MONITOR_EN,       /*!<If ADC_OUT <  threshold, Generates monitor interrupt. */
76                                /*!<If ADC_OUT >  threshold, Generates monitor interrupt. */
77 #else
78     ADC_DIGI_MONITOR_HIGH = 0,  /*!<If ADC_OUT >  threshold, Generates monitor interrupt. */
79     ADC_DIGI_MONITOR_LOW,       /*!<If ADC_OUT <  threshold, Generates monitor interrupt. */
80 #endif
81     ADC_DIGI_MONITOR_MAX
82 } adc_digi_monitor_mode_t;
83 
84 /**
85  * @brief ADC digital controller (DMA mode) monitor configuration.
86  *
87  */
88 typedef struct {
89     adc_unit_t adc_unit;            /*!<Set adc unit number for monitor.
90                                         For ESP32-S2, monitor IDX0/IDX1 can only be used to monitor all enabled channels of ADC1/ADC2 unit at the same time. */
91     adc_channel_t channel;          /*!<Set adc channel number for monitor.
92                                         For ESP32-S2, it's always `ADC_CHANNEL_MAX` */
93     adc_digi_monitor_mode_t mode;   /*!<Set adc monitor mode. See ``adc_digi_monitor_mode_t``. */
94     uint32_t h_threshold;           /*!<Set monitor threshold of adc digital controller. */
95     uint32_t l_threshold;           /*!<Set monitor threshold of adc digital controller. */
96 } adc_digi_monitor_t;
97 #endif  //#if SOC_ADC_MONITOR_SUPPORTED
98 
99 #ifdef __cplusplus
100 }
101 #endif
102