dac_priv_common.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "freertos/FreeRTOS.h"
  8. #include "hal/dac_types.h"
  9. #include "hal/dac_ll.h"
  10. #include "esp_err.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. extern portMUX_TYPE rtc_spinlock; /*!< Extern global rtc spinlock */
  15. #define DAC_RTC_ENTER_CRITICAL() portENTER_CRITICAL(&rtc_spinlock)
  16. #define DAC_RTC_EXIT_CRITICAL() portEXIT_CRITICAL(&rtc_spinlock)
  17. #define DAC_RTC_ENTER_CRITICAL_SAFE() portENTER_CRITICAL_SAFE(&rtc_spinlock)
  18. #define DAC_RTC_EXIT_CRITICAL_SAFE() portEXIT_CRITICAL_SAFE(&rtc_spinlock)
  19. #define DAC_NULL_POINTER_CHECK(p) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL")
  20. #define DAC_NULL_POINTER_CHECK_ISR(p) ESP_RETURN_ON_FALSE_ISR((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL")
  21. /**
  22. * @brief Register dac channel in the driver, in case a same channel is reused by different modes
  23. *
  24. * @param[in] chan_id DAC channel id
  25. * @param[in] mode_name The const string of mode name
  26. * @return
  27. * - ESP_ERR_INVALID_STATE The channel has been occupied
  28. * - ESP_ERR_INVALID_ARG The channel id is incorrect
  29. * - ESP_OK Register the channel success
  30. */
  31. esp_err_t dac_priv_register_channel(dac_channel_t chan_id, const char *mode_name);
  32. /**
  33. * @brief Deregister dac channel in the driver
  34. *
  35. * @param[in] chan_id DAC channel id
  36. * @return
  37. * - ESP_ERR_INVALID_STATE The channel has been freed
  38. * - ESP_ERR_INVALID_ARG The channel id is incorrect
  39. * - ESP_OK Deregister the channel success
  40. */
  41. esp_err_t dac_priv_deregister_channel(dac_channel_t chan_id);
  42. /**
  43. * @brief Enable the DAC channel and turn on its power
  44. *
  45. * @param chan_id DAC channel id
  46. * @return
  47. * - ESP_ERR_INVALID_STATE The channel has not been registered
  48. * - ESP_ERR_INVALID_ARG The channel id is incorrect
  49. * - ESP_OK Deregister the channel success
  50. */
  51. esp_err_t dac_priv_enable_channel(dac_channel_t chan_id);
  52. /**
  53. * @brief Disable the DAC channel and turn off its power
  54. *
  55. * @param chan_id DAC channel id
  56. * @return
  57. * - ESP_ERR_INVALID_STATE The channel has not been registered
  58. * - ESP_ERR_INVALID_ARG The channel id is incorrect
  59. * - ESP_OK Deregister the channel success
  60. */
  61. esp_err_t dac_priv_disable_channel(dac_channel_t chan_id);
  62. #ifdef __cplusplus
  63. }
  64. #endif