gd32f3x0_tsi.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*!
  2. \file gd32f3x0_tsi.h
  3. \brief definitions for the TSI
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #ifndef GD32F3X0_TSI_H
  10. #define GD32F3X0_TSI_H
  11. #include "gd32f3x0.h"
  12. /* TSI definitions */
  13. #define TSI TSI_BASE /*!< TSI base address */
  14. /* registers definitions */
  15. #define TSI_CTL0 REG32(TSI + 0x00U) /*!< TSI control register0 */
  16. #define TSI_INTEN REG32(TSI + 0x04U) /*!< TSI interrupt enable register */
  17. #define TSI_INTC REG32(TSI + 0x08U) /*!< TSI interrupt flag clear register */
  18. #define TSI_INTF REG32(TSI + 0x0CU) /*!< TSI interrupt flag register */
  19. #define TSI_PHM REG32(TSI + 0x10U) /*!< TSI pin hysteresis mode register */
  20. #define TSI_ASW REG32(TSI + 0x18U) /*!< TSI analog switch register */
  21. #define TSI_SAMPCFG REG32(TSI + 0x20U) /*!< TSI sample configuration register */
  22. #define TSI_CHCFG REG32(TSI + 0x28U) /*!< TSI channel configuration register */
  23. #define TSI_GCTL REG32(TSI + 0x30U) /*!< TSI group control register */
  24. #define TSI_G0CYCN REG32(TSI + 0x34U) /*!< TSI group 0 cycle number register */
  25. #define TSI_G1CYCN REG32(TSI + 0x38U) /*!< TSI group 1 cycle number register */
  26. #define TSI_G2CYCN REG32(TSI + 0x3CU) /*!< TSI group 2 cycle number register */
  27. #define TSI_G3CYCN REG32(TSI + 0x40U) /*!< TSI group 3 cycle number register */
  28. #define TSI_G4CYCN REG32(TSI + 0x44U) /*!< TSI group 4 cycle number register */
  29. #define TSI_G5CYCN REG32(TSI + 0x48U) /*!< TSI group 5 cycle number register */
  30. #define TSI_CTL1 REG32(TSI + 0x300U) /*!< TSI control registers1 */
  31. /* bits definitions */
  32. /* TSI_CTL0 */
  33. #define TSI_CTL0_TSIEN BIT(0) /*!< TSI enable */
  34. #define TSI_CTL0_TSIS BIT(1) /*!< TSI start */
  35. #define TSI_CTL0_TRGMOD BIT(2) /*!< trigger mode selection */
  36. #define TSI_CTL0_EGSEL BIT(3) /*!< edge selection */
  37. #define TSI_CTL0_PINMOD BIT(4) /*!< pin mode */
  38. #define TSI_CTL0_MCN BITS(5,7) /*!< max cycle number of a sequence */
  39. #define TSI_CTL0_CTCDIV BITS(12,14) /*!< CTCLK clock division factor */
  40. #define TSI_CTL0_ECDIV BIT(15) /*!< ECCLK clock division factor */
  41. #define TSI_CTL0_ECEN BIT(16) /*!< extend charge state enable */
  42. #define TSI_CTL0_ECDT BITS(17,23) /*!< extend charge State maximum duration time */
  43. #define TSI_CTL0_CTDT BITS(24,27) /*!< charge transfer state duration time */
  44. #define TSI_CTL0_CDT BITS(28,31) /*!< charge state duration time */
  45. /* TSI_INTEN */
  46. #define TSI_INTEN_CTCFIE BIT(0) /*!< charge transfer complete flag interrupt enable */
  47. #define TSI_INTEN_MNERRIE BIT(1) /*!< max cycle number error interrupt enable */
  48. /* TSI_INTC */
  49. #define TSI_INTC_CCTCF BIT(0) /*!< clear charge transfer complete flag */
  50. #define TSI_INTC_CMNERR BIT(1) /*!< clear max cycle number error */
  51. /* TSI_INTF */
  52. #define TSI_INTF_CTCF BIT(0) /*!< charge transfer complete flag */
  53. #define TSI_INTF_MNERR BIT(1) /*!< max cycle number error */
  54. /* TSI interrupt enable bit */
  55. #define TSI_INT_CCTCF TSI_INTEN_CTCFIE /*!< charge transfer complete flag interrupt enable */
  56. #define TSI_INT_MNERR TSI_INTEN_MNERRIE /*!< max cycle number error interrupt enable */
  57. /* I2C interrupt flags */
  58. #define TSI_INT_FLAG_CTCF TSI_INTF_CTCF /*!< charge transfer complete flag */
  59. #define TSI_INT_FLAG_MNERR TSI_INTF_MNERR /*!< max cycle number error */
  60. /* I2C interrupt clear flags */
  61. #define TSI_INT_FLAG_CTCF_CLR TSI_INTC_CCTCF /*!< clear charge transfer complete flag */
  62. #define TSI_INT_FLAG_MNERR_CLR TSI_INTC_CMNERR /*!< clear max cycle number error */
  63. /* I2C flags */
  64. #define TSI_FLAG_CTCF TSI_INTF_CTCF /*!< charge transfer complete flag */
  65. #define TSI_FLAG_MNERR TSI_INTF_MNERR /*!< max cycle number error */
  66. /* I2C clear flags */
  67. #define TSI_FLAG_CTCF_CLR TSI_INTC_CCTCF /*!< clear charge transfer complete flag */
  68. #define TSI_FLAG_MNERR_CLR TSI_INTC_CMNERR /*!< clear max cycle number error */
  69. /* TSI_PHM */
  70. #define TSI_PHM_G0P0 BIT(0) /*!< pin G0P0 Schmitt trigger hysteresis state */
  71. #define TSI_PHM_G0P1 BIT(1) /*!< pin G0P1 Schmitt trigger hysteresis state */
  72. #define TSI_PHM_G0P2 BIT(2) /*!< pin G0P2 Schmitt trigger hysteresis state */
  73. #define TSI_PHM_G0P3 BIT(3) /*!< pin G0P3 Schmitt trigger hysteresis state */
  74. #define TSI_PHM_G1P0 BIT(4) /*!< pin G1P0 Schmitt trigger hysteresis state */
  75. #define TSI_PHM_G1P1 BIT(5) /*!< pin G1P1 Schmitt trigger hysteresis state */
  76. #define TSI_PHM_G1P2 BIT(6) /*!< pin G1P2 Schmitt trigger hysteresis state */
  77. #define TSI_PHM_G1P3 BIT(7) /*!< pin G1P3 Schmitt trigger hysteresis state */
  78. #define TSI_PHM_G2P0 BIT(8) /*!< pin G2P0 Schmitt trigger hysteresis state */
  79. #define TSI_PHM_G2P1 BIT(9) /*!< pin G2P1 Schmitt trigger hysteresis state */
  80. #define TSI_PHM_G2P2 BIT(10) /*!< pin G2P2 Schmitt trigger hysteresis state */
  81. #define TSI_PHM_G2P3 BIT(11) /*!< pin G2P3 Schmitt trigger hysteresis state */
  82. #define TSI_PHM_G3P0 BIT(12) /*!< pin G3P0 Schmitt trigger hysteresis state */
  83. #define TSI_PHM_G3P1 BIT(13) /*!< pin G3P1 Schmitt trigger hysteresis state */
  84. #define TSI_PHM_G3P2 BIT(14) /*!< pin G3P2 Schmitt trigger hysteresis state */
  85. #define TSI_PHM_G3P3 BIT(15) /*!< pin G3P3 Schmitt trigger hysteresis state */
  86. #define TSI_PHM_G4P0 BIT(16) /*!< pin G4P0 Schmitt trigger hysteresis state */
  87. #define TSI_PHM_G4P1 BIT(17) /*!< pin G4P1 Schmitt trigger hysteresis state */
  88. #define TSI_PHM_G4P2 BIT(18) /*!< pin G4P2 Schmitt trigger hysteresis state */
  89. #define TSI_PHM_G4P3 BIT(19) /*!< pin G4P3 Schmitt trigger hysteresis state */
  90. #define TSI_PHM_G5P0 BIT(20) /*!< pin G5P0 Schmitt trigger hysteresis state */
  91. #define TSI_PHM_G5P1 BIT(21) /*!< pin G5P1 Schmitt trigger hysteresis state */
  92. #define TSI_PHM_G5P2 BIT(22) /*!< pin G5P2 Schmitt trigger hysteresis state */
  93. #define TSI_PHM_G5P3 BIT(23) /*!< pin G5P3 Schmitt trigger hysteresis state */
  94. /* TSI_ASW */
  95. #define TSI_ASW_G0P0 BIT(0) /*!< pin G0P0 analog switch state */
  96. #define TSI_ASW_G0P1 BIT(1) /*!< pin G0P1 analog switch state */
  97. #define TSI_ASW_G0P2 BIT(2) /*!< pin G0P2 analog switch state */
  98. #define TSI_ASW_G0P3 BIT(3) /*!< pin G0P3 analog switch state */
  99. #define TSI_ASW_G1P0 BIT(4) /*!< pin G1P0 analog switch state */
  100. #define TSI_ASW_G1P1 BIT(5) /*!< pin G1P1 analog switch state */
  101. #define TSI_ASW_G1P2 BIT(6) /*!< pin G1P2 analog switch state */
  102. #define TSI_ASW_G1P3 BIT(7) /*!< pin G1P3 analog switch state */
  103. #define TSI_ASW_G2P0 BIT(8) /*!< pin G2P0 analog switch state */
  104. #define TSI_ASW_G2P1 BIT(9) /*!< pin G2P1 analog switch state */
  105. #define TSI_ASW_G2P2 BIT(10) /*!< pin G2P2 analog switch state */
  106. #define TSI_ASW_G2P3 BIT(11) /*!< pin G2P3 analog switch state */
  107. #define TSI_ASW_G3P0 BIT(12) /*!< pin G3P0 analog switch state */
  108. #define TSI_ASW_G3P1 BIT(13) /*!< pin G3P1 analog switch state */
  109. #define TSI_ASW_G3P2 BIT(14) /*!< pin G3P2 analog switch state */
  110. #define TSI_ASW_G3P3 BIT(15) /*!< pin G3P3 analog switch state */
  111. #define TSI_ASW_G4P0 BIT(16) /*!< pin G4P0 analog switch state */
  112. #define TSI_ASW_G4P1 BIT(17) /*!< pin G4P1 analog switch state */
  113. #define TSI_ASW_G4P2 BIT(18) /*!< pin G4P2 analog switch state */
  114. #define TSI_ASW_G4P3 BIT(19) /*!< pin G4P3 analog switch state */
  115. #define TSI_ASW_G5P0 BIT(20) /*!< pin G5P0 analog switch state */
  116. #define TSI_ASW_G5P1 BIT(21) /*!< pin G5P1 analog switch state */
  117. #define TSI_ASW_G5P2 BIT(22) /*!< pin G5P2 analog switch state */
  118. #define TSI_ASW_G5P3 BIT(23) /*!< pin G5P3 analog switch state */
  119. /* TSI_SAMPCFG */
  120. #define TSI_SAMPCFG_G0P0 BIT(0) /*!< pin G0P0 sample pin mode */
  121. #define TSI_SAMPCFG_G0P1 BIT(1) /*!< pin G0P1 sample pin mode */
  122. #define TSI_SAMPCFG_G0P2 BIT(2) /*!< pin G0P2 sample pin mode */
  123. #define TSI_SAMPCFG_G0P3 BIT(3) /*!< pin G0P3 sample pin mode */
  124. #define TSI_SAMPCFG_G1P0 BIT(4) /*!< pin G1P0 sample pin mode */
  125. #define TSI_SAMPCFG_G1P1 BIT(5) /*!< pin G1P1 sample pin mode */
  126. #define TSI_SAMPCFG_G1P2 BIT(6) /*!< pin G1P2 sample pin mode */
  127. #define TSI_SAMPCFG_G1P3 BIT(7) /*!< pin G1P3 sample pin mode */
  128. #define TSI_SAMPCFG_G2P0 BIT(8) /*!< pin G2P0 sample pin mode */
  129. #define TSI_SAMPCFG_G2P1 BIT(9) /*!< pin G2P1 sample pin mode */
  130. #define TSI_SAMPCFG_G2P2 BIT(10) /*!< pin G2P2 sample pin mode */
  131. #define TSI_SAMPCFG_G2P3 BIT(11) /*!< pin G2P3 sample pin mode */
  132. #define TSI_SAMPCFG_G3P0 BIT(12) /*!< pin G3P0 sample pin mode */
  133. #define TSI_SAMPCFG_G3P1 BIT(13) /*!< pin G3P1 sample pin mode */
  134. #define TSI_SAMPCFG_G3P2 BIT(14) /*!< pin G3P2 sample pin mode */
  135. #define TSI_SAMPCFG_G3P3 BIT(15) /*!< pin G3P3 sample pin mode */
  136. #define TSI_SAMPCFG_G4P0 BIT(16) /*!< pin G4P0 sample pin mode */
  137. #define TSI_SAMPCFG_G4P1 BIT(17) /*!< pin G4P1 sample pin mode */
  138. #define TSI_SAMPCFG_G4P2 BIT(18) /*!< pin G4P2 sample pin mode */
  139. #define TSI_SAMPCFG_G4P3 BIT(19) /*!< pin G4P3 sample pin mode */
  140. #define TSI_SAMPCFG_G5P0 BIT(20) /*!< pin G5P0 sample pin mode */
  141. #define TSI_SAMPCFG_G5P1 BIT(21) /*!< pin G5P1 sample pin mode */
  142. #define TSI_SAMPCFG_G5P2 BIT(22) /*!< pin G5P2 sample pin mode */
  143. #define TSI_SAMPCFG_G5P3 BIT(23) /*!< pin G5P3 sample pin mode */
  144. /* TSI_CHCFG */
  145. #define TSI_CHCFG_G0P0 BIT(0) /*!< pin G0P0 channel pin mode */
  146. #define TSI_CHCFG_G0P1 BIT(1) /*!< pin G0P1 channel pin mode */
  147. #define TSI_CHCFG_G0P2 BIT(2) /*!< pin G0P2 channel pin mode */
  148. #define TSI_CHCFG_G0P3 BIT(3) /*!< pin G0P3 channel pin mode */
  149. #define TSI_CHCFG_G1P0 BIT(4) /*!< pin G1P0 channel pin mode */
  150. #define TSI_CHCFG_G1P1 BIT(5) /*!< pin G1P1 channel pin mode */
  151. #define TSI_CHCFG_G1P2 BIT(6) /*!< pin G1P2 channel pin mode */
  152. #define TSI_CHCFG_G1P3 BIT(7) /*!< pin G1P3 channel pin mode */
  153. #define TSI_CHCFG_G2P0 BIT(8) /*!< pin G2P0 channel pin mode */
  154. #define TSI_CHCFG_G2P1 BIT(9) /*!< pin G2P1 channel pin mode */
  155. #define TSI_CHCFG_G2P2 BIT(10) /*!< pin G2P2 channel pin mode */
  156. #define TSI_CHCFG_G2P3 BIT(11) /*!< pin G2P3 channel pin mode */
  157. #define TSI_CHCFG_G3P0 BIT(12) /*!< pin G3P0 channel pin mode */
  158. #define TSI_CHCFG_G3P1 BIT(13) /*!< pin G3P1 channel pin mode */
  159. #define TSI_CHCFG_G3P2 BIT(14) /*!< pin G3P2 channel pin mode */
  160. #define TSI_CHCFG_G3P3 BIT(15) /*!< pin G3P3 channel pin mode */
  161. #define TSI_CHCFG_G4P0 BIT(16) /*!< pin G4P0 channel pin mode */
  162. #define TSI_CHCFG_G4P1 BIT(17) /*!< pin G4P1 channel pin mode */
  163. #define TSI_CHCFG_G4P2 BIT(18) /*!< pin G4P2 channel pin mode */
  164. #define TSI_CHCFG_G4P3 BIT(19) /*!< pin G4P3 channel pin mode */
  165. #define TSI_CHCFG_G5P0 BIT(20) /*!< pin G5P0 channel pin mode */
  166. #define TSI_CHCFG_G5P1 BIT(21) /*!< pin G5P1 channel pin mode */
  167. #define TSI_CHCFG_G5P2 BIT(22) /*!< pin G5P2 channel pin mode */
  168. #define TSI_CHCFG_G5P3 BIT(23) /*!< pin G5P3 channel pin mode */
  169. /* TSI_GCTL */
  170. #define TSI_GCTL_GE0 BIT(0) /*!< group0 enable */
  171. #define TSI_GCTL_GE1 BIT(1) /*!< group1 enable */
  172. #define TSI_GCTL_GE2 BIT(2) /*!< group2 enable */
  173. #define TSI_GCTL_GE3 BIT(3) /*!< group3 enable */
  174. #define TSI_GCTL_GE4 BIT(4) /*!< group4 enable */
  175. #define TSI_GCTL_GE5 BIT(5) /*!< group5 enable */
  176. #define TSI_GCTL_GC0 BIT(16) /*!< group0 complete */
  177. #define TSI_GCTL_GC1 BIT(17) /*!< group1 complete */
  178. #define TSI_GCTL_GC2 BIT(18) /*!< group2 complete */
  179. #define TSI_GCTL_GC3 BIT(19) /*!< group3 complete */
  180. #define TSI_GCTL_GC4 BIT(20) /*!< group4 complete */
  181. #define TSI_GCTL_GC5 BIT(21) /*!< group5 complete */
  182. /* TSI_CTL1 */
  183. #define TSI_CTL1_CTCDIV BIT(24) /*!< CTCLK clock division factor */
  184. #define TSI_CTL1_ECDIV BITS(28,29) /*!< ECCLK clock division factor */
  185. /* constants definitions */
  186. /* CTCLK clock division factor */
  187. #define TSI_CTCDIV_DIV1 ((uint32_t)0x00000000U) /*!< fCTCLK = fHCLK */
  188. #define TSI_CTCDIV_DIV2 ((uint32_t)0x00000001U) /*!< fCTCLK = fHCLK/2 */
  189. #define TSI_CTCDIV_DIV4 ((uint32_t)0x00000002U) /*!< fCTCLK = fHCLK/4 */
  190. #define TSI_CTCDIV_DIV8 ((uint32_t)0x00000003U) /*!< fCTCLK = fHCLK/8 */
  191. #define TSI_CTCDIV_DIV16 ((uint32_t)0x00000004U) /*!< fCTCLK = fHCLK/16 */
  192. #define TSI_CTCDIV_DIV32 ((uint32_t)0x00000005U) /*!< fCTCLK = fHCLK/32 */
  193. #define TSI_CTCDIV_DIV64 ((uint32_t)0x00000006U) /*!< fCTCLK = fHCLK/64 */
  194. #define TSI_CTCDIV_DIV128 ((uint32_t)0x00000007U) /*!< fCTCLK = fHCLK/128 */
  195. #define TSI_CTCDIV_DIV256 ((uint32_t)0x00000008U) /*!< fCTCLK = fHCLK/256 */
  196. #define TSI_CTCDIV_DIV512 ((uint32_t)0x00000009U) /*!< fCTCLK = fHCLK/512 */
  197. #define TSI_CTCDIV_DIV1024 ((uint32_t)0x0000000AU) /*!< fCTCLK = fHCLK/1024 */
  198. #define TSI_CTCDIV_DIV2048 ((uint32_t)0x0000000BU) /*!< fCTCLK = fHCLK/2048 */
  199. #define TSI_CTCDIV_DIV4096 ((uint32_t)0x0000000CU) /*!< fCTCLK = fHCLK/4096 */
  200. #define TSI_CTCDIV_DIV8192 ((uint32_t)0x0000000DU) /*!< fCTCLK = fHCLK/8192 */
  201. #define TSI_CTCDIV_DIV16384 ((uint32_t)0x0000000EU) /*!< fCTCLK = fHCLK/16384 */
  202. #define TSI_CTCDIV_DIV32768 ((uint32_t)0x0000000FU) /*!< fCTCLK = fHCLK/32768 */
  203. /* charge transfer state duration Time */
  204. #define CTL_CTDT(regval) (BITS(24,27) & ((uint32_t)(regval) << 24U))
  205. #define TSI_TRANSFER_1CTCLK CTL_CTDT(0) /*!< the duration time of transfer state is 1 CTCLK */
  206. #define TSI_TRANSFER_2CTCLK CTL_CTDT(1) /*!< the duration time of transfer state is 2 CTCLK */
  207. #define TSI_TRANSFER_3CTCLK CTL_CTDT(2) /*!< the duration time of transfer state is 3 CTCLK */
  208. #define TSI_TRANSFER_4CTCLK CTL_CTDT(3) /*!< the duration time of transfer state is 4 CTCLK */
  209. #define TSI_TRANSFER_5CTCLK CTL_CTDT(4) /*!< the duration time of transfer state is 5 CTCLK */
  210. #define TSI_TRANSFER_6CTCLK CTL_CTDT(5) /*!< the duration time of transfer state is 6 CTCLK */
  211. #define TSI_TRANSFER_7CTCLK CTL_CTDT(6) /*!< the duration time of transfer state is 7 CTCLK */
  212. #define TSI_TRANSFER_8CTCLK CTL_CTDT(7) /*!< the duration time of transfer state is 8 CTCLK */
  213. #define TSI_TRANSFER_9CTCLK CTL_CTDT(8) /*!< the duration time of transfer state is 9 CTCLK */
  214. #define TSI_TRANSFER_10CTCLK CTL_CTDT(9) /*!< the duration time of transfer state is 10 CTCLK */
  215. #define TSI_TRANSFER_11CTCLK CTL_CTDT(10) /*!< the duration time of transfer state is 11 CTCLK */
  216. #define TSI_TRANSFER_12CTCLK CTL_CTDT(11) /*!< the duration time of transfer state is 12 CTCLK */
  217. #define TSI_TRANSFER_13CTCLK CTL_CTDT(12) /*!< the duration time of transfer state is 13 CTCLK */
  218. #define TSI_TRANSFER_14CTCLK CTL_CTDT(13) /*!< the duration time of transfer state is 14 CTCLK */
  219. #define TSI_TRANSFER_15CTCLK CTL_CTDT(14) /*!< the duration time of transfer state is 15 CTCLK */
  220. #define TSI_TRANSFER_16CTCLK CTL_CTDT(15) /*!< the duration time of transfer state is 16 CTCLK */
  221. /* charge state duration time */
  222. #define CTL_CDT(regval) (BITS(28,31) & ((uint32_t)(regval) << 28U))
  223. #define TSI_CHARGE_1CTCLK CTL_CDT(0) /*!< the duration time of charge state is 1 CTCLK */
  224. #define TSI_CHARGE_2CTCLK CTL_CDT(1) /*!< the duration time of charge state is 2 CTCLK */
  225. #define TSI_CHARGE_3CTCLK CTL_CDT(2) /*!< the duration time of charge state is 3 CTCLK */
  226. #define TSI_CHARGE_4CTCLK CTL_CDT(3) /*!< the duration time of charge state is 4 CTCLK */
  227. #define TSI_CHARGE_5CTCLK CTL_CDT(4) /*!< the duration time of charge state is 5 CTCLK */
  228. #define TSI_CHARGE_6CTCLK CTL_CDT(5) /*!< the duration time of charge state is 6 CTCLK */
  229. #define TSI_CHARGE_7CTCLK CTL_CDT(6) /*!< the duration time of charge state is 7 CTCLK */
  230. #define TSI_CHARGE_8CTCLK CTL_CDT(7) /*!< the duration time of charge state is 8 CTCLK */
  231. #define TSI_CHARGE_9CTCLK CTL_CDT(8) /*!< the duration time of charge state is 9 CTCLK */
  232. #define TSI_CHARGE_10CTCLK CTL_CDT(9) /*!< the duration time of charge state is 10 CTCLK */
  233. #define TSI_CHARGE_11CTCLK CTL_CDT(10) /*!< the duration time of charge state is 11 CTCLK */
  234. #define TSI_CHARGE_12CTCLK CTL_CDT(11) /*!< the duration time of charge state is 12 CTCLK */
  235. #define TSI_CHARGE_13CTCLK CTL_CDT(12) /*!< the duration time of charge state is 13 CTCLK */
  236. #define TSI_CHARGE_14CTCLK CTL_CDT(13) /*!< the duration time of charge state is 14 CTCLK */
  237. #define TSI_CHARGE_15CTCLK CTL_CDT(14) /*!< the duration time of charge state is 15 CTCLK */
  238. #define TSI_CHARGE_16CTCLK CTL_CDT(15) /*!< the duration time of charge state is 16 CTCLK */
  239. /* max cycle number of a sequence */
  240. #define CTL_MCN(regval) (BITS(5,7) & ((uint32_t)(regval) << 5U))
  241. #define TSI_MAXNUM255 CTL_MCN(0) /*!< the max cycle number of a sequence is 255 */
  242. #define TSI_MAXNUM511 CTL_MCN(1) /*!< the max cycle number of a sequence is 511 */
  243. #define TSI_MAXNUM1023 CTL_MCN(2) /*!< the max cycle number of a sequence is 1023 */
  244. #define TSI_MAXNUM2047 CTL_MCN(3) /*!< the max cycle number of a sequence is 2047 */
  245. #define TSI_MAXNUM4095 CTL_MCN(4) /*!< the max cycle number of a sequence is 4095 */
  246. #define TSI_MAXNUM8191 CTL_MCN(5) /*!< the max cycle number of a sequence is 8191 */
  247. #define TSI_MAXNUM16383 CTL_MCN(6) /*!< the max cycle number of a sequence is 16383 */
  248. /* ECCLK clock division factor */
  249. #define TSI_EXTEND_DIV1 ((uint32_t)0x00000000U) /*!< fECCLK = fHCLK */
  250. #define TSI_EXTEND_DIV2 ((uint32_t)0x00000001U) /*!< fECCLK = fHCLK/2 */
  251. #define TSI_EXTEND_DIV3 ((uint32_t)0x00000002U) /*!< fECCLK = fHCLK/3 */
  252. #define TSI_EXTEND_DIV4 ((uint32_t)0x00000003U) /*!< fECCLK = fHCLK/4 */
  253. #define TSI_EXTEND_DIV5 ((uint32_t)0x00000004U) /*!< fECCLK = fHCLK/5 */
  254. #define TSI_EXTEND_DIV6 ((uint32_t)0x00000005U) /*!< fECCLK = fHCLK/6 */
  255. #define TSI_EXTEND_DIV7 ((uint32_t)0x00000006U) /*!< fECCLK = fHCLK/7 */
  256. #define TSI_EXTEND_DIV8 ((uint32_t)0x00000007U) /*!< fECCLK = fHCLK/8 */
  257. /* extend charge state maximum duration time */
  258. #define TSI_EXTENDMAX(regval) (BITS(17,23) & ((uint32_t)(regval) << 17U)) /* value range 1..128,extend charge state maximum duration time */
  259. /* hardware trigger mode */
  260. #define TSI_FALLING_TRIGGER 0x00U /*!< falling edge trigger TSI charge transfer sequence */
  261. #define TSI_RISING_TRIGGER 0x01U /*!< rising edge trigger TSI charge transfer sequence */
  262. /* pin mode */
  263. #define TSI_OUTPUT_LOW 0x00U /*!< TSI pin will output low when IDLE */
  264. #define TSI_INPUT_FLOATING 0x01U /*!< TSI pin will keep input_floating when IDLE */
  265. /* function declarations */
  266. /* reset TSI peripheral */
  267. void tsi_deinit(void);
  268. /* initialize TSI plus prescaler,charge plus,transfer plus,max cycle number */
  269. void tsi_init(uint32_t prescaler,uint32_t charge_duration,uint32_t transfer_duration,uint32_t max_number);
  270. /* enable TSI module */
  271. void tsi_enable(void);
  272. /* disable TSI module */
  273. void tsi_disable(void);
  274. /* enable sample pin */
  275. void tsi_sample_pin_enable(uint32_t sample);
  276. /* disable sample pin */
  277. void tsi_sample_pin_disable(uint32_t sample);
  278. /* enable channel pin */
  279. void tsi_channel_pin_enable(uint32_t channel);
  280. /* disable channel pin */
  281. void tsi_channel_pin_disable(uint32_t channel);
  282. /* configure TSI triggering by software */
  283. void tsi_sofeware_mode_config(void);
  284. /* start a charge-transfer sequence when TSI is in software trigger mode */
  285. void tsi_software_start(void);
  286. /* stop a charge-transfer sequence when TSI is in software trigger mode */
  287. void tsi_software_stop(void);
  288. /* configure TSI triggering by hardware */
  289. void tsi_hardware_mode_config(uint8_t trigger_edge);
  290. /* configure TSI pin mode when charge-transfer sequence is IDLE */
  291. void tsi_pin_mode_config(uint8_t pin_mode);
  292. /* configure extend charge state */
  293. void tsi_extend_charge_config(ControlStatus extend,uint8_t prescaler,uint32_t max_duration);
  294. /* configure charge plus and transfer plus */
  295. void tsi_plus_config(uint32_t prescaler,uint32_t charge_duration,uint32_t transfer_duration);
  296. /* configure the max cycle number of a charge-transfer sequence */
  297. void tsi_max_number_config(uint32_t max_number);
  298. /* switch on hysteresis pin */
  299. void tsi_hysteresis_on(uint32_t group_pin);
  300. /* switch off hysteresis pin */
  301. void tsi_hysteresis_off(uint32_t group_pin);
  302. /* switch on analog pin */
  303. void tsi_analog_on(uint32_t group_pin);
  304. /* switch off analog pin */
  305. void tsi_analog_off(uint32_t group_pin);
  306. /* enable TSI interrupt */
  307. void tsi_interrupt_enable(uint32_t source);
  308. /* disable TSI interrupt */
  309. void tsi_interrupt_disable(uint32_t source);
  310. /* clear interrupt flag */
  311. void tsi_interrupt_flag_clear(uint32_t flag);
  312. /* get TSI interrupt flag */
  313. FlagStatus tsi_interrupt_flag_get(uint32_t flag);
  314. /* clear flag */
  315. void tsi_flag_clear(uint32_t flag);
  316. /* get flag */
  317. FlagStatus tsi_flag_get(uint32_t flag);
  318. /* enbale group */
  319. void tsi_group_enable(uint32_t group);
  320. /* disbale group */
  321. void tsi_group_disable(uint32_t group);
  322. /* get group complete status */
  323. FlagStatus tsi_group_status_get(uint32_t group);
  324. /* get the cycle number for group0 as soon as a charge-transfer sequence completes */
  325. uint16_t tsi_group0_cycle_get(void);
  326. /* get the cycle number for group1 as soon as a charge-transfer sequence completes */
  327. uint16_t tsi_group1_cycle_get(void);
  328. /* get the cycle number for group2 as soon as a charge-transfer sequence completes */
  329. uint16_t tsi_group2_cycle_get(void);
  330. /* get the cycle number for group3 as soon as a charge-transfer sequence completes */
  331. uint16_t tsi_group3_cycle_get(void);
  332. /* get the cycle number for group4 as soon as a charge-transfer sequence completes */
  333. uint16_t tsi_group4_cycle_get(void);
  334. /* get the cycle number for group5 as soon as a charge-transfer sequence completes */
  335. uint16_t tsi_group5_cycle_get(void);
  336. #endif /* GD32F3X0_TSI_H */