adc_private.h 2.8 KB

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