dac.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #ifndef _DRIVER_DAC_H_
  14. #define _DRIVER_DAC_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <stdint.h>
  19. #include "esp_err.h"
  20. #include "soc/dac_periph.h"
  21. typedef enum {
  22. DAC_CHANNEL_1 = 1, /*!< DAC channel 1 is GPIO25 (ESP32), GPIO17 (ESP32-S2) */
  23. DAC_CHANNEL_2, /*!< DAC channel 2 is GPIO26 (ESP32), GPIO18 (ESP32-S2) */
  24. DAC_CHANNEL_MAX,
  25. } dac_channel_t;
  26. /**
  27. * @brief Get the gpio number of a specific DAC channel.
  28. *
  29. * @param channel Channel to get the gpio number
  30. *
  31. * @param gpio_num output buffer to hold the gpio number
  32. *
  33. * @return
  34. * - ESP_OK if success
  35. * - ESP_ERR_INVALID_ARG if channal not valid
  36. */
  37. esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num);
  38. /** @cond */
  39. /**
  40. * @brief Set DAC output voltage.
  41. *
  42. * @note Function has been deprecated, please use dac_output_voltage instead.
  43. * This name will be removed in a future release.
  44. * The difference is that before calling dac_output_voltage, we need to initialize the dac pad by dac_output_enable
  45. *
  46. *
  47. * @param channel DAC channel
  48. * @param dac_value DAC output value
  49. *
  50. * @return
  51. * - ESP_OK success
  52. * - ESP_ERR_INVALID_ARG Parameter error
  53. */
  54. esp_err_t dac_out_voltage(dac_channel_t channel, uint8_t dac_value) __attribute__ ((deprecated));
  55. /** @endcond */
  56. /**
  57. * @brief Set DAC output voltage.
  58. *
  59. * DAC output is 8-bit. Maximum (255) corresponds to VDD.
  60. *
  61. * @note Need to configure DAC pad before calling this function.
  62. * DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  63. *
  64. * @param channel DAC channel
  65. * @param dac_value DAC output value
  66. *
  67. * @return
  68. * - ESP_OK success
  69. * - ESP_ERR_INVALID_ARG Parameter error
  70. */
  71. esp_err_t dac_output_voltage(dac_channel_t channel, uint8_t dac_value);
  72. /**
  73. * @brief DAC pad output enable
  74. *
  75. * @param channel DAC channel
  76. * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  77. * I2S left channel will be mapped to DAC channel 2
  78. * I2S right channel will be mapped to DAC channel 1
  79. */
  80. esp_err_t dac_output_enable(dac_channel_t channel);
  81. /**
  82. * @brief DAC pad output disable
  83. *
  84. * @param channel DAC channel
  85. * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
  86. */
  87. esp_err_t dac_output_disable(dac_channel_t channel);
  88. /**
  89. * @brief Enable DAC output data from I2S
  90. */
  91. esp_err_t dac_i2s_enable(void);
  92. /**
  93. * @brief Disable DAC output data from I2S
  94. */
  95. esp_err_t dac_i2s_disable(void);
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /*_DRIVER_DAC_H_*/