gd32f10x_usart.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /**
  2. ******************************************************************************
  3. * @brief USART header file of the firmware library.
  4. ******************************************************************************
  5. */
  6. /* Define to prevent recursive inclusion -------------------------------------*/
  7. #ifndef __GD32F10X_USART_H
  8. #define __GD32F10X_USART_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /* Includes ------------------------------------------------------------------*/
  13. #include "gd32f10x.h"
  14. /** @addtogroup GD32F10x_Firmware
  15. * @{
  16. */
  17. /** @addtogroup USART
  18. * @{
  19. */
  20. /** @defgroup USART_Exported_Types
  21. * @{
  22. */
  23. /**
  24. * @brief USART Initial Parameters
  25. */
  26. typedef struct {
  27. uint32_t USART_BRR; /*!< the USART communication baud rate configuration */
  28. uint16_t USART_WL; /*!< Set by USART_CTLR1_WL Word length 0: 8 Data bits,
  29. 1: 9 Data bits */
  30. uint16_t USART_STBits; /*!< Stop bits configuration */
  31. uint16_t USART_Parity; /*!< Set by USART_CTLR1_PCEN */
  32. uint16_t USART_RxorTx; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled. */
  33. uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
  34. or disabled.This parameter can be a value of @ref USART_Hardware_Flow_Control */
  35. } USART_InitPara;
  36. /**
  37. * @brief USART Clock Init Structure definition
  38. */
  39. typedef struct {
  40. uint16_t USART_CKEN; /*!< USART clock enabled this parameter can be a value of @ref USART_CKEN */
  41. uint16_t USART_CPL; /*!< Clock polarity of Steady state this parameter can be a value of @ref USART_Clock_Polarity */
  42. uint16_t USART_CPH; /*!< Clock phase this parameter can be a value of @ref USART_Clock_Phase */
  43. uint16_t USART_LBCP; /*!< Last bit clock pulse this parameter can be a value of @ref USART_Last_Bit */
  44. } USART_ClockInitPara;
  45. /**
  46. * @}
  47. */
  48. /** @defgroup USART_Exported_Constants
  49. * @{
  50. */
  51. /** @defgroup USART_WL
  52. * @{
  53. */
  54. #define USART_WL_8B ((uint16_t)0x0000)
  55. #define USART_WL_9B USART_CTLR1_WL
  56. /**
  57. * @}
  58. */
  59. /** @defgroup USART_STBits
  60. * @{
  61. */
  62. #define USART_STBITS_1 ((uint16_t)0x0000)
  63. #define USART_STBITS_0_5 ((uint16_t)0x1000)
  64. #define USART_STBITS_2 USART_CTLR2_STB_1
  65. #define USART_STBITS_1_5 (USART_CTLR2_STB_0 | USART_CTLR2_STB_1)
  66. /**
  67. * @}
  68. */
  69. /** @defgroup USART_Parity
  70. * @{
  71. */
  72. #define USART_PARITY_RESET ((uint16_t)0x0000)
  73. #define USART_PARITY_SETEVEN USART_CTLR1_PCEN
  74. #define USART_PARITY_SETODD (USART_CTLR1_PCEN | USART_CTLR1_PM)
  75. /**
  76. * @}
  77. */
  78. /** @defgroup USART_RxorTx
  79. * @{
  80. */
  81. #define USART_RXORTX_RX USART_CTLR1_REN
  82. #define USART_RXORTX_TX USART_CTLR1_TEN
  83. /**
  84. * @}
  85. */
  86. /** @defgroup USART_Hardware_Flow_Control
  87. * @{
  88. */
  89. #define USART_HARDWAREFLOWCONTROL_NONE ((uint16_t)0x0000)
  90. #define USART_HARDWAREFLOWCONTROL_RTS USART_CTLR3_RTSEN
  91. #define USART_HARDWAREFLOWCONTROL_CTS USART_CTLR3_CTSEN
  92. #define USART_HARDWAREFLOWCONTROL_RTS_CTS (USART_CTLR3_RTSEN | USART_CTLR3_CTSEN)
  93. /**
  94. * @}
  95. */
  96. /** @defgroup USART_CKEN
  97. * @{
  98. */
  99. #define USART_CKEN_RESET ((uint16_t)0x0000)
  100. #define USART_CKEN_SET USART_CTLR2_CKEN
  101. /**
  102. * @}
  103. */
  104. /** @defgroup USART_Clock_Polarity
  105. * @{
  106. */
  107. #define USART_CPL_LOW ((uint16_t)0x0000)
  108. #define USART_CPL_HIGH USART_CTLR2_CPL
  109. /**
  110. * @}
  111. */
  112. /** @defgroup USART_Clock_Phase
  113. * @{
  114. */
  115. #define USART_CPH_1EDGE ((uint16_t)0x0000)
  116. #define USART_CPH_2EDGE USART_CTLR2_CPH
  117. /**
  118. * @}
  119. */
  120. /** @defgroup USART_Last_Bit
  121. * @{
  122. */
  123. #define USART_LBCP_DISABLE ((uint16_t)0x0000)
  124. #define USART_LBCP_ENABLE USART_CTLR2_LBCP
  125. /**
  126. * @}
  127. */
  128. /** @defgroup USART_DMA_Requests
  129. * @{
  130. */
  131. #define USART_DMAREQ_TX USART_CTLR3_DENT
  132. #define USART_DMAREQ_RX USART_CTLR3_DENR
  133. /**
  134. * @}
  135. */
  136. /** @defgroup USART_Interrupt_definition
  137. * @brief USART Interrupt definition
  138. * USART_INT possible values
  139. * @{
  140. */
  141. #define USART_INT_PE ((uint16_t)0x0028)
  142. #define USART_INT_TBE ((uint16_t)0x0727)
  143. #define USART_INT_TC ((uint16_t)0x0626)
  144. #define USART_INT_RBNE ((uint16_t)0x0525)
  145. #define USART_INT_IDLEF ((uint16_t)0x0424)
  146. #define USART_INT_LBDF ((uint16_t)0x0846)
  147. #define USART_INT_CTSF ((uint16_t)0x096A)
  148. #define USART_INT_ERIE ((uint16_t)0x0060)
  149. #define USART_INT_ORE ((uint16_t)0x0360)
  150. #define USART_INT_NE ((uint16_t)0x0260)
  151. #define USART_INT_FE ((uint16_t)0x0160)
  152. /**
  153. * @}
  154. */
  155. /** @defgroup USART_MuteMode_WakeUp_methods
  156. * @{
  157. */
  158. #define USART_WAKEUP_IDLELINE ((uint16_t)0x0000)
  159. #define USART_WAKEUP_ADDRESSMARK USART_CTLR1_WM
  160. /**
  161. * @}
  162. */
  163. /** @defgroup USART_LIN_Break_Detection_Length
  164. * @{
  165. */
  166. #define USART_LINBREAKDETECTLENGTH_10B ((uint16_t)0x0000)
  167. #define USART_LINBREAKDETECTLENGTH_11B USART_CTLR2_LBDL
  168. /**
  169. * @}
  170. */
  171. /** @defgroup USART_IrDA_Low_Power
  172. * @{
  173. */
  174. #define USART_IRDAMODE_LOWPOWER USART_CTLR3_IRLP
  175. #define USART_IRDAMODE_NORMAL ((uint16_t)0x0000)
  176. /**
  177. * @}
  178. */
  179. /** @defgroup USART_Flags
  180. * @{
  181. */
  182. #define USART_FLAG_CTSF ((uint16_t)0x0200)
  183. #define USART_FLAG_LBDF ((uint16_t)0x0100)
  184. #define USART_FLAG_TBE ((uint16_t)0x0080)
  185. #define USART_FLAG_TC ((uint16_t)0x0040)
  186. #define USART_FLAG_RBNE ((uint16_t)0x0020)
  187. #define USART_FLAG_IDLEF ((uint16_t)0x0010)
  188. #define USART_FLAG_ORE ((uint16_t)0x0008)
  189. #define USART_FLAG_NE ((uint16_t)0x0004)
  190. #define USART_FLAG_FE ((uint16_t)0x0002)
  191. #define USART_FLAG_PE ((uint16_t)0x0001)
  192. /**
  193. * @}
  194. */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup USART_Exported_Functions
  199. * @{
  200. */
  201. void USART_DeInit(USART_TypeDef *USARTx);
  202. void USART_Init(USART_TypeDef *USARTx, USART_InitPara *USART_InitParaStruct);
  203. void USART_ParaInit(USART_InitPara *USART_InitParaStruct);
  204. void USART_ClockInit(USART_TypeDef *USARTx, USART_ClockInitPara *USART_ClockInitStruct);
  205. void USART_ClockStructInit(USART_ClockInitPara *USART_ClockInitParaStruct);
  206. void USART_Enable(USART_TypeDef *USARTx, TypeState NewValue);
  207. void USART_HalfDuplex_Enable(USART_TypeDef *USARTx, TypeState NewValue);
  208. void USART_SetPrescaler(USART_TypeDef *USARTx, uint8_t USART_Prescaler);
  209. void USART_DataSend(USART_TypeDef *USARTx, uint16_t Data);
  210. uint16_t USART_DataReceive(USART_TypeDef *USARTx);
  211. void USART_Address(USART_TypeDef *USARTx, uint8_t USART_Address);
  212. void USART_MuteMode_Enable(USART_TypeDef *USARTx, TypeState NewState);
  213. void USART_MuteModeWakeUp_Set(USART_TypeDef *USARTx, uint16_t USART_WakeUp);
  214. void USART_SetLINBDLength(USART_TypeDef *USARTx, uint16_t USART_LINBreakDetectLength);
  215. void USART_LIN_Enable(USART_TypeDef *USARTx, TypeState NewValue);
  216. void USART_GuardTime_Set(USART_TypeDef *USARTx, uint8_t USART_GuardTime);
  217. void USART_SmartCard_Enable(USART_TypeDef *USARTx, TypeState NewValue);
  218. void USART_SmartCardNACK_Enable(USART_TypeDef *USARTx, TypeState NewValue);
  219. void USART_IrDA_Set(USART_TypeDef *USARTx, uint16_t USART_IrDAMode);
  220. void USART_IrDA_Enable(USART_TypeDef *USARTx, TypeState NewValue);
  221. void USART_DMA_Enable(USART_TypeDef *USARTx, uint16_t USART_DMAEnable, TypeState NewValue);
  222. void USART_INT_Set(USART_TypeDef *USARTx, uint16_t USART_INT, TypeState NewValue);
  223. TypeState USART_GetBitState(USART_TypeDef *USARTx, uint16_t USART_FLAG);
  224. void USART_ClearBitState(USART_TypeDef *USARTx, uint16_t USART_FLAG);
  225. TypeState USART_GetIntBitState(USART_TypeDef *USARTx, uint16_t USART_INT);
  226. void USART_ClearIntBitState(USART_TypeDef *USARTx, uint16_t USART_INT);
  227. void USART_SendBreak(USART_TypeDef *USARTx);
  228. #ifdef __cplusplus
  229. }
  230. #endif
  231. #endif /*__GD32F10X_USART_H */
  232. /**
  233. * @}
  234. */
  235. /**
  236. * @}
  237. */
  238. /**
  239. * @}
  240. */