dac_common.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stdint.h>
  11. #include "esp_err.h"
  12. #include "driver/gpio.h"
  13. #include "hal/dac_types.h"
  14. /**
  15. * @brief Get the GPIO number of a specific DAC channel.
  16. *
  17. * @param channel Channel to get the gpio number
  18. * @param gpio_num output buffer to hold the gpio number
  19. * @return
  20. * - ESP_OK if success
  21. */
  22. esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num);
  23. /**
  24. * @brief Set DAC output voltage.
  25. * DAC output is 8-bit. Maximum (255) corresponds to VDD3P3_RTC.
  26. *
  27. * @note Need to configure DAC pad before calling this function.
  28. * DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  29. * @param channel DAC channel
  30. * @param dac_value DAC output value
  31. *
  32. * @return
  33. * - ESP_OK success
  34. */
  35. esp_err_t dac_output_voltage(dac_channel_t channel, uint8_t dac_value);
  36. /**
  37. * @brief DAC pad output enable
  38. *
  39. * @param channel DAC channel
  40. * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  41. * I2S left channel will be mapped to DAC channel 2
  42. * I2S right channel will be mapped to DAC channel 1
  43. */
  44. esp_err_t dac_output_enable(dac_channel_t channel);
  45. /**
  46. * @brief DAC pad output disable
  47. *
  48. * @param channel DAC channel
  49. * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  50. * @return
  51. * - ESP_OK success
  52. */
  53. esp_err_t dac_output_disable(dac_channel_t channel);
  54. /**
  55. * @brief Enable cosine wave generator output.
  56. *
  57. * @return
  58. * - ESP_OK success
  59. */
  60. esp_err_t dac_cw_generator_enable(void);
  61. /**
  62. * @brief Disable cosine wave generator output.
  63. *
  64. * @return
  65. * - ESP_OK success
  66. */
  67. esp_err_t dac_cw_generator_disable(void);
  68. /**
  69. * @brief Config the cosine wave generator function in DAC module.
  70. *
  71. * @param cw Configuration.
  72. * @return
  73. * - ESP_OK success
  74. * - ESP_ERR_INVALID_ARG The parameter is NULL.
  75. */
  76. esp_err_t dac_cw_generator_config(dac_cw_config_t *cw);
  77. #ifdef __cplusplus
  78. }
  79. #endif