hosal_dac.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2016-2022 Bouffalolab.
  3. *
  4. * This file is part of
  5. * *** Bouffalolab Software Dev Kit ***
  6. * (see www.bouffalolab.com).
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted provided that the following conditions are met:
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. Neither the name of Bouffalo Lab nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __HOSAL_DAC_H_
  31. #define __HOSAL_DAC_H_
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #include <stdint.h>
  36. #include "hosal_dma.h"
  37. /** @addtogroup hosal_dac DAC
  38. * HOSAL DAC API
  39. *
  40. * @{
  41. */
  42. /**
  43. * @brief hosal dac callback
  44. *
  45. * @param[in] arg Set the custom parameters specified when the callback function is set
  46. *
  47. */
  48. typedef void (*hosal_dac_cb_t)(void *arg);
  49. /**
  50. * @brief This struct define dac config args
  51. */
  52. typedef struct {
  53. uint8_t dma_enable; /**< @brief 1: use dma, 0: no dma */
  54. uint32_t pin; /**< @brief dac pin */
  55. uint32_t freq; /**< @brief dac freq */
  56. } hosal_dac_config_t;
  57. /**
  58. * @brief This struct define dac device type
  59. */
  60. typedef struct {
  61. uint8_t port; /**< @brief dac id */
  62. hosal_dac_config_t config; /**< @brief dac config */
  63. hosal_dac_cb_t cb; /**< @brief dma callback */
  64. hosal_dma_chan_t dma_chan; /**< @brief dac dma channel */
  65. void *arg; /**< @brief arg data */
  66. void *priv; /**< @brief priv data */
  67. } hosal_dac_dev_t;
  68. /**
  69. * @brief Initialises an dac interface
  70. *
  71. * @param[in] dac the interface which should be initialised
  72. *
  73. * @return
  74. * - 0 on success
  75. * - EIO if an error occurred with any step
  76. */
  77. int hosal_dac_init(hosal_dac_dev_t *dac);
  78. /**
  79. * @brief De-initialises an dac interface, Turns off an dac hardware interface
  80. *
  81. * @param[in] dac the interface which should be de-initialised
  82. *
  83. * @return
  84. * - 0 on success
  85. * - EIO if an error occurred with any step
  86. */
  87. int hosal_dac_finalize(hosal_dac_dev_t *dac);
  88. /**
  89. * @brief Start output dac (no DMA mode)
  90. *
  91. * @param[in] dac the interface which should be started
  92. *
  93. * @return
  94. * - 0 on success
  95. * - EIO if an error occurred with any step
  96. */
  97. int hosal_dac_start(hosal_dac_dev_t *dac);
  98. /**
  99. * @brief Stop output dac
  100. *
  101. * @param[in] dac the interface which should be stopped
  102. *
  103. * @return
  104. * - 0 on success
  105. * - EIO if an error occurred with any step
  106. */
  107. int hosal_dac_stop(hosal_dac_dev_t *dac);
  108. /**
  109. * @brief Output a value to an dac interface
  110. *
  111. * @param[in] dac the interface to set value
  112. *
  113. * @param[in] data the value to output, output unit: μV
  114. *
  115. * @return
  116. * - 0 on success
  117. * - EIO if an error occurred with any step
  118. */
  119. int hosal_dac_set_value(hosal_dac_dev_t *dac, uint32_t data);
  120. /**
  121. * @brief Returns the last data output value of the selected dac channel
  122. *
  123. * @param[in] dac the interface to get value
  124. *
  125. * @return dac output value, output unit: μV
  126. */
  127. int hosal_dac_get_value(hosal_dac_dev_t *dac);
  128. /**
  129. * @brief DAC cb register
  130. *
  131. * @param [in] dac the DAC interface
  132. * @param [in] callback callback handler
  133. * @param [in] arg callback arg
  134. *
  135. * @return
  136. * - 0 on success
  137. * - EIO if an error occurred with any step
  138. */
  139. int hosal_dac_dma_cb_reg(hosal_dac_dev_t *dac, hosal_dac_cb_t callback, void *arg);
  140. /**
  141. * @brief DAC use DMA mode
  142. *
  143. * @param[in] adc the DAC interface
  144. * @param[in] data dac data buffer
  145. * @param[in] size data buffer size
  146. *
  147. * @return
  148. * - 0 on success
  149. * - EIO if an error occurred with any step
  150. */
  151. int hosal_dac_dma_start(hosal_dac_dev_t *dac, uint32_t *data, uint32_t size);
  152. /**
  153. * @brief Stop output dac
  154. *
  155. * @param[in] dac the interface which should be stopped
  156. *
  157. * @return
  158. * - 0 on success
  159. * - EIO if an error occurred with any step
  160. */
  161. int hosal_dac_dma_stop(hosal_dac_dev_t *dac);
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif /* __HOSAL_DAC_H_ */
  166. /* end of file */