gd32f10x_adc.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /*!
  2. \file gd32f10x_adc.c
  3. \brief ADC driver
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #include "gd32f10x_adc.h"
  33. /* discontinuous mode macro*/
  34. #define ADC_CHANNEL_LENGTH_SUBTRACT_ONE ((uint8_t)1U)
  35. /* ADC regular channel macro */
  36. #define ADC_REGULAR_CHANNEL_RANK_SIX ((uint8_t)6U)
  37. #define ADC_REGULAR_CHANNEL_RANK_TWELVE ((uint8_t)12U)
  38. #define ADC_REGULAR_CHANNEL_RANK_SIXTEEN ((uint8_t)16U)
  39. #define ADC_REGULAR_CHANNEL_RANK_LENGTH ((uint8_t)5U)
  40. /* ADC sampling time macro */
  41. #define ADC_CHANNEL_SAMPLE_TEN ((uint8_t)10U)
  42. #define ADC_CHANNEL_SAMPLE_EIGHTEEN ((uint8_t)18U)
  43. #define ADC_CHANNEL_SAMPLE_LENGTH ((uint8_t)3U)
  44. /* ADC inserted channel macro */
  45. #define ADC_INSERTED_CHANNEL_RANK_LENGTH ((uint8_t)5U)
  46. #define ADC_INSERTED_CHANNEL_SHIFT_LENGTH ((uint8_t)15U)
  47. /* ADC inserted channel offset macro */
  48. #define ADC_OFFSET_LENGTH ((uint8_t)3U)
  49. #define ADC_OFFSET_SHIFT_LENGTH ((uint8_t)4U)
  50. /*!
  51. \brief reset ADC
  52. \param[in] adc_periph: ADCx, x=0,1,2
  53. \param[out] none
  54. \retval none
  55. */
  56. void adc_deinit(uint32_t adc_periph)
  57. {
  58. switch(adc_periph){
  59. case ADC0:
  60. /* reset ADC0 */
  61. rcu_periph_reset_enable(RCU_ADC0RST);
  62. rcu_periph_reset_disable(RCU_ADC0RST);
  63. break;
  64. case ADC1:
  65. /* reset ADC1 */
  66. rcu_periph_reset_enable(RCU_ADC1RST);
  67. rcu_periph_reset_disable(RCU_ADC1RST);
  68. break;
  69. #ifndef GD32F10X_CL
  70. case ADC2:
  71. rcu_periph_reset_enable(RCU_ADC2RST);
  72. rcu_periph_reset_disable(RCU_ADC2RST);
  73. break;
  74. #endif /* GD32F10X_CL */
  75. default:
  76. break;
  77. }
  78. }
  79. /*!
  80. \brief configure the ADC sync mode
  81. \param[in] mode: ADC mode
  82. only one parameter can be selected which is shown as below:
  83. \arg ADC_MODE_FREE: all the ADCs work independently
  84. \arg ADC_DAUL_REGULAL_PARALLEL_INSERTED_PARALLEL: ADC0 and ADC1 work in combined regular parallel + inserted parallel mode
  85. \arg ADC_DAUL_REGULAL_PARALLEL_INSERTED_ROTATION: ADC0 and ADC1 work in combined regular parallel + trigger rotation mode
  86. \arg ADC_DAUL_INSERTED_PARALLEL_REGULAL_FOLLOWUP_FAST: ADC0 and ADC1 work in combined inserted parallel + follow-up fast mode
  87. \arg ADC_DAUL_INSERTED_PARALLEL_REGULAL_FOLLOWUP_SLOW: ADC0 and ADC1 work in combined inserted parallel + follow-up slow mode
  88. \arg ADC_DAUL_INSERTED_PARALLEL: ADC0 and ADC1 work in inserted parallel mode only
  89. \arg ADC_DAUL_REGULAL_PARALLEL: ADC0 and ADC1 work in regular parallel mode only
  90. \arg ADC_DAUL_REGULAL_FOLLOWUP_FAST: ADC0 and ADC1 work in follow-up fast mode only
  91. \arg ADC_DAUL_REGULAL_FOLLOWUP_SLOW: ADC0 and ADC1 work in follow-up slow mode only
  92. \arg ADC_DAUL_INSERTED_TRIGGER_ROTATION: ADC0 and ADC1 work in trigger rotation mode only
  93. \param[out] none
  94. \retval none
  95. */
  96. void adc_mode_config(uint32_t mode)
  97. {
  98. ADC_CTL0(ADC0) &= ~(ADC_CTL0_SYNCM);
  99. ADC_CTL0(ADC0) |= mode;
  100. }
  101. /*!
  102. \brief enable or disable ADC special function
  103. \param[in] adc_periph: ADCx, x=0,1,2
  104. \param[in] function: the function to config
  105. only one parameter can be selected which is shown as below:
  106. \arg ADC_SCAN_MODE: scan mode select
  107. \arg ADC_INSERTED_CHANNEL_AUTO: inserted channel group convert automatically
  108. \arg ADC_CONTINUOUS_MODE: continuous mode select
  109. \param[in] newvalue: ENABLE or DISABLE
  110. \param[out] none
  111. \retval none
  112. */
  113. void adc_special_function_config(uint32_t adc_periph, uint32_t function, ControlStatus newvalue)
  114. {
  115. if(newvalue){
  116. if(0U != (function & ADC_SCAN_MODE)){
  117. /* enable scan mode */
  118. ADC_CTL0(adc_periph) |= ADC_SCAN_MODE;
  119. }
  120. if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
  121. /* enable inserted channel group convert automatically */
  122. ADC_CTL0(adc_periph) |= ADC_INSERTED_CHANNEL_AUTO;
  123. }
  124. if(0U != (function & ADC_CONTINUOUS_MODE)){
  125. /* enable continuous mode */
  126. ADC_CTL1(adc_periph) |= ADC_CONTINUOUS_MODE;
  127. }
  128. }else{
  129. if(0U != (function & ADC_SCAN_MODE)){
  130. /* disable scan mode */
  131. ADC_CTL0(adc_periph) &= ~ADC_SCAN_MODE;
  132. }
  133. if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
  134. /* disable inserted channel group convert automatically */
  135. ADC_CTL0(adc_periph) &= ~ADC_INSERTED_CHANNEL_AUTO;
  136. }
  137. if(0U != (function & ADC_CONTINUOUS_MODE)){
  138. /* disable continuous mode */
  139. ADC_CTL1(adc_periph) &= ~ADC_CONTINUOUS_MODE;
  140. }
  141. }
  142. }
  143. /*!
  144. \brief configure ADC data alignment
  145. \param[in] adc_periph: ADCx, x=0,1,2
  146. \param[in] data_alignment: data alignment select
  147. only one parameter can be selected which is shown as below:
  148. \arg ADC_DATAALIGN_RIGHT: LSB alignment
  149. \arg ADC_DATAALIGN_LEFT: MSB alignment
  150. \param[out] none
  151. \retval none
  152. */
  153. void adc_data_alignment_config(uint32_t adc_periph, uint32_t data_alignment)
  154. {
  155. if(ADC_DATAALIGN_RIGHT != data_alignment){
  156. /* MSB alignment */
  157. ADC_CTL1(adc_periph) |= ADC_CTL1_DAL;
  158. }else{
  159. /* LSB alignment */
  160. ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DAL);
  161. }
  162. }
  163. /*!
  164. \brief enable ADC interface
  165. \param[in] adc_periph: ADCx, x=0,1,2
  166. \param[out] none
  167. \retval none
  168. */
  169. void adc_enable(uint32_t adc_periph)
  170. {
  171. if(RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)){
  172. /* enable ADC */
  173. ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_ADCON;
  174. }
  175. }
  176. /*!
  177. \brief disable ADC interface
  178. \param[in] adc_periph: ADCx, x=0,1,2
  179. \param[out] none
  180. \retval none
  181. */
  182. void adc_disable(uint32_t adc_periph)
  183. {
  184. /* disable ADC */
  185. ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ADCON);
  186. }
  187. /*!
  188. \brief ADC calibration and reset calibration(GD32F10x_MD series without this function)
  189. \param[in] adc_periph: ADCx, x=0,1,2
  190. \param[out] none
  191. \retval none
  192. */
  193. void adc_calibration_enable(uint32_t adc_periph)
  194. {
  195. /* reset the selected ADC1 calibration registers */
  196. ADC_CTL1(adc_periph) |= (uint32_t) ADC_CTL1_RSTCLB;
  197. /* check the RSTCLB bit state */
  198. while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)){
  199. }
  200. /* enable ADC calibration process */
  201. ADC_CTL1(adc_periph) |= ADC_CTL1_CLB;
  202. /* check the CLB bit state */
  203. while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_CLB)){
  204. }
  205. }
  206. /*!
  207. \brief enable the temperature sensor and Vrefint channel
  208. \param[in] none
  209. \param[out] none
  210. \retval none
  211. */
  212. void adc_tempsensor_vrefint_enable(void)
  213. {
  214. /* enable the temperature sensor and Vrefint channel */
  215. ADC_CTL1(ADC0) |= ADC_CTL1_TSVREN;
  216. }
  217. /*!
  218. \brief disable the temperature sensor and Vrefint channel
  219. \param[in] none
  220. \param[out] none
  221. \retval none
  222. */
  223. void adc_tempsensor_vrefint_disable(void)
  224. {
  225. /* disable the temperature sensor and Vrefint channel */
  226. ADC_CTL1(ADC0) &= ~ADC_CTL1_TSVREN;
  227. }
  228. /*!
  229. \brief enable DMA request
  230. \param[in] adc_periph: ADCx, x=0,1,2
  231. \param[out] none
  232. \retval none
  233. */
  234. void adc_dma_mode_enable(uint32_t adc_periph)
  235. {
  236. /* enable DMA request */
  237. ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DMA);
  238. }
  239. /*!
  240. \brief disable DMA request
  241. \param[in] adc_periph: ADCx, x=0,1,2
  242. \param[out] none
  243. \retval none
  244. */
  245. void adc_dma_mode_disable(uint32_t adc_periph)
  246. {
  247. /* disable DMA request */
  248. ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DMA);
  249. }
  250. /*!
  251. \brief configure ADC discontinuous mode
  252. \param[in] adc_periph: ADCx, x=0,1,2
  253. \param[in] adc_channel_group: select the channel group
  254. only one parameter can be selected which is shown as below:
  255. \arg ADC_REGULAR_CHANNEL: regular channel group
  256. \arg ADC_INSERTED_CHANNEL: inserted channel group
  257. \arg ADC_CHANNEL_DISCON_DISABLE: disable discontinuous mode of regular & inserted channel
  258. \param[in] length: number of conversions in discontinuous mode,the number can be 1..8
  259. for regular channel, the number has no effect for inserted channel
  260. \param[out] none
  261. \retval none
  262. */
  263. void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t adc_channel_group, uint8_t length)
  264. {
  265. /* disable discontinuous mode of regular & inserted channel */
  266. ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_DISRC | ADC_CTL0_DISIC));
  267. switch(adc_channel_group){
  268. case ADC_REGULAR_CHANNEL:
  269. /* config the number of conversions in discontinuous mode */
  270. ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_DISNUM);
  271. ADC_CTL0(adc_periph) |= CTL0_DISNUM(((uint32_t)length - ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
  272. /* enable regular channel group discontinuous mode */
  273. ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_DISRC;
  274. break;
  275. case ADC_INSERTED_CHANNEL:
  276. /* enable inserted channel group discontinuous mode */
  277. ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_DISIC;
  278. break;
  279. case ADC_CHANNEL_DISCON_DISABLE:
  280. /* disable discontinuous mode of regular & inserted channel */
  281. default:
  282. break;
  283. }
  284. }
  285. /*!
  286. \brief configure the length of regular channel group or inserted channel group
  287. \param[in] adc_periph: ADCx, x=0,1,2
  288. \param[in] adc_channel_group: select the channel group
  289. only one parameter can be selected which is shown as below:
  290. \arg ADC_REGULAR_CHANNEL: regular channel group
  291. \arg ADC_INSERTED_CHANNEL: inserted channel group
  292. \param[in] length: the length of the channel
  293. regular channel 1-16
  294. inserted channel 1-4
  295. \param[out] none
  296. \retval none
  297. */
  298. void adc_channel_length_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t length)
  299. {
  300. switch(adc_channel_group){
  301. case ADC_REGULAR_CHANNEL:
  302. /* configure the length of regular channel group */
  303. ADC_RSQ0(adc_periph) &= ~((uint32_t)ADC_RSQ0_RL);
  304. ADC_RSQ0(adc_periph) |= RSQ0_RL((uint32_t)(length-ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
  305. break;
  306. case ADC_INSERTED_CHANNEL:
  307. /* configure the length of inserted channel group */
  308. ADC_ISQ(adc_periph) &= ~((uint32_t)ADC_ISQ_IL);
  309. ADC_ISQ(adc_periph) |= ISQ_IL((uint32_t)(length-ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
  310. break;
  311. default:
  312. break;
  313. }
  314. }
  315. /*!
  316. \brief configure ADC regular channel
  317. \param[in] adc_periph: ADCx, x=0,1,2
  318. \param[in] rank: the regular group sequence rank,this parameter must be between 0 to 15
  319. \param[in] adc_channel: the selected ADC channel
  320. only one parameter can be selected which is shown as below:
  321. \arg ADC_CHANNEL_x(x=0..17)(x=16 and x=17 are only for ADC0): ADC Channelx
  322. \param[in] sample_time: the sample time value
  323. only one parameter can be selected which is shown as below:
  324. \arg ADC_SAMPLETIME_1POINT5: 1.5 cycles
  325. \arg ADC_SAMPLETIME_7POINT5: 7.5 cycles
  326. \arg ADC_SAMPLETIME_13POINT5: 13.5 cycles
  327. \arg ADC_SAMPLETIME_28POINT5: 28.5 cycles
  328. \arg ADC_SAMPLETIME_41POINT5: 41.5 cycles
  329. \arg ADC_SAMPLETIME_55POINT5: 55.5 cycles
  330. \arg ADC_SAMPLETIME_71POINT5: 71.5 cycles
  331. \arg ADC_SAMPLETIME_239POINT5: 239.5 cycles
  332. \param[out] none
  333. \retval none
  334. */
  335. void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
  336. {
  337. uint32_t rsq,sampt;
  338. /* ADC regular sequence config */
  339. if(rank < ADC_REGULAR_CHANNEL_RANK_SIX){
  340. /* the regular group sequence rank is smaller than six */
  341. rsq = ADC_RSQ2(adc_periph);
  342. rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*rank)));
  343. /* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
  344. rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*rank));
  345. ADC_RSQ2(adc_periph) = rsq;
  346. }else if(rank < ADC_REGULAR_CHANNEL_RANK_TWELVE){
  347. /* the regular group sequence rank is smaller than twelve */
  348. rsq = ADC_RSQ1(adc_periph);
  349. rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_SIX))));
  350. /* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
  351. rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_SIX)));
  352. ADC_RSQ1(adc_periph) = rsq;
  353. }else if(rank < ADC_REGULAR_CHANNEL_RANK_SIXTEEN){
  354. /* the regular group sequence rank is smaller than sixteen */
  355. rsq = ADC_RSQ0(adc_periph);
  356. rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_TWELVE))));
  357. /* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
  358. rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_TWELVE)));
  359. ADC_RSQ0(adc_periph) = rsq;
  360. }else{
  361. }
  362. /* ADC sampling time config */
  363. if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
  364. /* the regular group sequence rank is smaller than ten */
  365. sampt = ADC_SAMPT1(adc_periph);
  366. sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel)));
  367. /* channel sample time set*/
  368. sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel));
  369. ADC_SAMPT1(adc_periph) = sampt;
  370. }else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN){
  371. /* the regular group sequence rank is smaller than eighteen */
  372. sampt = ADC_SAMPT0(adc_periph);
  373. sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN))));
  374. /* channel sample time set*/
  375. sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN)));
  376. ADC_SAMPT0(adc_periph) = sampt;
  377. }else{
  378. }
  379. }
  380. /*!
  381. \brief configure ADC inserted channel
  382. \param[in] adc_periph: ADCx, x=0,1,2
  383. \param[in] rank: the inserted group sequencer rank,this parameter must be between 0 to 3
  384. \param[in] adc_channel: the selected ADC channel
  385. only one parameter can be selected which is shown as below:
  386. \arg ADC_CHANNEL_x(x=0..17)(x=16 and x=17 are only for ADC0): ADC Channelx
  387. \param[in] sample_time: The sample time value
  388. only one parameter can be selected which is shown as below:
  389. \arg ADC_SAMPLETIME_1POINT5: 1.5 cycles
  390. \arg ADC_SAMPLETIME_7POINT5: 7.5 cycles
  391. \arg ADC_SAMPLETIME_13POINT5: 13.5 cycles
  392. \arg ADC_SAMPLETIME_28POINT5: 28.5 cycles
  393. \arg ADC_SAMPLETIME_41POINT5: 41.5 cycles
  394. \arg ADC_SAMPLETIME_55POINT5: 55.5 cycles
  395. \arg ADC_SAMPLETIME_71POINT5: 71.5 cycles
  396. \arg ADC_SAMPLETIME_239POINT5: 239.5 cycles
  397. \param[out] none
  398. \retval none
  399. */
  400. void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t adc_channel, uint32_t sample_time)
  401. {
  402. uint8_t inserted_length;
  403. uint32_t isq,sampt;
  404. /* get inserted channel group length */
  405. inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph) , 20U , 21U);
  406. /* the channel number is written to these bits to select a channel as the nth conversion in the inserted channel group */
  407. isq = ADC_ISQ(adc_periph);
  408. isq &= ~((uint32_t)(ADC_ISQ_ISQN << (ADC_INSERTED_CHANNEL_SHIFT_LENGTH-(inserted_length-rank)*ADC_INSERTED_CHANNEL_RANK_LENGTH)));
  409. isq |= ((uint32_t)adc_channel << (ADC_INSERTED_CHANNEL_SHIFT_LENGTH-(inserted_length-rank)*ADC_INSERTED_CHANNEL_RANK_LENGTH));
  410. ADC_ISQ(adc_periph) = isq;
  411. /* ADC sampling time config */
  412. if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
  413. /* the inserted group sequence rank is smaller than ten */
  414. sampt = ADC_SAMPT1(adc_periph);
  415. sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel)));
  416. /* channel sample time set*/
  417. sampt |= (uint32_t) sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel);
  418. ADC_SAMPT1(adc_periph) = sampt;
  419. }else if(adc_channel < ADC_CHANNEL_SAMPLE_EIGHTEEN){
  420. /* the inserted group sequence rank is smaller than eighteen */
  421. sampt = ADC_SAMPT0(adc_periph);
  422. sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN))));
  423. /* channel sample time set*/
  424. sampt |= ((uint32_t)sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN)));
  425. ADC_SAMPT0(adc_periph) = sampt;
  426. }else{
  427. }
  428. }
  429. /*!
  430. \brief configure ADC inserted channel offset
  431. \param[in] adc_periph: ADCx, x=0,1,2
  432. \param[in] inserted_channel: insert channel select
  433. only one parameter can be selected
  434. \arg ADC_INSERTED_CHANNEL_0: inserted channel0
  435. \arg ADC_INSERTED_CHANNEL_1: inserted channel1
  436. \arg ADC_INSERTED_CHANNEL_2: inserted channel2
  437. \arg ADC_INSERTED_CHANNEL_3: inserted channel3
  438. \param[in] offset: the offset data
  439. \param[out] none
  440. \retval none
  441. */
  442. void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t inserted_channel, uint16_t offset)
  443. {
  444. uint8_t inserted_length;
  445. uint32_t num = 0U;
  446. inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph) , 20U , 21U);
  447. num = ((uint32_t)ADC_OFFSET_LENGTH - ((uint32_t)inserted_length - (uint32_t)inserted_channel));
  448. if(num <= ADC_OFFSET_LENGTH){
  449. /* calculate the offset of the register */
  450. num = num * ADC_OFFSET_SHIFT_LENGTH;
  451. /* config the offset of the selected channels */
  452. REG32((adc_periph) + 0x14U + num) = IOFFX_IOFF((uint32_t)offset);
  453. }
  454. }
  455. /*!
  456. \brief configure ADC external trigger source
  457. \param[in] adc_periph: ADCx, x=0,1,2
  458. \param[in] adc_channel_group: select the channel group
  459. only one parameter can be selected which is shown as below:
  460. \arg ADC_REGULAR_CHANNEL: regular channel group
  461. \arg ADC_INSERTED_CHANNEL: inserted channel group
  462. \param[in] external_trigger_source: regular or inserted group trigger source
  463. only one parameter can be selected
  464. for regular channel:
  465. \arg ADC0_1_EXTTRIG_REGULAR_T0_CH0: TIMER0 CH0 event select
  466. \arg ADC0_1_EXTTRIG_REGULAR_T0_CH1: TIMER0 CH1 event select
  467. \arg ADC0_1_EXTTRIG_REGULAR_T0_CH2: TIMER0 CH2 event select
  468. \arg ADC0_1_EXTTRIG_REGULAR_T1_CH1: TIMER1 CH1 event select
  469. \arg ADC0_1_EXTTRIG_REGULAR_T2_TRGO: TIMER2 TRGO event select
  470. \arg ADC0_1_EXTTRIG_REGULAR_T3_CH3: TIMER3 CH3 event select
  471. \arg ADC0_1_EXTTRIG_REGULAR_T7_TRGO: TIMER7 TRGO event select
  472. \arg ADC0_1_EXTTRIG_REGULAR_EXTI_11: external interrupt line 11
  473. \arg ADC2_EXTTRIG_REGULAR_T2_CH0: TIMER2 CH0 event select
  474. \arg ADC2_EXTTRIG_REGULAR_T1_CH2: TIMER1 CH2 event select
  475. \arg ADC2_EXTTRIG_REGULAR_T0_CH2: TIMER0 CH2 event select
  476. \arg ADC2_EXTTRIG_REGULAR_T7_CH0: TIMER7 CH0 event select
  477. \arg ADC2_EXTTRIG_REGULAR_T7_TRGO: TIMER7 TRGO event select
  478. \arg ADC2_EXTTRIG_REGULAR_T4_CH0: TIMER4 CH0 event select
  479. \arg ADC2_EXTTRIG_REGULAR_T4_CH2: TIMER4 CH2 event select
  480. \arg ADC0_1_2_EXTTRIG_REGULAR_NONE: software trigger
  481. for inserted channel:
  482. \arg ADC0_1_EXTTRIG_INSERTED_T0_TRGO: TIMER0 TRGO event select
  483. \arg ADC0_1_EXTTRIG_INSERTED_T0_CH3: TIMER0 CH3 event select
  484. \arg ADC0_1_EXTTRIG_INSERTED_T1_TRGO: TIMER1 TRGO event select
  485. \arg ADC0_1_EXTTRIG_INSERTED_T1_CH0: TIMER1 CH0 event select
  486. \arg ADC0_1_EXTTRIG_INSERTED_T2_CH3: TIMER2 CH3 event select
  487. \arg ADC0_1_EXTTRIG_INSERTED_T3_TRGO: TIMER3 TRGO event select
  488. \arg ADC0_1_EXTTRIG_INSERTED_EXTI_15: external interrupt line 15
  489. \arg ADC0_1_EXTTRIG_INSERTED_T7_CH3: TIMER7 CH3 event select
  490. \arg ADC2_EXTTRIG_INSERTED_T0_TRGO: TIMER0 TRGO event select
  491. \arg ADC2_EXTTRIG_INSERTED_T0_CH3: TIMER0 CH3 event select
  492. \arg ADC2_EXTTRIG_INSERTED_T3_CH2: TIMER3 CH2 event select
  493. \arg ADC2_EXTTRIG_INSERTED_T7_CH1: TIMER7 CH1 event select
  494. \arg ADC2_EXTTRIG_INSERTED_T7_CH3: TIMER7 CH3 event select
  495. \arg ADC2_EXTTRIG_INSERTED_T4_TRGO: TIMER4 TRGO event select
  496. \arg ADC2_EXTTRIG_INSERTED_T4_CH3: TIMER4 CH3 event select
  497. \arg ADC0_1_2_EXTTRIG_INSERTED_NONE: software trigger
  498. \param[out] none
  499. \retval none
  500. */
  501. void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t adc_channel_group, uint32_t external_trigger_source)
  502. {
  503. switch(adc_channel_group){
  504. case ADC_REGULAR_CHANNEL:
  505. /* configure ADC regular group external trigger source */
  506. ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSRC);
  507. ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
  508. break;
  509. case ADC_INSERTED_CHANNEL:
  510. /* configure ADC inserted group external trigger source */
  511. ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSIC);
  512. ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
  513. break;
  514. default:
  515. break;
  516. }
  517. }
  518. /*!
  519. \brief configure ADC external trigger
  520. \param[in] adc_periph: ADCx, x=0,1,2
  521. \param[in] adc_channel_group: select the channel group
  522. one or more parameters can be selected which are shown as below:
  523. \arg ADC_REGULAR_CHANNEL: regular channel group
  524. \arg ADC_INSERTED_CHANNEL: inserted channel group
  525. \param[in] newvalue: ENABLE or DISABLE
  526. \param[out] none
  527. \retval none
  528. */
  529. void adc_external_trigger_config(uint32_t adc_periph, uint8_t adc_channel_group, ControlStatus newvalue)
  530. {
  531. if(newvalue){
  532. if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
  533. /* enable ADC regular channel group external trigger */
  534. ADC_CTL1(adc_periph) |= ADC_CTL1_ETERC;
  535. }
  536. if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
  537. /* enable ADC inserted channel group external trigger */
  538. ADC_CTL1(adc_periph) |= ADC_CTL1_ETEIC;
  539. }
  540. }else{
  541. if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
  542. /* disable ADC regular channel group external trigger */
  543. ADC_CTL1(adc_periph) &= ~ADC_CTL1_ETERC;
  544. }
  545. if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
  546. /* disable ADC regular channel group external trigger */
  547. ADC_CTL1(adc_periph) &= ~ADC_CTL1_ETEIC;
  548. }
  549. }
  550. }
  551. /*!
  552. \brief enable ADC software trigger
  553. \param[in] adc_periph: ADCx, x=0,1,2
  554. \param[in] adc_channel_group: select the channel group
  555. one or more parameters can be selected which are shown as below:
  556. \arg ADC_REGULAR_CHANNEL: regular channel group
  557. \arg ADC_INSERTED_CHANNEL: inserted channel group
  558. \param[out] none
  559. \retval none
  560. */
  561. void adc_software_trigger_enable(uint32_t adc_periph, uint8_t adc_channel_group)
  562. {
  563. if(0U != (adc_channel_group & ADC_REGULAR_CHANNEL)){
  564. /* enable ADC regular channel group software trigger */
  565. ADC_CTL1(adc_periph) |= ADC_CTL1_SWRCST;
  566. }
  567. if(0U != (adc_channel_group & ADC_INSERTED_CHANNEL)){
  568. /* enable ADC inserted channel group software trigger */
  569. ADC_CTL1(adc_periph) |= ADC_CTL1_SWICST;
  570. }
  571. }
  572. /*!
  573. \brief read ADC regular group data register
  574. \param[in] adc_periph: ADCx, x=0,1,2
  575. \param[in] none
  576. \param[out] none
  577. \retval the conversion value
  578. */
  579. uint16_t adc_regular_data_read(uint32_t adc_periph)
  580. {
  581. return (uint16_t)(ADC_RDATA(adc_periph));
  582. }
  583. /*!
  584. \brief read ADC inserted group data register
  585. \param[in] adc_periph: ADCx, x=0,1,2
  586. \param[in] inserted_channel: insert channel select
  587. only one parameter can be selected
  588. \arg ADC_INSERTED_CHANNEL_0: inserted Channel0
  589. \arg ADC_INSERTED_CHANNEL_1: inserted channel1
  590. \arg ADC_INSERTED_CHANNEL_2: inserted Channel2
  591. \arg ADC_INSERTED_CHANNEL_3: inserted Channel3
  592. \param[out] none
  593. \retval the conversion value
  594. */
  595. uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t inserted_channel)
  596. {
  597. uint32_t idata;
  598. /* read the data of the selected channel */
  599. switch(inserted_channel){
  600. case ADC_INSERTED_CHANNEL_0:
  601. /* read the data of channel 0 */
  602. idata = ADC_IDATA0(adc_periph);
  603. break;
  604. case ADC_INSERTED_CHANNEL_1:
  605. /* read the data of channel 1 */
  606. idata = ADC_IDATA1(adc_periph);
  607. break;
  608. case ADC_INSERTED_CHANNEL_2:
  609. /* read the data of channel 2 */
  610. idata = ADC_IDATA2(adc_periph);
  611. break;
  612. case ADC_INSERTED_CHANNEL_3:
  613. /* read the data of channel 3 */
  614. idata = ADC_IDATA3(adc_periph);
  615. break;
  616. default:
  617. idata = 0U;
  618. break;
  619. }
  620. return (uint16_t)idata;
  621. }
  622. /*!
  623. \brief read the last ADC0 and ADC1 conversion result data in sync mode
  624. \param[in] none
  625. \param[out] none
  626. \retval the conversion value
  627. */
  628. uint32_t adc_sync_mode_convert_value_read(void)
  629. {
  630. /* return conversion value */
  631. return ADC_RDATA(ADC0);
  632. }
  633. /*!
  634. \brief configure ADC analog watchdog single channel
  635. \param[in] adc_periph: ADCx, x=0,1,2
  636. \param[in] adc_channel: the selected ADC channel
  637. only one parameter can be selected which is shown as below:
  638. \arg ADC_CHANNEL_x: ADC Channelx(x=0..17)(x=16 and x=17 are only for ADC0)
  639. \param[out] none
  640. \retval none
  641. */
  642. void adc_watchdog_single_channel_enable(uint32_t adc_periph, uint8_t adc_channel)
  643. {
  644. ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL);
  645. /* analog watchdog channel select */
  646. ADC_CTL0(adc_periph) |= (uint32_t)adc_channel;
  647. ADC_CTL0(adc_periph) |= (uint32_t)(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC);
  648. }
  649. /*!
  650. \brief configure ADC analog watchdog group channel
  651. \param[in] adc_periph: ADCx, x=0,1,2
  652. \param[in] adc_channel_group: the channel group use analog watchdog
  653. only one parameter can be selected which is shown as below:
  654. \arg ADC_REGULAR_CHANNEL: regular channel group
  655. \arg ADC_INSERTED_CHANNEL: inserted channel group
  656. \arg ADC_REGULAR_INSERTED_CHANNEL: both regular and inserted group
  657. \param[out] none
  658. \retval none
  659. */
  660. void adc_watchdog_group_channel_enable(uint32_t adc_periph, uint8_t adc_channel_group)
  661. {
  662. ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC);
  663. /* select the group */
  664. switch(adc_channel_group){
  665. case ADC_REGULAR_CHANNEL:
  666. /* regular channel analog watchdog enable */
  667. ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_RWDEN;
  668. break;
  669. case ADC_INSERTED_CHANNEL:
  670. /* inserted channel analog watchdog enable */
  671. ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_IWDEN;
  672. break;
  673. case ADC_REGULAR_INSERTED_CHANNEL:
  674. /* regular and inserted channel analog watchdog enable */
  675. ADC_CTL0(adc_periph) |= (uint32_t)(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN);
  676. break;
  677. default:
  678. break;
  679. }
  680. }
  681. /*!
  682. \brief disable ADC analog watchdog
  683. \param[in] adc_periph: ADCx, x=0,1,2
  684. \param[out] none
  685. \retval none
  686. */
  687. void adc_watchdog_disable(uint32_t adc_periph)
  688. {
  689. ADC_CTL0(adc_periph) &= (uint32_t)~(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC | ADC_CTL0_WDCHSEL);
  690. }
  691. /*!
  692. \brief configure ADC analog watchdog threshold
  693. \param[in] adc_periph: ADCx, x=0,1,2
  694. \param[in] low_threshold: analog watchdog low threshold, 0..4095
  695. \param[in] high_threshold: analog watchdog high threshold, 0..4095
  696. \param[out] none
  697. \retval none
  698. */
  699. void adc_watchdog_threshold_config(uint32_t adc_periph, uint16_t low_threshold, uint16_t high_threshold)
  700. {
  701. ADC_WDLT(adc_periph) = (uint32_t)WDLT_WDLT(low_threshold);
  702. ADC_WDHT(adc_periph) = (uint32_t)WDHT_WDHT(high_threshold);
  703. }
  704. /*!
  705. \brief get the ADC flag bits
  706. \param[in] adc_periph: ADCx, x=0,1,2
  707. \param[in] adc_flag: the adc flag bits
  708. only one parameter can be selected which is shown as below:
  709. \arg ADC_FLAG_WDE: analog watchdog event flag
  710. \arg ADC_FLAG_EOC: end of group conversion flag
  711. \arg ADC_FLAG_EOIC: end of inserted group conversion flag
  712. \arg ADC_FLAG_STIC: start flag of inserted channel group
  713. \arg ADC_FLAG_STRC: start flag of regular channel group
  714. \param[out] none
  715. \retval FlagStatus: SET or RESET
  716. */
  717. FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t adc_flag)
  718. {
  719. FlagStatus reval = RESET;
  720. if(ADC_STAT(adc_periph) & adc_flag){
  721. reval = SET;
  722. }
  723. return reval;
  724. }
  725. /*!
  726. \brief clear the ADC flag bits
  727. \param[in] adc_periph: ADCx, x=0,1,2
  728. \param[in] adc_flag: the adc flag bits
  729. one or more parameters can be selected which are shown as below:
  730. \arg ADC_FLAG_WDE: analog watchdog event flag
  731. \arg ADC_FLAG_EOC: end of group conversion flag
  732. \arg ADC_FLAG_EOIC: end of inserted group conversion flag
  733. \arg ADC_FLAG_STIC: start flag of inserted channel group
  734. \arg ADC_FLAG_STRC: start flag of regular channel group
  735. \param[out] none
  736. \retval none
  737. */
  738. void adc_flag_clear(uint32_t adc_periph, uint32_t adc_flag)
  739. {
  740. ADC_STAT(adc_periph) &= ~((uint32_t)adc_flag);
  741. }
  742. /*!
  743. \brief get the bit state of ADCx software start conversion
  744. \param[in] adc_periph: ADCx, x=0,1,2
  745. \param[in] none
  746. \param[out] none
  747. \retval FlagStatus: SET or RESET
  748. */
  749. FlagStatus adc_regular_software_startconv_flag_get(uint32_t adc_periph)
  750. {
  751. FlagStatus reval = RESET;
  752. if((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWRCST)){
  753. reval = SET;
  754. }
  755. return reval;
  756. }
  757. /*!
  758. \brief get the bit state of ADCx software inserted channel start conversion
  759. \param[in] adc_periph: ADCx, x=0,1,2
  760. \param[in] none
  761. \param[out] none
  762. \retval FlagStatus: SET or RESET
  763. */
  764. FlagStatus adc_inserted_software_startconv_flag_get(uint32_t adc_periph)
  765. {
  766. FlagStatus reval = RESET;
  767. if((uint32_t)RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_SWICST)){
  768. reval = SET;
  769. }
  770. return reval;
  771. }
  772. /*!
  773. \brief get the ADC interrupt bits
  774. \param[in] adc_periph: ADCx, x=0,1,2
  775. \param[in] adc_interrupt: the adc interrupt bits
  776. only one parameter can be selected which is shown as below:
  777. \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
  778. \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
  779. \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
  780. \param[out] none
  781. \retval FlagStatus: SET or RESET
  782. */
  783. FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t adc_interrupt)
  784. {
  785. FlagStatus interrupt_flag = RESET;
  786. uint32_t state;
  787. /* check the interrupt bits */
  788. switch(adc_interrupt){
  789. case ADC_INT_FLAG_WDE:
  790. /* get the ADC analog watchdog interrupt bits */
  791. state = ADC_STAT(adc_periph) & ADC_STAT_WDE;
  792. if((ADC_CTL0(adc_periph) & ADC_CTL0_WDEIE) && state){
  793. interrupt_flag = SET;
  794. }
  795. break;
  796. case ADC_INT_FLAG_EOC:
  797. /* get the ADC end of group conversion interrupt bits */
  798. state = ADC_STAT(adc_periph) & ADC_STAT_EOC;
  799. if((ADC_CTL0(adc_periph) & ADC_CTL0_EOCIE) && state){
  800. interrupt_flag = SET;
  801. }
  802. break;
  803. case ADC_INT_FLAG_EOIC:
  804. /* get the ADC end of inserted group conversion interrupt bits */
  805. state = ADC_STAT(adc_periph) & ADC_STAT_EOIC;
  806. if((ADC_CTL0(adc_periph) & ADC_CTL0_EOICIE) && state){
  807. interrupt_flag = SET;
  808. }
  809. break;
  810. default:
  811. break;
  812. }
  813. return interrupt_flag;
  814. }
  815. /*!
  816. \brief clear the ADC flag
  817. \param[in] adc_periph: ADCx, x=0,1,2
  818. \param[in] adc_interrupt: the adc status flag
  819. one or more parameters can be selected which are shown as below:
  820. \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
  821. \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
  822. \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
  823. \param[out] none
  824. \retval none
  825. */
  826. void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t adc_interrupt)
  827. {
  828. ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt);
  829. }
  830. /*!
  831. \brief enable ADC interrupt
  832. \param[in] adc_periph: ADCx, x=0,1,2
  833. \param[in] adc_interrupt: the adc interrupt
  834. one or more parameters can be selected which are shown as below:
  835. \arg ADC_INT_WDE: analog watchdog interrupt flag
  836. \arg ADC_INT_EOC: end of group conversion interrupt flag
  837. \arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
  838. \param[out] none
  839. \retval none
  840. */
  841. void adc_interrupt_enable(uint32_t adc_periph, uint32_t adc_interrupt)
  842. {
  843. /* enable ADC analog watchdog interrupt */
  844. if(0U != (adc_interrupt & ADC_INT_WDE)){
  845. ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_WDEIE;
  846. }
  847. /* enable ADC end of group conversion interrupt */
  848. if(0U != (adc_interrupt & ADC_INT_EOC)){
  849. ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOCIE;
  850. }
  851. /* enable ADC end of inserted group conversion interrupt */
  852. if(0U != (adc_interrupt & ADC_INT_EOIC)){
  853. ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOICIE;
  854. }
  855. }
  856. /*!
  857. \brief disable ADC interrupt
  858. \param[in] adc_periph: ADCx, x=0,1,2
  859. \param[in] adc_interrupt: the adc interrupt flag
  860. one or more parameters can be selected which are shown as below:
  861. \arg ADC_INT_WDE: analog watchdog interrupt flag
  862. \arg ADC_INT_EOC: end of group conversion interrupt flag
  863. \arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
  864. \param[out] none
  865. \retval none
  866. */
  867. void adc_interrupt_disable(uint32_t adc_periph, uint32_t adc_interrupt)
  868. {
  869. /* disable ADC analog watchdog interrupt */
  870. if(0U != (adc_interrupt & ADC_INT_WDE)){
  871. ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_WDEIE;
  872. }
  873. /* disable ADC end of group conversion interrupt */
  874. if(0U != (adc_interrupt & ADC_INT_EOC)){
  875. ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_EOCIE;
  876. }
  877. /* disable ADC end of inserted group conversion interrupt */
  878. if(0U != (adc_interrupt & ADC_INT_EOIC)){
  879. ADC_CTL0(adc_periph) &= ~(uint32_t) ADC_CTL0_EOICIE;
  880. }
  881. }