dac.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #include <stdint.h>
  18. #include "esp_err.h"
  19. #include "driver/gpio.h"
  20. #include "hal/dac_types.h"
  21. /**
  22. * @brief Get the gpio number of a specific DAC channel.
  23. *
  24. * @param channel Channel to get the gpio number
  25. * @param gpio_num output buffer to hold the gpio number
  26. * @return
  27. * - ESP_OK if success
  28. */
  29. esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num);
  30. /**
  31. * @brief Set DAC output voltage.
  32. * DAC output is 8-bit. Maximum (255) corresponds to VDD3P3_RTC.
  33. *
  34. * @note Need to configure DAC pad before calling this function.
  35. * DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  36. * @param channel DAC channel
  37. * @param dac_value DAC output value
  38. *
  39. * @return
  40. * - ESP_OK success
  41. */
  42. esp_err_t dac_output_voltage(dac_channel_t channel, uint8_t dac_value);
  43. /**
  44. * @brief DAC pad output enable
  45. *
  46. * @param channel DAC channel
  47. * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  48. * I2S left channel will be mapped to DAC channel 2
  49. * I2S right channel will be mapped to DAC channel 1
  50. */
  51. esp_err_t dac_output_enable(dac_channel_t channel);
  52. /**
  53. * @brief DAC pad output disable
  54. *
  55. * @param channel DAC channel
  56. * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  57. * @return
  58. * - ESP_OK success
  59. */
  60. esp_err_t dac_output_disable(dac_channel_t channel);
  61. /**
  62. * @brief Enable DAC output data from I2S
  63. *
  64. * @return
  65. * - ESP_OK success
  66. */
  67. esp_err_t dac_i2s_enable(void);
  68. /**
  69. * @brief Disable DAC output data from I2S
  70. *
  71. * @return
  72. * - ESP_OK success
  73. */
  74. esp_err_t dac_i2s_disable(void);
  75. /**
  76. * @brief Enable cosine wave generator output.
  77. *
  78. * @return
  79. * - ESP_OK success
  80. */
  81. esp_err_t dac_cw_generator_enable(void);
  82. /**
  83. * @brief Disable cosine wave generator output.
  84. *
  85. * @return
  86. * - ESP_OK success
  87. */
  88. esp_err_t dac_cw_generator_disable(void);
  89. /**
  90. * @brief Config the cosine wave generator function in DAC module.
  91. *
  92. * @param cw Configuration.
  93. * @return
  94. * - ESP_OK success
  95. */
  96. esp_err_t dac_cw_generator_config(dac_cw_config_t *cw);
  97. #ifdef __cplusplus
  98. }
  99. #endif