gd32f3x0_tsi.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*!
  2. \file gd32f3x0_tsi.c
  3. \brief tsi driver
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #include "gd32f3x0_tsi.h"
  10. /*!
  11. \brief reset TSI peripheral
  12. \param[in] none
  13. \param[out] none
  14. \retval none
  15. */
  16. void tsi_deinit(void)
  17. {
  18. rcu_periph_reset_enable(RCU_TSIRST);
  19. rcu_periph_reset_disable(RCU_TSIRST);
  20. }
  21. /*!
  22. \brief initialize TSI plus prescaler,charge plus,transfer plus,max cycle number
  23. \param[in] prescaler: CTCLK clock division factor
  24. \arg TSI_CTCDIV_DIV1: fCTCLK = fHCLK
  25. \arg TSI_CTCDIV_DIV2: fCTCLK = fHCLK/2
  26. \arg TSI_CTCDIV_DIV4: fCTCLK = fHCLK/4
  27. \arg TSI_CTCDIV_DIV8: fCTCLK = fHCLK/8
  28. \arg TSI_CTCDIV_DIV16: fCTCLK = fHCLK/16
  29. \arg TSI_CTCDIV_DIV32: fCTCLK = fHCLK/32
  30. \arg TSI_CTCDIV_DIV64: fCTCLK = fHCLK/64
  31. \arg TSI_CTCDIV_DIV128: fCTCLK = fHCLK/128
  32. \arg TSI_CTCDIV_DIV256: fCTCLK = fHCLK/256
  33. \arg TSI_CTCDIV_DIV512: fCTCLK = fHCLK/512
  34. \arg TSI_CTCDIV_DIV1024: fCTCLK = fHCLK/1024
  35. \arg TSI_CTCDIV_DIV2048: fCTCLK = fHCLK/2048
  36. \arg TSI_CTCDIV_DIV4096: fCTCLK = fHCLK/4096
  37. \arg TSI_CTCDIV_DIV8192: fCTCLK = fHCLK/8192
  38. \arg TSI_CTCDIV_DIV16384: fCTCLK = fHCLK/16384
  39. \arg TSI_CTCDIV_DIV32768: fCTCLK = fHCLK/32768
  40. \param[in] charge_duration: charge state duration time
  41. \arg TSI_CHARGE_1CTCLK(x=1..16): the duration time of charge state is x CTCLK
  42. \param[in] transfer_duration: charge transfer state duration time
  43. \arg TSI_TRANSFER_xCTCLK(x=1..16): the duration time of transfer state is x CTCLK
  44. \param[in] max_number: max cycle number
  45. \arg TSI_MAXNUM255: the max cycle number of a sequence is 255
  46. \arg TSI_MAXNUM511: the max cycle number of a sequence is 511
  47. \arg TSI_MAXNUM1023: the max cycle number of a sequence is 1023
  48. \arg TSI_MAXNUM2047: the max cycle number of a sequence is 2047
  49. \arg TSI_MAXNUM4095: the max cycle number of a sequence is 4095
  50. \arg TSI_MAXNUM8191: the max cycle number of a sequence is 8191
  51. \arg TSI_MAXNUM16383: the max cycle number of a sequence is 16383
  52. \param[out] none
  53. \retval none
  54. */
  55. void tsi_init(uint32_t prescaler,uint32_t charge_duration,uint32_t transfer_duration,uint32_t max_number)
  56. {
  57. uint32_t ctl0,ctl1;
  58. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  59. if(TSI_CTCDIV_DIV256 > prescaler){
  60. /* config TSI_CTL0 */
  61. ctl0 = TSI_CTL0;
  62. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  63. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT|TSI_CTL0_MCN);
  64. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration|max_number);
  65. TSI_CTL0 = ctl0;
  66. /* config TSI_CTL1 */
  67. ctl1 = TSI_CTL1;
  68. ctl1 &= ~TSI_CTL1_CTCDIV;
  69. TSI_CTL1 = ctl1;
  70. }else{
  71. /* config TSI_CTL0 */
  72. ctl0 = TSI_CTL0;
  73. prescaler &= ~0x08U;
  74. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  75. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT|TSI_CTL0_MCN);
  76. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration|max_number);
  77. TSI_CTL0 = ctl0;
  78. /* config TSI_CTL1 */
  79. ctl1 = TSI_CTL1;
  80. ctl1 |= TSI_CTL1_CTCDIV;
  81. TSI_CTL1 = ctl1;
  82. }
  83. }
  84. }
  85. /*!
  86. \brief enable sample pin
  87. \param[in] sample: sample pin
  88. \arg TSI_SAMPCFG_GxPy( x=0..5,y=0..3):pin y of group x is sample pin
  89. \param[out] none
  90. \retval none
  91. */
  92. void tsi_sample_pin_enable(uint32_t sample)
  93. {
  94. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  95. TSI_SAMPCFG |= sample;
  96. }
  97. }
  98. /*!
  99. \brief disable sample pin
  100. \param[in] sample: sample pin
  101. \arg TSI_SAMPCFG_GxPy( x=0..5,y=0..3): pin y of group x is sample pin
  102. \param[out] none
  103. \retval none
  104. */
  105. void tsi_sample_pin_disable(uint32_t sample)
  106. {
  107. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  108. TSI_SAMPCFG &= ~sample;
  109. }
  110. }
  111. /*!
  112. \brief enable channel pin
  113. \param[in] channel: channel pin
  114. \arg TSI_CHCFG_GxPy( x=0..5,y=0..3): pin y of group x
  115. \param[out] none
  116. \retval none
  117. */
  118. void tsi_channel_pin_enable(uint32_t channel)
  119. {
  120. TSI_CHCFG |= channel;
  121. }
  122. /*!
  123. \brief disable channel pin
  124. \param[in] channel: channel pin
  125. \arg TSI_CHCFG_GxPy( x=0..5,y=0..3): pin y of group x
  126. \param[out] none
  127. \retval none
  128. */
  129. void tsi_channel_pin_disable(uint32_t channel)
  130. {
  131. TSI_CHCFG &= ~channel;
  132. }
  133. /*!
  134. \brief configure charge plus and transfer plus
  135. \param[in] prescaler: CTCLK clock division factor
  136. \arg TSI_CTCDIV_DIV1: fCTCLK = fHCLK
  137. \arg TSI_CTCDIV_DIV2: fCTCLK = fHCLK/2
  138. \arg TSI_CTCDIV_DIV4: fCTCLK = fHCLK/4
  139. \arg TSI_CTCDIV_DIV8: fCTCLK = fHCLK/8
  140. \arg TSI_CTCDIV_DIV16: fCTCLK = fHCLK/16
  141. \arg TSI_CTCDIV_DIV32: fCTCLK = fHCLK/32
  142. \arg TSI_CTCDIV_DIV64: fCTCLK = fHCLK/64
  143. \arg TSI_CTCDIV_DIV128: fCTCLK = fHCLK/128
  144. \arg TSI_CTCDIV_DIV256: fCTCLK = fHCLK/256
  145. \arg TSI_CTCDIV_DIV512: fCTCLK = fHCLK/512
  146. \arg TSI_CTCDIV_DIV1024: fCTCLK = fHCLK/1024
  147. \arg TSI_CTCDIV_DIV2048: fCTCLK = fHCLK/2048
  148. \arg TSI_CTCDIV_DIV4096: fCTCLK = fHCLK/4096
  149. \arg TSI_CTCDIV_DIV8192: fCTCLK = fHCLK/8192
  150. \arg TSI_CTCDIV_DIV16384: fCTCLK = fHCLK/16384
  151. \arg TSI_CTCDIV_DIV32768: fCTCLK = fHCLK/32768
  152. \param[in] charge_duration: charge state duration time
  153. \arg TSI_CHARGE_xCTCLK(x=1..16): the duration time of charge state is x CTCLK
  154. \param[in] transfer_duration: charge transfer state duration time
  155. \arg TSI_TRANSFER_xCTCLK(x=1..16): the duration time of transfer state is x CTCLK
  156. \param[out] none
  157. \retval none
  158. */
  159. void tsi_plus_config(uint32_t prescaler,uint32_t charge_duration,uint32_t transfer_duration)
  160. {
  161. uint32_t ctl0,ctl1;
  162. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  163. if(TSI_CTCDIV_DIV256 > prescaler){
  164. /* config TSI_CTL0 */
  165. ctl0 = TSI_CTL0;
  166. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  167. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT);
  168. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration);
  169. TSI_CTL0 = ctl0;
  170. /* config TSI_CTL1 */
  171. ctl1 = TSI_CTL1;
  172. ctl1 &= ~TSI_CTL1_CTCDIV;
  173. TSI_CTL1 = ctl1;
  174. }else{
  175. /* config TSI_CTL */
  176. ctl0 = TSI_CTL0;
  177. prescaler &= ~0x08U;
  178. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  179. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT);
  180. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration);
  181. TSI_CTL0 = ctl0;
  182. /* config TSI_CTL2 */
  183. ctl1 = TSI_CTL1;
  184. ctl1 |= TSI_CTL1_CTCDIV;
  185. TSI_CTL1 = ctl1;
  186. }
  187. }
  188. }
  189. /*!
  190. \brief configure TSI triggering by software
  191. \param[in] none
  192. \param[out] none
  193. \retval none
  194. */
  195. void tsi_sofeware_mode_config(void)
  196. {
  197. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  198. TSI_CTL0 &= ~TSI_CTL0_TRGMOD;
  199. }
  200. }
  201. /*!
  202. \brief configure TSI triggering by hardware
  203. \param[in] trigger_edge: the edge type in hardware trigger mode
  204. \arg TSI_FALLING_TRIGGER: falling edge trigger TSI charge transfer sequence
  205. \arg TSI_RISING_TRIGGER: rising edge trigger TSI charge transfer sequence
  206. \param[out] none
  207. \retval none
  208. */
  209. void tsi_hardware_mode_config(uint8_t trigger_edge)
  210. {
  211. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  212. /*enable hardware mode*/
  213. TSI_CTL0 |= TSI_CTL0_TRGMOD;
  214. /*configure the edge type in hardware trigger mode*/
  215. if(TSI_FALLING_TRIGGER == trigger_edge){
  216. TSI_CTL0 &= ~TSI_CTL0_EGSEL;
  217. }else{
  218. TSI_CTL0 |= TSI_CTL0_EGSEL;
  219. }
  220. }
  221. }
  222. /*!
  223. \brief configure TSI pin mode when charge-transfer sequence is IDLE
  224. \param[in] pin_mode: pin mode when charge-transfer sequence is IDLE
  225. \arg TSI_OUTPUT_LOW: TSI pin will output low when IDLE
  226. \arg TSI_INPUT_FLOATING: TSI pin will keep input_floating when IDLE
  227. \param[out] none
  228. \retval none
  229. */
  230. void tsi_pin_mode_config(uint8_t pin_mode)
  231. {
  232. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  233. if(TSI_OUTPUT_LOW == pin_mode){
  234. TSI_CTL0 &= ~TSI_CTL0_PINMOD;
  235. }else{
  236. TSI_CTL0 |= TSI_CTL0_PINMOD;
  237. }
  238. }
  239. }
  240. /*!
  241. \brief configure the max cycle number of a charge-transfer sequence
  242. \param[in] max_number: max cycle number
  243. \arg TSI_MAXNUM255: the max cycle number of a sequence is 255
  244. \arg TSI_MAXNUM511: the max cycle number of a sequence is 511
  245. \arg TSI_MAXNUM1023: the max cycle number of a sequence is 1023
  246. \arg TSI_MAXNUM2047: the max cycle number of a sequence is 2047
  247. \arg TSI_MAXNUM4095: the max cycle number of a sequence is 4095
  248. \arg TSI_MAXNUM8191: the max cycle number of a sequence is 8191
  249. \arg TSI_MAXNUM16383: the max cycle number of a sequence is 16383
  250. \param[out] none
  251. \retval none
  252. */
  253. void tsi_max_number_config(uint32_t max_number)
  254. {
  255. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  256. uint32_t maxnum;
  257. maxnum = TSI_CTL0;
  258. /*configure the max cycle number of a charge-transfer sequence*/
  259. maxnum &= ~TSI_CTL0_MCN;
  260. maxnum |= max_number;
  261. TSI_CTL0 = maxnum;
  262. }
  263. }
  264. /*!
  265. \brief start a charge-transfer sequence when TSI is in software trigger mode
  266. \param[in] none
  267. \param[out] none
  268. \retval none
  269. */
  270. void tsi_software_start(void)
  271. {
  272. TSI_CTL0 |= TSI_CTL0_TSIS;
  273. }
  274. /*!
  275. \brief stop a charge-transfer sequence when TSI is in software trigger mode
  276. \param[in] none
  277. \param[out] none
  278. \retval none
  279. */
  280. void tsi_software_stop(void)
  281. {
  282. TSI_CTL0 &= ~TSI_CTL0_TSIS;
  283. }
  284. /*!
  285. \brief enable TSI module
  286. \param[in] none
  287. \param[out] none
  288. \retval none
  289. */
  290. void tsi_enable(void)
  291. {
  292. TSI_CTL0 |= TSI_CTL0_TSIEN;
  293. }
  294. /*!
  295. \brief disable TSI module
  296. \param[in] none
  297. \param[out] none
  298. \retval none
  299. */
  300. void tsi_disable(void)
  301. {
  302. TSI_CTL0 &= ~TSI_CTL0_TSIEN;
  303. }
  304. /*!
  305. \brief configure extend charge state
  306. \param[in] extend: enable or disable extend charge state
  307. \arg ENABLE: enable extend charge state
  308. \arg DISABLE: disable extend charge state
  309. \param[in] prescaler: ECCLK clock division factor
  310. \arg TSI_EXTEND_DIV1: fECCLK = fHCLK
  311. \arg TSI_EXTEND_DIV2: fECCLK = fHCLK/2
  312. \arg TSI_EXTEND_DIV3: fECCLK = fHCLK/3
  313. \arg TSI_EXTEND_DIV4: fECCLK = fHCLK/4
  314. \arg TSI_EXTEND_DIV5: fECCLK = fHCLK/5
  315. \arg TSI_EXTEND_DIV6: fECCLK = fHCLK/6
  316. \arg TSI_EXTEND_DIV7: fECCLK = fHCLK/7
  317. \arg TSI_EXTEND_DIV8: fECCLK = fHCLK/8
  318. \param[in] max_duration: value range 1...128,extend charge state maximum duration time is 1*tECCLK~128*tECCLK
  319. \param[out] none
  320. \retval none
  321. */
  322. void tsi_extend_charge_config(ControlStatus extend,uint8_t prescaler,uint32_t max_duration)
  323. {
  324. uint32_t ctl0,ctl1;
  325. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  326. if(DISABLE == extend){
  327. /*disable extend charge state*/
  328. TSI_CTL0 &= ~TSI_CTL0_ECEN;
  329. }else{
  330. if(TSI_EXTEND_DIV3 > prescaler){
  331. /*configure extend charge state maximum duration time*/
  332. ctl0 = TSI_CTL0;
  333. ctl0 &= ~TSI_CTL0_ECDT;
  334. ctl0 |= TSI_EXTENDMAX((max_duration-1U));
  335. TSI_CTL0 = ctl0;
  336. /*configure ECCLK clock division factor*/
  337. ctl0 = TSI_CTL0;
  338. ctl0 &= ~TSI_CTL0_ECDIV;
  339. ctl0 |= (uint32_t)prescaler<<15U;
  340. TSI_CTL0 = ctl0;
  341. /*enable extend charge state*/
  342. TSI_CTL0 |= TSI_CTL0_ECEN;
  343. }else{
  344. /*configure extend charge state maximum duration time*/
  345. ctl0 = TSI_CTL0;
  346. ctl0 &= ~TSI_CTL0_ECDT;
  347. ctl0 |= TSI_EXTENDMAX((max_duration-1U));
  348. TSI_CTL0 = ctl0;
  349. /*configure ECCLK clock division factor*/
  350. ctl0 = TSI_CTL0;
  351. ctl0 &= ~TSI_CTL0_ECDIV;
  352. ctl0 |= (prescaler & 0x01U)<<15U;
  353. TSI_CTL0 = ctl0;
  354. ctl1 = TSI_CTL1;
  355. ctl1 &= ~TSI_CTL1_ECDIV;
  356. ctl1 |= (prescaler & 0x06U)<<28U;
  357. TSI_CTL1 = ctl1;
  358. /*enable extend charge state*/
  359. TSI_CTL0 |= TSI_CTL0_ECEN;
  360. }
  361. }
  362. }
  363. }
  364. /*!
  365. \brief enable TSI interrupt
  366. \param[in] source: select interrupt which will be enabled
  367. \arg TSI_INT_CCTCF: charge-transfer complete flag interrupt enable
  368. \arg TSI_INT_MNERR: max cycle number error interrupt enable
  369. \param[out] none
  370. \retval none
  371. */
  372. void tsi_interrupt_enable(uint32_t source)
  373. {
  374. TSI_INTEN |= source;
  375. }
  376. /*!
  377. \brief disable TSI interrupt
  378. \param[in] source: select interrupt which will be disabled
  379. \arg TSI_INT_CCTCF: charge-transfer complete flag interrupt disable
  380. \arg TSI_INT_MNERR: max cycle number error interrupt disable
  381. \param[out] none
  382. \retval none
  383. */
  384. void tsi_interrupt_disable(uint32_t source)
  385. {
  386. TSI_INTEN &= ~source;
  387. }
  388. /*!
  389. \brief clear TSI interrupt flag
  390. \param[in] source: select flag which will be cleared
  391. \arg TSI_INT_FLAG_CTCF_CLR: clear charge-transfer complete flag
  392. \arg TSI_INT_FLAG_MNERR_CLR: clear max cycle number error
  393. \param[out] none
  394. \retval none
  395. */
  396. void tsi_interrupt_flag_clear(uint32_t flag)
  397. {
  398. TSI_INTC |= flag;
  399. }
  400. /*!
  401. \brief get TSI interrupt flag
  402. \param[in] status:
  403. \arg TSI_INT_FLAG_CTCF: charge-transfer complete flag
  404. \arg TSI_INT_FLAG_MNERR: max Cycle Number Error
  405. \param[out] none
  406. \retval FlagStatus:SET or RESET
  407. */
  408. FlagStatus tsi_interrupt_flag_get(uint32_t flag)
  409. {
  410. FlagStatus flag_status;
  411. uint32_t tsi_inten;
  412. tsi_inten = TSI_INTEN;
  413. if(TSI_INT_FLAG_CTCF == flag){
  414. if(TSI_INT_CCTCF & tsi_inten){
  415. if(TSI_INTF & flag){
  416. flag_status = SET;
  417. }else{
  418. flag_status = RESET;
  419. }
  420. }else{
  421. flag_status = RESET;
  422. }
  423. }else if(TSI_INT_FLAG_MNERR == flag){
  424. if(TSI_INT_MNERR & tsi_inten){
  425. if(TSI_INTF & flag){
  426. flag_status = SET;
  427. }else{
  428. flag_status = RESET;
  429. }
  430. }else{
  431. flag_status = RESET;
  432. }
  433. }else{
  434. flag_status = RESET;
  435. }
  436. return flag_status;
  437. }
  438. /*!
  439. \brief clear flag
  440. \param[in] source: select flag which will be cleared
  441. \arg TSI_FLAG_CTCF_CLR: clear charge-transfer complete flag
  442. \arg TSI_FLAG_MNERR_CLR: clear max cycle number error
  443. \param[out] none
  444. \retval none
  445. */
  446. void tsi_flag_clear(uint32_t flag)
  447. {
  448. TSI_INTC |= flag;
  449. }
  450. /*!
  451. \brief get flag
  452. \param[in] status:
  453. \arg TSI_FLAG_CTCF: charge-transfer complete flag
  454. \arg TSI_FLAG_MNERR: max Cycle Number Error
  455. \param[out] none
  456. \retval FlagStatus:SET or RESET
  457. */
  458. FlagStatus tsi_flag_get(uint32_t flag)
  459. {
  460. FlagStatus flag_status;
  461. if(TSI_INTF & flag){
  462. flag_status = SET;
  463. }else{
  464. flag_status = RESET;
  465. }
  466. return flag_status;
  467. }
  468. /*!
  469. \brief switch on hysteresis pin
  470. \param[in] group_pin: select pin which will be switched on hysteresis
  471. \arg TSI_PHM_GxPy(x=0..5,y=0..3): pin y of group x switch on hysteresis
  472. \param[out] none
  473. \retval none
  474. */
  475. void tsi_hysteresis_on(uint32_t group_pin)
  476. {
  477. TSI_PHM |= group_pin;
  478. }
  479. /*!
  480. \brief switch off hysteresis pin
  481. \param[in] group_pin: select pin which will be switched off hysteresis
  482. \arg TSI_PHM_GxPy(x=0..5,y=0..3): pin y of group x switch off hysteresis
  483. \param[out] none
  484. \retval none
  485. */
  486. void tsi_hysteresis_off(uint32_t group_pin)
  487. {
  488. TSI_PHM &= ~group_pin;
  489. }
  490. /*!
  491. \brief switch on analog pin
  492. \param[in] group_pin: select pin which will be switched on analog
  493. \arg TSI_ASW_GxPy(x=0..5,y=0..3):pin y of group x switch on analog
  494. \param[out] none
  495. \retval none
  496. */
  497. void tsi_analog_on(uint32_t group_pin)
  498. {
  499. TSI_ASW |= group_pin;
  500. }
  501. /*!
  502. \brief switch off analog pin
  503. \param[in] group_pin: select pin which will be switched off analog
  504. \arg TSI_ASW_GxPy(x=0..5,y=0..3):pin y of group x switch off analog
  505. \param[out] none
  506. \retval none
  507. */
  508. void tsi_analog_off(uint32_t group_pin)
  509. {
  510. TSI_ASW &= ~group_pin;
  511. }
  512. /*!
  513. \brief enbale group
  514. \param[in] group: select group to be enabled
  515. \arg TSI_GCTL_GEx(x=0..5): the x group will be enabled
  516. \param[out] none
  517. \retval none
  518. */
  519. void tsi_group_enable(uint32_t group)
  520. {
  521. TSI_GCTL |= group;
  522. }
  523. /*!
  524. \brief disbale group
  525. \param[in] group: select group to be disabled
  526. \arg TSI_GCTL_GEx(x=0..5):the x group will be disabled
  527. \param[out] none
  528. \retval none
  529. */
  530. void tsi_group_disable(uint32_t group)
  531. {
  532. TSI_GCTL &= ~group;
  533. }
  534. /*!
  535. \brief get group complete status
  536. \param[in] group: select group
  537. \arg TSI_GCTL_GCx(x=0..5): get the complete status of group x
  538. \param[out] none
  539. \retval FlagStatus: group complete status,SET or RESET
  540. */
  541. FlagStatus tsi_group_status_get(uint32_t group)
  542. {
  543. FlagStatus flag_status;
  544. if(TSI_GCTL & group){
  545. flag_status = SET;
  546. }else{
  547. flag_status = RESET;
  548. }
  549. return flag_status;
  550. }
  551. /*!
  552. \brief get the cycle number for group0 as soon as a charge-transfer sequence completes
  553. \param[in] none
  554. \param[out] none
  555. \retval group0 cycle number
  556. */
  557. uint16_t tsi_group0_cycle_get(void)
  558. {
  559. return (uint16_t)TSI_G0CYCN;
  560. }
  561. /*!
  562. \brief get the cycle number for group1 as soon as a charge-transfer sequence completes
  563. \param[in] none
  564. \param[out] none
  565. \retval group1 cycle number
  566. */
  567. uint16_t tsi_group1_cycle_get(void)
  568. {
  569. return (uint16_t)TSI_G1CYCN;
  570. }
  571. /*!
  572. \brief get the cycle number for group2 as soon as a charge-transfer sequence completes
  573. \param[in] none
  574. \param[out] none
  575. \retval group2 cycle number
  576. */
  577. uint16_t tsi_group2_cycle_get(void)
  578. {
  579. return (uint16_t)TSI_G2CYCN;
  580. }
  581. /*!
  582. \brief get the cycle number for group3 as soon as a charge-transfer sequence completes
  583. \param[in] none
  584. \param[out] none
  585. \retval group3 cycle number
  586. */
  587. uint16_t tsi_group3_cycle_get(void)
  588. {
  589. return (uint16_t)TSI_G3CYCN;
  590. }
  591. /*!
  592. \brief get the cycle number for group4 as soon as a charge-transfer sequence completes
  593. \param[in] none
  594. \param[out] none
  595. \retval group4 cycle number
  596. */
  597. uint16_t tsi_group4_cycle_get(void)
  598. {
  599. return (uint16_t)TSI_G4CYCN;
  600. }
  601. /*!
  602. \brief get the cycle number for group5 as soon as a charge-transfer sequence completes
  603. \param[in] none
  604. \param[out] none
  605. \retval group5 cycle number
  606. */
  607. uint16_t tsi_group5_cycle_get(void)
  608. {
  609. return (uint16_t)TSI_G5CYCN;
  610. }