at32f423_adc.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. /**
  2. **************************************************************************
  3. * @file at32f423_adc.h
  4. * @brief at32f423 adc 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_ADC_H
  26. #define __AT32F423_ADC_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "at32f423.h"
  32. /** @addtogroup AT32F423_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup ADC
  36. * @{
  37. */
  38. /** @defgroup ADC_interrupts_definition
  39. * @brief adc interrupt
  40. * @{
  41. */
  42. #define ADC_OCCE_INT ((uint32_t)0x00000020) /*!< ordinary channels conversion end interrupt */
  43. #define ADC_VMOR_INT ((uint32_t)0x00000040) /*!< voltage monitoring out of range interrupt */
  44. #define ADC_PCCE_INT ((uint32_t)0x00000080) /*!< preempt channels conversion end interrupt */
  45. #define ADC_OCCO_INT ((uint32_t)0x04000000) /*!< ordinary channel conversion overflow interrupt */
  46. /**
  47. * @}
  48. */
  49. /** @defgroup ADC_flags_definition
  50. * @brief adc flag
  51. * @{
  52. */
  53. #define ADC_VMOR_FLAG ((uint8_t)0x01) /*!< voltage monitoring out of range flag */
  54. #define ADC_OCCE_FLAG ((uint8_t)0x02) /*!< ordinary channels conversion end flag */
  55. #define ADC_PCCE_FLAG ((uint8_t)0x04) /*!< preempt channels conversion end flag */
  56. #define ADC_PCCS_FLAG ((uint8_t)0x08) /*!< preempt channel conversion start flag */
  57. #define ADC_OCCS_FLAG ((uint8_t)0x10) /*!< ordinary channel conversion start flag */
  58. #define ADC_OCCO_FLAG ((uint8_t)0x20) /*!< ordinary channel conversion overflow flag */
  59. #define ADC_RDY_FLAG ((uint8_t)0x40) /*!< adc ready to conversion flag */
  60. /**
  61. * @}
  62. */
  63. /** @defgroup ADC_exported_types
  64. * @{
  65. */
  66. /**
  67. * @brief adc division type
  68. */
  69. typedef enum
  70. {
  71. ADC_HCLK_DIV_2 = 0x00, /*!< adcclk is hclk/2 */
  72. ADC_HCLK_DIV_3 = 0x01, /*!< adcclk is hclk/3 */
  73. ADC_HCLK_DIV_4 = 0x02, /*!< adcclk is hclk/4 */
  74. ADC_HCLK_DIV_5 = 0x03, /*!< adcclk is hclk/5 */
  75. ADC_HCLK_DIV_6 = 0x04, /*!< adcclk is hclk/6 */
  76. ADC_HCLK_DIV_7 = 0x05, /*!< adcclk is hclk/7 */
  77. ADC_HCLK_DIV_8 = 0x06, /*!< adcclk is hclk/8 */
  78. ADC_HCLK_DIV_9 = 0x07, /*!< adcclk is hclk/9 */
  79. ADC_HCLK_DIV_10 = 0x08, /*!< adcclk is hclk/10 */
  80. ADC_HCLK_DIV_11 = 0x09, /*!< adcclk is hclk/11 */
  81. ADC_HCLK_DIV_12 = 0x0A, /*!< adcclk is hclk/12 */
  82. ADC_HCLK_DIV_13 = 0x0B, /*!< adcclk is hclk/13 */
  83. ADC_HCLK_DIV_14 = 0x0C, /*!< adcclk is hclk/14 */
  84. ADC_HCLK_DIV_15 = 0x0D, /*!< adcclk is hclk/15 */
  85. ADC_HCLK_DIV_16 = 0x0E, /*!< adcclk is hclk/16 */
  86. ADC_HCLK_DIV_17 = 0x0F /*!< adcclk is hclk/17 */
  87. } adc_div_type;
  88. /**
  89. * @brief adc conversion resolution type
  90. */
  91. typedef enum
  92. {
  93. ADC_RESOLUTION_12B = 0x00, /*!< conversion resolution 12 bit */
  94. ADC_RESOLUTION_10B = 0x01, /*!< conversion resolution 10 bit */
  95. ADC_RESOLUTION_8B = 0x02, /*!< conversion resolution 8 bit */
  96. ADC_RESOLUTION_6B = 0x03 /*!< conversion resolution 6 bit */
  97. } adc_resolution_type;
  98. /**
  99. * @brief adc data align type
  100. */
  101. typedef enum
  102. {
  103. ADC_RIGHT_ALIGNMENT = 0x00, /*!< data right alignment */
  104. ADC_LEFT_ALIGNMENT = 0x01 /*!< data left alignment */
  105. } adc_data_align_type;
  106. /**
  107. * @brief adc channel select type
  108. */
  109. typedef enum
  110. {
  111. ADC_CHANNEL_0 = 0x00, /*!< adc channel 0 */
  112. ADC_CHANNEL_1 = 0x01, /*!< adc channel 1 */
  113. ADC_CHANNEL_2 = 0x02, /*!< adc channel 2 */
  114. ADC_CHANNEL_3 = 0x03, /*!< adc channel 3 */
  115. ADC_CHANNEL_4 = 0x04, /*!< adc channel 4 */
  116. ADC_CHANNEL_5 = 0x05, /*!< adc channel 5 */
  117. ADC_CHANNEL_6 = 0x06, /*!< adc channel 6 */
  118. ADC_CHANNEL_7 = 0x07, /*!< adc channel 7 */
  119. ADC_CHANNEL_8 = 0x08, /*!< adc channel 8 */
  120. ADC_CHANNEL_9 = 0x09, /*!< adc channel 9 */
  121. ADC_CHANNEL_10 = 0x0A, /*!< adc channel 10 */
  122. ADC_CHANNEL_11 = 0x0B, /*!< adc channel 11 */
  123. ADC_CHANNEL_12 = 0x0C, /*!< adc channel 12 */
  124. ADC_CHANNEL_13 = 0x0D, /*!< adc channel 13 */
  125. ADC_CHANNEL_14 = 0x0E, /*!< adc channel 14 */
  126. ADC_CHANNEL_15 = 0x0F, /*!< adc channel 15 */
  127. ADC_CHANNEL_16 = 0x10, /*!< adc channel 16 */
  128. ADC_CHANNEL_17 = 0x11, /*!< adc channel 17 */
  129. ADC_CHANNEL_20 = 0x14, /*!< adc channel 20 */
  130. ADC_CHANNEL_21 = 0x15, /*!< adc channel 21 */
  131. ADC_CHANNEL_22 = 0x16, /*!< adc channel 22 */
  132. ADC_CHANNEL_23 = 0x17, /*!< adc channel 23 */
  133. ADC_CHANNEL_24 = 0x18, /*!< adc channel 24 */
  134. ADC_CHANNEL_25 = 0x19, /*!< adc channel 25 */
  135. ADC_CHANNEL_26 = 0x1A, /*!< adc channel 26 */
  136. ADC_CHANNEL_27 = 0x1B /*!< adc channel 27 */
  137. } adc_channel_select_type;
  138. /**
  139. * @brief adc sampletime select type
  140. */
  141. typedef enum
  142. {
  143. ADC_SAMPLETIME_2_5 = 0x00, /*!< adc sample time 2.5 cycle */
  144. ADC_SAMPLETIME_6_5 = 0x01, /*!< adc sample time 6.5 cycle */
  145. ADC_SAMPLETIME_12_5 = 0x02, /*!< adc sample time 12.5 cycle */
  146. ADC_SAMPLETIME_24_5 = 0x03, /*!< adc sample time 24.5 cycle */
  147. ADC_SAMPLETIME_47_5 = 0x04, /*!< adc sample time 47.5 cycle */
  148. ADC_SAMPLETIME_92_5 = 0x05, /*!< adc sample time 92.5 cycle */
  149. ADC_SAMPLETIME_247_5 = 0x06, /*!< adc sample time 247.5 cycle */
  150. ADC_SAMPLETIME_640_5 = 0x07 /*!< adc sample time 640.5 cycle */
  151. } adc_sampletime_select_type;
  152. /**
  153. * @brief adc ordinary group trigger event select type
  154. */
  155. typedef enum
  156. {
  157. ADC_ORDINARY_TRIG_TMR1TRGOUT = 0x00, /*!< timer1 trgout event as trigger source of ordinary sequence */
  158. ADC_ORDINARY_TRIG_TMR1CH4 = 0x01, /*!< timer1 ch4 event as trigger source of ordinary sequence */
  159. ADC_ORDINARY_TRIG_TMR2TRGOUT = 0x02, /*!< timer2 trgout event as trigger source of ordinary sequence */
  160. ADC_ORDINARY_TRIG_TMR3TRGOUT = 0x03, /*!< timer3 trgout event as trigger source of ordinary sequence */
  161. ADC_ORDINARY_TRIG_TMR9TRGOUT = 0x04, /*!< timer9 trgout event as trigger source of ordinary sequence */
  162. ADC_ORDINARY_TRIG_TMR1CH1 = 0x05, /*!< timer1 ch1 event as trigger source of ordinary sequence */
  163. ADC_ORDINARY_TRIG_EXINT11 = 0x06, /*!< exint line11 event as trigger source of ordinary sequence */
  164. ADC_ORDINARY_TRIG_SOFTWARE = 0x07 /*!< software(OCSWTRG) as trigger source of ordinary sequence */
  165. } adc_ordinary_trig_select_type;
  166. /**
  167. * @brief adc ordinary channel conversion's external_trigger_edge type
  168. */
  169. typedef enum
  170. {
  171. ADC_ORDINARY_TRIG_EDGE_NONE = 0x00, /*!< ordinary channels trigger detection disabled */
  172. ADC_ORDINARY_TRIG_EDGE_RISING = 0x01, /*!< ordinary channels trigger detection on the rising edge */
  173. ADC_ORDINARY_TRIG_EDGE_FALLING = 0x02, /*!< ordinary channels trigger detection on the falling edge */
  174. ADC_ORDINARY_TRIG_EDGE_RISING_FALLING = 0x03 /*!< ordinary channels trigger detection on both the rising and falling edges */
  175. } adc_ordinary_trig_edge_type;
  176. /**
  177. * @brief adc preempt group external trigger event select type
  178. */
  179. typedef enum
  180. {
  181. ADC_PREEMPT_TRIG_TMR1CH2 = 0x00, /*!< timer1 ch2 event as trigger source of preempt sequence */
  182. ADC_PREEMPT_TRIG_TMR1CH3 = 0x01, /*!< timer1 ch3 event as trigger source of preempt sequence */
  183. ADC_PREEMPT_TRIG_TMR2CH4 = 0x02, /*!< timer2 ch4 event as trigger source of preempt sequence */
  184. ADC_PREEMPT_TRIG_TMR3CH4 = 0x03, /*!< timer3 ch4 event as trigger source of preempt sequence */
  185. ADC_PREEMPT_TRIG_TMR9CH1 = 0x04, /*!< timer9 ch1 event as trigger source of preempt sequence */
  186. ADC_PREEMPT_TRIG_TMR6TRGOUT = 0x05, /*!< timer6 trgout event as trigger source of preempt sequence */
  187. ADC_PREEMPT_TRIG_EXINT15 = 0x06, /*!< exint line15 event as trigger source of preempt sequence */
  188. ADC_PREEMPT_TRIG_SOFTWARE = 0x07 /*!< software(PCSWTRG) as trigger source of preempt sequence */
  189. } adc_preempt_trig_select_type;
  190. /**
  191. * @brief adc preempt channel conversion's external_trigger_edge type
  192. */
  193. typedef enum
  194. {
  195. ADC_PREEMPT_TRIG_EDGE_NONE = 0x00, /*!< preempt channels trigger detection disabled */
  196. ADC_PREEMPT_TRIG_EDGE_RISING = 0x01, /*!< preempt channels trigger detection on the rising edge */
  197. ADC_PREEMPT_TRIG_EDGE_FALLING = 0x02, /*!< preempt channels trigger detection on the falling edge */
  198. ADC_PREEMPT_TRIG_EDGE_RISING_FALLING = 0x03 /*!< preempt channels trigger detection on both the rising and falling edges */
  199. } adc_preempt_trig_edge_type;
  200. /**
  201. * @brief adc preempt channel type
  202. */
  203. typedef enum
  204. {
  205. ADC_PREEMPT_CHANNEL_1 = 0x00, /*!< adc preempt channel 1 */
  206. ADC_PREEMPT_CHANNEL_2 = 0x01, /*!< adc preempt channel 2 */
  207. ADC_PREEMPT_CHANNEL_3 = 0x02, /*!< adc preempt channel 3 */
  208. ADC_PREEMPT_CHANNEL_4 = 0x03 /*!< adc preempt channel 4 */
  209. } adc_preempt_channel_type;
  210. /**
  211. * @brief adc voltage_monitoring type
  212. */
  213. typedef enum
  214. {
  215. ADC_VMONITOR_SINGLE_ORDINARY = 0x00800200, /*!< voltage_monitoring on a single ordinary channel */
  216. ADC_VMONITOR_SINGLE_PREEMPT = 0x00400200, /*!< voltage_monitoring on a single preempt channel */
  217. ADC_VMONITOR_SINGLE_ORDINARY_PREEMPT = 0x00C00200, /*!< voltage_monitoring on a single ordinary or preempt channel */
  218. ADC_VMONITOR_ALL_ORDINARY = 0x00800000, /*!< voltage_monitoring on all ordinary channel */
  219. ADC_VMONITOR_ALL_PREEMPT = 0x00400000, /*!< voltage_monitoring on all preempt channel */
  220. ADC_VMONITOR_ALL_ORDINARY_PREEMPT = 0x00C00000, /*!< voltage_monitoring on all ordinary and preempt channel */
  221. ADC_VMONITOR_NONE = 0x00000000 /*!< no channel guarded by the voltage_monitoring */
  222. } adc_voltage_monitoring_type;
  223. /**
  224. * @brief adc oversample ratio type
  225. */
  226. typedef enum
  227. {
  228. ADC_OVERSAMPLE_RATIO_2 = 0x00, /*!< adc oversample ratio 2 */
  229. ADC_OVERSAMPLE_RATIO_4 = 0x01, /*!< adc oversample ratio 4 */
  230. ADC_OVERSAMPLE_RATIO_8 = 0x02, /*!< adc oversample ratio 8 */
  231. ADC_OVERSAMPLE_RATIO_16 = 0x03, /*!< adc oversample ratio 16 */
  232. ADC_OVERSAMPLE_RATIO_32 = 0x04, /*!< adc oversample ratio 32 */
  233. ADC_OVERSAMPLE_RATIO_64 = 0x05, /*!< adc oversample ratio 64 */
  234. ADC_OVERSAMPLE_RATIO_128 = 0x06, /*!< adc oversample ratio 128 */
  235. ADC_OVERSAMPLE_RATIO_256 = 0x07 /*!< adc oversample ratio 256 */
  236. } adc_oversample_ratio_type;
  237. /**
  238. * @brief adc oversample shift type
  239. */
  240. typedef enum
  241. {
  242. ADC_OVERSAMPLE_SHIFT_0 = 0x00, /*!< adc oversample shift 0 */
  243. ADC_OVERSAMPLE_SHIFT_1 = 0x01, /*!< adc oversample shift 1 */
  244. ADC_OVERSAMPLE_SHIFT_2 = 0x02, /*!< adc oversample shift 2 */
  245. ADC_OVERSAMPLE_SHIFT_3 = 0x03, /*!< adc oversample shift 3 */
  246. ADC_OVERSAMPLE_SHIFT_4 = 0x04, /*!< adc oversample shift 4 */
  247. ADC_OVERSAMPLE_SHIFT_5 = 0x05, /*!< adc oversample shift 5 */
  248. ADC_OVERSAMPLE_SHIFT_6 = 0x06, /*!< adc oversample shift 6 */
  249. ADC_OVERSAMPLE_SHIFT_7 = 0x07, /*!< adc oversample shift 7 */
  250. ADC_OVERSAMPLE_SHIFT_8 = 0x08 /*!< adc oversample shift 8 */
  251. } adc_oversample_shift_type;
  252. /**
  253. * @brief adc ordinary oversample recover type
  254. */
  255. typedef enum
  256. {
  257. ADC_OVERSAMPLE_CONTINUE = 0x00, /*!< continue mode:when preempt triggered,oversampling is temporary stopped and continued after preempt sequence */
  258. ADC_OVERSAMPLE_RESTART = 0x01 /*!< restart mode:when preempt triggered,oversampling is aborted and resumed from start after preempt sequence */
  259. } adc_ordinary_oversample_restart_type;
  260. /**
  261. * @brief adc common config type
  262. */
  263. typedef struct
  264. {
  265. adc_div_type div; /*!< adc division select */
  266. confirm_state tempervintrv_state; /*!< adc temperature sensor and vintrv state */
  267. } adc_common_config_type;
  268. /**
  269. * @brief adc base config type
  270. */
  271. typedef struct
  272. {
  273. confirm_state sequence_mode; /*!< adc sequence mode */
  274. confirm_state repeat_mode; /*!< adc repeat mode */
  275. adc_data_align_type data_align; /*!< adc data alignment */
  276. uint8_t ordinary_channel_length; /*!< adc ordinary channel sequence length*/
  277. } adc_base_config_type;
  278. /**
  279. * @brief type define adc register all
  280. */
  281. typedef struct
  282. {
  283. /**
  284. * @brief adc sts register, offset:0x00
  285. */
  286. union
  287. {
  288. __IO uint32_t sts;
  289. struct
  290. {
  291. __IO uint32_t vmor : 1; /* [0] */
  292. __IO uint32_t occe : 1; /* [1] */
  293. __IO uint32_t pcce : 1; /* [2] */
  294. __IO uint32_t pccs : 1; /* [3] */
  295. __IO uint32_t occs : 1; /* [4] */
  296. __IO uint32_t occo : 1; /* [5] */
  297. __IO uint32_t rdy : 1; /* [6] */
  298. __IO uint32_t reserved1 : 25;/* [31:7] */
  299. } sts_bit;
  300. };
  301. /**
  302. * @brief adc ctrl1 register, offset:0x04
  303. */
  304. union
  305. {
  306. __IO uint32_t ctrl1;
  307. struct
  308. {
  309. __IO uint32_t vmcsel : 5; /* [4:0] */
  310. __IO uint32_t occeien : 1; /* [5] */
  311. __IO uint32_t vmorien : 1; /* [6] */
  312. __IO uint32_t pcceien : 1; /* [7] */
  313. __IO uint32_t sqen : 1; /* [8] */
  314. __IO uint32_t vmsgen : 1; /* [9] */
  315. __IO uint32_t pcautoen : 1; /* [10] */
  316. __IO uint32_t ocpen : 1; /* [11] */
  317. __IO uint32_t pcpen : 1; /* [12] */
  318. __IO uint32_t ocpcnt : 3; /* [15:13] */
  319. __IO uint32_t reserved1 : 6; /* [21:16] */
  320. __IO uint32_t pcvmen : 1; /* [22] */
  321. __IO uint32_t ocvmen : 1; /* [23] */
  322. __IO uint32_t crsel : 2; /* [25:24] */
  323. __IO uint32_t occoien : 1; /* [26] */
  324. __IO uint32_t reserved2 : 5; /* [31:27] */
  325. } ctrl1_bit;
  326. };
  327. /**
  328. * @brief adc ctrl2 register, offset:0x08
  329. */
  330. union
  331. {
  332. __IO uint32_t ctrl2;
  333. struct
  334. {
  335. __IO uint32_t adcen : 1; /* [0] */
  336. __IO uint32_t rpen : 1; /* [1] */
  337. __IO uint32_t adcal : 1; /* [2] */
  338. __IO uint32_t adcalinit : 1; /* [3] */
  339. __IO uint32_t adabrt : 1; /* [4] */
  340. __IO uint32_t reserved1 : 3; /* [7:5] */
  341. __IO uint32_t ocdmaen : 1; /* [8] */
  342. __IO uint32_t ocdrcen : 1; /* [9] */
  343. __IO uint32_t eocsfen : 1; /* [10] */
  344. __IO uint32_t dtalign : 1; /* [11] */
  345. __IO uint32_t reserved2 : 4; /* [15:12] */
  346. __IO uint32_t pctesel : 4; /* [19:16] */
  347. __IO uint32_t pcete : 2; /* [21:20] */
  348. __IO uint32_t pcswtrg : 1; /* [22] */
  349. __IO uint32_t reserved3 : 1; /* [23] */
  350. __IO uint32_t octesel : 4; /* [27:24] */
  351. __IO uint32_t ocete : 2; /* [29:28] */
  352. __IO uint32_t ocswtrg : 1; /* [30] */
  353. __IO uint32_t reserved4 : 1; /* [31] */
  354. } ctrl2_bit;
  355. };
  356. /**
  357. * @brief adc spt1 register, offset:0x0C
  358. */
  359. union
  360. {
  361. __IO uint32_t spt1;
  362. struct
  363. {
  364. __IO uint32_t cspt10 : 3; /* [2:0] */
  365. __IO uint32_t cspt11 : 3; /* [5:3] */
  366. __IO uint32_t cspt12 : 3; /* [8:6] */
  367. __IO uint32_t cspt13 : 3; /* [11:9] */
  368. __IO uint32_t cspt14 : 3; /* [14:12] */
  369. __IO uint32_t cspt15 : 3; /* [17:15] */
  370. __IO uint32_t cspt16 : 3; /* [20:18] */
  371. __IO uint32_t cspt17 : 3; /* [23:21] */
  372. __IO uint32_t cspt18 : 3; /* [26:24] */
  373. __IO uint32_t reserved1 : 5;/* [31:27] */
  374. } spt1_bit;
  375. };
  376. /**
  377. * @brief adc spt2 register, offset:0x10
  378. */
  379. union
  380. {
  381. __IO uint32_t spt2;
  382. struct
  383. {
  384. __IO uint32_t cspt0 : 3;/* [2:0] */
  385. __IO uint32_t cspt1 : 3;/* [5:3] */
  386. __IO uint32_t cspt2 : 3;/* [8:6] */
  387. __IO uint32_t cspt3 : 3;/* [11:9] */
  388. __IO uint32_t cspt4 : 3;/* [14:12] */
  389. __IO uint32_t cspt5 : 3;/* [17:15] */
  390. __IO uint32_t cspt6 : 3;/* [20:18] */
  391. __IO uint32_t cspt7 : 3;/* [23:21] */
  392. __IO uint32_t cspt8 : 3;/* [26:24] */
  393. __IO uint32_t cspt9 : 3;/* [29:27] */
  394. __IO uint32_t reserved1 : 2;/* [31:30] */
  395. } spt2_bit;
  396. };
  397. /**
  398. * @brief adc pcdto1 register, offset:0x14
  399. */
  400. union
  401. {
  402. __IO uint32_t pcdto1;
  403. struct
  404. {
  405. __IO uint32_t pcdto1 : 12; /* [11:0] */
  406. __IO uint32_t reserved1 : 20; /* [31:12] */
  407. } pcdto1_bit;
  408. };
  409. /**
  410. * @brief adc pcdto2 register, offset:0x18
  411. */
  412. union
  413. {
  414. __IO uint32_t pcdto2;
  415. struct
  416. {
  417. __IO uint32_t pcdto2 : 12; /* [11:0] */
  418. __IO uint32_t reserved1 : 20; /* [31:12] */
  419. } pcdto2_bit;
  420. };
  421. /**
  422. * @brief adc pcdto3 register, offset:0x1C
  423. */
  424. union
  425. {
  426. __IO uint32_t pcdto3;
  427. struct
  428. {
  429. __IO uint32_t pcdto3 : 12; /* [11:0] */
  430. __IO uint32_t reserved1 : 20; /* [31:12] */
  431. } pcdto3_bit;
  432. };
  433. /**
  434. * @brief adc pcdto4 register, offset:0x20
  435. */
  436. union
  437. {
  438. __IO uint32_t pcdto4;
  439. struct
  440. {
  441. __IO uint32_t pcdto4 : 12; /* [11:0] */
  442. __IO uint32_t reserved1 : 20; /* [31:12] */
  443. } pcdto4_bit;
  444. };
  445. /**
  446. * @brief adc vmhb register, offset:0x24
  447. */
  448. union
  449. {
  450. __IO uint32_t vmhb;
  451. struct
  452. {
  453. __IO uint32_t vmhb : 12; /* [11:0] */
  454. __IO uint32_t reserved1 : 20; /* [31:12] */
  455. } vmhb_bit;
  456. };
  457. /**
  458. * @brief adc vmlb register, offset:0x28
  459. */
  460. union
  461. {
  462. __IO uint32_t vmlb;
  463. struct
  464. {
  465. __IO uint32_t vmlb : 12; /* [11:0] */
  466. __IO uint32_t reserved1 : 20; /* [31:12] */
  467. } vmlb_bit;
  468. };
  469. /**
  470. * @brief adc osq1 register, offset:0x2C
  471. */
  472. union
  473. {
  474. __IO uint32_t osq1;
  475. struct
  476. {
  477. __IO uint32_t osn13 : 5; /* [4:0] */
  478. __IO uint32_t osn14 : 5; /* [9:5] */
  479. __IO uint32_t osn15 : 5; /* [14:10] */
  480. __IO uint32_t osn16 : 5; /* [19:15] */
  481. __IO uint32_t oclen : 5; /* [24:20] */
  482. __IO uint32_t reserved1 : 7; /* [31:25] */
  483. } osq1_bit;
  484. };
  485. /**
  486. * @brief adc osq2 register, offset:0x30
  487. */
  488. union
  489. {
  490. __IO uint32_t osq2;
  491. struct
  492. {
  493. __IO uint32_t osn7 : 5; /* [4:0] */
  494. __IO uint32_t osn8 : 5; /* [9:5] */
  495. __IO uint32_t osn9 : 5; /* [14:10] */
  496. __IO uint32_t osn10 : 5; /* [19:15] */
  497. __IO uint32_t osn11 : 5; /* [24:20] */
  498. __IO uint32_t osn12 : 5; /* [29:25] */
  499. __IO uint32_t reserved1 : 2; /* [31:30] */
  500. } osq2_bit;
  501. };
  502. /**
  503. * @brief adc osq3 register, offset:0x34
  504. */
  505. union
  506. {
  507. __IO uint32_t osq3;
  508. struct
  509. {
  510. __IO uint32_t osn1 : 5; /* [4:0] */
  511. __IO uint32_t osn2 : 5; /* [9:5] */
  512. __IO uint32_t osn3 : 5; /* [14:10] */
  513. __IO uint32_t osn4 : 5; /* [19:15] */
  514. __IO uint32_t osn5 : 5; /* [24:20] */
  515. __IO uint32_t osn6 : 5; /* [29:25] */
  516. __IO uint32_t reserved1 : 2; /* [31:30] */
  517. } osq3_bit;
  518. };
  519. /**
  520. * @brief adc psq register, offset:0x38
  521. */
  522. union
  523. {
  524. __IO uint32_t psq;
  525. struct
  526. {
  527. __IO uint32_t psn1 : 5; /* [4:0] */
  528. __IO uint32_t psn2 : 5; /* [9:5] */
  529. __IO uint32_t psn3 : 5; /* [14:10] */
  530. __IO uint32_t psn4 : 5; /* [19:15] */
  531. __IO uint32_t pclen : 2; /* [21:20] */
  532. __IO uint32_t reserved1 : 10;/* [31:22] */
  533. } psq_bit;
  534. };
  535. /**
  536. * @brief adc pdt1 register, offset:0x3C
  537. */
  538. union
  539. {
  540. __IO uint32_t pdt1;
  541. struct
  542. {
  543. __IO uint32_t pdt1 : 16; /* [15:0] */
  544. __IO uint32_t reserved1 : 16; /* [31:16] */
  545. } pdt1_bit;
  546. };
  547. /**
  548. * @brief adc pdt2 register, offset:0x40
  549. */
  550. union
  551. {
  552. __IO uint32_t pdt2;
  553. struct
  554. {
  555. __IO uint32_t pdt2 : 16; /* [15:0] */
  556. __IO uint32_t reserved1 : 16; /* [31:16] */
  557. } pdt2_bit;
  558. };
  559. /**
  560. * @brief adc pdt3 register, offset:0x44
  561. */
  562. union
  563. {
  564. __IO uint32_t pdt3;
  565. struct
  566. {
  567. __IO uint32_t pdt3 : 16; /* [15:0] */
  568. __IO uint32_t reserved1 : 16; /* [31:16] */
  569. } pdt3_bit;
  570. };
  571. /**
  572. * @brief adc pdt4 register, offset:0x48
  573. */
  574. union
  575. {
  576. __IO uint32_t pdt4;
  577. struct
  578. {
  579. __IO uint32_t pdt4 : 16; /* [15:0] */
  580. __IO uint32_t reserved1 : 16; /* [31:16] */
  581. } pdt4_bit;
  582. };
  583. /**
  584. * @brief adc odt register, offset:0x4C
  585. */
  586. union
  587. {
  588. __IO uint32_t odt;
  589. struct
  590. {
  591. __IO uint32_t odt : 16; /* [15:0] */
  592. __IO uint32_t reserved1 : 16; /* [31:16] */
  593. } odt_bit;
  594. };
  595. /**
  596. * @brief adc spt3 register, offset:0x10
  597. */
  598. union
  599. {
  600. __IO uint32_t spt3;
  601. struct
  602. {
  603. __IO uint32_t cspt20 : 3;/* [2:0] */
  604. __IO uint32_t cspt21 : 3;/* [5:3] */
  605. __IO uint32_t cspt22 : 3;/* [8:6] */
  606. __IO uint32_t cspt23 : 3;/* [11:9] */
  607. __IO uint32_t cspt24 : 3;/* [14:12] */
  608. __IO uint32_t cspt25 : 3;/* [17:15] */
  609. __IO uint32_t cspt26 : 3;/* [20:18] */
  610. __IO uint32_t cspt27 : 3;/* [23:21] */
  611. __IO uint32_t reserved1 : 8;/* [31:24] */
  612. } spt3_bit;
  613. };
  614. /**
  615. * @brief adc osq4 register, offset:0x34
  616. */
  617. union
  618. {
  619. __IO uint32_t osq4;
  620. struct
  621. {
  622. __IO uint32_t osn17 : 5; /* [4:0] */
  623. __IO uint32_t osn18 : 5; /* [9:5] */
  624. __IO uint32_t osn19 : 5; /* [14:10] */
  625. __IO uint32_t osn20 : 5; /* [19:15] */
  626. __IO uint32_t osn21 : 5; /* [24:20] */
  627. __IO uint32_t osn22 : 5; /* [29:25] */
  628. __IO uint32_t reserved1 : 2; /* [31:30] */
  629. } osq4_bit;
  630. };
  631. /**
  632. * @brief adc osq5 register, offset:0x34
  633. */
  634. union
  635. {
  636. __IO uint32_t osq5;
  637. struct
  638. {
  639. __IO uint32_t osn23 : 5; /* [4:0] */
  640. __IO uint32_t osn24 : 5; /* [9:5] */
  641. __IO uint32_t osn25 : 5; /* [14:10] */
  642. __IO uint32_t osn26 : 5; /* [19:15] */
  643. __IO uint32_t osn27 : 5; /* [24:20] */
  644. __IO uint32_t osn28 : 5; /* [29:25] */
  645. __IO uint32_t reserved1 : 2; /* [31:30] */
  646. } osq5_bit;
  647. };
  648. /**
  649. * @brief adc osq6 register, offset:0x34
  650. */
  651. union
  652. {
  653. __IO uint32_t osq6;
  654. struct
  655. {
  656. __IO uint32_t osn29 : 5; /* [4:0] */
  657. __IO uint32_t osn30 : 5; /* [9:5] */
  658. __IO uint32_t osn31 : 5; /* [14:10] */
  659. __IO uint32_t osn32 : 5; /* [19:15] */
  660. __IO uint32_t reserved1 : 12; /* [31:20] */
  661. } osq6_bit;
  662. };
  663. __IO uint32_t reserved1[8];
  664. /**
  665. * @brief adc ovsp register, offset:0x80
  666. */
  667. union
  668. {
  669. __IO uint32_t ovsp;
  670. struct
  671. {
  672. __IO uint32_t oosen : 1; /* [0] */
  673. __IO uint32_t posen : 1; /* [1] */
  674. __IO uint32_t osrsel : 3; /* [4:2] */
  675. __IO uint32_t osssel : 4; /* [8:5] */
  676. __IO uint32_t oostren : 1; /* [9] */
  677. __IO uint32_t oosrsel : 1; /* [10] */
  678. __IO uint32_t reserved1 : 21; /* [31:11] */
  679. } ovsp_bit;
  680. };
  681. __IO uint32_t reserved2[12];
  682. /**
  683. * @brief adc calval register, offset:0xB4
  684. */
  685. union
  686. {
  687. __IO uint32_t calval;
  688. struct
  689. {
  690. __IO uint32_t calval : 7; /* [6:0] */
  691. __IO uint32_t reserved1 : 25; /* [31:7] */
  692. } calval_bit;
  693. };
  694. __IO uint32_t reserved3[6];
  695. /**
  696. * @brief adc misc register, offset:0xD0
  697. */
  698. union
  699. {
  700. __IO uint32_t misc;
  701. struct
  702. {
  703. __IO uint32_t xtest : 6; /* [5:0] */
  704. __IO uint32_t reserved1 : 26; /* [31:6] */
  705. } misc_bit;
  706. };
  707. } adc_type;
  708. /**
  709. * @brief type define adc register all
  710. */
  711. typedef struct
  712. {
  713. /**
  714. * @brief adc csts register, offset:0x00
  715. */
  716. union
  717. {
  718. __IO uint32_t csts;
  719. struct
  720. {
  721. __IO uint32_t vmor1 : 1; /* [0] */
  722. __IO uint32_t occe1 : 1; /* [1] */
  723. __IO uint32_t pcce1 : 1; /* [2] */
  724. __IO uint32_t pccs1 : 1; /* [3] */
  725. __IO uint32_t occs1 : 1; /* [4] */
  726. __IO uint32_t occo1 : 1; /* [5] */
  727. __IO uint32_t rdy1 : 1; /* [6] */
  728. __IO uint32_t reserved1 : 25; /* [31:7] */
  729. } csts_bit;
  730. };
  731. /**
  732. * @brief adc cctrl register, offset:0x04
  733. */
  734. union
  735. {
  736. __IO uint32_t cctrl;
  737. struct
  738. {
  739. __IO uint32_t reserved1 : 16; /* [15:0] */
  740. __IO uint32_t adcdiv : 4; /* [19:16] */
  741. __IO uint32_t reserved2 : 3; /* [22:20] */
  742. __IO uint32_t itsrven : 1; /* [23] */
  743. __IO uint32_t reserved3 : 8; /* [31:24] */
  744. } cctrl_bit;
  745. };
  746. } adccom_type;
  747. /**
  748. * @}
  749. */
  750. #define ADC1 ((adc_type *) ADC1_BASE)
  751. #define ADCCOM ((adccom_type *) ADCCOM_BASE)
  752. /** @defgroup ADC_exported_functions
  753. * @{
  754. */
  755. void adc_reset(void);
  756. void adc_enable(adc_type *adc_x, confirm_state new_state);
  757. void adc_base_default_para_init(adc_base_config_type *adc_base_struct);
  758. void adc_base_config(adc_type *adc_x, adc_base_config_type *adc_base_struct);
  759. void adc_common_default_para_init(adc_common_config_type *adc_common_struct);
  760. void adc_common_config(adc_common_config_type *adc_common_struct);
  761. void adc_resolution_set(adc_type *adc_x, adc_resolution_type resolution);
  762. void adc_dma_mode_enable(adc_type *adc_x, confirm_state new_state);
  763. void adc_dma_request_repeat_enable(adc_type *adc_x, confirm_state new_state);
  764. void adc_interrupt_enable(adc_type *adc_x, uint32_t adc_int, confirm_state new_state);
  765. void adc_calibration_value_set(adc_type *adc_x, uint8_t adc_calibration_value);
  766. void adc_calibration_init(adc_type *adc_x);
  767. flag_status adc_calibration_init_status_get(adc_type *adc_x);
  768. void adc_calibration_start(adc_type *adc_x);
  769. flag_status adc_calibration_status_get(adc_type *adc_x);
  770. void adc_voltage_monitor_enable(adc_type *adc_x, adc_voltage_monitoring_type adc_voltage_monitoring);
  771. void adc_voltage_monitor_threshold_value_set(adc_type *adc_x, uint16_t adc_high_threshold, uint16_t adc_low_threshold);
  772. void adc_voltage_monitor_single_channel_select(adc_type *adc_x, adc_channel_select_type adc_channel);
  773. void adc_ordinary_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime);
  774. void adc_preempt_channel_length_set(adc_type *adc_x, uint8_t adc_channel_lenght);
  775. void adc_preempt_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime);
  776. void adc_ordinary_conversion_trigger_set(adc_type *adc_x, adc_ordinary_trig_select_type adc_ordinary_trig, adc_ordinary_trig_edge_type adc_ordinary_trig_edge);
  777. void adc_preempt_conversion_trigger_set(adc_type *adc_x, adc_preempt_trig_select_type adc_preempt_trig, adc_preempt_trig_edge_type adc_preempt_trig_edge);
  778. void adc_preempt_offset_value_set(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel, uint16_t adc_offset_value);
  779. void adc_ordinary_part_count_set(adc_type *adc_x, uint8_t adc_channel_count);
  780. void adc_ordinary_part_mode_enable(adc_type *adc_x, confirm_state new_state);
  781. void adc_preempt_part_mode_enable(adc_type *adc_x, confirm_state new_state);
  782. void adc_preempt_auto_mode_enable(adc_type *adc_x, confirm_state new_state);
  783. void adc_conversion_stop(adc_type *adc_x);
  784. flag_status adc_conversion_stop_status_get(adc_type *adc_x);
  785. void adc_occe_each_conversion_enable(adc_type *adc_x, confirm_state new_state);
  786. void adc_ordinary_software_trigger_enable(adc_type *adc_x, confirm_state new_state);
  787. flag_status adc_ordinary_software_trigger_status_get(adc_type *adc_x);
  788. void adc_preempt_software_trigger_enable(adc_type *adc_x, confirm_state new_state);
  789. flag_status adc_preempt_software_trigger_status_get(adc_type *adc_x);
  790. uint16_t adc_ordinary_conversion_data_get(adc_type *adc_x);
  791. uint16_t adc_preempt_conversion_data_get(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel);
  792. flag_status adc_flag_get(adc_type *adc_x, uint8_t adc_flag);
  793. void adc_flag_clear(adc_type *adc_x, uint32_t adc_flag);
  794. void adc_ordinary_oversample_enable(adc_type *adc_x, confirm_state new_state);
  795. void adc_preempt_oversample_enable(adc_type *adc_x, confirm_state new_state);
  796. void adc_oversample_ratio_shift_set(adc_type *adc_x, adc_oversample_ratio_type adc_oversample_ratio, adc_oversample_shift_type adc_oversample_shift);
  797. void adc_ordinary_oversample_trig_enable(adc_type *adc_x, confirm_state new_state);
  798. void adc_ordinary_oversample_restart_set(adc_type *adc_x, adc_ordinary_oversample_restart_type adc_ordinary_oversample_restart);
  799. /**
  800. * @}
  801. */
  802. /**
  803. * @}
  804. */
  805. /**
  806. * @}
  807. */
  808. #ifdef __cplusplus
  809. }
  810. #endif
  811. #endif