1 /*
2  * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 // DO NOT USE THESE APIS IN ANY APPLICATIONS
8 
9 #pragma once
10 #include "esp_err.h"
11 #include "hal/adc_types.h"
12 #include "soc/soc_caps.h"
13 
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 
20 /*---------------------------------------------------------------
21             ADC IOs
22 ---------------------------------------------------------------*/
23 /**
24  * @brief Get ADC channel from the given GPIO number
25  *
26  * @param[in]  io_num     GPIO number
27  * @param[out] unit_id    ADC unit
28  * @param[out] channel    ADC channel
29  *
30  * @return
31  *        - ESP_OK:              On success
32  *        - ESP_ERR_INVALID_ARG: Invalid argument
33  *        - ESP_ERR_NOT_FOUND:   The IO is not a valid ADC pad
34  */
35 esp_err_t adc_io_to_channel(int io_num, adc_unit_t *unit_id, adc_channel_t *channel);
36 
37 /**
38  * @brief Get GPIO number from the given ADC channel
39  *
40  * @param[in]  unit_id    ADC unit
41  * @param[in]  channel    ADC channel
42  * @param[out] io_num     GPIO number
43  *
44  * @param
45  *       - ESP_OK:              On success
46  *       - ESP_ERR_INVALID_ARG: Invalid argument
47  */
48 esp_err_t adc_channel_to_io(adc_unit_t unit_id, adc_channel_t channel, int *io_num);
49 
50 
51 /*---------------------------------------------------------------
52             ADC Oneshot Read API ISR Version
53 ---------------------------------------------------------------*/
54 typedef struct adc_oneshot_unit_ctx_t *adc_oneshot_unit_handle_t;
55 /**
56  * @brief ISR version to get one ADC conversion raw result
57  *
58  * @note This API only provide atomic register settings, without hardware resources protection. When other drivers are using
59  *       SAR-ADCs, calling this API may get wrong ADC result.
60  * @note This API can be called in an ISR context.
61  * @note Strongly suggest using this function when there's no concurrent hardware usage to the ADC. You can refer to ADC Oneshot
62  *       Programming Guide to know ADC Hardware Limitations
63  *
64  * @param[in] handle    ADC handle
65  * @param[in] chan      ADC channel
66  * @param[out] out_raw  ADC conversion raw result
67  *
68  * @return
69  *        - ESP_OK:                On success
70  *        - ESP_ERR_INVALID_ARG:   Invalid arguments
71  *        - ESP_ERR_INVALID_STATE: Invalid state, the ADC result is invalid
72  */
73 esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t chan, int *out_raw);
74 
75 
76 #ifdef __cplusplus
77 }
78 #endif
79