hc32_ll_adc.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_adc.h
  4. * @brief This file contains all the functions prototypes of the ADC driver
  5. * library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2022-12-31 CDT First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by XHSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32_LL_ADC_H__
  22. #define __HC32_LL_ADC_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_ll_def.h"
  32. #include "hc32f4xx.h"
  33. #include "hc32f4xx_conf.h"
  34. /**
  35. * @addtogroup LL_Driver
  36. * @{
  37. */
  38. /**
  39. * @addtogroup LL_ADC
  40. * @{
  41. */
  42. #if (LL_ADC_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup ADC_Global_Types ADC Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief Structure definition of analog watchdog(AWD) configuration.
  52. */
  53. typedef struct {
  54. uint16_t u16WatchdogMode; /*!< Specifies the ADC analog watchdog mode.
  55. This parameter can be a value of @ref ADC_AWD_Mode */
  56. uint16_t u16LowThreshold; /*!< Specifies the ADC analog watchdog Low threshold value. */
  57. uint16_t u16HighThreshold; /*!< Specifies the ADC analog watchdog High threshold value. */
  58. } stc_adc_awd_config_t;
  59. /**
  60. * @brief Structure definition of ADC initialization.
  61. */
  62. typedef struct {
  63. uint16_t u16ScanMode; /*!< Specifies the ADC scan convert mode.
  64. This parameter can be a value of @ref ADC_Scan_Mode */
  65. uint16_t u16Resolution; /*!< Specifies the ADC resolution.
  66. This parameter can be a value of @ref ADC_Resolution */
  67. uint16_t u16DataAlign; /*!< Specifies ADC data alignment.
  68. This parameter can be a value of @ref ADC_Data_Align */
  69. } stc_adc_init_t;
  70. /**
  71. * @}
  72. */
  73. /*******************************************************************************
  74. * Global pre-processor symbols/macros ('#define')
  75. ******************************************************************************/
  76. /**
  77. * @defgroup ADC_Global_Macros ADC Global Macros
  78. * @{
  79. */
  80. /**
  81. * @defgroup ADC_Sequence ADC Sequence
  82. * @{
  83. */
  84. #define ADC_SEQ_A (0U) /*!< ADC sequence A. */
  85. #define ADC_SEQ_B (1U) /*!< ADC sequence B. */
  86. /**
  87. * @}
  88. */
  89. /**
  90. * @defgroup ADC_Channel ADC Channel
  91. * @{
  92. */
  93. #define ADC_CH0 (0U) /*!< Default input pin: PA0 for ADC1, PA4 for ADC2, PE2 for ADC3. */
  94. #define ADC_CH1 (1U) /*!< Default input pin: PA1 for ADC1, PA5 for ADC2, PE3 for ADC3. */
  95. #define ADC_CH2 (2U) /*!< Default input pin: PA2 for ADC1, PA6 for ADC2, PE4 for ADC3. */
  96. #define ADC_CH3 (3U) /*!< Default input pin: PA3 for ADC1, PA7 for ADC2, PE12 for ADC3. */
  97. #define ADC_CH4 (4U) /*!< Default input pin: PA4 for ADC1, PB0 for ADC2, PE13 for ADC3. */
  98. #define ADC_CH5 (5U) /*!< Default input pin: PA5 for ADC1, PB1 for ADC2, PE14 for ADC3. */
  99. #define ADC_CH6 (6U) /*!< Default input pin: PA6 for ADC1, PC0 for ADC2, PA6 for ADC3. */
  100. #define ADC_CH7 (7U) /*!< Default input pin: PA7 for ADC1, PC1 for ADC2, PA7 for ADC3. */
  101. #define ADC_CH8 (8U) /*!< Default input pin: PB0 for ADC1, ADC2 not supported, PB0 for ADC3. */
  102. #define ADC_CH9 (9U) /*!< Default input pin: PB1 for ADC1, ADC2 not supported, PB1 for ADC3. */
  103. #define ADC_CH10 (10U) /*!< Default input pin: PC0 for ADC1, ADC2 not supported, PE15 for ADC3. */
  104. #define ADC_CH11 (11U) /*!< Default input pin: PC1 for ADC1, ADC2 not supported, PB10 for ADC3. */
  105. #define ADC_CH12 (12U) /*!< Default input pin: PC2 for ADC1, ADC2 and ADC3 not supported. */
  106. #define ADC_CH13 (13U) /*!< Default input pin: PC3 for ADC1, ADC2 and ADC3 not supported. */
  107. #define ADC_CH14 (14U) /*!< Default input pin: PC4 for ADC1, ADC2 and ADC3 not supported. */
  108. #define ADC_CH15 (15U) /*!< Default input pin: PC5 for ADC1, ADC2 and ADC3 not supported. */
  109. #define ADC1_EXT_CH (ADC_CH15) /*!< ADC1 extended channel, internal reference voltage. */
  110. #define ADC2_EXT_CH (ADC_CH7) /*!< ADC2 extended channel, internal reference voltage. */
  111. #define ADC3_EXT_CH (ADC_CH11) /*!< ADC3 extended channel, internal reference voltage. */
  112. /**
  113. * @}
  114. */
  115. /**
  116. * @defgroup ADC_Scan_Mode ADC Scan Convert Mode
  117. * @{
  118. */
  119. #define ADC_MD_SEQA_SINGLESHOT (0x0U) /*!< Sequence A single shot. Sequence B is disabled. */
  120. #define ADC_MD_SEQA_CONT (0x1U << ADC_CR0_MS_POS) /*!< Sequence A continuous. Sequence B is disabled. */
  121. #define ADC_MD_SEQA_SEQB_SINGLESHOT (0x2U << ADC_CR0_MS_POS) /*!< Sequence A and B both single shot. */
  122. #define ADC_MD_SEQA_CONT_SEQB_SINGLESHOT (0x3U << ADC_CR0_MS_POS) /*!< Sequence A continuous and sequence B single shot. */
  123. #define ADC_MD_SEQA_BUF (0x4U << ADC_CR0_MS_POS) /*!< Sequence A data buffer. Sequence B is disabled. */
  124. #define ADC_MD_SEQA_BUF_SEQB_SINGLESHOT (0x6U << ADC_CR0_MS_POS) /*!< Sequence A data buffer and sequence B single shot. */
  125. /**
  126. * @}
  127. */
  128. /**
  129. * @defgroup ADC_Resolution ADC Resolution
  130. * @{
  131. */
  132. #define ADC_RESOLUTION_12BIT (0x0U) /*!< Resolution is 12 bit. */
  133. #define ADC_RESOLUTION_10BIT (ADC_CR0_ACCSEL_0) /*!< Resolution is 10 bit. */
  134. #define ADC_RESOLUTION_8BIT (ADC_CR0_ACCSEL_1) /*!< Resolution is 8 bit. */
  135. /**
  136. * @}
  137. */
  138. /**
  139. * @defgroup ADC_Data_Align ADC Data Align
  140. * @{
  141. */
  142. #define ADC_DATAALIGN_RIGHT (0x0U) /*!< Right alignment of converted data. */
  143. #define ADC_DATAALIGN_LEFT (ADC_CR0_DFMT) /*!< Left alignment of converted data. */
  144. /**
  145. * @}
  146. */
  147. /**
  148. * @defgroup ADC_Average_Count ADC Average Count
  149. * @{
  150. */
  151. #define ADC_AVG_CNT2 (0x0U) /*!< 2 consecutive average conversions. */
  152. #define ADC_AVG_CNT4 (0x1U << ADC_CR0_AVCNT_POS) /*!< 4 consecutive average conversions. */
  153. #define ADC_AVG_CNT8 (0x2U << ADC_CR0_AVCNT_POS) /*!< 8 consecutive average conversions. */
  154. #define ADC_AVG_CNT16 (0x3U << ADC_CR0_AVCNT_POS) /*!< 16 consecutive average conversions. */
  155. #define ADC_AVG_CNT32 (0x4U << ADC_CR0_AVCNT_POS) /*!< 32 consecutive average conversions. */
  156. #define ADC_AVG_CNT64 (0x5U << ADC_CR0_AVCNT_POS) /*!< 64 consecutive average conversions. */
  157. #define ADC_AVG_CNT128 (0x6U << ADC_CR0_AVCNT_POS) /*!< 128 consecutive average conversions. */
  158. #define ADC_AVG_CNT256 (0x7U << ADC_CR0_AVCNT_POS) /*!< 256 consecutive average conversions. */
  159. /**
  160. * @}
  161. */
  162. /**
  163. * @defgroup ADC_SeqA_Resume_Mode ADC Sequence A Resume Mode
  164. * @brief After interrupted by sequence B, sequence A continues to scan from the interrupt channel or the first channel.
  165. * @{
  166. */
  167. #define ADC_SEQA_RESUME_SCAN_CONT (0U) /*!< Scanning will continue from the interrupted channel. */
  168. #define ADC_SEQA_RESUME_SCAN_RESTART (ADC_CR1_RSCHSEL) /*!< Scanning will start from the first channel. */
  169. /**
  170. * @}
  171. */
  172. /**
  173. * @defgroup ADC_Sample_Mode ADC Sample Mode
  174. * @{
  175. */
  176. #define ADC_SPL_MD_NORMAL (0U) /*!< ADC normal sampling mode. */
  177. #define ADC_SPL_MD_OVER (ADC_CR2_OVSMOD) /*!< ADC over sampling mode. */
  178. /**
  179. * @}
  180. */
  181. /**
  182. * @defgroup ADC_Over_Sample_Shift ADC Over Sample Shift
  183. * @{
  184. */
  185. #define ADC_OVER_SPL_SHIFT_0BIT (0U) /*!< Right shift 0 bit when use over sampling mode. */
  186. #define ADC_OVER_SPL_SHIFT_1BIT (1U << ADC_CR2_OVSS_POS) /*!< Right shift 1 bit when use over sampling mode. */
  187. #define ADC_OVER_SPL_SHIFT_2BIT (2U << ADC_CR2_OVSS_POS) /*!< Right shift 2 bits when use over sampling mode. */
  188. #define ADC_OVER_SPL_SHIFT_3BIT (3U << ADC_CR2_OVSS_POS) /*!< Right shift 3 bits when use over sampling mode. */
  189. #define ADC_OVER_SPL_SHIFT_4BIT (4U << ADC_CR2_OVSS_POS) /*!< Right shift 4 bits when use over sampling mode. */
  190. #define ADC_OVER_SPL_SHIFT_5BIT (5U << ADC_CR2_OVSS_POS) /*!< Right shift 5 bits when use over sampling mode. */
  191. #define ADC_OVER_SPL_SHIFT_6BIT (6U << ADC_CR2_OVSS_POS) /*!< Right shift 6 bits when use over sampling mode. */
  192. #define ADC_OVER_SPL_SHIFT_7BIT (7U << ADC_CR2_OVSS_POS) /*!< Right shift 7 bits when use over sampling mode. */
  193. #define ADC_OVER_SPL_SHIFT_8BIT (8U << ADC_CR2_OVSS_POS) /*!< Right shift 8 bits when use over sampling mode. */
  194. /**
  195. * @}
  196. */
  197. /**
  198. * @defgroup ADC_Hard_Trigger_Sel ADC Hard Trigger Selection
  199. * @{
  200. */
  201. #define ADC_HARDTRIG_ADTRG_PIN (0x0U) /*!< Selects the following edge of pin ADTRG as the trigger of ADC sequence. */
  202. #define ADC_HARDTRIG_EVT0 (ADC_TRGSR_TRGSELA_0) /*!< Selects an internal event as the trigger of ADC sequence.
  203. This event is specified by register ADCx_ITRGSELR0(x=(null), 1, 2, 3). */
  204. #define ADC_HARDTRIG_EVT1 (ADC_TRGSR_TRGSELA_1) /*!< Selects an internal event as the trigger of ADC sequence.
  205. This event is specified by register ADCx_ITRGSELR1(x=(null), 1, 2, 3). */
  206. #define ADC_HARDTRIG_EVT0_EVT1 (ADC_TRGSR_TRGSELA) /*!< Selects two internal events as the trigger of ADC sequence.
  207. The two events are specified by register ADCx_ITRGSELR0 and register ADCx_ITRGSELR1. */
  208. /**
  209. * @}
  210. */
  211. /**
  212. * @defgroup ADC_Int_Type ADC Interrupt Type
  213. * @{
  214. */
  215. #define ADC_INT_EOCA (ADC_ICR_EOCAIEN) /*!< Interrupt of the end of conversion of sequence A. */
  216. #define ADC_INT_EOCB (ADC_ICR_EOCBIEN) /*!< Interrupt of the end of conversion of sequence B. */
  217. #define ADC_INT_ALL (ADC_INT_EOCA | ADC_INT_EOCB)
  218. /**
  219. * @}
  220. */
  221. /**
  222. * @defgroup ADC_Ext_Ch_Analog_Src ADC Extended Channel Analog Source
  223. * @{
  224. */
  225. #define ADC_EXTCH_EXTERN_ANALOG_PIN (0x0U) /*!< The analog source of extended channel is external analog input pin. */
  226. #define ADC_EXTCH_INTERN_ANALOG_SRC (ADC_EXCHSELR_EXCHSEL) /*!< The analog source of extended channel is internal analog signal. */
  227. /**
  228. * @}
  229. */
  230. /**
  231. * @defgroup ADC_Status_Flag ADC Status Flag
  232. * @{
  233. */
  234. #define ADC_FLAG_EOCA (ADC_ISR_EOCAF) /*!< Status flag of the end of conversion of sequence A. */
  235. #define ADC_FLAG_EOCB (ADC_ISR_EOCBF) /*!< Status flag of the end of conversion of sequence B. */
  236. #define ADC_FLAG_NESTED (ADC_ISR_SASTPDF) /*!< Status flag of sequence A was interrupted by sequence B. */
  237. #define ADC_FLAG_ALL (ADC_FLAG_EOCA | ADC_FLAG_EOCB | ADC_FLAG_NESTED)
  238. /**
  239. * @}
  240. */
  241. /**
  242. * @defgroup ADC_Sync_Unit ADC Synchronous Unit
  243. * @{
  244. */
  245. #define ADC_SYNC_ADC1_ADC2 (0U) /*!< ADC1 and ADC2 work synchronously. */
  246. #define ADC_SYNC_ADC1_ADC2_ADC3 (0x1U << ADC_SYNCCR_SYNCMD_POS) /*!< ADC1, ADC2 and ADC3 work synchronously. */
  247. /**
  248. * @}
  249. */
  250. /**
  251. * @defgroup ADC_Sync_Mode ADC Synchronous Mode
  252. * @{
  253. */
  254. #define ADC_SYNC_SINGLE_DELAY_TRIG (0U) /*!< Single shot delayed trigger mode.
  255. When the trigger condition occurs, ADC1 starts first, then ADC2, last ADC3(if has).
  256. All ADCs scan once. */
  257. #define ADC_SYNC_SINGLE_PARALLEL_TRIG (0x2U << ADC_SYNCCR_SYNCMD_POS) /*!< Single shot parallel trigger mode.
  258. When the trigger condition occurs, all ADCs start at the same time.
  259. All ADCs scan once. */
  260. #define ADC_SYNC_CYCLIC_DELAY_TRIG (0x4U << ADC_SYNCCR_SYNCMD_POS) /*!< Cyclic delayed trigger mode.
  261. When the trigger condition occurs, ADC1 starts first, then ADC2, last ADC3(if has).
  262. All ADCs scan cyclicly(keep scaning till you stop them). */
  263. #define ADC_SYNC_CYCLIC_PARALLEL_TRIG (0x6U << ADC_SYNCCR_SYNCMD_POS) /*!< Single shot parallel trigger mode.
  264. When the trigger condition occurs, all ADCs start at the same time.
  265. All ADCs scan cyclicly(keep scaning till you stop them). */
  266. /**
  267. * @}
  268. */
  269. /**
  270. * @defgroup ADC_AWD_Unit ADC Analog Watchdog Unit
  271. * @{
  272. */
  273. #define ADC_AWD0 (0U) /*!< ADC analog watchdog 0. */
  274. #define ADC_AWD1 (1U) /*!< ADC analog watchdog 1. */
  275. /**
  276. * @}
  277. */
  278. /**
  279. * @defgroup ADC_AWD_Int_Type ADC AWD Interrupt Type
  280. * @{
  281. */
  282. #define ADC_AWD_INT_AWD0 (ADC_AWDCR_AWD0IEN) /*!< Interrupt of AWD0. */
  283. #define ADC_AWD_INT_AWD1 (ADC_AWDCR_AWD1IEN) /*!< Interrupt of AWD1. */
  284. #define ADC_AWD_INT_ALL (ADC_AWD_INT_AWD0 | ADC_AWD_INT_AWD1)
  285. /**
  286. * @}
  287. */
  288. /**
  289. * @defgroup ADC_AWD_Mode ADC Analog Watchdog Mode
  290. * @{
  291. */
  292. #define ADC_AWD_MD_CMP_OUT (0x0U) /*!< ADCValue > HighThreshold or ADCValue < LowThreshold */
  293. #define ADC_AWD_MD_CMP_IN (0x1U) /*!< LowThreshold < ADCValue < HighThreshold */
  294. /**
  295. * @}
  296. */
  297. /**
  298. * @defgroup ADC_AWD_Comb_Mode ADC AWD(Analog Watchdog) Combination Mode
  299. * @note If combination mode is valid(ADC_AWD_COMB_OR/ADC_AWD_COMB_AND/ADC_AWD_COMB_XOR) and
  300. * the Channels selected by the AWD0 and AWD1 are deferent, make sure that the channel
  301. * of AWD1 is converted after the channel conversion of AWD0 ends.
  302. * @{
  303. */
  304. #define ADC_AWD_COMB_INVD (0U) /*!< Combination mode is invalid. */
  305. #define ADC_AWD_COMB_OR (ADC_AWDCR_AWDCM_0) /*!< The status of AWD0 is set or the status of AWD1 is set, the status of combination mode is set. */
  306. #define ADC_AWD_COMB_AND (ADC_AWDCR_AWDCM_1) /*!< The status of AWD0 is set and the status of AWD1 is set, the status of combination mode is set. */
  307. #define ADC_AWD_COMB_XOR (ADC_AWDCR_AWDCM) /*!< Only one of the status of AWD0 and AWD1 is set, the status of combination mode is set. */
  308. /**
  309. * @}
  310. */
  311. /**
  312. * @defgroup ADC_AWD_Status_Flag ADC AWD Status Flag
  313. * @{
  314. */
  315. #define ADC_AWD_FLAG_AWD0 (ADC_AWDSR_AWD0F) /*!< Flag of AWD0. */
  316. #define ADC_AWD_FLAG_AWD1 (ADC_AWDSR_AWD1F) /*!< Flag of AWD1. */
  317. #define ADC_AWD_FLAG_COMB (ADC_AWDSR_AWDCMF) /*!< Flag of combination of mode. */
  318. #define ADC_AWD_FLAG_ALL (ADC_AWD_FLAG_AWD0 | ADC_AWD_FLAG_AWD1 | ADC_AWD_FLAG_COMB)
  319. /**
  320. * @}
  321. */
  322. /**
  323. * @defgroup ADC_Remap_Pin ADC Remap Pin
  324. * @{
  325. */
  326. #define ADC1_PIN_PA0 (0U) /*!< ADC1_IN0(PA0): default channel is ADC_CH0 of ADC1 */
  327. #define ADC1_PIN_PA1 (1U) /*!< ADC1_IN1(PA1): default channel is ADC_CH1 of ADC1 */
  328. #define ADC1_PIN_PA2 (2U) /*!< ADC1_IN2(PA2): default channel is ADC_CH2 of ADC1 */
  329. #define ADC1_PIN_PA3 (3U) /*!< ADC1_IN3(PA3): default channel is ADC_CH3 of ADC1 */
  330. #define ADC1_PIN_PA4 (4U) /*!< ADC12_IN4(PA4): default channel is ADC_CH4 of ADC1 */
  331. #define ADC1_PIN_PA5 (5U) /*!< ADC12_IN5(PA5): default channel is ADC_CH5 of ADC1 */
  332. #define ADC1_PIN_PA6 (6U) /*!< ADC123_IN6(PA6): default channel is ADC_CH6 of ADC1 */
  333. #define ADC1_PIN_PA7 (7U) /*!< ADC123_IN7(PA7): default channel is ADC_CH7 of ADC1 */
  334. #define ADC1_PIN_PB0 (8U) /*!< ADC123_IN8(PB0): default channel is ADC_CH8 of ADC1 */
  335. #define ADC1_PIN_PB1 (9U) /*!< ADC123_IN9(PB1): default channel is ADC_CH9 of ADC1 */
  336. #define ADC1_PIN_PC0 (10U) /*!< ADC12_IN10(PC0): default channel is ADC_CH10 of ADC1 */
  337. #define ADC1_PIN_PC1 (11U) /*!< ADC12_IN11(PC1): default channel is ADC_CH11 of ADC1 */
  338. #define ADC1_PIN_PC2 (12U) /*!< ADC1_IN12(PC2): default channel is ADC_CH12 of ADC1 */
  339. #define ADC1_PIN_PC3 (13U) /*!< ADC1_IN13(PC3): default channel is ADC_CH13 of ADC1 */
  340. #define ADC1_PIN_PC4 (14U) /*!< ADC1_IN14(PC4): default channel is ADC_CH14 of ADC1 */
  341. #define ADC1_PIN_PC5 (15U) /*!< ADC1_IN15(PC5): default channel is ADC_CH15 of ADC1 */
  342. #define ADC2_PIN_PA4 (0U) /*!< ADC12_IN4(PA4): default channel is ADC_CH0 ADC2 */
  343. #define ADC2_PIN_PA5 (1U) /*!< ADC12_IN5(PA5): default channel is ADC_CH1 ADC2 */
  344. #define ADC2_PIN_PA6 (2U) /*!< ADC123_IN6(PA6): default channel is ADC_CH2 ADC2 */
  345. #define ADC2_PIN_PA7 (3U) /*!< ADC123_IN7(PA7): default channel is ADC_CH3 ADC2 */
  346. #define ADC2_PIN_PB0 (4U) /*!< ADC123_IN8(PB0): default channel is ADC_CH4 ADC2 */
  347. #define ADC2_PIN_PB1 (5U) /*!< ADC123_IN9(PB1): default channel is ADC_CH5 ADC2 */
  348. #define ADC2_PIN_PC0 (6U) /*!< ADC12_IN10(PC0): default channel is ADC_CH6 ADC2 */
  349. #define ADC2_PIN_PC1 (7U) /*!< ADC12_IN11(PC1): default channel is ADC_CH7 ADC2 */
  350. #define ADC3_PIN_PE2 (0U) /*!< ADC3_IN0(PE2): default channel is ADC_CH0 of ADC3 */
  351. #define ADC3_PIN_PE3 (1U) /*!< ADC3_IN1(PE3): default channel is ADC_CH1 of ADC3 */
  352. #define ADC3_PIN_PE4 (2U) /*!< ADC3_IN2(PE4): default channel is ADC_CH2 of ADC3 */
  353. #define ADC3_PIN_PE12 (3U) /*!< ADC3_IN3(PE12): default channel is ADC_CH3 of ADC3 */
  354. #define ADC3_PIN_PE13 (4U) /*!< ADC3_IN4(PE13): default channel is ADC_CH4 of ADC3 */
  355. #define ADC3_PIN_PE14 (5U) /*!< ADC3_IN5(PE14): default channel is ADC_CH5 of ADC3 */
  356. #define ADC3_PIN_PA6 (6U) /*!< ADC123_IN6(PA6): default channel is ADC_CH6 of ADC3 */
  357. #define ADC3_PIN_PA7 (7U) /*!< ADC123_IN7(PA7): default channel is ADC_CH7 of ADC3 */
  358. #define ADC3_PIN_PB0 (8U) /*!< ADC123_IN8(PB0): default channel is ADC_CH8 of ADC3 */
  359. #define ADC3_PIN_PB1 (9U) /*!< ADC123_IN9(PB1): default channel is ADC_CH9 of ADC3 */
  360. #define ADC3_PIN_PE15 (10U) /*!< ADC3_IN10(PE15): default channel is ADC_CH10 of ADC3 */
  361. #define ADC3_PIN_PB10 (11U) /*!< ADC3_IN11(PB10): default channel is ADC_CH11 of ADC3 */
  362. /**
  363. * @}
  364. */
  365. /**
  366. * @}
  367. */
  368. /*******************************************************************************
  369. * Global variable definitions ('extern')
  370. ******************************************************************************/
  371. /*******************************************************************************
  372. Global function prototypes (definition in C source)
  373. ******************************************************************************/
  374. /**
  375. * @addtogroup ADC_Global_Functions
  376. * @{
  377. */
  378. /*******************************************************************************
  379. Basic features
  380. ******************************************************************************/
  381. int32_t ADC_Init(CM_ADC_TypeDef *ADCx, const stc_adc_init_t *pstcAdcInit);
  382. void ADC_DeInit(CM_ADC_TypeDef *ADCx);
  383. int32_t ADC_StructInit(stc_adc_init_t *pstcAdcInit);
  384. void ADC_ChCmd(CM_ADC_TypeDef *ADCx, uint8_t u8Seq, uint8_t u8Ch, en_functional_state_t enNewState);
  385. void ADC_SetSampleTime(CM_ADC_TypeDef *ADCx, uint8_t u8Ch, uint8_t u8SampleTime);
  386. /* Conversion data average calculation function. */
  387. void ADC_ConvDataAverageConfig(CM_ADC_TypeDef *ADCx, uint16_t u16AverageCount);
  388. void ADC_ConvDataAverageChCmd(CM_ADC_TypeDef *ADCx, uint8_t u8Ch, en_functional_state_t enNewState);
  389. /* Extended channel. */
  390. void ADC_SetExtChSrc(CM_ADC_TypeDef *ADCx, uint8_t u8ExtChSrc);
  391. void ADC_SetSampleMode(CM_ADC_TypeDef *ADCx, uint16_t u16Mode);
  392. void ADC_SetOverSampleShift(CM_ADC_TypeDef *ADCx, uint16_t u16ShiftValue);
  393. void ADC_TriggerConfig(CM_ADC_TypeDef *ADCx, uint8_t u8Seq, uint16_t u16TriggerSel);
  394. void ADC_TriggerCmd(CM_ADC_TypeDef *ADCx, uint8_t u8Seq, en_functional_state_t enNewState);
  395. void ADC_IntCmd(CM_ADC_TypeDef *ADCx, uint8_t u8IntType, en_functional_state_t enNewState);
  396. void ADC_Start(CM_ADC_TypeDef *ADCx);
  397. void ADC_Stop(CM_ADC_TypeDef *ADCx);
  398. uint16_t ADC_GetValue(const CM_ADC_TypeDef *ADCx, uint8_t u8Ch);
  399. en_flag_status_t ADC_GetStatus(const CM_ADC_TypeDef *ADCx, uint8_t u8Flag);
  400. void ADC_ClearStatus(CM_ADC_TypeDef *ADCx, uint8_t u8Flag);
  401. /*******************************************************************************
  402. Advanced features
  403. ******************************************************************************/
  404. /* Channel remap. */
  405. void ADC_ChRemap(CM_ADC_TypeDef *ADCx, uint8_t u8Ch, uint8_t u8AdcPin);
  406. uint8_t ADC_GetChPin(const CM_ADC_TypeDef *ADCx, uint8_t u8Ch);
  407. void ADC_ResetChMapping(CM_ADC_TypeDef *ADCx);
  408. /* Sync mode. */
  409. void ADC_SyncModeConfig(uint16_t u16SyncUnit, uint16_t u16SyncMode, uint8_t u8TriggerDelay);
  410. void ADC_SyncModeCmd(en_functional_state_t enNewState);
  411. /* Analog watchdog */
  412. int32_t ADC_AWD_Config(CM_ADC_TypeDef *ADCx, uint8_t u8AwdUnit, uint8_t u8Ch, const stc_adc_awd_config_t *pstcAwd);
  413. /* Combination mode. */
  414. void ADC_AWD_SetCombMode(CM_ADC_TypeDef *ADCx, uint16_t u16CombMode);
  415. void ADC_AWD_SetMode(CM_ADC_TypeDef *ADCx, uint8_t u8AwdUnit, uint16_t u16WatchdogMode);
  416. uint16_t ADC_AWD_GetMode(CM_ADC_TypeDef *ADCx, uint8_t u8AwdUnit);
  417. void ADC_AWD_SetThreshold(CM_ADC_TypeDef *ADCx, uint8_t u8AwdUnit, uint16_t u16LowThreshold, uint16_t u16HighThreshold);
  418. void ADC_AWD_SelectCh(CM_ADC_TypeDef *ADCx, uint8_t u8AwdUnit, uint8_t u8Ch);
  419. void ADC_AWD_Cmd(CM_ADC_TypeDef *ADCx, uint8_t u8AwdUnit, en_functional_state_t enNewState);
  420. void ADC_AWD_IntCmd(CM_ADC_TypeDef *ADCx, uint16_t u16IntType, en_functional_state_t enNewState);
  421. en_flag_status_t ADC_AWD_GetStatus(const CM_ADC_TypeDef *ADCx, uint32_t u32Flag);
  422. void ADC_AWD_ClearStatus(CM_ADC_TypeDef *ADCx, uint32_t u32Flag);
  423. void ADC_DataRegAutoClearCmd(CM_ADC_TypeDef *ADCx, en_functional_state_t enNewState);
  424. void ADC_SetSeqAResumeMode(CM_ADC_TypeDef *ADCx, uint16_t u16SeqAResumeMode);
  425. /**
  426. * @}
  427. */
  428. #endif /* LL_ADC_ENABLE */
  429. /**
  430. * @}
  431. */
  432. /**
  433. * @}
  434. */
  435. #ifdef __cplusplus
  436. }
  437. #endif
  438. #endif /* __HC32_LL_ADC_H__ */
  439. /*******************************************************************************
  440. * EOF (not truncated)
  441. ******************************************************************************/