ald_adc.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /**
  2. ******************************************************************************
  3. * @file ald_adc.h
  4. * @brief Header file of ADC Module library.
  5. *
  6. * @version V1.0
  7. * @date 15 Dec 2017
  8. * @author AE Team
  9. * @note
  10. *
  11. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  12. *
  13. ******************************************************************************
  14. */
  15. #ifndef __ALD_ADC_H__
  16. #define __ALD_ADC_H__
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "utils.h"
  21. #include "ald_dma.h"
  22. #include "ald_pis.h"
  23. #include "ald_timer.h"
  24. /** @addtogroup ES32FXXX_ALD
  25. * @{
  26. */
  27. /** @addtogroup ADC
  28. * @{
  29. */
  30. /** @defgroup ADC_Pubulic_Types ADC Pubulic Types
  31. * @{
  32. */
  33. /**
  34. * @brief ADC State structures definition
  35. */
  36. typedef enum {
  37. ADC_STATE_RESET = 0x0, /**< ADC not yet initialized or disabled */
  38. ADC_STATE_READY = 0x1, /**< ADC peripheral ready for use */
  39. ADC_STATE_BUSY_INTERNAL = 0x2, /**< ADC is busy to internal process */
  40. ADC_STATE_TIMEOUT = 0x4, /**< TimeOut occurrence */
  41. ADC_STATE_ERROR = 0x10, /**< Internal error occurrence */
  42. ADC_STATE_NM_BUSY = 0x100, /**< Conversion on group normal is ongoing or can occur */
  43. ADC_STATE_NM_EOC = 0x200, /**< Conversion data available on group normal */
  44. ADC_STATE_IST_BUSY = 0x1000, /**< Conversion on group insert is ongoing or can occur */
  45. ADC_STATE_IST_EOC = 0x2000, /**< Conversion data available on group insert */
  46. ADC_STATE_AWD = 0x10000, /**< Out-of-window occurrence of analog watchdog */
  47. } adc_state_t;
  48. /**
  49. *@brief ADC Error Code
  50. */
  51. typedef enum {
  52. ADC_ERROR_NONE = 0x0, /**< No error */
  53. ADC_ERROR_INTERNAL = 0x1, /**< ADC IP internal error*/
  54. ADC_ERROR_OVR = 0x2, /**< Overrun error */
  55. ADC_ERROR_DMA = 0x4, /**< DMA transfer error */
  56. } adc_error_t;
  57. /**
  58. *@brief ADC data alignment
  59. */
  60. typedef enum {
  61. ADC_DATAALIGN_RIGHT = 0x0, /**< ADC data alignment right */
  62. ADC_DATAALIGN_LEFT = 0x1, /**< ADC data alignment left */
  63. } adc_align_t;
  64. /**
  65. *@brief ADC scan mode
  66. */
  67. typedef enum {
  68. ADC_SCAN_DISABLE = 0x0, /**< ADC scan disable */
  69. ADC_SCAN_ENABLE = 0x1, /**< ADC scan enable */
  70. } adc_scan_t;
  71. /**
  72. *@brief ADC config hannal trigger the EOC IT mode
  73. */
  74. typedef enum {
  75. ADC_NCHESEL_MODE_ALL = 0x0, /**< ADC set RCHE after convert sequence finish */
  76. ADC_NCHESEL_MODE_ONE = 0x1, /**< ADC set RCHE after one convert finish */
  77. } adc_nchesel_t;
  78. /**
  79. *@brief ADC channels
  80. */
  81. typedef enum {
  82. ADC_CHANNEL_0 = 0x0, /**< ADC channel 0 */
  83. ADC_CHANNEL_1 = 0x1, /**< ADC channel 1 */
  84. ADC_CHANNEL_2 = 0x2, /**< ADC channel 2 */
  85. ADC_CHANNEL_3 = 0x3, /**< ADC channel 3 */
  86. ADC_CHANNEL_4 = 0x4, /**< ADC channel 4 */
  87. ADC_CHANNEL_5 = 0x5, /**< ADC channel 5 */
  88. ADC_CHANNEL_6 = 0x6, /**< ADC channel 6 */
  89. ADC_CHANNEL_7 = 0x7, /**< ADC channel 7 */
  90. ADC_CHANNEL_8 = 0x8, /**< ADC channel 8 */
  91. ADC_CHANNEL_9 = 0x9, /**< ADC channel 9 */
  92. ADC_CHANNEL_10 = 0xA, /**< ADC channel 10 */
  93. ADC_CHANNEL_11 = 0xB, /**< ADC channel 11 */
  94. ADC_CHANNEL_12 = 0xC, /**< ADC channel 12 */
  95. ADC_CHANNEL_13 = 0xD, /**< ADC channel 13 */
  96. ADC_CHANNEL_14 = 0xE, /**< ADC channel 14 */
  97. ADC_CHANNEL_15 = 0xF, /**< ADC channel 15 */
  98. ADC_CHANNEL_16 = 0x10, /**< ADC channel 16 */
  99. ADC_CHANNEL_17 = 0x11, /**< ADC channel 17 */
  100. ADC_CHANNEL_18 = 0x12, /**< ADC channel 18 */
  101. ADC_CHANNEL_19 = 0x13, /**< ADC channel 19 */
  102. } adc_channel_t;
  103. /**
  104. *@brief ADC sampling times
  105. */
  106. typedef enum {
  107. ADC_SAMPLETIME_1 = 0x0, /**< ADC sampling times 1 clk */
  108. ADC_SAMPLETIME_2 = 0x1, /**< ADC sampling times 2 clk */
  109. ADC_SAMPLETIME_4 = 0x2, /**< ADC sampling times 4 clk */
  110. ADC_SAMPLETIME_15 = 0x3, /**< ADC sampling times 15 clk */
  111. } adc_samp_t;
  112. /**
  113. *@brief ADC rank into normal group
  114. */
  115. typedef enum {
  116. ADC_NC_RANK_1 = 0x1, /**< ADC normal channel rank 1 */
  117. ADC_NC_RANK_2 = 0x2, /**< ADC normal channel rank 2 */
  118. ADC_NC_RANK_3 = 0x3, /**< ADC normal channel rank 3 */
  119. ADC_NC_RANK_4 = 0x4, /**< ADC normal channel rank 4 */
  120. ADC_NC_RANK_5 = 0x5, /**< ADC normal channel rank 5 */
  121. ADC_NC_RANK_6 = 0x6, /**< ADC normal channel rank 6 */
  122. ADC_NC_RANK_7 = 0x7, /**< ADC normal channel rank 7 */
  123. ADC_NC_RANK_8 = 0x8, /**< ADC normal channel rank 8 */
  124. ADC_NC_RANK_9 = 0x9, /**< ADC normal channel rank 9 */
  125. ADC_NC_RANK_10 = 0xA, /**< ADC normal channel rank 10 */
  126. ADC_NC_RANK_11 = 0xB, /**< ADC normal channel rank 11 */
  127. ADC_NC_RANK_12 = 0xC, /**< ADC normal channel rank 12 */
  128. ADC_NC_RANK_13 = 0xD, /**< ADC normal channel rank 13 */
  129. ADC_NC_RANK_14 = 0xE, /**< ADC normal channel rank 14 */
  130. ADC_NC_RANK_15 = 0xF, /**< ADC normal channel rank 15 */
  131. ADC_NC_RANK_16 = 0x10, /**< ADC normal channel rank 16 */
  132. } adc_nc_rank_t;
  133. /**
  134. * @brief ADC rank into insert group
  135. */
  136. typedef enum {
  137. ADC_IH_RANK_1 = 0x1, /**< ADC insert channel rank 1 */
  138. ADC_IH_RANK_2 = 0x2, /**< ADC insert channel rank 2 */
  139. ADC_IH_RANK_3 = 0x3, /**< ADC insert channel rank 3 */
  140. ADC_IH_RANK_4 = 0x4, /**< ADC insert channel rank 4 */
  141. } adc_ih_rank_t;
  142. /**
  143. * @brief ADC analog watchdog mode
  144. */
  145. typedef enum {
  146. ADC_ANAWTD_NONE = 0x0, /**< No watch dog */
  147. ADC_ANAWTD_SING_NM = 0x800200, /**< One normal channel watch dog */
  148. ADC_ANAWTD_SING_IST = 0x400200, /**< One inset channel Injec watch dog */
  149. ADC_ANAWTD_SING_NMIST = 0xC00200, /**< One normal and inset channel watch dog */
  150. ADC_ANAWTD_ALL_NM = 0x800000, /**< All normal channel watch dog */
  151. ADC_ANAWTD_ALL_IST = 0x400000, /**< All inset channel watch dog */
  152. ADC_ANAWTD_ALL_NMIST = 0xC00000, /**< All normal and inset channel watch dog */
  153. } adc_ana_wtd_t;
  154. /**
  155. * @brief ADC Event type
  156. */
  157. typedef enum {
  158. ADC_AWD_EVENT = (1U << 0), /**< ADC analog watch dog event */
  159. } adc_event_type_t;
  160. /**
  161. * @brief ADC interrupts definition
  162. */
  163. typedef enum {
  164. ADC_IT_NH = (1U << 5), /**< ADC it normal */
  165. ADC_IT_AWD = (1U << 6), /**< ADC it awd */
  166. ADC_IT_IH = (1U << 7), /**< ADC it insert */
  167. ADC_IT_OVR = (1U << 26), /**< ADC it overring */
  168. } adc_it_t;
  169. /**
  170. * @brief ADC flags definition
  171. */
  172. typedef enum {
  173. ADC_FLAG_AWD = (1U << 0), /**<ADC flag awd */
  174. ADC_FLAG_NH = (1U << 1), /**<ADC flag normal mode */
  175. ADC_FLAG_IH = (1U << 2), /**<ADC flag inset mode */
  176. ADC_FLAG_OVR = (1U << 3), /**<ADC flag ovr */
  177. ADC_FLAG_NHS = (1U << 8), /**<ADC flag normal start */
  178. ADC_FLAG_IHS = (1U << 9), /**<ADC flag inset start */
  179. } adc_flag_t;
  180. /**
  181. * @brief ADC CLD DIV definition
  182. */
  183. typedef enum {
  184. ADC_CKDIV_1 = 0x0, /**< ADC CLK DIV 1 */
  185. ADC_CKDIV_2 = 0x1, /**< ADC CLK DIV 2 */
  186. ADC_CKDIV_4 = 0x2, /**< ADC CLK DIV 4 */
  187. ADC_CKDIV_8 = 0x3, /**< ADC CLK DIV 8 */
  188. ADC_CKDIV_16 = 0x4, /**< ADC CLK DIV 16 */
  189. ADC_CKDIV_32 = 0x5, /**< ADC CLK DIV 32 */
  190. ADC_CKDIV_64 = 0x6, /**< ADC CLK DIV 64 */
  191. ADC_CKDIV_128 = 0x7, /**< ADC CLK DIV 128 */
  192. } adc_clk_div_t;
  193. /**
  194. * @brief ADC negative reference voltage definition
  195. */
  196. typedef enum {
  197. ADC_NEG_REF_VSS = 0x0, /**< ADC negative regerence voltage vss */
  198. ADC_NEG_REF_VREFN = 0x1, /**< ADC negative regerence voltage vrefn */
  199. } adc_neg_ref_t;
  200. /**
  201. * @brief ADC positive reference voltage definition
  202. */
  203. typedef enum {
  204. ADC_POS_REF_VDD = 0x0, /**< ADC posotove reference is VDD */
  205. ADC_POS_REF_2V = 0x1, /**< ADC posotove reference is internal 2V */
  206. ADC_POS_REF_VREEFP = 0x2, /**< ADC posotove reference is VREEFP */
  207. ADC_POS_REF_VREEFP_BUF = 0x3, /**< ADC posotove reference is VREEFP BUFFER */
  208. } adc_pos_ref_t;
  209. /**
  210. * @brief ADC numbers of normal conversion channals
  211. */
  212. typedef enum {
  213. ADC_NM_NBR_1 = 0x0, /**< ADC number of normal conversion 1 */
  214. ADC_NM_NBR_2 = 0x1, /**< ADC number of normal conversion 2 */
  215. ADC_NM_NBR_3 = 0x2, /**< ADC number of normal conversion 3 */
  216. ADC_NM_NBR_4 = 0x3, /**< ADC number of normal conversion 4 */
  217. ADC_NM_NBR_5 = 0x4, /**< ADC number of normal conversion 5 */
  218. ADC_NM_NBR_6 = 0x5, /**< ADC number of normal conversion 6 */
  219. ADC_NM_NBR_7 = 0x6, /**< ADC number of normal conversion 7 */
  220. ADC_NM_NBR_8 = 0x7, /**< ADC number of normal conversion 8 */
  221. ADC_NM_NBR_9 = 0x8, /**< ADC number of normal conversion 9 */
  222. ADC_NM_NBR_10 = 0x9, /**< ADC number of normal conversion 10 */
  223. ADC_NM_NBR_11 = 0xA, /**< ADC number of normal conversion 11 */
  224. ADC_NM_NBR_12 = 0xB, /**< ADC number of normal conversion 12 */
  225. ADC_NM_NBR_13 = 0xC, /**< ADC number of normal conversion 13 */
  226. ADC_NM_NBR_14 = 0xD, /**< ADC number of normal conversion 14 */
  227. ADC_NM_NBR_15 = 0xE, /**< ADC number of normal conversion 15 */
  228. ADC_NM_NBR_16 = 0xF, /**< ADC number of normal conversion 16 */
  229. } adc_nm_nbr_t;
  230. /**
  231. * @brief ADC numbers of insert conversion channals
  232. */
  233. typedef enum {
  234. ADC_IST_NBR_1 = 0x0, /**< ADC number of insert conversion 1 */
  235. ADC_IST_NBR_2 = 0x1, /**< ADC number of insert conversion 2 */
  236. ADC_IST_NBR_3 = 0x2, /**< ADC number of insert conversion 3 */
  237. ADC_IST_NBR_4 = 0x3, /**< ADC number of insert conversion 4 */
  238. } adc_ist_nbr_t;
  239. /**
  240. * @brief ADC numbers of channals in discontinuous conversion mode
  241. */
  242. typedef enum {
  243. ADC_DISC_NBR_1 = 0x0, /**< ADC number of discontinuous conversion 1 */
  244. ADC_DISC_NBR_2 = 0x1, /**< ADC number of discontinuous conversion 2 */
  245. ADC_DISC_NBR_3 = 0x2, /**< ADC number of discontinuous conversion 3 */
  246. ADC_DISC_NBR_4 = 0x3, /**< ADC number of discontinuous conversion 4 */
  247. ADC_DISC_NBR_5 = 0x4, /**< ADC number of discontinuous conversion 5 */
  248. ADC_DISC_NBR_6 = 0x5, /**< ADC number of discontinuous conversion 6 */
  249. ADC_DISC_NBR_7 = 0x6, /**< ADC number of discontinuous conversion 7 */
  250. ADC_DISC_NBR_8 = 0x7, /**< ADC number of discontinuous conversion 8 */
  251. } adc_disc_nbr_t;
  252. /**
  253. * @brief ADC resolution of conversion
  254. */
  255. typedef enum {
  256. ADC_CONV_RES_6 = 0x0, /**< ADC resolution of conversion 6 */
  257. ADC_CONV_RES_8 = 0x1, /**< ADC resolution of conversion 8 */
  258. ADC_CONV_RES_10 = 0x2, /**< ADC resolution of conversion 10 */
  259. ADC_CONV_RES_12 = 0x3, /**< ADC resolution of conversion 12 */
  260. } adc_conv_res_t;
  261. /**
  262. * @brief ADC trigger conversion mode
  263. */
  264. typedef enum {
  265. ADC_TRIG_SOFT = 0x0, /**< ADC tirgger conversion soft */
  266. ADC_TRIG_PIS = 0x1, /**< ADC tirgger conversion pis */
  267. ADC_TRIG_PIS_SOFT = 0x2, /**< ADC tirgger conversion all */
  268. } adc_trig_mode_t;
  269. /**
  270. * @brief Structure definition of ADC and normal group initialization
  271. */
  272. typedef struct {
  273. adc_align_t data_align; /**< Specifies ADC data alignment */
  274. adc_scan_t scan_mode; /**< Choose scan mode enable or not */
  275. type_func_t cont_mode; /**< Choose continuous mode enable or not */
  276. adc_nm_nbr_t conv_nbr; /**< Number of normal ranks will be converted */
  277. type_func_t disc_mode; /**< Discontinuous mode enable or not */
  278. adc_disc_nbr_t disc_nbr; /**< Number of discontinuous conversions channel */
  279. adc_conv_res_t conv_res; /**< The precision of conversion */
  280. adc_clk_div_t clk_div; /**< ADCCLK divider */
  281. adc_nchesel_t nche_mode; /**< Trigger the NCHE FALG mode */
  282. adc_neg_ref_t neg_ref; /**< The negative reference voltage*/
  283. adc_pos_ref_t pos_ref; /**< The positive reference voltage*/
  284. } adc_init_t;
  285. /**
  286. * @brief Structure definition of ADC channel for normal group
  287. */
  288. typedef struct {
  289. adc_channel_t channel; /**< The channel to configure into ADC normal group */
  290. adc_nc_rank_t rank; /**< The rank in the normal group sequencer */
  291. adc_samp_t sampling_time; /**< Sampling time value to be set */
  292. } adc_channel_conf_t;
  293. /**
  294. * @brief ADC Configuration analog watchdog definition
  295. */
  296. typedef struct {
  297. adc_ana_wtd_t watchdog_mode; /**< Configures the ADC analog watchdog mode*/
  298. adc_channel_t channel; /**< Selects which ADC channel to monitor by analog watchdog */
  299. type_func_t it_mode; /**< Whether the analog watchdog is configured in interrupt */
  300. uint32_t high_threshold; /**< The ADC analog watchdog High threshold value. */
  301. uint32_t low_threshold; /**< The ADC analog watchdog Low threshold value. */
  302. } adc_analog_wdg_conf_t;
  303. /**
  304. * @brief ADC Configuration insert Channel structure definition
  305. */
  306. typedef struct {
  307. adc_channel_t channel; /**< Selection of ADC channel to configure */
  308. adc_ih_rank_t rank; /**< Rank in the insert group sequencer */
  309. adc_samp_t samp_time; /**< Sampling time value for selected channel */
  310. uint32_t offset; /**< The offset about converted data */
  311. adc_ist_nbr_t nbr; /**< The number of insert ranks */
  312. type_func_t disc_mode; /**< insert sequence's Discontinuous function */
  313. type_func_t auto_inj; /**< insert sequence's auto function */
  314. } adc_ih_conf_t;
  315. /**
  316. * @brief ADC handle Structure definition
  317. */
  318. typedef struct adc_handle_s {
  319. ADC_TypeDef *perh; /**< Register base address */
  320. adc_init_t init; /**< ADC required parameters */
  321. #ifdef ALD_DMA
  322. dma_handle_t hdma; /**< Pointer DMA Handler */
  323. pis_handle_t hpis; /**< Pointer PIS Handler for connect adc and dma */
  324. #endif
  325. lock_state_t lock; /**< ADC locking object */
  326. adc_state_t state; /**< ADC communication state */
  327. adc_error_t error_code; /**< ADC Error code */
  328. pis_handle_t reg_pis_handle; /**< PIS for connect normal channel and trigger */
  329. pis_handle_t inj_pis_handle; /**< PIS for connect insert channel and trigger */
  330. adc_trig_mode_t nm_trig_mode; /**< ADC normal channel trigger mode */
  331. adc_trig_mode_t ist_trig_mode; /**< ADC insert channel trigger mode */
  332. void (*adc_reg_cplt_cbk)( struct adc_handle_s *arg); /**< Regluar Conversion complete callback */
  333. void (*adc_inj_cplt_cbk)( struct adc_handle_s *arg); /**< insert Conversion complete callback */
  334. void (*adc_out_of_win_cbk)( struct adc_handle_s *arg); /**< Level out of window callback */
  335. void (*adc_error_cbk)(struct adc_handle_s *arg); /**< adc error callback */
  336. void (*adc_ovr_cbk)(struct adc_handle_s *arg); /**< adc ovr callback */
  337. } adc_handle_t;
  338. /**
  339. * @brief Timer trigger adc config structure definition
  340. */
  341. typedef struct {
  342. uint32_t time; /**< Timer period time uint: us */
  343. uint16_t size; /**< Adc convert times */
  344. uint16_t *buf; /**< Convert data buffer */
  345. adc_neg_ref_t n_ref; /**< The negative reference voltage for adc*/
  346. adc_pos_ref_t p_ref; /**< The positive reference voltage for adc*/
  347. adc_channel_t adc_ch; /**< Adc channel */
  348. uint8_t dma_ch; /**< Dma channel */
  349. TIMER_TypeDef *p_timer; /**< Adc peripheral */
  350. ADC_TypeDef *p_adc; /**< Dma peripheral */
  351. void (*adc_cplt_cbk)( struct adc_handle_s *arg); /**< Conversion complete callback */
  352. /* private variable */
  353. lock_state_t lock; /**< Locking object */
  354. pis_handle_t lh_pis; /**< Handle of PIS module */
  355. dma_handle_t lh_dma; /**< Handle of DMA module */
  356. timer_handle_t lh_timer; /**< Handle of TIMER module */
  357. adc_handle_t lh_adc; /**< Handle of ADC module */
  358. adc_channel_conf_t lnm_config; /**< Struct for chanel configure */
  359. } adc_timer_config_t;
  360. /**
  361. * @}
  362. */
  363. /** @defgroup ADC_Public_Macros ADC Public Macros
  364. * @{
  365. */
  366. #define ADC_ENABLE(handle) (SET_BIT((handle)->perh->CON1, ADC_CON1_ADCEN_MSK))
  367. #define ADC_DISABLE(handle) (CLEAR_BIT((handle)->perh->CON1, ADC_CON1_ADCEN_MSK))
  368. #define ADC_NH_TRIG_BY_SOFT(handle) (SET_BIT((handle)->perh->CON1, ADC_CON1_NCHTRG_MSK))
  369. #define ADC_IH_TRIG_BY_SOFT(handle) (SET_BIT((handle)->perh->CON1, ADC_CON1_ICHTRG_MSK))
  370. #define ADC_RESET_HANDLE_STATE(handle) ((handle)->state = ADC_STATE_RESET)
  371. #define ADC_VREF_OUT_ENABLE(handle) (SET_BIT((handle)->perh->CCR, ADC_CCR_VREFOEN_MSK))
  372. #define ADC_VREF_OUT_DISABLE(handle) (CLEAR_BIT((handle)->perh->CCR, ADC_CCR_VREFOEN_MSK))
  373. /**
  374. * @}
  375. */
  376. /** @defgroup ADC_Private_Macros ADC Private Macros
  377. * @{
  378. */
  379. #define IS_ADC_IH_RANK_TYPE(x) ((x) <= ADC_IH_RANK_4)
  380. #define IS_ADC_NC_RANK_TYPE(x) ((x) <= ADC_NC_RANK_16)
  381. #define IS_ADC_SAMPLING_TIMES_TYPE(x) (((x) == ADC_SAMPLETIME_1) || \
  382. ((x) == ADC_SAMPLETIME_2) || \
  383. ((x) == ADC_SAMPLETIME_4) || \
  384. ((x) == ADC_SAMPLETIME_15))
  385. #define IS_ADC_CHANNELS_TYPE(x) ((x) <= ADC_CHANNEL_19)
  386. #define IS_ADC_SCAN_MODE_TYPE(x) (((x) == ADC_SCAN_DISABLE) || \
  387. ((x) == ADC_SCAN_ENABLE) )
  388. #define IS_ADC_DATA_ALIGN_TYPE(x) (((x) == ADC_DATAALIGN_RIGHT) || \
  389. ((x) == ADC_DATAALIGN_LEFT))
  390. #define IS_ADC_ANALOG_WTD_MODE_TYPE(x) (((x) == ADC_ANAWTD_NONE) || \
  391. ((x) == ADC_ANAWTD_SING_NM) || \
  392. ((x) == ADC_ANAWTD_SING_IST) || \
  393. ((x) == ADC_ANAWTD_SING_NMIST) || \
  394. ((x) == ADC_ANAWTD_ALL_NM) || \
  395. ((x) == ADC_ANAWTD_ALL_IST) || \
  396. ((x) == ADC_ANAWTD_ALL_NMIST))
  397. #define IS_ADC_IT_TYPE(x) (((x) == ADC_IT_NH) || \
  398. ((x) == ADC_IT_AWD) || \
  399. ((x) == ADC_IT_IH) || \
  400. ((x) == ADC_IT_OVR ))
  401. #define IS_ADC_FLAGS_TYPE(x) (((x) == ADC_FLAG_AWD) || \
  402. ((x) == ADC_FLAG_NH) || \
  403. ((x) == ADC_FLAG_IH) || \
  404. ((x) == ADC_FLAG_OVR) || \
  405. ((x) == ADC_FLAG_NHS) || \
  406. ((x) == ADC_FLAG_IHS))
  407. #define IS_ADC_CLK_DIV_TYPE(x) (((x) == ADC_CKDIV_1) || \
  408. ((x) == ADC_CKDIV_2) || \
  409. ((x) == ADC_CKDIV_4) || \
  410. ((x) == ADC_CKDIV_8) || \
  411. ((x) == ADC_CKDIV_16) || \
  412. ((x) == ADC_CKDIV_32) || \
  413. ((x) == ADC_CKDIV_64) || \
  414. ((x) == ADC_CKDIV_128))
  415. #define IS_ADC_NEG_REF_VOLTAGE_TYPE(x) (((x) == ADC_NEG_REF_VSS ) || \
  416. ((x) == ADC_NEG_REF_VREFN ))
  417. #define IS_POS_REF_VOLTAGE_TYPE(x) (((x) == ADC_POS_REF_VDD) || \
  418. ((x) == ADC_POS_REF_2V) || \
  419. ((x) == ADC_POS_REF_VREEFP) || \
  420. ((x) == ADC_POS_REF_VREEFP_BUF))
  421. #define IS_ADC_NBR_OF_NM_TYPE(x) ((x) <= ADC_NM_NBR_16)
  422. #define IS_ADC_NBR_OF_IST_TYPE(x) ((x) <= ADC_IST_NBR_4)
  423. #define IS_ADC_DISC_NBR_TYPE(x) ((x) <= ADC_DISC_NBR_8)
  424. #define IS_ADC_CONV_RES_TYPE(x) (((x) == ADC_CONV_RES_12) || \
  425. ((x) == ADC_CONV_RES_6) || \
  426. ((x) == ADC_CONV_RES_8) || \
  427. ((x) == ADC_CONV_RES_10))
  428. #define IS_ADC_TRIG_MODE_TYPE(x) (((x) == ADC_TRIG_SOFT) || \
  429. ((x) == ADC_TRIG_PIS) || \
  430. ((x) == ADC_TRIG_PIS_SOFT))
  431. #define IS_ADC_TYPE(x) (((x) == ADC0) || \
  432. ((x) == ADC1))
  433. #define IS_ADC_NCHESEL_MODE_TYPE(x) (((x) == ADC_NCHESEL_MODE_ALL) || \
  434. ((x) == ADC_NCHESEL_MODE_ONE))
  435. #define IS_ADC_EVENT_TYPE(x) ((x) == ADC_AWD_EVENT)
  436. #define IS_ADC_IST_OFFSET_TYPE(x) ((x) <= 0xfff)
  437. #define IS_HTR_TYPE(x) ((x) <= 0xfff)
  438. #define IS_LTR_TYPE(x) ((x) <= 0xfff)
  439. /**
  440. * @}
  441. */
  442. /** @addtogroup ADC_Public_Functions
  443. * @{
  444. */
  445. /** @addtogroup ADC_Public_Functions_Group1
  446. * @{
  447. */
  448. ald_status_t adc_init(adc_handle_t *hperh);
  449. ald_status_t adc_reset(adc_handle_t *hperh);
  450. /**
  451. * @}
  452. */
  453. /** @addtogroup ADC_Public_Functions_Group2
  454. * @{
  455. */
  456. ald_status_t adc_normal_start(adc_handle_t *hperh);
  457. ald_status_t adc_normal_stop(adc_handle_t *hperh);
  458. ald_status_t adc_normal_poll_for_conversion(adc_handle_t *hperh, uint32_t timeout);
  459. ald_status_t adc_poll_for_event(adc_handle_t *hperh, adc_event_type_t event_type, uint32_t timeout);
  460. ald_status_t adc_normal_start_by_it(adc_handle_t *hperh);
  461. ald_status_t adc_normal_stop_by_it(adc_handle_t *hperh);
  462. #ifdef ALD_DMA
  463. ald_status_t adc_start_by_dma(adc_handle_t *hperh, uint16_t *buf, uint16_t size, uint8_t channel);
  464. ald_status_t adc_stop_by_dma(adc_handle_t *hperh);
  465. ald_status_t adc_timer_trigger_adc_by_dma(adc_timer_config_t *config);
  466. #endif
  467. uint32_t adc_normal_get_value(adc_handle_t *hperh);
  468. ald_status_t adc_insert_start(adc_handle_t *hperh);
  469. ald_status_t adc_insert_stop(adc_handle_t *hperh);
  470. ald_status_t adc_insert_poll_for_conversion(adc_handle_t *hperh, uint32_t timeout);
  471. ald_status_t adc_insert_start_by_it(adc_handle_t *hperh);
  472. ald_status_t adc_insert_stop_by_it(adc_handle_t *hperh);
  473. uint32_t adc_insert_get_value(adc_handle_t *hperh, adc_ih_rank_t ih_rank);
  474. void adc_irq_handler(adc_handle_t *hperh);
  475. /**
  476. * @}
  477. */
  478. /** @addtogroup ADC_Public_Functions_Group3
  479. * @{
  480. */
  481. ald_status_t adc_normal_channel_config(adc_handle_t *hperh, adc_channel_conf_t *config);
  482. ald_status_t adc_insert_channel_config(adc_handle_t *hperh, adc_ih_conf_t *config);
  483. ald_status_t adc_analog_wdg_config(adc_handle_t *hperh, adc_analog_wdg_conf_t *config);
  484. void adc_interrupt_config(adc_handle_t *hperh, adc_it_t it, type_func_t state);
  485. it_status_t adc_get_it_status(adc_handle_t *hperh, adc_it_t it);
  486. flag_status_t adc_get_flag_status(adc_handle_t *hperh, adc_flag_t flag);
  487. void adc_clear_flag_status(adc_handle_t *hperh, adc_flag_t flag);
  488. /**
  489. * @}
  490. */
  491. /** @addtogroup ADC_Public_Functions_Group4
  492. * @{
  493. */
  494. uint32_t adc_get_state(adc_handle_t *hperh);
  495. uint32_t adc_get_error(adc_handle_t *hperh);
  496. /**
  497. * @}
  498. */
  499. /**
  500. * @}
  501. */
  502. /**
  503. * @}
  504. */
  505. /**
  506. * @}
  507. */
  508. #ifdef __cplusplus
  509. extern "C" }
  510. #endif
  511. #endif /* __ALD_ADC_H */