n32g45x_dac.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_dac.h
  29. * @author Nations
  30. * @version v1.0.1
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __N32G45X_DAC_H__
  35. #define __N32G45X_DAC_H__
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include "n32g45x.h"
  40. /** @addtogroup N32G45X_StdPeriph_Driver
  41. * @{
  42. */
  43. /** @addtogroup DAC
  44. * @{
  45. */
  46. /** @addtogroup DAC_Exported_Types
  47. * @{
  48. */
  49. /**
  50. * @brief DAC Init structure definition
  51. */
  52. typedef struct
  53. {
  54. uint32_t Trigger; /*!< Specifies the external trigger for the selected DAC channel.
  55. This parameter can be a value of @ref DAC_trigger_selection */
  56. uint32_t WaveGen; /*!< Specifies whether DAC channel noise waves or triangle waves
  57. are generated, or whether no wave is generated.
  58. This parameter can be a value of @ref DAC_wave_generation */
  59. uint32_t
  60. LfsrUnMaskTriAmp; /*!< Specifies the LFSR mask for noise wave generation or
  61. the maximum amplitude triangle generation for the DAC channel.
  62. This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
  63. uint32_t BufferOutput; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  64. This parameter can be a value of @ref DAC_output_buffer */
  65. } DAC_InitType;
  66. /**
  67. * @}
  68. */
  69. /** @addtogroup DAC_Exported_Constants
  70. * @{
  71. */
  72. /** @addtogroup DAC_trigger_selection
  73. * @{
  74. */
  75. #define DAC_TRG_NONE \
  76. ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register \
  77. has been loaded, and not by external trigger */
  78. #define DAC_TRG_T6_TRGO \
  79. ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel \
  80. */
  81. #define DAC_TRG_T8_TRGO \
  82. ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel \
  83. only in High-density devices*/
  84. #define DAC_TRG_T3_TRGO \
  85. ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel \
  86. only in Connectivity line, Medium-density and Low-density Value Line devices */
  87. #define DAC_TRG_T7_TRGO \
  88. ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel \
  89. */
  90. #define DAC_TRG_T5_TRGO \
  91. ((uint32_t)0x0000001C) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel \
  92. */
  93. #define DAC_TRG_T15_TRGO \
  94. ((uint32_t)0x0000001C) /*!< TIM15 TRGO selected as external conversion trigger for DAC channel \
  95. only in Medium-density and Low-density Value Line devices*/
  96. #define DAC_TRG_T2_TRGO \
  97. ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel \
  98. */
  99. #define DAC_TRG_T4_TRGO \
  100. ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel \
  101. */
  102. #define DAC_TRG_EXT_IT9 \
  103. ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
  104. #define DAC_TRG_SOFTWARE ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC channel */
  105. #define IS_DAC_TRIGGER(TRIGGER) \
  106. (((TRIGGER) == DAC_TRG_NONE) || ((TRIGGER) == DAC_TRG_T6_TRGO) || ((TRIGGER) == DAC_TRG_T8_TRGO) \
  107. || ((TRIGGER) == DAC_TRG_T7_TRGO) || ((TRIGGER) == DAC_TRG_T5_TRGO) || ((TRIGGER) == DAC_TRG_T2_TRGO) \
  108. || ((TRIGGER) == DAC_TRG_T4_TRGO) || ((TRIGGER) == DAC_TRG_EXT_IT9) || ((TRIGGER) == DAC_TRG_SOFTWARE))
  109. /**
  110. * @}
  111. */
  112. /** @addtogroup DAC_wave_generation
  113. * @{
  114. */
  115. #define DAC_WAVEGEN_NONE ((uint32_t)0x00000000)
  116. #define DAC_WAVEGEN_NOISE ((uint32_t)0x00000040)
  117. #define DAC_WAVEGEN_TRIANGLE ((uint32_t)0x00000080)
  118. #define IS_DAC_GENERATE_WAVE(WAVE) \
  119. (((WAVE) == DAC_WAVEGEN_NONE) || ((WAVE) == DAC_WAVEGEN_NOISE) || ((WAVE) == DAC_WAVEGEN_TRIANGLE))
  120. /**
  121. * @}
  122. */
  123. /** @addtogroup DAC_lfsrunmask_triangleamplitude
  124. * @{
  125. */
  126. #define DAC_UNMASK_LFSRBIT0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
  127. #define DAC_UNMASK_LFSRBITS1_0 \
  128. ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation \
  129. */
  130. #define DAC_UNMASK_LFSRBITS2_0 \
  131. ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation \
  132. */
  133. #define DAC_UNMASK_LFSRBITS3_0 \
  134. ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation \
  135. */
  136. #define DAC_UNMASK_LFSRBITS4_0 \
  137. ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation \
  138. */
  139. #define DAC_UNMASK_LFSRBITS5_0 \
  140. ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation \
  141. */
  142. #define DAC_UNMASK_LFSRBITS6_0 \
  143. ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation \
  144. */
  145. #define DAC_UNMASK_LFSRBITS7_0 \
  146. ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation \
  147. */
  148. #define DAC_UNMASK_LFSRBITS8_0 \
  149. ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation \
  150. */
  151. #define DAC_UNMASK_LFSRBITS9_0 \
  152. ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation \
  153. */
  154. #define DAC_UNMASK_LFSRBITS10_0 \
  155. ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
  156. #define DAC_UNMASK_LFSRBITS11_0 \
  157. ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
  158. #define DAC_TRIAMP_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
  159. #define DAC_TRIAMP_3 ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
  160. #define DAC_TRIAMP_7 ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
  161. #define DAC_TRIAMP_15 ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
  162. #define DAC_TRIAMP_31 ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
  163. #define DAC_TRIAMP_63 ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
  164. #define DAC_TRIAMP_127 ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
  165. #define DAC_TRIAMP_255 ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
  166. #define DAC_TRIAMP_511 ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
  167. #define DAC_TRIAMP_1023 ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
  168. #define DAC_TRIAMP_2047 ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
  169. #define DAC_TRIAMP_4095 ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
  170. #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) \
  171. (((VALUE) == DAC_UNMASK_LFSRBIT0) || ((VALUE) == DAC_UNMASK_LFSRBITS1_0) || ((VALUE) == DAC_UNMASK_LFSRBITS2_0) \
  172. || ((VALUE) == DAC_UNMASK_LFSRBITS3_0) || ((VALUE) == DAC_UNMASK_LFSRBITS4_0) \
  173. || ((VALUE) == DAC_UNMASK_LFSRBITS5_0) || ((VALUE) == DAC_UNMASK_LFSRBITS6_0) \
  174. || ((VALUE) == DAC_UNMASK_LFSRBITS7_0) || ((VALUE) == DAC_UNMASK_LFSRBITS8_0) \
  175. || ((VALUE) == DAC_UNMASK_LFSRBITS9_0) || ((VALUE) == DAC_UNMASK_LFSRBITS10_0) \
  176. || ((VALUE) == DAC_UNMASK_LFSRBITS11_0) || ((VALUE) == DAC_TRIAMP_1) || ((VALUE) == DAC_TRIAMP_3) \
  177. || ((VALUE) == DAC_TRIAMP_7) || ((VALUE) == DAC_TRIAMP_15) || ((VALUE) == DAC_TRIAMP_31) \
  178. || ((VALUE) == DAC_TRIAMP_63) || ((VALUE) == DAC_TRIAMP_127) || ((VALUE) == DAC_TRIAMP_255) \
  179. || ((VALUE) == DAC_TRIAMP_511) || ((VALUE) == DAC_TRIAMP_1023) || ((VALUE) == DAC_TRIAMP_2047) \
  180. || ((VALUE) == DAC_TRIAMP_4095))
  181. /**
  182. * @}
  183. */
  184. /** @addtogroup DAC_output_buffer
  185. * @{
  186. */
  187. #define DAC_BUFFOUTPUT_ENABLE ((uint32_t)0x00000002)
  188. #define DAC_BUFFOUTPUT_DISABLE ((uint32_t)0x00000000)
  189. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_BUFFOUTPUT_ENABLE) || ((STATE) == DAC_BUFFOUTPUT_DISABLE))
  190. /**
  191. * @}
  192. */
  193. /** @addtogroup DAC_Channel_selection
  194. * @{
  195. */
  196. #define DAC_CHANNEL_1 ((uint32_t)0x00000000)
  197. #define DAC_CHANNEL_2 ((uint32_t)0x00000010)
  198. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || ((CHANNEL) == DAC_CHANNEL_2))
  199. /**
  200. * @}
  201. */
  202. /** @addtogroup DAC_data_alignment
  203. * @{
  204. */
  205. #define DAC_ALIGN_R_12BIT ((uint32_t)0x00000000)
  206. #define DAC_ALIGN_L_12BIT ((uint32_t)0x00000004)
  207. #define DAC_ALIGN_R_8BIT ((uint32_t)0x00000008)
  208. #define IS_DAC_ALIGN(ALIGN) \
  209. (((ALIGN) == DAC_ALIGN_R_12BIT) || ((ALIGN) == DAC_ALIGN_L_12BIT) || ((ALIGN) == DAC_ALIGN_R_8BIT))
  210. /**
  211. * @}
  212. */
  213. /** @addtogroup DAC_wave_generation
  214. * @{
  215. */
  216. #define DAC_WAVE_NOISE ((uint32_t)0x00000040)
  217. #define DAC_WAVE_TRIANGLE ((uint32_t)0x00000080)
  218. #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_WAVE_NOISE) || ((WAVE) == DAC_WAVE_TRIANGLE))
  219. /**
  220. * @}
  221. */
  222. /** @addtogroup DAC_data
  223. * @{
  224. */
  225. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
  226. /**
  227. * @}
  228. */
  229. /**
  230. * @}
  231. */
  232. /** @addtogroup DAC_Exported_Macros
  233. * @{
  234. */
  235. /**
  236. * @}
  237. */
  238. /** @addtogroup DAC_Exported_Functions
  239. * @{
  240. */
  241. void DAC_DeInit(void);
  242. void DAC_Init(uint32_t DAC_Channel, DAC_InitType* DAC_InitStruct);
  243. void DAC_ClearStruct(DAC_InitType* DAC_InitStruct);
  244. void DAC_Enable(uint32_t DAC_Channel, FunctionalState Cmd);
  245. void DAC_DmaEnable(uint32_t DAC_Channel, FunctionalState Cmd);
  246. void DAC_SoftTrgEnable(uint32_t DAC_Channel, FunctionalState Cmd);
  247. void DAC_DualSoftwareTrgEnable(FunctionalState Cmd);
  248. void DAC_WaveGenerationEnable(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState Cmd);
  249. void DAC_SetCh1Data(uint32_t DAC_Align, uint16_t Data);
  250. void DAC_SetCh2Data(uint32_t DAC_Align, uint16_t Data);
  251. void DAC_SetDualChData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
  252. uint16_t DAC_GetOutputDataVal(uint32_t DAC_Channel);
  253. #ifdef __cplusplus
  254. }
  255. #endif
  256. #endif /*__N32G45X_DAC_H__ */
  257. /**
  258. * @}
  259. */
  260. /**
  261. * @}
  262. */
  263. /**
  264. * @}
  265. */