at32f403a_407_dac.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /**
  2. **************************************************************************
  3. * @file at32f403a_407_dac.h
  4. * @brief at32f403a_407 dac header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /* Define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F403A_407_DAC_H
  26. #define __AT32F403A_407_DAC_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "at32f403a_407.h"
  32. /** @addtogroup AT32F403A_407_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup DAC
  36. * @{
  37. */
  38. #define DAC1_D1DMAUDRF ((uint32_t)(0x00002000))
  39. #define DAC2_D2DMAUDRF ((uint32_t)(0x20000000))
  40. /** @defgroup DAC_exported_types
  41. * @{
  42. */
  43. /**
  44. * @brief dac select type
  45. */
  46. typedef enum
  47. {
  48. DAC1_SELECT = 0x01, /*!< dac1 select */
  49. DAC2_SELECT = 0x02 /*!< dac2 select */
  50. } dac_select_type;
  51. /**
  52. * @brief dac trigger type
  53. */
  54. typedef enum
  55. {
  56. DAC_TMR6_TRGOUT_EVENT = 0x00, /*!< dac trigger selection:timer6 trgout event */
  57. DAC_TMR8_TRGOUT_EVENT = 0x01, /*!< dac trigger selection:timer8 trgout event */
  58. DAC_TMR7_TRGOUT_EVENT = 0x02, /*!< dac trigger selection:timer7 trgout event */
  59. DAC_TMR5_TRGOUT_EVENT = 0x03, /*!< dac trigger selection:timer5 trgout event */
  60. DAC_TMR2_TRGOUT_EVENT = 0x04, /*!< dac trigger selection:timer2 trgout event */
  61. DAC_TMR4_TRGOUT_EVENT = 0x05, /*!< dac trigger selection:timer4 trgout event */
  62. DAC_EXTERNAL_INTERRUPT_LINE_9 = 0x06, /*!< dac trigger selection:external line9 */
  63. DAC_SOFTWARE_TRIGGER = 0x07 /*!< dac trigger selection:software trigger */
  64. } dac_trigger_type;
  65. /**
  66. * @brief dac wave type
  67. */
  68. typedef enum
  69. {
  70. DAC_WAVE_GENERATE_NONE = 0x00, /*!< dac wave generation disabled */
  71. DAC_WAVE_GENERATE_NOISE = 0x01, /*!< dac noise wave generation enabled */
  72. DAC_WAVE_GENERATE_TRIANGLE = 0x02 /*!< dac triangle wave generation enabled */
  73. } dac_wave_type;
  74. /**
  75. * @brief dac mask amplitude type
  76. */
  77. typedef enum
  78. {
  79. DAC_LSFR_BIT0_AMPLITUDE_1 = 0x00, /*!< unmask bit0/ triangle amplitude equal to 1 */
  80. DAC_LSFR_BIT10_AMPLITUDE_3 = 0x01, /*!< unmask bit[1:0]/ triangle amplitude equal to 3 */
  81. DAC_LSFR_BIT20_AMPLITUDE_7 = 0x02, /*!< unmask bit[2:0]/ triangle amplitude equal to 7 */
  82. DAC_LSFR_BIT30_AMPLITUDE_15 = 0x03, /*!< unmask bit[3:0]/ triangle amplitude equal to 15 */
  83. DAC_LSFR_BIT40_AMPLITUDE_31 = 0x04, /*!< unmask bit[4:0]/ triangle amplitude equal to 31 */
  84. DAC_LSFR_BIT50_AMPLITUDE_63 = 0x05, /*!< unmask bit[5:0]/ triangle amplitude equal to 63 */
  85. DAC_LSFR_BIT60_AMPLITUDE_127 = 0x06, /*!< unmask bit[6:0]/ triangle amplitude equal to 127 */
  86. DAC_LSFR_BIT70_AMPLITUDE_255 = 0x07, /*!< unmask bit[7:0]/ triangle amplitude equal to 255 */
  87. DAC_LSFR_BIT80_AMPLITUDE_511 = 0x08, /*!< unmask bit[8:0]/ triangle amplitude equal to 511 */
  88. DAC_LSFR_BIT90_AMPLITUDE_1023 = 0x09, /*!< unmask bit[9:0]/ triangle amplitude equal to 1023 */
  89. DAC_LSFR_BITA0_AMPLITUDE_2047 = 0x0A, /*!< unmask bit[10:0]/ triangle amplitude equal to 2047 */
  90. DAC_LSFR_BITB0_AMPLITUDE_4095 = 0x0B /*!< unmask bit[11:0]/ triangle amplitude equal to 4095 */
  91. } dac_mask_amplitude_type;
  92. /**
  93. * @brief dac1 aligned data type
  94. */
  95. typedef enum
  96. {
  97. DAC1_12BIT_RIGHT = 0x40007408, /*!< dac1 12-bit data right-aligned */
  98. DAC1_12BIT_LEFT = 0x4000740C, /*!< dac1 12-bit data left-aligned */
  99. DAC1_8BIT_RIGHT = 0x40007410 /*!< dac1 8-bit data right-aligned */
  100. } dac1_aligned_data_type;
  101. /**
  102. * @brief dac2 aligned data type
  103. */
  104. typedef enum
  105. {
  106. DAC2_12BIT_RIGHT = 0x40007414, /*!< dac2 12-bit data right-aligned */
  107. DAC2_12BIT_LEFT = 0x40007418, /*!< dac2 12-bit data left-aligned */
  108. DAC2_8BIT_RIGHT = 0x4000741C /*!< dac2 8-bit data right-aligned */
  109. } dac2_aligned_data_type;
  110. /**
  111. * @brief dac dual data type
  112. */
  113. typedef enum
  114. {
  115. DAC_DUAL_12BIT_RIGHT = 0x40007420, /*!<double dac 12-bit data right-aligned */
  116. DAC_DUAL_12BIT_LEFT = 0x40007424, /*!<double dac 12-bit data left-aligned */
  117. DAC_DUAL_8BIT_RIGHT = 0x40007428 /*!<double dac 8-bit data right-aligned */
  118. } dac_dual_data_type;
  119. /**
  120. * @brief type define dac register all
  121. */
  122. typedef struct
  123. {
  124. /**
  125. * @brief dac ctrl register, offset:0x00
  126. */
  127. union
  128. {
  129. __IO uint32_t ctrl;
  130. struct
  131. {
  132. __IO uint32_t d1en : 1; /* [0] */
  133. __IO uint32_t d1obdis : 1; /* [1] */
  134. __IO uint32_t d1trgen : 1; /* [2] */
  135. __IO uint32_t d1trgsel : 3; /* [5:3] */
  136. __IO uint32_t d1nm : 2; /* [7:6] */
  137. __IO uint32_t d1nbsel : 4; /* [11:8] */
  138. __IO uint32_t d1dmaen : 1; /* [12] */
  139. __IO uint32_t reserved1 : 3; /* [15:13] */
  140. __IO uint32_t d2en : 1; /* [16] */
  141. __IO uint32_t d2obdis : 1; /* [17] */
  142. __IO uint32_t d2trgen : 1; /* [18] */
  143. __IO uint32_t d2trgsel : 3; /* [21:19] */
  144. __IO uint32_t d2nm : 2; /* [23:22] */
  145. __IO uint32_t d2nbsel : 4; /* [27:24] */
  146. __IO uint32_t d2dmaen : 1; /* [28] */
  147. __IO uint32_t reserved2 : 3; /* [31:29] */
  148. } ctrl_bit;
  149. };
  150. /**
  151. * @brief dac swtrg register, offset:0x04
  152. */
  153. union
  154. {
  155. __IO uint32_t swtrg;
  156. struct
  157. {
  158. __IO uint32_t d1swtrg : 1; /* [0] */
  159. __IO uint32_t d2swtrg : 1; /* [1] */
  160. __IO uint32_t reserved1 : 30;/* [31:2] */
  161. } swtrg_bit;
  162. };
  163. /**
  164. * @brief dac d1dth12r register, offset:0x08
  165. */
  166. union
  167. {
  168. __IO uint32_t d1dth12r;
  169. struct
  170. {
  171. __IO uint32_t d1dt12r : 12;/* [11:0] */
  172. __IO uint32_t reserved1 : 20;/* [31:2] */
  173. } d1dth12r_bit;
  174. };
  175. /**
  176. * @brief dac d1dth12l register, offset:0x0C
  177. */
  178. union
  179. {
  180. __IO uint32_t d1dth12l;
  181. struct
  182. {
  183. __IO uint32_t d1dt12l : 12;/* [11:0] */
  184. __IO uint32_t reserved1 : 20;/* [31:2] */
  185. } d1dth12l_bit;
  186. };
  187. /**
  188. * @brief dac d1dth8r register, offset:0x10
  189. */
  190. union
  191. {
  192. __IO uint32_t d1dth8r;
  193. struct
  194. {
  195. __IO uint32_t d1dt8r : 8; /* [7:0] */
  196. __IO uint32_t reserved1 : 24;/* [31:8] */
  197. } d1dth8r_bit;
  198. };
  199. /**
  200. * @brief dac d2dth12r register, offset:0x14
  201. */
  202. union
  203. {
  204. __IO uint32_t d2dth12r;
  205. struct
  206. {
  207. __IO uint32_t d2dt12r : 12;/* [11:0] */
  208. __IO uint32_t reserved1 : 20;/* [31:2] */
  209. } d2dth12r_bit;
  210. };
  211. /**
  212. * @brief dac d2dth12l register, offset:0x18
  213. */
  214. union
  215. {
  216. __IO uint32_t d2dth12l;
  217. struct
  218. {
  219. __IO uint32_t d2dt12l : 12;/* [11:0] */
  220. __IO uint32_t reserved1 : 20;/* [31:2] */
  221. } d2dth12l_bit;
  222. };
  223. /**
  224. * @brief dac d2dth8r register, offset:0x1C
  225. */
  226. union
  227. {
  228. __IO uint32_t d2dth8r;
  229. struct
  230. {
  231. __IO uint32_t d2dt8r : 8; /* [7:0] */
  232. __IO uint32_t reserved1 : 24;/* [31:8] */
  233. } d2dth8r_bit;
  234. };
  235. /**
  236. * @brief dac ddth12r register, offset:0x20
  237. */
  238. union
  239. {
  240. __IO uint32_t ddth12r;
  241. struct
  242. {
  243. __IO uint32_t dd1dt12r : 12;/* [11:0] */
  244. __IO uint32_t reserved1 : 4; /* [15:12] */
  245. __IO uint32_t dd2dt12r : 12;/* [27:16] */
  246. __IO uint32_t reserved2 : 4; /* [31:28] */
  247. } ddth12r_bit;
  248. };
  249. /**
  250. * @brief dac ddth12l register, offset:0x24
  251. */
  252. union
  253. {
  254. __IO uint32_t ddth12l;
  255. struct
  256. {
  257. __IO uint32_t reserved1 : 4; /* [3:0] */
  258. __IO uint32_t dd1dt12l : 12;/* [15:4] */
  259. __IO uint32_t reserved2 : 4; /* [19:16] */
  260. __IO uint32_t dd2dt12l : 12;/* [31:20] */
  261. } ddth12l_bit;
  262. };
  263. /**
  264. * @brief dac ddth8r register, offset:0x28
  265. */
  266. union
  267. {
  268. __IO uint32_t ddth8r;
  269. struct
  270. {
  271. __IO uint32_t dd1dt8r : 8; /* [7:0] */
  272. __IO uint32_t dd2dt8r : 8; /* [15:8] */
  273. __IO uint32_t reserved1 : 16;/* [31:16] */
  274. } ddth8r_bit;
  275. };
  276. /**
  277. * @brief dac d1odt register, offset:0x2c
  278. */
  279. union
  280. {
  281. __IO uint32_t d1odt;
  282. struct
  283. {
  284. __IO uint32_t d1odt : 12;/* [11:0] */
  285. __IO uint32_t reserved1 : 20;/* [31:12] */
  286. } d1odt_bit;
  287. };
  288. /**
  289. * @brief dac d2odt register, offset:0x30
  290. */
  291. union
  292. {
  293. __IO uint32_t d2odt;
  294. struct
  295. {
  296. __IO uint32_t d2odt : 12;/* [11:0] */
  297. __IO uint32_t reserved1 : 20;/* [31:12] */
  298. } d2odt_bit;
  299. };
  300. } dac_type;
  301. /**
  302. * @}
  303. */
  304. #define DAC ((dac_type *) DAC_BASE)
  305. /** @defgroup DAC_exported_functions
  306. * @{
  307. */
  308. void dac_reset(void);
  309. void dac_enable(dac_select_type dac_select, confirm_state new_state);
  310. void dac_output_buffer_enable(dac_select_type dac_select, confirm_state new_state);
  311. void dac_trigger_enable(dac_select_type dac_select, confirm_state new_state);
  312. void dac_trigger_select(dac_select_type dac_select, dac_trigger_type dac_trigger_source);
  313. void dac_software_trigger_generate(dac_select_type dac_select);
  314. void dac_dual_software_trigger_generate(void);
  315. void dac_wave_generate(dac_select_type dac_select, dac_wave_type dac_wave);
  316. void dac_mask_amplitude_select(dac_select_type dac_select, dac_mask_amplitude_type dac_mask_amplitude);
  317. void dac_dma_enable(dac_select_type dac_select, confirm_state new_state);
  318. uint16_t dac_data_output_get(dac_select_type dac_select);
  319. void dac_1_data_set(dac1_aligned_data_type dac1_aligned, uint16_t dac1_data);
  320. void dac_2_data_set(dac2_aligned_data_type dac2_aligned, uint16_t dac2_data);
  321. void dac_dual_data_set(dac_dual_data_type dac_dual, uint16_t data1, uint16_t data2);
  322. /**
  323. * @}
  324. */
  325. /**
  326. * @}
  327. */
  328. /**
  329. * @}
  330. */
  331. #ifdef __cplusplus
  332. }
  333. #endif
  334. #endif