at32f423_dac.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /**
  2. **************************************************************************
  3. * @file at32f423_dac.h
  4. * @brief at32f423 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 __AT32F423_DAC_H
  26. #define __AT32F423_DAC_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "at32f423.h"
  32. /** @addtogroup AT32F423_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_TMR3_TRGOUT_EVENT = 0x01, /*!< dac trigger selection:timer3 trgout event */
  58. DAC_TMR7_TRGOUT_EVENT = 0x02, /*!< dac trigger selection:timer7 trgout event */
  59. DAC_TMR9_TRGOUT_EVENT = 0x03, /*!< dac trigger selection:timer9 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 d1dmaudrien : 1; /* [13] */
  140. __IO uint32_t reserved1 : 2; /* [15:14] */
  141. __IO uint32_t d2en : 1; /* [16] */
  142. __IO uint32_t d2obdis : 1; /* [17] */
  143. __IO uint32_t d2trgen : 1; /* [18] */
  144. __IO uint32_t d2trgsel : 3; /* [21:19] */
  145. __IO uint32_t d2nm : 2; /* [23:22] */
  146. __IO uint32_t d2nbsel : 4; /* [27:24] */
  147. __IO uint32_t d2dmaen : 1; /* [28] */
  148. __IO uint32_t d2dmaudrien : 1; /* [29] */
  149. __IO uint32_t reserved2 : 2; /* [31:30] */
  150. } ctrl_bit;
  151. };
  152. /**
  153. * @brief dac swtrg register, offset:0x04
  154. */
  155. union
  156. {
  157. __IO uint32_t swtrg;
  158. struct
  159. {
  160. __IO uint32_t d1swtrg : 1; /* [0] */
  161. __IO uint32_t d2swtrg : 1; /* [1] */
  162. __IO uint32_t reserved1 : 30;/* [31:2] */
  163. } swtrg_bit;
  164. };
  165. /**
  166. * @brief dac d1dth12r register, offset:0x08
  167. */
  168. union
  169. {
  170. __IO uint32_t d1dth12r;
  171. struct
  172. {
  173. __IO uint32_t d1dt12r : 12;/* [11:0] */
  174. __IO uint32_t reserved1 : 20;/* [31:2] */
  175. } d1dth12r_bit;
  176. };
  177. /**
  178. * @brief dac d1dth12l register, offset:0x0C
  179. */
  180. union
  181. {
  182. __IO uint32_t d1dth12l;
  183. struct
  184. {
  185. __IO uint32_t d1dt12l : 12;/* [11:0] */
  186. __IO uint32_t reserved1 : 20;/* [31:2] */
  187. } d1dth12l_bit;
  188. };
  189. /**
  190. * @brief dac d1dth8r register, offset:0x10
  191. */
  192. union
  193. {
  194. __IO uint32_t d1dth8r;
  195. struct
  196. {
  197. __IO uint32_t d1dt8r : 8; /* [7:0] */
  198. __IO uint32_t reserved1 : 24;/* [31:8] */
  199. } d1dth8r_bit;
  200. };
  201. /**
  202. * @brief dac d2dth12r register, offset:0x14
  203. */
  204. union
  205. {
  206. __IO uint32_t d2dth12r;
  207. struct
  208. {
  209. __IO uint32_t d2dt12r : 12;/* [11:0] */
  210. __IO uint32_t reserved1 : 20;/* [31:2] */
  211. } d2dth12r_bit;
  212. };
  213. /**
  214. * @brief dac d2dth12l register, offset:0x18
  215. */
  216. union
  217. {
  218. __IO uint32_t d2dth12l;
  219. struct
  220. {
  221. __IO uint32_t d2dt12l : 12;/* [11:0] */
  222. __IO uint32_t reserved1 : 20;/* [31:2] */
  223. } d2dth12l_bit;
  224. };
  225. /**
  226. * @brief dac d2dth8r register, offset:0x1C
  227. */
  228. union
  229. {
  230. __IO uint32_t d2dth8r;
  231. struct
  232. {
  233. __IO uint32_t d2dt8r : 8; /* [7:0] */
  234. __IO uint32_t reserved1 : 24;/* [31:8] */
  235. } d2dth8r_bit;
  236. };
  237. /**
  238. * @brief dac ddth12r register, offset:0x20
  239. */
  240. union
  241. {
  242. __IO uint32_t ddth12r;
  243. struct
  244. {
  245. __IO uint32_t dd1dt12r : 12;/* [11:0] */
  246. __IO uint32_t reserved1 : 4; /* [15:12] */
  247. __IO uint32_t dd2dt12r : 12;/* [27:16] */
  248. __IO uint32_t reserved2 : 4; /* [31:28] */
  249. } ddth12r_bit;
  250. };
  251. /**
  252. * @brief dac ddth12l register, offset:0x24
  253. */
  254. union
  255. {
  256. __IO uint32_t ddth12l;
  257. struct
  258. {
  259. __IO uint32_t reserved1 : 4; /* [3:0] */
  260. __IO uint32_t dd1dt12l : 12;/* [15:4] */
  261. __IO uint32_t reserved2 : 4; /* [19:16] */
  262. __IO uint32_t dd2dt12l : 12;/* [31:20] */
  263. } ddth12l_bit;
  264. };
  265. /**
  266. * @brief dac ddth8r register, offset:0x28
  267. */
  268. union
  269. {
  270. __IO uint32_t ddth8r;
  271. struct
  272. {
  273. __IO uint32_t dd1dt8r : 8; /* [7:0] */
  274. __IO uint32_t dd2dt8r : 8; /* [15:8] */
  275. __IO uint32_t reserved1 : 16;/* [31:16] */
  276. } ddth8r_bit;
  277. };
  278. /**
  279. * @brief dac d1odt register, offset:0x2c
  280. */
  281. union
  282. {
  283. __IO uint32_t d1odt;
  284. struct
  285. {
  286. __IO uint32_t d1odt : 12;/* [11:0] */
  287. __IO uint32_t reserved1 : 20;/* [31:12] */
  288. } d1odt_bit;
  289. };
  290. /**
  291. * @brief dac d2odt register, offset:0x30
  292. */
  293. union
  294. {
  295. __IO uint32_t d2odt;
  296. struct
  297. {
  298. __IO uint32_t d2odt : 12;/* [11:0] */
  299. __IO uint32_t reserved1 : 20;/* [31:12] */
  300. } d2odt_bit;
  301. };
  302. /**
  303. * @brief dac sr register, offset:0x34
  304. */
  305. union
  306. {
  307. __IO uint32_t sts;
  308. struct
  309. {
  310. __IO uint32_t reserved1 : 13;/* [12:0] */
  311. __IO uint32_t d1dmaudrf : 1; /* [13] */
  312. __IO uint32_t reserved2 : 15;/* [28:14] */
  313. __IO uint32_t d2dmaudrf : 1; /* [29] */
  314. __IO uint32_t reserved3 : 2;/* [31:30] */
  315. } sts_bit;
  316. };
  317. } dac_type;
  318. /**
  319. * @}
  320. */
  321. #define DAC ((dac_type *) DAC_BASE)
  322. /** @defgroup DAC_exported_functions
  323. * @{
  324. */
  325. void dac_reset(void);
  326. void dac_enable(dac_select_type dac_select, confirm_state new_state);
  327. void dac_output_buffer_enable(dac_select_type dac_select, confirm_state new_state);
  328. void dac_trigger_enable(dac_select_type dac_select, confirm_state new_state);
  329. void dac_trigger_select(dac_select_type dac_select, dac_trigger_type dac_trigger_source);
  330. void dac_software_trigger_generate(dac_select_type dac_select);
  331. void dac_dual_software_trigger_generate(void);
  332. void dac_wave_generate(dac_select_type dac_select, dac_wave_type dac_wave);
  333. void dac_mask_amplitude_select(dac_select_type dac_select, dac_mask_amplitude_type dac_mask_amplitude);
  334. void dac_dma_enable(dac_select_type dac_select, confirm_state new_state);
  335. uint16_t dac_data_output_get(dac_select_type dac_select);
  336. void dac_1_data_set(dac1_aligned_data_type dac1_aligned, uint16_t dac1_data);
  337. void dac_2_data_set(dac2_aligned_data_type dac2_aligned, uint16_t dac2_data);
  338. void dac_dual_data_set(dac_dual_data_type dac_dual, uint16_t data1, uint16_t data2);
  339. void dac_udr_enable(dac_select_type dac_select, confirm_state new_state);
  340. flag_status dac_udr_flag_get(dac_select_type dac_select);
  341. void dac_udr_flag_clear(dac_select_type dac_select);
  342. /**
  343. * @}
  344. */
  345. /**
  346. * @}
  347. */
  348. /**
  349. * @}
  350. */
  351. #ifdef __cplusplus
  352. }
  353. #endif
  354. #endif