apm32f10x_usart.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*!
  2. * @file apm32f10x_usart.h
  3. *
  4. * @brief This file contains all the functions prototypes for the USART firmware library
  5. *
  6. * @version V1.0.4
  7. *
  8. * @date 2022-12-01
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F10X_USART_H
  27. #define __APM32F10X_USART_H
  28. /* Includes */
  29. #include "apm32f10x.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** @addtogroup APM32F10x_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup USART_Driver USART Driver
  37. @{
  38. */
  39. /** @defgroup USART_Enumerations Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief USART Word Length definition
  44. */
  45. typedef enum
  46. {
  47. USART_WORD_LEN_8B = 0,
  48. USART_WORD_LEN_9B = BIT12
  49. } USART_WORD_LEN_T;
  50. /**
  51. * @brief USART Stop bits definition
  52. */
  53. typedef enum
  54. {
  55. USART_STOP_BIT_1 = 0,
  56. USART_STOP_BIT_0_5 = BIT12,
  57. USART_STOP_BIT_2 = BIT13,
  58. USART_STOP_BIT_1_5 = BIT12 | BIT13
  59. } USART_STOP_BIT_T;
  60. /**
  61. * @brief USART Parity definition
  62. */
  63. typedef enum
  64. {
  65. USART_PARITY_NONE = 0,
  66. USART_PARITY_EVEN = BIT10,
  67. USART_PARITY_ODD = BIT10 | BIT9
  68. } USART_PARITY_T;
  69. /**
  70. * @brief USART mode definition
  71. */
  72. typedef enum
  73. {
  74. USART_MODE_RX = BIT2,
  75. USART_MODE_TX = BIT3,
  76. USART_MODE_TX_RX = BIT2 | BIT3
  77. } USART_MODE_T;
  78. /**
  79. * @brief USART hardware flow control definition
  80. */
  81. typedef enum
  82. {
  83. USART_HARDWARE_FLOW_NONE = 0,
  84. USART_HARDWARE_FLOW_RTS = BIT8,
  85. USART_HARDWARE_FLOW_CTS = BIT9,
  86. USART_HARDWARE_FLOW_RTS_CTS = BIT8 | BIT9
  87. } USART_HARDWARE_FLOW_T;
  88. /**
  89. * @brief USART Clock enable
  90. */
  91. typedef enum
  92. {
  93. USART_CLKEN_DISABLE,
  94. USART_CLKEN_ENABLE
  95. } USART_CLKEN_T;
  96. /**
  97. * @brief USART Clock polarity definition
  98. */
  99. typedef enum
  100. {
  101. USART_CLKPOL_LOW,
  102. USART_CLKPOL_HIGH
  103. } USART_CLKPOL_T;
  104. /**
  105. * @brief USART Clock phase definition
  106. */
  107. typedef enum
  108. {
  109. USART_CLKPHA_1EDGE,
  110. USART_CLKPHA_2EDGE
  111. } USART_CLKPHA_T;
  112. /**
  113. * @brief USART Last bit clock pulse definition
  114. */
  115. typedef enum
  116. {
  117. USART_LBCP_DISABLE,
  118. USART_LBCP_ENABLE,
  119. } USART_LBCP_T;
  120. /**
  121. * @brief USART Interrupt Source
  122. */
  123. typedef enum
  124. {
  125. USART_INT_PE = 0x0010100,
  126. USART_INT_TXBE = 0x7010080,
  127. USART_INT_TXC = 0x6010040,
  128. USART_INT_RXBNE = 0x5010020,
  129. USART_INT_IDLE = 0x4010010,
  130. USART_INT_LBD = 0x8020040,
  131. USART_INT_CTS = 0x9040400,
  132. USART_INT_ERR = 0x0040001,
  133. USART_INT_OVRE = 0x3040001,
  134. USART_INT_NE = 0x2040001,
  135. USART_INT_FE = 0x1040001
  136. } USART_INT_T;
  137. /**
  138. * @brief USART DMA enable
  139. */
  140. typedef enum
  141. {
  142. USART_DMA_TX = BIT7,
  143. USART_DMA_RX = BIT6,
  144. USART_DMA_TX_RX = BIT6 | BIT7
  145. } USART_DMA_T;
  146. /**
  147. * @brief USART Wakeup method
  148. */
  149. typedef enum
  150. {
  151. USART_WAKEUP_IDLE_LINE,
  152. USART_WAKEUP_ADDRESS_MARK
  153. } USART_WAKEUP_T;
  154. /**
  155. * @brief USART LIN break detection length
  156. */
  157. typedef enum
  158. {
  159. USART_LBDL_10B,
  160. USART_LBDL_11B
  161. } USART_LBDL_T;
  162. /**
  163. * @brief USART IrDA low-power
  164. */
  165. typedef enum
  166. {
  167. USART_IRDALP_NORMAL,
  168. USART_IRDALP_LOWPOWER
  169. } USART_IRDALP_T;
  170. /**
  171. * @brief USART flag definition
  172. */
  173. typedef enum
  174. {
  175. USART_FLAG_CTS = 0x0200,
  176. USART_FLAG_LBD = 0x0100,
  177. USART_FLAG_TXBE = 0x0080,
  178. USART_FLAG_TXC = 0x0040,
  179. USART_FLAG_RXBNE = 0x0020,
  180. USART_FLAG_IDLE = 0x0010,
  181. USART_FLAG_OVRE = 0x0008,
  182. USART_FLAG_NE = 0x0004,
  183. USART_FLAG_FE = 0x0002,
  184. USART_FLAG_PE = 0x0001
  185. } USART_FLAG_T;
  186. /**@} end of group USART_Enumerations */
  187. /** @defgroup USART_Structures Structures
  188. @{
  189. */
  190. /**
  191. * @brief USART Configure structure definition
  192. */
  193. typedef struct
  194. {
  195. uint32_t baudRate; /*!< Specifies the baud rate */
  196. USART_WORD_LEN_T wordLength; /*!< Specifies the word length */
  197. USART_STOP_BIT_T stopBits; /*!< Specifies the stop bits */
  198. USART_PARITY_T parity; /*!< Specifies the parity */
  199. USART_MODE_T mode; /*!< Specifies the mode */
  200. USART_HARDWARE_FLOW_T hardwareFlow; /*!< Specifies the hardware flow control */
  201. } USART_Config_T;
  202. /**
  203. * @brief USART synchronous communication clock configure structure definition
  204. */
  205. typedef struct
  206. {
  207. USART_CLKEN_T clock; /*!< Enable or Disable Clock */
  208. USART_CLKPOL_T polarity; /*!< Specifies the clock polarity */
  209. USART_CLKPHA_T phase; /*!< Specifies the clock phase */
  210. USART_LBCP_T lastBit; /*!< Enable or Disable last bit clock */
  211. } USART_ClockConfig_T;
  212. /**@} end of group USART_Structures */
  213. /** @defgroup USART_Functions Functions
  214. @{
  215. */
  216. /* USART Reset and Configuration */
  217. void USART_Reset(USART_T* usart);
  218. void USART_Config(USART_T* uart, USART_Config_T* usartConfig);
  219. void USART_ConfigStructInit(USART_Config_T* usartConfig);
  220. void USART_Address(USART_T* usart, uint8_t address);
  221. void USART_Enable(USART_T* usart);
  222. void USART_Disable(USART_T* usart);
  223. /* Clock communication */
  224. void USART_ConfigClock(USART_T* usart, USART_ClockConfig_T* clockConfig);
  225. void USART_ConfigClockStructInit(USART_ClockConfig_T* clockConfig);
  226. /* DMA mode */
  227. void USART_EnableDMA(USART_T* usart, USART_DMA_T dmaReq);
  228. void USART_DisableDMA(USART_T* usart, USART_DMA_T dmaReq);
  229. /* Mute mode */
  230. void USART_ConfigWakeUp(USART_T* usart, USART_WAKEUP_T wakeup);
  231. void USART_EnableMuteMode(USART_T* usart);
  232. void USART_DisableMuteMode(USART_T* usart);
  233. /* LIN mode */
  234. void USART_ConfigLINBreakDetectLength(USART_T* usart, USART_LBDL_T length);
  235. void USART_EnableLIN(USART_T* usart);
  236. void USART_DisableLIN(USART_T* usart);
  237. /* Transmit and receive */
  238. void USART_EnableTx(USART_T* usart);
  239. void USART_DisableTx(USART_T* usart);
  240. void USART_EnableRx(USART_T* usart);
  241. void USART_DisableRx(USART_T* usart);
  242. void USART_TxData(USART_T* usart, uint16_t data);
  243. uint16_t USART_RxData(USART_T* usart);
  244. void USART_TxBreak(USART_T* usart);
  245. /* Smartcard mode */
  246. void USART_ConfigGuardTime(USART_T* usart, uint8_t guardTime);
  247. void USART_ConfigPrescaler(USART_T* usart, uint8_t div);
  248. void USART_EnableSmartCard(USART_T* usart);
  249. void USART_DisableSmartCard(USART_T* usart);
  250. void USART_EnableSmartCardNACK(USART_T* usart);
  251. void USART_DisableSmartCardNACK(USART_T* usart);
  252. /* Half-duplex mode */
  253. void USART_EnableHalfDuplex(USART_T* usart);
  254. void USART_DisableHalfDuplex(USART_T* usart);
  255. /* IrDA mode */
  256. void USART_ConfigIrDA(USART_T* usart, USART_IRDALP_T IrDAMode);
  257. void USART_EnableIrDA(USART_T* usart);
  258. void USART_DisableIrDA(USART_T* usart);
  259. /* Interrupt and flag */
  260. void USART_EnableInterrupt(USART_T* usart, USART_INT_T interrupt);
  261. void USART_DisableInterrupt(USART_T* usart, USART_INT_T interrupt);
  262. uint8_t USART_ReadStatusFlag(USART_T* usart, USART_FLAG_T flag);
  263. void USART_ClearStatusFlag(USART_T* usart, USART_FLAG_T flag);
  264. uint8_t USART_ReadIntFlag(USART_T* usart, USART_INT_T flag);
  265. void USART_ClearIntFlag(USART_T* usart, USART_INT_T flag);
  266. /**@} end of group USART_Functions */
  267. /**@} end of group USART_Driver */
  268. /**@} end of group APM32F10x_StdPeriphDriver */
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif /* __APM32F10X_USART_H */