gd32f10x_adc.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. /**
  2. ******************************************************************************
  3. * @brief ADC functions of the firmware library.
  4. ******************************************************************************
  5. */
  6. /* Includes ------------------------------------------------------------------*/
  7. #include "gd32f10x_adc.h"
  8. #include "gd32f10x_rcc.h"
  9. /** @addtogroup GD32F10x_Firmware
  10. * @{
  11. */
  12. /** @defgroup ADC
  13. * @brief ADC driver modules
  14. * @{
  15. */
  16. /** @defgroup ADC_Private_Defines
  17. * @{
  18. */
  19. /* ADC CTLR1_DISNUM mask */
  20. #define CTLR1_DISNUM_RESET ((uint32_t)0xFFFF1FFF)
  21. /* ADC CTLR1_DISRC mask */
  22. #define CTLR1_DISRC_SET ((uint32_t)0x00000800)
  23. /* ADC CTLR1_ICA mask */
  24. #define CTLR1_ICA_SET ((uint32_t)0x00000400)
  25. /* ADC CTLR1_DISIC mask */
  26. #define CTLR1_DISIC_SET ((uint32_t)0x00001000)
  27. /* ADC CTLR1_AWCS mask */
  28. #define CTLR1_AWCS_RESET ((uint32_t)0xFFFFFFE0)
  29. /* ADC CTLR1_AWDMode mask */
  30. #define CTLR1_AWDMODE_RESET ((uint32_t)0xFF3FFDFF)
  31. /* CTLR1 register mask */
  32. #define CTLR1_BITS_CLEAR ((uint32_t)0xFFF0FEFF)
  33. /* ADC CTLR2_ADCON mask */
  34. #define CTLR2_ADCON_SET ((uint32_t)0x00000001)
  35. /* ADC CTLR2_DMA mask */
  36. #define CTLR2_DMA_SET ((uint32_t)0x00000100)
  37. /* ADC CTLR2_RSTCLB mask */
  38. #define CTLR2_RSTCLB_SET ((uint32_t)0x00000008)
  39. /* ADC CTLR2_CLB mask */
  40. #define CTLR2_CLB_SET ((uint32_t)0x00000004)
  41. /* ADC CTLR2_SWRCST mask */
  42. #define CTLR2_SWRCST_SET ((uint32_t)0x00400000)
  43. /* ADC CTLR2_ETERC mask */
  44. #define CTLR2_ETERC_SET ((uint32_t)0x00100000)
  45. /* ADC CTLR2_ETERC_SWRCST mask */
  46. #define CTLR2_ETERC_SWRCST_SET ((uint32_t)0x00500000)
  47. /* ADC CTLR2_ETSIC mask */
  48. #define CTLR2_ETSIC_RESET ((uint32_t)0xFFFF8FFF)
  49. /* ADC CTLR2_ETEIC mask */
  50. #define CTLR2_ETEIC_SET ((uint32_t)0x00008000)
  51. /* ADC CTLR2_SWICST mask */
  52. #define CTLR2_SWICST_SET ((uint32_t)0x00200000)
  53. /* ADC CTLR2_ETEIC_SWICST mask */
  54. #define CTLR2_ETEIC_SWICST_SET ((uint32_t)0x00208000)
  55. /* ADC CTLR2_TSVREN mask */
  56. #define CTLR2_TSVREN_SET ((uint32_t)0x00800000)
  57. /* CTLR2 register mask */
  58. #define CTLR2_BITS_CLEAR ((uint32_t)0xFFF1F7FD)
  59. /* ADC RSQx mask */
  60. #define RSQ3_RSQ_SET ((uint32_t)0x0000001F)
  61. #define RSQ2_RSQ_SET ((uint32_t)0x0000001F)
  62. #define RSQ1_RSQ_SET ((uint32_t)0x0000001F)
  63. /* RSQ1 register mask */
  64. #define RSQ1_BITS_CLEAR ((uint32_t)0xFF0FFFFF)
  65. /* ADC ISQx mask */
  66. #define ISQ_ISQ_SET ((uint32_t)0x0000001F)
  67. /* ADC IL mask */
  68. #define ISQ_IL_SET ((uint32_t)0x00300000)
  69. /* ADC SPTx mask */
  70. #define SPT1_SPT_SET ((uint32_t)0x00000007)
  71. #define SPT2_SPT_SET ((uint32_t)0x00000007)
  72. /* ADC IDTRx registers offset */
  73. #define IDTR_OFFSET ((uint8_t)0x28)
  74. /* ADC0 RDTR register base address */
  75. #define RDTR_ADDRESS ((uint32_t)0x4001244C)
  76. /**
  77. * @}
  78. */
  79. /** @defgroup ADC_Private_Functions
  80. * @{
  81. */
  82. /**
  83. * @brief Reset the ADC interface and init the sturct ADC_InitPara.
  84. * @param ADCx: the ADC interface where x can be 1..3.
  85. * @param ADC_InitParaStruct : the sturct ADC_InitPara pointer.
  86. * @retval None
  87. */
  88. void ADC_DeInit(ADC_TypeDef *ADCx, ADC_InitPara *ADC_InitParaStruct)
  89. {
  90. if (ADCx == ADC0) {
  91. /* Enable ADC0 reset state */
  92. RCC_APB2PeriphReset_Enable(RCC_APB2PERIPH_ADC0RST, ENABLE);
  93. /* Release ADC0 from reset state */
  94. RCC_APB2PeriphReset_Enable(RCC_APB2PERIPH_ADC0RST, DISABLE);
  95. } else if (ADCx == ADC1) {
  96. /* Enable ADC1 reset state */
  97. RCC_APB2PeriphReset_Enable(RCC_APB2PERIPH_ADC1RST, ENABLE);
  98. /* Release ADC1 from reset state */
  99. RCC_APB2PeriphReset_Enable(RCC_APB2PERIPH_ADC1RST, DISABLE);
  100. }
  101. /* Initialize the ADC_Mode member,independent mode */
  102. ADC_InitParaStruct->ADC_Mode = ADC_MODE_INDEPENDENT;
  103. /* Initialize the ADC_Mode_Scan member,disable scan mode */
  104. ADC_InitParaStruct->ADC_Mode_Scan = DISABLE;
  105. /* Initialize the ADC_Mode_Continuous member,disable continuous mode */
  106. ADC_InitParaStruct->ADC_Mode_Continuous = DISABLE;
  107. /* Initialize the ADC_Trig_External member,choose T1 CC1 as external trigger */
  108. ADC_InitParaStruct->ADC_Trig_External = ADC_EXTERNAL_TRIGGER_MODE_T1_CC1;
  109. /* Initialize the ADC_Data_Align member,specifies the ADC data alignment right */
  110. ADC_InitParaStruct->ADC_Data_Align = ADC_DATAALIGN_RIGHT;
  111. /* Initialize the ADC_Channel_Number member,only 1 channel */
  112. ADC_InitParaStruct->ADC_Channel_Number = 1;
  113. }
  114. /**
  115. * @brief Initialize the ADCx interface parameters.
  116. * @param ADCx: the ADC interface where x can be 1..3.
  117. * @param ADC_InitParaStruct: the sturct ADC_InitPara pointer.
  118. * @retval None
  119. */
  120. void ADC_Init(ADC_TypeDef *ADCx, ADC_InitPara *ADC_InitParaStruct)
  121. {
  122. uint32_t temp1 = 0;
  123. uint8_t temp2 = 0;
  124. /* ADCx CTLR1 Configuration */
  125. /* Get the ADCx CTLR1 previous value */
  126. temp1 = ADCx->CTLR1;
  127. /* Clear SM bits */
  128. temp1 &= CTLR1_BITS_CLEAR;
  129. /* Configure ADCx: Dual mode and scan conversion mode */
  130. /* Set DUALMOD bits according to ADC_Mode value */
  131. /* Configure SCAN bit according to ADC_Mode_Scan value */
  132. temp1 |= (uint32_t)(ADC_InitParaStruct->ADC_Mode | ((uint32_t)ADC_InitParaStruct->ADC_Mode_Scan << 8));
  133. /* Write new value to ADCx CTLR1 */
  134. ADCx->CTLR1 = temp1;
  135. /* ADCx CTLR2 Configuration */
  136. /* Get the ADCx CTLR2 previous value */
  137. temp1 = ADCx->CTLR2;
  138. /* Clear CTN, DAL and ETSRC bits */
  139. temp1 &= CTLR2_BITS_CLEAR;
  140. /* Configure ADCx: select external trigger mode and continuous conversion mode */
  141. /* Configure DAL bit according to ADC_Data_Align value */
  142. /* Configure ETSRC bits according to ADC_Trig_External value */
  143. /* Configure CTN bit according to ADC_Mode_Continuous value */
  144. temp1 |= (uint32_t)(ADC_InitParaStruct->ADC_Data_Align | ADC_InitParaStruct->ADC_Trig_External |
  145. ((uint32_t)ADC_InitParaStruct->ADC_Mode_Continuous << 1));
  146. /* Write new value to ADCx CTLR2 */
  147. ADCx->CTLR2 = temp1;
  148. /* ADCx RSQ1 Configuration */
  149. /* Get the ADCx RSQ1 previous value */
  150. temp1 = ADCx->RSQ1;
  151. /* Clear RL bits */
  152. temp1 &= RSQ1_BITS_CLEAR;
  153. /* Configure ADCx: regular channel sequence length */
  154. /* Configure RL bits according to ADC_Channel_Number value */
  155. temp2 |= (uint8_t)(ADC_InitParaStruct->ADC_Channel_Number - (uint8_t)1);
  156. temp1 |= (uint32_t)temp2 << 20;
  157. /* Write new value to ADCx RSQ1 */
  158. ADCx->RSQ1 = temp1;
  159. }
  160. /**
  161. * @brief Enable or disable the ADCx interface.
  162. * @param ADCx: the ADC interface where x can be 1..3.
  163. * @param NewValue: New state of the ADCx interface.
  164. * This parameter can be: ENABLE or DISABLE.
  165. * @retval None
  166. */
  167. void ADC_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  168. {
  169. if (NewValue != DISABLE) {
  170. /* Enable the ADCx interface */
  171. ADCx->CTLR2 |= CTLR2_ADCON_SET;
  172. } else {
  173. /* Disable the ADCx interface */
  174. ADCx->CTLR2 &= ~CTLR2_ADCON_SET;
  175. }
  176. }
  177. /**
  178. * @brief Enable or disable the ADCx DMA request.
  179. * @param ADCx: the ADC interface where x can be 1..3.
  180. * Note: ADC1 doesn't support DMA function.
  181. * @param NewValue: New state of ADCx DMA transfer.
  182. * This parameter can be: ENABLE or DISABLE.
  183. * @retval None
  184. */
  185. void ADC_DMA_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  186. {
  187. if (NewValue != DISABLE) {
  188. /* Enable ADCx DMA request */
  189. ADCx->CTLR2 |= CTLR2_DMA_SET;
  190. } else {
  191. /* Disable ADCx DMA request */
  192. ADCx->CTLR2 &= ~CTLR2_DMA_SET;
  193. }
  194. }
  195. /**
  196. * @brief Enable or disable ADCx interrupts.
  197. * @param ADCx: the ADC interface where x can be 1..3.
  198. * @param ADC_INT: ADCx interrupt sources.
  199. * This parameter can be any combination of the following values:
  200. * @arg ADC_INT_EOC: Regular conversion over interrupt mask
  201. * @arg ADC_INT_AWE: Analog watchdog interrupt mask
  202. * @arg ADC_INT_EOIC: Inserted conversion over interrupt mask
  203. * @param NewValue: ADCx interrupts state.
  204. * This parameter can be: ENABLE or DISABLE.
  205. * @retval None
  206. */
  207. void ADC_INTConfig(ADC_TypeDef *ADCx, uint16_t ADC_INT, TypeState NewValue)
  208. {
  209. uint8_t temp_it = 0;
  210. /* ADCx INT old state */
  211. temp_it = (uint8_t)ADC_INT;
  212. if (NewValue != DISABLE) {
  213. /* Enable the ADCx interrupt */
  214. ADCx->CTLR1 |= temp_it;
  215. } else {
  216. /* Disable the ADCx interrupt */
  217. ADCx->CTLR1 &= (~(uint32_t)temp_it);
  218. }
  219. }
  220. /**
  221. * @brief ADCx calibration.
  222. * @param ADCx: the ADC interface where x can be 1..3.
  223. * @retval None
  224. */
  225. void ADC_Calibration(ADC_TypeDef *ADCx)
  226. {
  227. /* Reset the selected ADCx calibration registers */
  228. ADCx->CTLR2 |= CTLR2_RSTCLB_SET;
  229. /* Check the RSTCLB bit state */
  230. while ((ADCx->CTLR2 & CTLR2_RSTCLB_SET));
  231. /* Enable ADCx calibration process */
  232. ADCx->CTLR2 |= CTLR2_CLB_SET;
  233. /* Check the CLB bit state */
  234. while ((ADCx->CTLR2 & CTLR2_CLB_SET) != (uint32_t)RESET);
  235. }
  236. /**
  237. * @brief Enable or disable ADCx software start conversion.
  238. * @param ADCx: the ADC interface where x can be 1..3.
  239. * @param NewValue: ADCx software start conversion state.
  240. * This parameter can be: ENABLE or DISABLE.
  241. * @retval None
  242. */
  243. void ADC_SoftwareStartConv_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  244. {
  245. if (NewValue != DISABLE) {
  246. /* ADCx software conversion start */
  247. ADCx->CTLR2 |= CTLR2_ETERC_SWRCST_SET;
  248. } else {
  249. /* ADCx software conversion stop */
  250. ADCx->CTLR2 &= ~CTLR2_ETERC_SWRCST_SET;
  251. }
  252. }
  253. /**
  254. * @brief Get the bit state of ADCx software start conversion.
  255. * @param ADCx: the ADC interface where x can be 1..3.
  256. * @retval ADCx software start conversion state(SET or RESET).
  257. */
  258. TypeState ADC_GetSoftwareStartConvBitState(ADC_TypeDef *ADCx)
  259. {
  260. /* Check the SWRCST bit state*/
  261. if ((ADCx->CTLR2 & CTLR2_SWRCST_SET) != (uint32_t)RESET) {
  262. return SET;
  263. } else {
  264. return RESET;
  265. }
  266. }
  267. /**
  268. * @brief Configure the ADCx channel discontinuous mode.
  269. * @param ADCx: the ADC interface where x can be 1..3.
  270. * @param Number: the count value of discontinuous mode regular channel.
  271. * This number must be 1~8.
  272. * @retval None
  273. */
  274. void ADC_DiscModeChannelCount_Config(ADC_TypeDef *ADCx, uint8_t Number)
  275. {
  276. uint32_t temp1 = 0;
  277. uint32_t temp2 = 0;
  278. /* Get the old value of CTLR1 */
  279. temp1 = ADCx->CTLR1;
  280. /* Clear discontinuous mode channel count */
  281. temp1 &= CTLR1_DISNUM_RESET;
  282. /* Set the discontinuous mode channel count */
  283. temp2 = Number - 1;
  284. temp1 |= temp2 << 13;
  285. /* Write new value to CTLR1 */
  286. ADCx->CTLR1 = temp1;
  287. }
  288. /**
  289. * @brief Enable or disable the discontinuous mode.
  290. * @param ADCx: the ADC interface where x can be 1..3.
  291. * @param NewValue: ADCx discontinuous mode state.
  292. * This parameter can be: ENABLE or DISABLE.
  293. * @retval None
  294. */
  295. void ADC_DiscMode_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  296. {
  297. if (NewValue != DISABLE) {
  298. /* Enable ADCx regular discontinuous mode */
  299. ADCx->CTLR1 |= CTLR1_DISRC_SET;
  300. } else {
  301. /* Disable ADCx regular discontinuous mode */
  302. ADCx->CTLR1 &= ~CTLR1_DISRC_SET;
  303. }
  304. }
  305. /**
  306. * @brief Configure array and sample time.
  307. * @param ADCx: the ADC interface where x can be 1..3.
  308. * @param ADC_Channel: the selected ADC channel.
  309. * This parameter can be as follows:
  310. * @arg ADC_CHANNEL_0: ADC Channel0
  311. * @arg ADC_CHANNEL_1: ADC Channel1
  312. * @arg ADC_CHANNEL_2: ADC Channel2
  313. * @arg ADC_CHANNEL_3: ADC Channel3
  314. * @arg ADC_CHANNEL_4: ADC Channel4
  315. * @arg ADC_CHANNEL_5: ADC Channel5
  316. * @arg ADC_CHANNEL_6: ADC Channel6
  317. * @arg ADC_CHANNEL_7: ADC Channel7
  318. * @arg ADC_CHANNEL_8: ADC Channel8
  319. * @arg ADC_CHANNEL_9: ADC Channel9
  320. * @arg ADC_CHANNEL_10: ADC Channel10
  321. * @arg ADC_CHANNEL_11: ADC Channel11
  322. * @arg ADC_CHANNEL_12: ADC Channel12
  323. * @arg ADC_CHANNEL_13: ADC Channel13
  324. * @arg ADC_CHANNEL_14: ADC Channel14
  325. * @arg ADC_CHANNEL_15: ADC Channel15
  326. * @arg ADC_CHANNEL_16: ADC Channel16
  327. * @arg ADC_CHANNEL_17: ADC Channel17
  328. * @param Array: The regular group sequencer rank. This parameter must be between 1 to 16.
  329. * @param ADC_SampleTime: The sample time value.
  330. * This parameter can be one of the following values:
  331. * @arg ADC_SAMPLETIME_1POINT5: 1.5 cycles
  332. * @arg ADC_SAMPLETIME_7POINT5: 7.5 cycles
  333. * @arg ADC_SAMPLETIME_13POINT5: 13.5 cycles
  334. * @arg ADC_SAMPLETIME_28POINT5: 28.5 cycles
  335. * @arg ADC_SAMPLETIME_41POINT5: 41.5 cycles
  336. * @arg ADC_SAMPLETIME_55POINT5: 55.5 cycles
  337. * @arg ADC_SAMPLETIME_71POINT5: 71.5 cycles
  338. * @arg ADC_SAMPLETIME_239POINT5: 239.5 cycles
  339. * @retval None
  340. */
  341. void ADC_RegularChannel_Config(ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Array, uint8_t ADC_SampleTime)
  342. {
  343. uint32_t temp1 = 0, temp2 = 0;
  344. /* if ADC_Channel is between 10 to 17 */
  345. if (ADC_Channel > ADC_CHANNEL_9) {
  346. /* Get SPT1 value */
  347. temp1 = ADCx->SPT1;
  348. /* Calculate the mask to clear */
  349. temp2 = SPT1_SPT_SET << (3 * (ADC_Channel - 10));
  350. /* Clear sample time */
  351. temp1 &= ~temp2;
  352. /* Calculate the mask to set */
  353. temp2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
  354. /* Configure sample time */
  355. temp1 |= temp2;
  356. /* Write to SPT1 */
  357. ADCx->SPT1 = temp1;
  358. } else { /* ADC_Channel is between 0 to 9 */
  359. /* Get SPT2 value */
  360. temp1 = ADCx->SPT2;
  361. /* Calculate the mask to clear */
  362. temp2 = SPT2_SPT_SET << (3 * ADC_Channel);
  363. /* Clear sample time */
  364. temp1 &= ~temp2;
  365. /* Calculate the mask to set */
  366. temp2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
  367. /* Set sample time */
  368. temp1 |= temp2;
  369. /* Write to SPT2 */
  370. ADCx->SPT2 = temp1;
  371. }
  372. /* For Array 1 to 6 */
  373. if (Array < 7) {
  374. /* Get RSQ3 value */
  375. temp1 = ADCx->RSQ3;
  376. /* Calculate the mask to clear */
  377. temp2 = RSQ3_RSQ_SET << (5 * (Array - 1));
  378. /* Clear RSQ3 bits */
  379. temp1 &= ~temp2;
  380. /* Calculate the mask to set */
  381. temp2 = (uint32_t)ADC_Channel << (5 * (Array - 1));
  382. /* Configure the RSQ3 bits */
  383. temp1 |= temp2;
  384. /* Write to RSQ3 */
  385. ADCx->RSQ3 = temp1;
  386. }
  387. /* For Array 7 to 12 */
  388. else if (Array < 13) {
  389. /* Get RSQ2 value */
  390. temp1 = ADCx->RSQ2;
  391. /* Calculate the mask to clear */
  392. temp2 = RSQ2_RSQ_SET << (5 * (Array - 7));
  393. /* Clear the old RSQ2 bits */
  394. temp1 &= ~temp2;
  395. /* Calculate the mask to set */
  396. temp2 = (uint32_t)ADC_Channel << (5 * (Array - 7));
  397. /* Set the RSQ2 bits */
  398. temp1 |= temp2;
  399. /* Write to RSQ2 */
  400. ADCx->RSQ2 = temp1;
  401. }
  402. /* For Array 13 to 16 */
  403. else {
  404. /* Get RSQ1 value */
  405. temp1 = ADCx->RSQ1;
  406. /* Calculate the mask to clear */
  407. temp2 = RSQ1_RSQ_SET << (5 * (Array - 13));
  408. /* Clear the old RSQ1 bits */
  409. temp1 &= ~temp2;
  410. /* Calculate the mask to set */
  411. temp2 = (uint32_t)ADC_Channel << (5 * (Array - 13));
  412. /* Set the RSQ1 bits */
  413. temp1 |= temp2;
  414. /* Write to RSQ1 */
  415. ADCx->RSQ1 = temp1;
  416. }
  417. }
  418. /**
  419. * @brief Enable or disable the ADCx external conversion.
  420. * @param ADCx: the ADC interface where x can be 1..3.
  421. * @param NewValue: ADCx external trigger state.
  422. * This parameter can be: ENABLE or DISABLE.
  423. * @retval None
  424. */
  425. void ADC_ExternalTrigConv_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  426. {
  427. if (NewValue != DISABLE) {
  428. /* Enable external trigger conversion */
  429. ADCx->CTLR2 |= CTLR2_ETERC_SET;
  430. } else {
  431. /* Disable external trigger conversion */
  432. ADCx->CTLR2 &= ~CTLR2_ETERC_SET;
  433. }
  434. }
  435. /**
  436. * @brief Return the ADCx regular channel conversion data.
  437. * @param ADCx: the ADC interface where x can be 1..3.
  438. * @retval conversion data.
  439. */
  440. uint16_t ADC_GetConversionValue(ADC_TypeDef *ADCx)
  441. {
  442. /* Return ADCx conversion data */
  443. return (uint16_t) ADCx->RDTR;
  444. }
  445. /**
  446. * @brief Return the last ADC0 and ADC1 conversion result data in dual mode.
  447. * @retval The Data conversion value.
  448. */
  449. uint32_t ADC_GetDualModeConversionValue(void)
  450. {
  451. /* Return conversion value */
  452. return (*(__IO uint32_t *) RDTR_ADDRESS);
  453. }
  454. /**
  455. * @brief Enable or disable ADCx automatic inserted conversion.
  456. * @param ADCx: the ADC interface where x can be 1..3.
  457. * @param NewValue: ADCx auto inserted conversion state.
  458. * This parameter can be: ENABLE or DISABLE.
  459. * @retval None
  460. */
  461. void ADC_AutoInsertedConv_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  462. {
  463. if (NewValue != DISABLE) {
  464. /* Enable ADCx automatic inserted conversion */
  465. ADCx->CTLR1 |= CTLR1_ICA_SET;
  466. } else {
  467. /* Disable ADCx automatic inserted conversion */
  468. ADCx->CTLR1 &= ~CTLR1_ICA_SET;
  469. }
  470. }
  471. /**
  472. * @brief Enable or disable the discontinuous mode for ADCx inserted group channel.
  473. * @param ADCx: the ADC interface where x can be 1..3.
  474. * @param NewValue: ADCx discontinuous mode state.
  475. * This parameter can be: ENABLE or DISABLE.
  476. * @retval None
  477. */
  478. void ADC_InsertedDiscMode_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  479. {
  480. if (NewValue != DISABLE) {
  481. /* Enable the inserted discontinuous mode of the selected ADC channel */
  482. ADCx->CTLR1 |= CTLR1_DISIC_SET;
  483. } else {
  484. /* Disable the inserted discontinuous mode of the selected ADC channel */
  485. ADCx->CTLR1 &= ~CTLR1_DISIC_SET;
  486. }
  487. }
  488. /**
  489. * @brief Configure the ADCx inserted channels external trigger conversion.
  490. * @param ADCx: the ADC interface where x can be 1..3.
  491. * @param ADC_ExternalTrigInsertConv: ADC inserted conversion trigger.
  492. * This parameter can be as follows:
  493. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T1_TRGO: Timer1 TRIG event (used in ADC0, ADC1 and ADC2)
  494. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T1_CC4: Timer1 capture compare4 (used in ADC0, ADC1 and ADC2)
  495. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T2_TRGO: Timer2 TRIG event (used in ADC0 and ADC1)
  496. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T2_CC1: Timer2 capture compare1 (used in ADC0 and ADC1)
  497. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T3_CC4: Timer3 capture compare4 (used in ADC0 and ADC1)
  498. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T4_TRGO: Timer4 TRIG event (used in ADC0 and ADC1)
  499. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_EXT_IT15_T8_CC4: External interrupt line 15 or Timer8
  500. * capture compare4 (used in ADC0 and ADC1)
  501. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T4_CC3: Timer4 capture compare3 (used in ADC2)
  502. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T8_CC2: Timer8 capture compare2 (used in ADC2)
  503. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T8_CC4: Timer8 capture compare4 (used in ADC2)
  504. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T5_TRGO: Timer5 TRIG event (used in ADC2)
  505. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_T5_CC4: Timer5 capture compare4 (used in ADC2)
  506. * @arg ADC_EXTERNAL_TRIG_INSERTCONV_NONE: Inserted conversion started by software (used in ADC0, ADC1 and ADC2)
  507. * @retval None
  508. */
  509. void ADC_ExternalTrigInsertedConv_Config(ADC_TypeDef *ADCx, uint32_t ADC_ExternalTrigInsertConv)
  510. {
  511. uint32_t temp = 0;
  512. /* Get CRLR2 value */
  513. temp = ADCx->CTLR2;
  514. /* Clear inserted external event */
  515. temp &= CTLR2_ETSIC_RESET;
  516. /* Configure inserted external event */
  517. temp |= ADC_ExternalTrigInsertConv;
  518. /* Write to CTLR2 */
  519. ADCx->CTLR2 = temp;
  520. }
  521. /**
  522. * @brief Enable or disable the ADCx inserted channels conversion through
  523. * external trigger
  524. * @param ADCx: the ADC interface where x can be 1..3.
  525. * @param NewValue: ADCx external trigger start of inserted conversion state.
  526. * This parameter can be: ENABLE or DISABLE.
  527. * @retval None
  528. */
  529. void ADC_ExternalTrigInsertedConv_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  530. {
  531. if (NewValue != DISABLE) {
  532. /* Enable external event */
  533. ADCx->CTLR2 |= CTLR2_ETEIC_SET;
  534. } else {
  535. /* Disable external event */
  536. ADCx->CTLR2 &= ~CTLR2_ETEIC_SET;
  537. }
  538. }
  539. /**
  540. * @brief Enable or disable ADCx inserted channels conversion start.
  541. * @param ADCx: the ADC interface where x can be 1..3.
  542. * @param NewValue: ADC software start inserted conversion state.
  543. * This parameter can be: ENABLE or DISABLE.
  544. * @retval None
  545. */
  546. void ADC_SoftwareStartInsertedConv_Enable(ADC_TypeDef *ADCx, TypeState NewValue)
  547. {
  548. if (NewValue != DISABLE) {
  549. /* Start ADCx inserted conversion */
  550. ADCx->CTLR2 |= CTLR2_ETEIC_SWICST_SET;
  551. } else {
  552. /* Stop ADCx inserted conversion */
  553. ADCx->CTLR2 &= ~CTLR2_ETEIC_SWICST_SET;
  554. }
  555. }
  556. /**
  557. * @brief Get ADC Software start inserted conversion State.
  558. * @param ADCx: the ADC interface where x can be 1..3.
  559. * @retval ADC software start inserted conversion state(SET or RESET).
  560. */
  561. TypeState ADC_GetSoftwareStartInsertedConvCmdBitState(ADC_TypeDef *ADCx)
  562. {
  563. /* Check SWICST bit */
  564. if ((ADCx->CTLR2 & CTLR2_SWICST_SET) != (uint32_t)RESET) {
  565. /* Set SWICST bit */
  566. return SET;
  567. } else {
  568. /* Reset SWICST bit */
  569. return RESET;
  570. }
  571. }
  572. /**
  573. * @brief Configure Array and sample time for the selected ADC inserted channel.
  574. * @param ADCx: the ADC interface where x can be 1..3.
  575. * @param ADC_Channel: the selected ADC channel.
  576. * This parameter can be as follows:
  577. * @arg ADC_CHANNEL_0: ADC Channel0
  578. * @arg ADC_CHANNEL_1: ADC Channel1
  579. * @arg ADC_CHANNEL_2: ADC Channel2
  580. * @arg ADC_CHANNEL_3: ADC Channel3
  581. * @arg ADC_CHANNEL_4: ADC Channel4
  582. * @arg ADC_CHANNEL_5: ADC Channel5
  583. * @arg ADC_CHANNEL_6: ADC Channel6
  584. * @arg ADC_CHANNEL_7: ADC Channel7
  585. * @arg ADC_CHANNEL_8: ADC Channel8
  586. * @arg ADC_CHANNEL_9: ADC Channel9
  587. * @arg ADC_CHANNEL_10: ADC Channel10
  588. * @arg ADC_CHANNEL_11: ADC Channel11
  589. * @arg ADC_CHANNEL_12: ADC Channel12
  590. * @arg ADC_CHANNEL_13: ADC Channel13
  591. * @arg ADC_CHANNEL_14: ADC Channel14
  592. * @arg ADC_CHANNEL_15: ADC Channel15
  593. * @arg ADC_CHANNEL_16: ADC Channel16
  594. * @arg ADC_CHANNEL_17: ADC Channel17
  595. * @param Array: The inserted group sequencer Array. This parameter must be between 1 and 4.
  596. * @param ADC_SampleTime: The sample time of the selected channel.
  597. * This parameter can be as follows:
  598. * @arg ADC_SAMPLETIME_1POINT5: 1.5 cycles
  599. * @arg ADC_SAMPLETIME_7POINT5: 7.5 cycles
  600. * @arg ADC_SAMPLETIME_13POINT5: 13.5 cycles
  601. * @arg ADC_SAMPLETIME_28POINT5: 28.5 cycles
  602. * @arg ADC_SAMPLETIME_41POINT5: 41.5 cycles
  603. * @arg ADC_SAMPLETIME_55POINT5: 55.5 cycles
  604. * @arg ADC_SAMPLETIME_71POINT5: 71.5 cycles
  605. * @arg ADC_SAMPLETIME_239POINT5: 239.5 cycles
  606. * @retval None
  607. */
  608. void ADC_InsertedChannel_Config(ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Array, uint8_t ADC_SampleTime)
  609. {
  610. uint32_t temp1 = 0, temp2 = 0, temp3 = 0;
  611. /* if ADC_Channel is between 10 to 17 */
  612. if (ADC_Channel > ADC_CHANNEL_9) {
  613. /* Get SPT1 value */
  614. temp1 = ADCx->SPT1;
  615. /* Calculate the sample time mask */
  616. temp2 = SPT1_SPT_SET << (3 * (ADC_Channel - 10));
  617. /* Clear sample time */
  618. temp1 &= ~temp2;
  619. /* Calculate the sample time mask */
  620. temp2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
  621. /* Set sample time */
  622. temp1 |= temp2;
  623. /* Write to SPT1 */
  624. ADCx->SPT1 = temp1;
  625. } else { /* ADC_Channel is between 0 to 9 */
  626. /* Get SPT2 value */
  627. temp1 = ADCx->SPT2;
  628. /* Calculate the sample time mask */
  629. temp2 = SPT2_SPT_SET << (3 * ADC_Channel);
  630. /* Clear sample time */
  631. temp1 &= ~temp2;
  632. /* Calculate the sample time mask */
  633. temp2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
  634. /* Set sample time */
  635. temp1 |= temp2;
  636. /* Write to SPT2 */
  637. ADCx->SPT2 = temp1;
  638. }
  639. /* Array configuration */
  640. /* Get ISQ value */
  641. temp1 = ADCx->ISQ;
  642. /* Get IL value: Number = IL+1 */
  643. temp3 = (temp1 & ISQ_IL_SET) >> 20;
  644. /* Calculate the ISQ mask : ((Array-1)+(4-IL-1)) */
  645. temp2 = ISQ_ISQ_SET << (5 * (uint8_t)((Array + 3) - (temp3 + 1)));
  646. /* Clear ISQx bits */
  647. temp1 &= ~temp2;
  648. /* Calculate the ISQ mask: ((Array-1)+(4-IL-1)) */
  649. temp2 = (uint32_t)ADC_Channel << (5 * (uint8_t)((Array + 3) - (temp3 + 1)));
  650. /* Set ISQx bits */
  651. temp1 |= temp2;
  652. /* Write to ISQ */
  653. ADCx->ISQ = temp1;
  654. }
  655. /**
  656. * @brief Configure the sequencer length of inserted channels
  657. * @param ADCx: the ADC interface where x can be 1..3.
  658. * @param Length: The sequencer length.
  659. * This parameter must be a number between 1 to 4.
  660. * @retval None
  661. */
  662. void ADC_InsertedSequencerLength_Config(ADC_TypeDef *ADCx, uint8_t Length)
  663. {
  664. uint32_t temp1 = 0;
  665. uint32_t temp2 = 0;
  666. /* Get ISQ value */
  667. temp1 = ADCx->ISQ;
  668. /* Clear IL bits */
  669. temp1 &= ~ISQ_IL_SET;
  670. /* Set IL bits */
  671. temp2 = Length - 1;
  672. temp1 |= temp2 << 20;
  673. /* Write to ISQ */
  674. ADCx->ISQ = temp1;
  675. }
  676. /**
  677. * @brief Set the offset of the inserted channels conversion value.
  678. * @param ADCx: the ADC interface where x can be 1..3.
  679. * @param ADC_InsertedChannel: one of the four inserted channels to set its offset.
  680. * This parameter can be one of the following values:
  681. * @arg ADC_INSERTEDCHANNEL_1: Inserted Channel1
  682. * @arg ADC_INSERTEDCHANNEL_2: Inserted Channel2
  683. * @arg ADC_INSERTEDCHANNEL_3: Inserted Channel3
  684. * @arg ADC_INSERTEDCHANNEL_4: Inserted Channel4
  685. * @param Offset: the offset value of the selected ADC inserted channel
  686. * This parameter must be a 12bit value.
  687. * @retval None
  688. */
  689. void ADC_SetInsertedOffset(ADC_TypeDef *ADCx, uint8_t ADC_InsertedChannel, uint16_t Offset)
  690. {
  691. __IO uint32_t temp = 0;
  692. temp = (uint32_t)ADCx;
  693. temp += ADC_InsertedChannel;
  694. /* Set the offset of the selected inserted channel */
  695. *(__IO uint32_t *) temp = (uint32_t)Offset;
  696. }
  697. /**
  698. * @brief Get the ADC inserted channel conversion result
  699. * @param ADCx: the ADC interface where x can be 1..3.
  700. * @param ADC_InsertedChannel: ADC inserted channel.
  701. * This parameter can be one of the following values:
  702. * @arg ADC_INSERTEDCHANNEL_1: Inserted Channel1
  703. * @arg ADC_INSERTEDCHANNEL_2: Inserted Channel2
  704. * @arg ADC_INSERTEDCHANNEL_3: Inserted Channel3
  705. * @arg ADC_INSERTEDCHANNEL_4: Inserted Channel4
  706. * @retval The conversion value.
  707. */
  708. uint16_t ADC_GetInsertedConversionValue(ADC_TypeDef *ADCx, uint8_t ADC_InsertedChannel)
  709. {
  710. __IO uint32_t temp = 0;
  711. temp = (uint32_t)ADCx;
  712. temp += ADC_InsertedChannel + IDTR_OFFSET;
  713. /* Return the result of the selected inserted channel conversion */
  714. return (uint16_t)(*(__IO uint32_t *) temp);
  715. }
  716. /**
  717. * @brief Enable or disable the analog watchdog.
  718. * @param ADCx: the ADC interface where x can be 1..3.
  719. * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration.
  720. * This parameter can be one of the following values:
  721. * @arg ADC_ANALOGWATCHDOG_SINGLEREGENABLE: single regular channel
  722. * @arg ADC_ANALOGWATCHDOG_SINGLEINSERTENABLE: single inserted channel
  723. * @arg ADC_ANALOGWATCHDOG_SINGLEREGORINSERTENABLE: single regular or inserted channel
  724. * @arg ADC_ANALOGWATCHDOG_ALLREGENABLE: all regular channel
  725. * @arg ADC_ANALOGWATCHDOG_ALLINSERTENABLE: all inserted channel
  726. * @arg ADC_ANALOGWATCHDOG_ALLREGALLINSERTENABLE: all regular and inserted channels
  727. * @arg ADC_ANALOGWATCHDOG_NONE: No channel
  728. * @retval None
  729. */
  730. void ADC_AnalogWatchdog_Enable(ADC_TypeDef *ADCx, uint32_t ADC_AnalogWatchdog)
  731. {
  732. uint32_t temp = 0;
  733. /* Get CTLR1 value */
  734. temp = ADCx->CTLR1;
  735. /* Clear AWDEN, AWDENJ and AWDSGL bits */
  736. temp &= CTLR1_AWDMODE_RESET;
  737. /* Set the analog watchdog mode */
  738. temp |= ADC_AnalogWatchdog;
  739. /* Write to CTLR1 */
  740. ADCx->CTLR1 = temp;
  741. }
  742. /**
  743. * @brief Configure the high and low thresholds of the analog watchdog.
  744. * @param ADCx: the ADC interface where x can be 1..3.
  745. * @param HighThreshold: the ADC analog watchdog High threshold value.
  746. * This parameter must be a 12bit value.
  747. * @param LowThreshold: the ADC analog watchdog Low threshold value.
  748. * This parameter must be a 12bit value.
  749. * @retval None
  750. */
  751. void ADC_AnalogWatchdogThresholds_Config(ADC_TypeDef *ADCx, uint16_t HighThreshold,
  752. uint16_t LowThreshold)
  753. {
  754. /* Set the ADCx high threshold */
  755. ADCx->AWHT = HighThreshold;
  756. /* Set the ADCx low threshold */
  757. ADCx->AWLT = LowThreshold;
  758. }
  759. /**
  760. * @brief Configure the analog watchdog on single channel mode.
  761. * @param ADCx: the ADC interface where x can be 1..3.
  762. * @param ADC_Channel: ADC channel.
  763. * This parameter can be as follows:
  764. * @arg ADC_CHANNEL_0: ADC Channel0
  765. * @arg ADC_CHANNEL_1: ADC Channel1
  766. * @arg ADC_CHANNEL_2: ADC Channel2
  767. * @arg ADC_CHANNEL_3: ADC Channel3
  768. * @arg ADC_CHANNEL_4: ADC Channel4
  769. * @arg ADC_CHANNEL_5: ADC Channel5
  770. * @arg ADC_CHANNEL_6: ADC Channel6
  771. * @arg ADC_CHANNEL_7: ADC Channel7
  772. * @arg ADC_CHANNEL_8: ADC Channel8
  773. * @arg ADC_CHANNEL_9: ADC Channel9
  774. * @arg ADC_CHANNEL_10: ADC Channel10
  775. * @arg ADC_CHANNEL_11: ADC Channel11
  776. * @arg ADC_CHANNEL_12: ADC Channel12
  777. * @arg ADC_CHANNEL_13: ADC Channel13
  778. * @arg ADC_CHANNEL_14: ADC Channel14
  779. * @arg ADC_CHANNEL_15: ADC Channel15
  780. * @arg ADC_CHANNEL_16: ADC Channel16
  781. * @arg ADC_CHANNEL_17: ADC Channel17
  782. * @retval None
  783. */
  784. void ADC_AnalogWatchdogSingleChannel_Config(ADC_TypeDef *ADCx, uint8_t ADC_Channel)
  785. {
  786. uint32_t temp = 0;
  787. /* Get CTLR1 value */
  788. temp = ADCx->CTLR1;
  789. /* Clear AWCS */
  790. temp &= CTLR1_AWCS_RESET;
  791. /* Set the Analog watchdog channel */
  792. temp |= ADC_Channel;
  793. /* Write to CTLR1 */
  794. ADCx->CTLR1 = temp;
  795. }
  796. /**
  797. * @brief Enable or disable the temperature sensor and Vrefint channel.
  798. * @param NewValue: the state of the temperature sensor.
  799. * This parameter can be: ENABLE or DISABLE.
  800. * @retval None
  801. */
  802. void ADC_TempSensorVrefint_Enable(TypeState NewValue)
  803. {
  804. if (NewValue != DISABLE) {
  805. /* Enable the temperature sensor and Vrefint channel*/
  806. ADC0->CTLR2 |= CTLR2_TSVREN_SET;
  807. } else {
  808. /* Disable the temperature sensor and Vrefint channel*/
  809. ADC0->CTLR2 &= ~CTLR2_TSVREN_SET;
  810. }
  811. }
  812. /**
  813. * @brief Check the ADC flag.
  814. * @param ADCx: the ADC interface where x can be 1..3.
  815. * @param ADC_FLAG: the flag to check.
  816. * This parameter can be as follows:
  817. * @arg ADC_FLAG_AWE: The flag of the analog watchdog
  818. * @arg ADC_FLAG_EOC: The flag of the end of conversion
  819. * @arg ADC_FLAG_EOIC: The flag of the end of inserted group conversion
  820. * @arg ADC_FLAG_STIC: The flag of the start of inserted group conversion
  821. * @arg ADC_FLAG_STRC: The flag of the start of regular group conversion
  822. * @retval ADC_FLAG state(SET or RESET).
  823. */
  824. TypeState ADC_GetBitState(ADC_TypeDef *ADCx, uint8_t ADC_FLAG)
  825. {
  826. /* Check the specified ADC flag state */
  827. if ((ADCx->STR & ADC_FLAG) != (uint8_t)RESET) {
  828. /* ADC_FLAG is set */
  829. return SET;
  830. } else {
  831. /* ADC_FLAG is reset */
  832. return RESET;
  833. }
  834. }
  835. /**
  836. * @brief Clear the ADCx's pending flags.
  837. * @param ADCx: the ADC interface where x can be 1..3.
  838. * @param ADC_FLAG: the flag to clear.
  839. * This parameter can be any combination of the following values:
  840. * @arg ADC_FLAG_AWE: The flag of the analog watchdog
  841. * @arg ADC_FLAG_EOC: The flag of the end of conversion
  842. * @arg ADC_FLAG_EOIC: The flag of the end of inserted group conversion
  843. * @arg ADC_FLAG_STIC: The flag of the start of inserted group conversion
  844. * @arg ADC_FLAG_STRC: The flag of the start of regular group conversion
  845. * @retval None
  846. */
  847. void ADC_ClearBitState(ADC_TypeDef *ADCx, uint8_t ADC_FLAG)
  848. {
  849. /* Clear the selected ADC flags */
  850. ADCx->STR = ~(uint32_t)ADC_FLAG;
  851. }
  852. /**
  853. * @brief Check the specified ADC interrupt.
  854. * @param ADCx: the ADC interface where x can be 1..3.
  855. * @param ADC_INT: ADC interrupt source.
  856. * This parameter can be one of the following values:
  857. * @arg ADC_INT_EOC: The interrupt mask of the end of conversion
  858. * @arg ADC_INT_AWE: The interrupt mask of the analog watchdog
  859. * @arg ADC_INT_EOIC: The interrupt mask of the end of inserted conversion
  860. * @retval The new value of ADC_INT (SET or RESET).
  861. */
  862. TypeState ADC_GetIntState(ADC_TypeDef *ADCx, uint16_t ADC_INT)
  863. {
  864. uint32_t temp_it = 0, temp_enable = 0;
  865. /* Get the ADC interrupt mask index */
  866. temp_it = ADC_INT >> 8;
  867. /* Get the ADC_INT enable bit state */
  868. temp_enable = (ADCx->CTLR1 & (uint8_t)ADC_INT) ;
  869. /* Check the state of the specified ADC interrupt */
  870. if (((ADCx->STR & temp_it) != (uint32_t)RESET) && temp_enable) {
  871. /* ADC_INT is set */
  872. return SET;
  873. } else {
  874. /* ADC_INT is reset */
  875. return RESET;
  876. }
  877. }
  878. /**
  879. * @brief Clear the ADCx's interrupt pending bits.
  880. * @param ADCx: the ADC interface where x can be 1..3.
  881. * @param ADC_INT: the ADC interrupt pending bit.
  882. * This parameter can be any combination of the following values:
  883. * @arg ADC_INT_EOC: The interrupt mask of the end of conversion
  884. * @arg ADC_INT_AWE: The interrupt mask of the analog watchdog
  885. * @arg ADC_INT_EOIC: The interrupt mask of the end of inserted conversion
  886. * @retval None
  887. */
  888. void ADC_ClearIntBitState(ADC_TypeDef *ADCx, uint16_t ADC_INT)
  889. {
  890. uint8_t temp_it = 0;
  891. /* Get the ADC interrupt mask index */
  892. temp_it = (uint8_t)(ADC_INT >> 8);
  893. /* Clear ADCx interrupt pending bits */
  894. ADCx->STR = ~(uint32_t)temp_it;
  895. }
  896. /**
  897. * @}
  898. */
  899. /**
  900. * @}
  901. */
  902. /**
  903. * @}
  904. */