gd32f10x_usart.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*!
  2. \file gd32f10x_usart.h
  3. \brief definitions for the USART
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.1, 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. #ifndef GD32F10X_USART_H
  33. #define GD32F10X_USART_H
  34. #include "gd32f10x.h"
  35. /* USARTx(x=0,1,2)/UARTx(x=3,4) definitions */
  36. #define USART1 USART_BASE /*!< USART1 base address */
  37. #define USART2 (USART_BASE+(0x00000400U)) /*!< USART2 base address */
  38. #define UART3 (USART_BASE+(0x00000800U)) /*!< UART3 base address */
  39. #define UART4 (USART_BASE+(0x00000C00U)) /*!< UART4 base address */
  40. #define USART0 (USART_BASE+(0x0000F400U)) /*!< USART0 base address */
  41. /* registers definitions */
  42. #define USART_STAT(usartx) REG32((usartx) + (0x00000000U)) /*!< USART status register */
  43. #define USART_DATA(usartx) REG32((usartx) + (0x00000004U)) /*!< USART data register */
  44. #define USART_BAUD(usartx) REG32((usartx) + (0x00000008U)) /*!< USART baud rate register */
  45. #define USART_CTL0(usartx) REG32((usartx) + (0x0000000CU)) /*!< USART control register 0 */
  46. #define USART_CTL1(usartx) REG32((usartx) + (0x00000010U)) /*!< USART control register 1 */
  47. #define USART_CTL2(usartx) REG32((usartx) + (0x00000014U)) /*!< USART control register 2 */
  48. #define USART_GP(usartx) REG32((usartx) + (0x00000018U)) /*!< USART guard time and prescaler register */
  49. /* bits definitions */
  50. /* USARTx_STAT */
  51. #define USART_STAT_PERR BIT(0) /*!< parity error flag */
  52. #define USART_STAT_FERR BIT(1) /*!< frame error flag */
  53. #define USART_STAT_NERR BIT(2) /*!< noise error flag */
  54. #define USART_STAT_ORERR BIT(3) /*!< overrun error */
  55. #define USART_STAT_IDLEF BIT(4) /*!< IDLE frame detected flag */
  56. #define USART_STAT_RBNE BIT(5) /*!< read data buffer not empty */
  57. #define USART_STAT_TC BIT(6) /*!< transmission complete */
  58. #define USART_STAT_TBE BIT(7) /*!< transmit data buffer empty */
  59. #define USART_STAT_LBDF BIT(8) /*!< LIN break detected flag */
  60. #define USART_STAT_CTSF BIT(9) /*!< CTS change flag */
  61. /* USARTx_DATA */
  62. #define USART_DATA_DATA BITS(0,8) /*!< transmit or read data value */
  63. /* USARTx_BAUD */
  64. #define USART_BAUD_FRADIV BITS(0,3) /*!< fraction part of baud-rate divider */
  65. #define USART_BAUD_INTDIV BITS(4,15) /*!< integer part of baud-rate divider */
  66. /* USARTx_CTL0 */
  67. #define USART_CTL0_SBKCMD BIT(0) /*!< send break command */
  68. #define USART_CTL0_RWU BIT(1) /*!< receiver wakeup from mute mode */
  69. #define USART_CTL0_REN BIT(2) /*!< receiver enable */
  70. #define USART_CTL0_TEN BIT(3) /*!< transmitter enable */
  71. #define USART_CTL0_IDLEIE BIT(4) /*!< idle line detected interrupt enable */
  72. #define USART_CTL0_RBNEIE BIT(5) /*!< read data buffer not empty interrupt and overrun error interrupt enable */
  73. #define USART_CTL0_TCIE BIT(6) /*!< transmission complete interrupt enable */
  74. #define USART_CTL0_TBEIE BIT(7) /*!< transmitter buffer empty interrupt enable */
  75. #define USART_CTL0_PERRIE BIT(8) /*!< parity error interrupt enable */
  76. #define USART_CTL0_PM BIT(9) /*!< parity mode */
  77. #define USART_CTL0_PCEN BIT(10) /*!< parity check function enable */
  78. #define USART_CTL0_WM BIT(11) /*!< wakeup method in mute mode */
  79. #define USART_CTL0_WL BIT(12) /*!< word length */
  80. #define USART_CTL0_UEN BIT(13) /*!< USART enable */
  81. /* USARTx_CTL1 */
  82. #define USART_CTL1_ADDR BITS(0,3) /*!< address of USART */
  83. #define USART_CTL1_LBLEN BIT(5) /*!< LIN break frame length */
  84. #define USART_CTL1_LBDIE BIT(6) /*!< LIN break detected interrupt eanble */
  85. #define USART_CTL1_CLEN BIT(8) /*!< CK length */
  86. #define USART_CTL1_CPH BIT(9) /*!< CK phase */
  87. #define USART_CTL1_CPL BIT(10) /*!< CK polarity */
  88. #define USART_CTL1_CKEN BIT(11) /*!< CK pin enable */
  89. #define USART_CTL1_STB BITS(12,13) /*!< STOP bits length */
  90. #define USART_CTL1_LMEN BIT(14) /*!< LIN mode enable */
  91. /* USARTx_CTL2 */
  92. #define USART_CTL2_ERRIE BIT(0) /*!< error interrupt enable */
  93. #define USART_CTL2_IREN BIT(1) /*!< IrDA mode enable */
  94. #define USART_CTL2_IRLP BIT(2) /*!< IrDA low-power */
  95. #define USART_CTL2_HDEN BIT(3) /*!< half-duplex enable */
  96. #define USART_CTL2_NKEN BIT(4) /*!< NACK enable in smartcard mode */
  97. #define USART_CTL2_SCEN BIT(5) /*!< smartcard mode enable */
  98. #define USART_CTL2_DENR BIT(6) /*!< DMA request enable for reception */
  99. #define USART_CTL2_DENT BIT(7) /*!< DMA request enable for transmission */
  100. #define USART_CTL2_RTSEN BIT(8) /*!< RTS enable */
  101. #define USART_CTL2_CTSEN BIT(9) /*!< CTS enable */
  102. #define USART_CTL2_CTSIE BIT(10) /*!< CTS interrupt enable */
  103. /* USARTx_GP */
  104. #define USART_GP_PSC BITS(0,7) /*!< prescaler value for dividing the system clock */
  105. #define USART_GP_GUAT BITS(8,15) /*!< guard time value in smartcard mode */
  106. /* constants definitions */
  107. /* define the USART bit position and its register index offset */
  108. #define USART_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
  109. #define USART_REG_VAL(usartx, offset) (REG32((usartx) + (((uint32_t)(offset) & (0x0000FFFFU)) >> 6)))
  110. #define USART_BIT_POS(val) ((uint32_t)(val) & (0x0000001FU))
  111. #define USART_REGIDX_BIT2(regidx, bitpos, regidx2, bitpos2) (((uint32_t)(regidx2) << 22) | (uint32_t)((bitpos2) << 16)\
  112. | (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos)))
  113. #define USART_REG_VAL2(usartx, offset) (REG32((usartx) + ((uint32_t)(offset) >> 22)))
  114. #define USART_BIT_POS2(val) (((uint32_t)(val) & (0x001F0000U)) >> 16)
  115. /* register offset */
  116. #define USART_STAT_REG_OFFSET (0x00000000U) /*!< STAT register offset */
  117. #define USART_CTL0_REG_OFFSET (0x0000000CU) /*!< CTL0 register offset */
  118. #define USART_CTL1_REG_OFFSET (0x00000010U) /*!< CTL1 register offset */
  119. #define USART_CTL2_REG_OFFSET (0x00000014U) /*!< CTL2 register offset */
  120. /* USART flags */
  121. typedef enum
  122. {
  123. /* flags in STAT register */
  124. USART_FLAG_CTSF = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 9U), /*!< CTS change flag */
  125. USART_FLAG_LBDF = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 8U), /*!< LIN break detected flag */
  126. USART_FLAG_TBE = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 7U), /*!< transmit data buffer empty */
  127. USART_FLAG_TC = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 6U), /*!< transmission complete */
  128. USART_FLAG_RBNE = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 5U), /*!< read data buffer not empty */
  129. USART_FLAG_IDLEF = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 4U), /*!< IDLE frame detected flag */
  130. USART_FLAG_ORERR = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 3U), /*!< overrun error */
  131. USART_FLAG_NERR = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 2U), /*!< noise error flag */
  132. USART_FLAG_FERR = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 1U), /*!< frame error flag */
  133. USART_FLAG_PERR = USART_REGIDX_BIT(USART_STAT_REG_OFFSET, 0U), /*!< parity error flag */
  134. }usart_flag_enum;
  135. /* USART interrupt flags */
  136. typedef enum
  137. {
  138. /* interrupt flags in CTL0 register */
  139. USART_INT_FLAG_PERR = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 8U, USART_STAT_REG_OFFSET, 0U), /*!< parity error interrupt and flag */
  140. USART_INT_FLAG_TBE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 7U, USART_STAT_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt and flag */
  141. USART_INT_FLAG_TC = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 6U, USART_STAT_REG_OFFSET, 6U), /*!< transmission complete interrupt and flag */
  142. USART_INT_FLAG_RBNE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 5U, USART_STAT_REG_OFFSET, 5U), /*!< read data buffer not empty interrupt and flag */
  143. USART_INT_FLAG_RBNE_ORERR = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 5U, USART_STAT_REG_OFFSET, 3U), /*!< read data buffer not empty interrupt and overrun error flag */
  144. USART_INT_FLAG_IDLE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 4U, USART_STAT_REG_OFFSET, 4U), /*!< IDLE line detected interrupt and flag */
  145. /* interrupt flags in CTL1 register */
  146. USART_INT_FLAG_LBD = USART_REGIDX_BIT2(USART_CTL1_REG_OFFSET, 6U, USART_STAT_REG_OFFSET, 8U), /*!< LIN break detected interrupt and flag */
  147. /* interrupt flags in CTL2 register */
  148. USART_INT_FLAG_CTS = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 10U, USART_STAT_REG_OFFSET, 9U), /*!< CTS interrupt and flag */
  149. USART_INT_FLAG_ERR_ORERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT_REG_OFFSET, 3U), /*!< error interrupt and overrun error */
  150. USART_INT_FLAG_ERR_NERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT_REG_OFFSET, 2U), /*!< error interrupt and noise error flag */
  151. USART_INT_FLAG_ERR_FERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT_REG_OFFSET, 1U), /*!< error interrupt and frame error flag */
  152. }usart_interrupt_flag_enum;
  153. /* USART interrupt enable or disable */
  154. typedef enum
  155. {
  156. /* interrupt in CTL0 register */
  157. USART_INT_PERR = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 8U), /*!< parity error interrupt */
  158. USART_INT_TBE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt */
  159. USART_INT_TC = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 6U), /*!< transmission complete interrupt */
  160. USART_INT_RBNE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 5U), /*!< read data buffer not empty interrupt and overrun error interrupt */
  161. USART_INT_IDLE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 4U), /*!< IDLE line detected interrupt */
  162. /* interrupt in CTL1 register */
  163. USART_INT_LBD = USART_REGIDX_BIT(USART_CTL1_REG_OFFSET, 6U), /*!< LIN break detected interrupt */
  164. /* interrupt in CTL2 register */
  165. USART_INT_CTS = USART_REGIDX_BIT(USART_CTL2_REG_OFFSET, 10U), /*!< CTS interrupt */
  166. USART_INT_ERR = USART_REGIDX_BIT(USART_CTL2_REG_OFFSET, 0U), /*!< error interrupt */
  167. }usart_interrupt_enum;
  168. /* USART receiver configure */
  169. #define CTL0_REN(regval) (BIT(2) & ((uint32_t)(regval) << 2))
  170. #define USART_RECEIVE_ENABLE CTL0_REN(1) /*!< enable receiver */
  171. #define USART_RECEIVE_DISABLE CTL0_REN(0) /*!< disable receiver */
  172. /* USART transmitter configure */
  173. #define CTL0_TEN(regval) (BIT(3) & ((uint32_t)(regval) << 3))
  174. #define USART_TRANSMIT_ENABLE CTL0_TEN(1) /*!< enable transmitter */
  175. #define USART_TRANSMIT_DISABLE CTL0_TEN(0) /*!< disable transmitter */
  176. /* USART parity bits definitions */
  177. #define CTL0_PM(regval) (BITS(9,10) & ((uint32_t)(regval) << 9))
  178. #define USART_PM_NONE CTL0_PM(0) /*!< no parity */
  179. #define USART_PM_EVEN CTL0_PM(2) /*!< even parity */
  180. #define USART_PM_ODD CTL0_PM(3) /*!< odd parity */
  181. /* USART wakeup method in mute mode */
  182. #define CTL0_WM(regval) (BIT(11) & ((uint32_t)(regval) << 11))
  183. #define USART_WM_IDLE CTL0_WM(0) /*!< idle line */
  184. #define USART_WM_ADDR CTL0_WM(1) /*!< address match */
  185. /* USART word length definitions */
  186. #define CTL0_WL(regval) (BIT(12) & ((uint32_t)(regval) << 12))
  187. #define USART_WL_8BIT CTL0_WL(0) /*!< 8 bits */
  188. #define USART_WL_9BIT CTL0_WL(1) /*!< 9 bits */
  189. /* USART stop bits definitions */
  190. #define CTL1_STB(regval) (BITS(12,13) & ((uint32_t)(regval) << 12))
  191. #define USART_STB_1BIT CTL1_STB(0) /*!< 1 bit */
  192. #define USART_STB_0_5BIT CTL1_STB(1) /*!< 0.5 bit */
  193. #define USART_STB_2BIT CTL1_STB(2) /*!< 2 bits */
  194. #define USART_STB_1_5BIT CTL1_STB(3) /*!< 1.5 bits */
  195. /* USART LIN break frame length */
  196. #define CTL1_LBLEN(regval) (BIT(5) & ((uint32_t)(regval) << 5))
  197. #define USART_LBLEN_10B CTL1_LBLEN(0) /*!< 10 bits */
  198. #define USART_LBLEN_11B CTL1_LBLEN(1) /*!< 11 bits */
  199. /* USART CK length */
  200. #define CTL1_CLEN(regval) (BIT(8) & ((uint32_t)(regval) << 8))
  201. #define USART_CLEN_NONE CTL1_CLEN(0) /*!< there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame */
  202. #define USART_CLEN_EN CTL1_CLEN(1) /*!< there are 8 CK pulses for an 8 bit frame and 9 CK pulses for a 9 bit frame */
  203. /* USART clock phase */
  204. #define CTL1_CPH(regval) (BIT(9) & ((uint32_t)(regval) << 9))
  205. #define USART_CPH_1CK CTL1_CPH(0) /*!< first clock transition is the first data capture edge */
  206. #define USART_CPH_2CK CTL1_CPH(1) /*!< second clock transition is the first data capture edge */
  207. /* USART clock polarity */
  208. #define CTL1_CPL(regval) (BIT(10) & ((uint32_t)(regval) << 10))
  209. #define USART_CPL_LOW CTL1_CPL(0) /*!< steady low value on CK pin */
  210. #define USART_CPL_HIGH CTL1_CPL(1) /*!< steady high value on CK pin */
  211. /* USART DMA request for receive configure */
  212. #define CLT2_DENR(regval) (BIT(6) & ((uint32_t)(regval) << 6))
  213. #define USART_DENR_ENABLE CLT2_DENR(1) /*!< DMA request enable for reception */
  214. #define USART_DENR_DISABLE CLT2_DENR(0) /*!< DMA request disable for reception */
  215. /* USART DMA request for transmission configure */
  216. #define CLT2_DENT(regval) (BIT(7) & ((uint32_t)(regval) << 7))
  217. #define USART_DENT_ENABLE CLT2_DENT(1) /*!< DMA request enable for transmission */
  218. #define USART_DENT_DISABLE CLT2_DENT(0) /*!< DMA request disable for transmission */
  219. /* USART RTS configure */
  220. #define CLT2_RTSEN(regval) (BIT(8) & ((uint32_t)(regval) << 8))
  221. #define USART_RTS_ENABLE CLT2_RTSEN(1) /*!< RTS enable */
  222. #define USART_RTS_DISABLE CLT2_RTSEN(0) /*!< RTS disable */
  223. /* USART CTS configure */
  224. #define CLT2_CTSEN(regval) (BIT(9) & ((uint32_t)(regval) << 9))
  225. #define USART_CTS_ENABLE CLT2_CTSEN(1) /*!< CTS enable */
  226. #define USART_CTS_DISABLE CLT2_CTSEN(0) /*!< CTS disable */
  227. /* USART IrDA low-power enable */
  228. #define CTL2_IRLP(regval) (BIT(2) & ((uint32_t)(regval) << 2))
  229. #define USART_IRLP_LOW CTL2_IRLP(1) /*!< low-power */
  230. #define USART_IRLP_NORMAL CTL2_IRLP(0) /*!< normal */
  231. /* function declarations */
  232. /* initialization functions */
  233. /* reset USART */
  234. void usart_deinit(uint32_t usart_periph);
  235. /* configure USART baud rate value */
  236. void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval);
  237. /* configure USART parity function */
  238. void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg);
  239. /* configure USART word length */
  240. void usart_word_length_set(uint32_t usart_periph, uint32_t wlen);
  241. /* configure USART stop bit length */
  242. void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen);
  243. /* USART normal mode communication */
  244. /* enable USART */
  245. void usart_enable(uint32_t usart_periph);
  246. /* disable USART */
  247. void usart_disable(uint32_t usart_periph);
  248. /* configure USART transmitter */
  249. void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig);
  250. /* configure USART receiver */
  251. void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig);
  252. /* USART transmit data function */
  253. void usart_data_transmit(uint32_t usart_periph, uint16_t data);
  254. /* USART receive data function */
  255. uint16_t usart_data_receive(uint32_t usart_periph);
  256. /* multi-processor communication */
  257. /* configure address of the USART */
  258. void usart_address_config(uint32_t usart_periph, uint8_t addr);
  259. /* enable mute mode */
  260. void usart_mute_mode_enable(uint32_t usart_periph);
  261. /* disable mute mode */
  262. void usart_mute_mode_disable(uint32_t usart_periph);
  263. /* configure wakeup method in mute mode */
  264. void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmethod);
  265. /* LIN mode communication */
  266. /* enable LIN mode */
  267. void usart_lin_mode_enable(uint32_t usart_periph);
  268. /* disable LIN mode */
  269. void usart_lin_mode_disable(uint32_t usart_periph);
  270. /* configure LIN break frame length */
  271. void usart_lin_break_detection_length_config(uint32_t usart_periph, uint32_t lblen);
  272. /* send break frame */
  273. void usart_send_break(uint32_t usart_periph);
  274. /* half-duplex communication */
  275. /* enable half-duplex */
  276. void usart_halfduplex_enable(uint32_t usart_periph);
  277. /* disable half-duplex */
  278. void usart_halfduplex_disable(uint32_t usart_periph);
  279. /* synchronous communication */
  280. /* enable CK pin in synchronous mode */
  281. void usart_synchronous_clock_enable(uint32_t usart_periph);
  282. /* disable CK pin in synchronous mode */
  283. void usart_synchronous_clock_disable(uint32_t usart_periph);
  284. /* configure usart synchronous mode parameters */
  285. void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl);
  286. /* smartcard communication */
  287. /* configure guard time value in smartcard mode */
  288. void usart_guard_time_config(uint32_t usart_periph,uint32_t gaut);
  289. /* enable smartcard mode */
  290. void usart_smartcard_mode_enable(uint32_t usart_periph);
  291. /* disable smartcard mode */
  292. void usart_smartcard_mode_disable(uint32_t usart_periph);
  293. /* enable NACK in smartcard mode */
  294. void usart_smartcard_mode_nack_enable(uint32_t usart_periph);
  295. /* disable NACK in smartcard mode */
  296. void usart_smartcard_mode_nack_disable(uint32_t usart_periph);
  297. /* IrDA communication */
  298. /* enable IrDA mode */
  299. void usart_irda_mode_enable(uint32_t usart_periph);
  300. /* disable IrDA mode */
  301. void usart_irda_mode_disable(uint32_t usart_periph);
  302. /* configure the peripheral clock prescaler */
  303. void usart_prescaler_config(uint32_t usart_periph, uint8_t psc);
  304. /* configure IrDA low-power */
  305. void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp);
  306. /* hardware flow communication */
  307. /* configure hardware flow control RTS */
  308. void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig);
  309. /* configure hardware flow control CTS */
  310. void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig);
  311. /* configure USART DMA for reception */
  312. void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd);
  313. /* configure USART DMA for transmission */
  314. void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd);
  315. /* flag functions */
  316. /* get flag in STAT register */
  317. FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag);
  318. /* clear flag in STAT register */
  319. void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag);
  320. /* interrupt functions */
  321. /* enable USART interrupt */
  322. void usart_interrupt_enable(uint32_t usart_periph, uint32_t interrupt);
  323. /* disable USART interrupt */
  324. void usart_interrupt_disable(uint32_t usart_periph, uint32_t interrupt);
  325. /* get USART interrupt and flag status */
  326. FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag);
  327. /* clear interrupt flag in STAT register */
  328. void usart_interrupt_flag_clear(uint32_t usart_periph, uint32_t int_flag);
  329. #endif /* GD32F10X_USART_H */