hc32l196_dac.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /******************************************************************************
  2. * Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
  3. *
  4. * This software is owned and published by:
  5. * Huada Semiconductor Co.,Ltd ("HDSC").
  6. *
  7. * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
  8. * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
  9. *
  10. * This software contains source code for use with HDSC
  11. * components. This software is licensed by HDSC to be adapted only
  12. * for use in systems utilizing HDSC components. HDSC shall not be
  13. * responsible for misuse or illegal use of this software for devices not
  14. * supported herein. HDSC is providing this software "AS IS" and will
  15. * not be responsible for issues arising from incorrect user implementation
  16. * of the software.
  17. *
  18. * Disclaimer:
  19. * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
  20. * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
  21. * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
  22. * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
  23. * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
  24. * WARRANTY OF NONINFRINGEMENT.
  25. * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
  26. * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
  27. * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
  28. * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
  29. * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
  30. * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
  31. * SAVINGS OR PROFITS,
  32. * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  33. * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
  34. * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
  35. * FROM, THE SOFTWARE.
  36. *
  37. * This software may be replicated in part or whole for the licensed use,
  38. * with the restriction that this Disclaimer and Copyright notice must be
  39. * included with each copy of this software, whether used in part or whole,
  40. * at all times.
  41. */
  42. /******************************************************************************/
  43. /** \file dac.h
  44. **
  45. ** Header file for dac Converter functions
  46. ** @link DAC Group Some description @endlink
  47. **
  48. ** - 2019-04-10 First Version
  49. **
  50. ******************************************************************************/
  51. #ifndef __DAC_H__
  52. #define __DAC_H__
  53. /******************************************************************************/
  54. /* Include files */
  55. /******************************************************************************/
  56. #include "ddl.h"
  57. /* C binding of definitions if building with C++ compiler */
  58. #ifdef __cplusplus
  59. extern "C"
  60. {
  61. #endif
  62. /**
  63. ******************************************************************************
  64. ** \brief 使能或者禁止指令
  65. ******************************************************************************/
  66. typedef enum
  67. {
  68. DacDisable = 0u, //禁止
  69. DacEnable = 1u //使能
  70. }en_en_state_t;
  71. /**
  72. ******************************************************************************
  73. ** \brief 使能或者禁止DAC0通道输出缓冲器 DAC_CR0:BOFF0
  74. ******************************************************************************/
  75. typedef enum
  76. {
  77. DacBoffDisable = 1u,
  78. DacBoffEnable = 0u
  79. }en_dac_boff_t;
  80. /**
  81. ******************************************************************************
  82. ** \brief 使能或者禁止DAC0通道触发使能 DAC_CR0: TEN0
  83. ******************************************************************************/
  84. typedef enum
  85. {
  86. DacTenDisable = 0u,
  87. DacTenEnable = 1u
  88. }en_dac_ten_t;
  89. /**
  90. ******************************************************************************
  91. ** \brief DAC0通道触发选择 DAC_CR0: TSEL0
  92. ******************************************************************************/
  93. typedef enum
  94. {
  95. DacTim0Tradc = 0u, //TIM0_TRADC触发
  96. DacTim1Tradc = 1u, //TIM1_TRADC触发
  97. DacTim2Tradc = 2u, //TIM2_TRADC触发
  98. DacTim3Tradc = 3u, //TIM3_TRADC触发
  99. DacTim4Tradc = 4u, //TIM4_TRADC触发
  100. DacTim5Tradc = 5u, //TIM5_TRADC触发
  101. DacSwTriger = 6u, //软件触发
  102. DacExPortTriger = 7u //外部端口触发
  103. }en_dac_tsel_t;
  104. /**
  105. ******************************************************************************
  106. ** \brief DAC0通道噪声/三角波生产使能或禁止 DAC_CR0: WAVE0
  107. ******************************************************************************/
  108. typedef enum
  109. {
  110. DacWaveDisable = 0u, //禁止生产波
  111. DacNoiseEnable = 1u, //使能生成噪声波
  112. DacTrWaveEnable = 2u //使能生产三角波
  113. }en_dac_wave_t;
  114. /**
  115. ******************************************************************************
  116. ** \brief DACx通道掩码/振幅选择器 DAC_CR0: MAMP0 & MAMP1
  117. ******************************************************************************/
  118. typedef enum
  119. {
  120. DacMemp01 = 0u,
  121. DacMenp03 = 1u,
  122. DacMenp07 = 2u,
  123. DacMenp15 = 3u,
  124. DacMenp31 = 4u,
  125. DacMenp63 = 5u,
  126. DacMenp127 = 6u,
  127. DacMenp255 = 7u,
  128. DacMenp511 = 8u,
  129. DacMenp1023 = 9u,
  130. DacMenp2047 = 10u,
  131. DacMenp4095 = 11u
  132. }en_dac_mamp_t;
  133. /**
  134. ******************************************************************************
  135. ** \brief DACx通道DMA使能或禁止 DAC_CR0: DMAEN0 & DMAEN1
  136. ******************************************************************************/
  137. /**
  138. ******************************************************************************
  139. ** \brief DACx通道DMA下溢中断使能或禁止 DAC_CR0: DMAUDRIE0 & DMAUDRIE1
  140. ******************************************************************************/
  141. /**
  142. ******************************************************************************
  143. ** \brief DACx参考电压选择 DAC_CR0: SREF0 & SREF1
  144. ******************************************************************************/
  145. typedef enum
  146. {
  147. DacVoltage1V5 = 0u, //内部1.5V
  148. DacVoltage2V5 = 1u, //内部2.5V
  149. DacVoltageExRef = 2u, //外部参考电压ExRef(PB01)
  150. DacVoltageAvcc = 3u //AVCC电压
  151. }en_dac_sref_t;
  152. /**
  153. ******************************************************************************
  154. ** \brief DACx触发选择寄存器DAC_ETRS DAC_ETRS
  155. ******************************************************************************/
  156. typedef enum
  157. {
  158. DacPortTrigPA9 = 0u, //触发端口为PA9
  159. DacPortTrigPB9 = 1u, //触发端口为PB9
  160. DacPortTrigPC9 = 2u, //触发端口为PC9
  161. DacPortTrigPD9 = 3u, //触发端口为PD9
  162. DacPortTrigPE9 = 4u, //触发端口为PE9
  163. DacPortTrigPF9 = 5u //触发端口为PF9
  164. }en_port_trig_t;
  165. /**
  166. ******************************************************************************
  167. ** \brief 对齐方式
  168. ******************************************************************************/
  169. typedef enum
  170. {
  171. DacRightAlign = 0u, //右对齐
  172. DacLeftAlign = 1u //左对齐
  173. }en_align_t;
  174. /**
  175. ******************************************************************************
  176. ** \brief 数据位数
  177. ******************************************************************************/
  178. typedef enum
  179. {
  180. DacBit8 = 0u, //8位
  181. DacBit12 = 1u //12位
  182. }en_bitno_t;
  183. /**
  184. ******************************************************************************
  185. ** \brief 初始化配置结构体
  186. ******************************************************************************/
  187. typedef struct
  188. {
  189. en_dac_boff_t boff_t;
  190. en_dac_ten_t ten_t;
  191. en_dac_tsel_t tsel_t;
  192. en_dac_wave_t wave_t;
  193. en_dac_mamp_t mamp_t;
  194. en_dac_sref_t sref_t;
  195. en_port_trig_t port_trig_t;
  196. en_align_t align;
  197. uint16_t dhr12;
  198. uint8_t dhr8;
  199. }stc_dac_cfg_t;
  200. extern void Dac_DmaCmd(boolean_t NewState);
  201. extern void Dac_DmaITCfg(boolean_t NewState);
  202. extern boolean_t Dac_GetITStatus(void);
  203. extern void Dac_Cmd(boolean_t NewState);
  204. extern void Dac_SoftwareTriggerCmd(void);
  205. extern void Dac_Init(stc_dac_cfg_t* DAC_InitStruct);
  206. extern void Dac_SetChannelData(en_align_t DAC_Align, en_bitno_t DAC_Bit, uint16_t Data);
  207. extern uint16_t Dac_GetDataOutputValue(void);
  208. #ifdef __cplusplus
  209. }
  210. #endif
  211. #endif //__DAC_H__
  212. /******************************************************************************/
  213. /* EOF (not truncated) */
  214. /******************************************************************************/