apm32f10x_usart.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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.2
  7. *
  8. * @date 2022-01-05
  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 usefull 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. #ifndef __APM32F10X_USART_H
  26. #define __APM32F10X_USART_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #include "apm32f10x.h"
  31. /** @addtogroup Peripherals_Library Standard Peripheral Library
  32. @{
  33. */
  34. /** @addtogroup USART_Driver USART Driver
  35. @{
  36. */
  37. /** @addtogroup USART_Enumerations Enumerations
  38. @{
  39. */
  40. /**
  41. * @brief USART Word Length define
  42. */
  43. typedef enum
  44. {
  45. USART_WORD_LEN_8B = 0,
  46. USART_WORD_LEN_9B = BIT12
  47. } USART_WORD_LEN_T;
  48. /**
  49. * @brief USART Stop bits define
  50. */
  51. typedef enum
  52. {
  53. USART_STOP_BIT_1 = 0,
  54. USART_STOP_BIT_0_5 = BIT12,
  55. USART_STOP_BIT_2 = BIT13,
  56. USART_STOP_BIT_1_5 = BIT12 | BIT13
  57. } USART_STOP_BIT_T;
  58. /**
  59. * @brief USART Parity define
  60. */
  61. typedef enum
  62. {
  63. USART_PARITY_NONE = 0,
  64. USART_PARITY_EVEN = BIT10,
  65. USART_PARITY_ODD = BIT10 | BIT9
  66. } USART_PARITY_T;
  67. /**
  68. * @brief USART mode define
  69. */
  70. typedef enum
  71. {
  72. USART_MODE_RX = BIT2,
  73. USART_MODE_TX = BIT3,
  74. USART_MODE_TX_RX = BIT2 | BIT3
  75. } USART_MODE_T;
  76. /**
  77. * @brief USART hardware flow control define
  78. */
  79. typedef enum
  80. {
  81. USART_HARDWARE_FLOW_NONE = 0,
  82. USART_HARDWARE_FLOW_RTS = BIT8,
  83. USART_HARDWARE_FLOW_CTS = BIT9,
  84. USART_HARDWARE_FLOW_RTS_CTS = BIT8 | BIT9
  85. } USART_HARDWARE_FLOW_T;
  86. /**
  87. * @brief USART Clock enable
  88. */
  89. typedef enum
  90. {
  91. USART_CLKEN_DISABLE,
  92. USART_CLKEN_ENABLE
  93. } USART_CLKEN_T;
  94. /**
  95. * @brief USART Clock polarity define
  96. */
  97. typedef enum
  98. {
  99. USART_CLKPOL_LOW,
  100. USART_CLKPOL_HIGH
  101. } USART_CLKPOL_T;
  102. /**
  103. * @brief USART Clock phase define
  104. */
  105. typedef enum
  106. {
  107. USART_CLKPHA_1EDGE,
  108. USART_CLKPHA_2EDGE
  109. } USART_CLKPHA_T;
  110. /**
  111. * @brief USART Last bit clock pulse enable
  112. */
  113. typedef enum
  114. {
  115. USART_LBCP_DISABLE,
  116. USART_LBCP_ENABLE,
  117. } USART_LBCP_T;
  118. /**
  119. * @brief USART Interrupt Source
  120. */
  121. typedef enum
  122. {
  123. USART_INT_PE = 0x0010100,
  124. USART_INT_TXBE = 0x7010080,
  125. USART_INT_TXC = 0x6010040,
  126. USART_INT_RXBNE = 0x5010020,
  127. USART_INT_IDLE = 0x4010010,
  128. USART_INT_LBD = 0x8020040,
  129. USART_INT_CTS = 0x9040400,
  130. USART_INT_ERR = 0x0040001,
  131. USART_INT_OVRE = 0x3040001,
  132. USART_INT_NE = 0x2040001,
  133. USART_INT_FE = 0x1040001
  134. } USART_INT_T;
  135. /**
  136. * @brief USART DMA enable
  137. */
  138. typedef enum
  139. {
  140. USART_DMA_TX = BIT7,
  141. USART_DMA_RX = BIT6,
  142. USART_DMA_TX_RX = BIT6 | BIT7
  143. } USART_DMA_T;
  144. /**
  145. * @brief USART Wakeup method
  146. */
  147. typedef enum
  148. {
  149. USART_WAKEUP_IDLE_LINE,
  150. USART_WAKEUP_ADDRESS_MARK
  151. } USART_WAKEUP_T;
  152. /**
  153. * @brief USART LIN break detection length
  154. */
  155. typedef enum
  156. {
  157. USART_LBDL_10B,
  158. USART_LBDL_11B
  159. } USART_LBDL_T;
  160. /**
  161. * @brief USART IrDA low-power
  162. */
  163. typedef enum
  164. {
  165. USART_IRDALP_NORMAL,
  166. USART_IRDALP_LOWPOWER
  167. } USART_IRDALP_T;
  168. /**
  169. * @brief USART flag define
  170. */
  171. typedef enum
  172. {
  173. USART_FLAG_CTS = 0x0200,
  174. USART_FLAG_LBD = 0x0100,
  175. USART_FLAG_TXBE = 0x0080,
  176. USART_FLAG_TXC = 0x0040,
  177. USART_FLAG_RXBNE = 0x0020,
  178. USART_FLAG_IDLE = 0x0010,
  179. USART_FLAG_OVRE = 0x0008,
  180. USART_FLAG_NE = 0x0004,
  181. USART_FLAG_FE = 0x0002,
  182. USART_FLAG_PE = 0x0001
  183. } USART_FLAG_T;
  184. /**@} end of group USART_Enumerations*/
  185. /** @addtogroup USART_Structure Data Structure
  186. @{
  187. */
  188. /**
  189. * @brief USART Config struct definition
  190. */
  191. typedef struct
  192. {
  193. uint32_t baudRate; //!< Specifies the baud rate
  194. USART_WORD_LEN_T wordLength; //!< Specifies the word length
  195. USART_STOP_BIT_T stopBits; //!< Specifies the stop bits
  196. USART_PARITY_T parity; //!< Specifies the parity
  197. USART_MODE_T mode; //!< Specifies the mode
  198. USART_HARDWARE_FLOW_T hardwareFlow; //!< Specifies the hardware flow control
  199. } USART_Config_T;
  200. /**
  201. * @brief USART synchronous communication clock config struct definition
  202. */
  203. typedef struct
  204. {
  205. USART_CLKEN_T clock; //!< Enable or Disable Clock
  206. USART_CLKPOL_T polarity; //!< Specifies the clock polarity
  207. USART_CLKPHA_T phase; //!< Specifies the clock phase
  208. USART_LBCP_T lastBit; //!< Enable or Disable last bit clock
  209. } USART_ClockConfig_T;
  210. /**@} end of group USART_Structure*/
  211. /** @addtogroup USART_Fuctions Fuctions
  212. @{
  213. */
  214. /** USART Reset and Configuration */
  215. void USART_Reset(USART_T* usart);
  216. void USART_Config(USART_T* uart, USART_Config_T* usartConfig);
  217. void USART_ConfigStructInit(USART_Config_T* usartConfig);
  218. void USART_Address(USART_T* usart, uint8_t address);
  219. void USART_Enable(USART_T* usart);
  220. void USART_Disable(USART_T* usart);
  221. /** Clock communication */
  222. void USART_ConfigClock(USART_T* usart, USART_ClockConfig_T* clockConfig);
  223. void USART_ConfigClockStructInit(USART_ClockConfig_T* clockConfig);
  224. /** DMA mode */
  225. void USART_EnableDMA(USART_T* usart, USART_DMA_T dmaReq);
  226. void USART_DisableDMA(USART_T* usart, USART_DMA_T dmaReq);
  227. /** Mute mode */
  228. void USART_ConfigWakeUp(USART_T* usart, USART_WAKEUP_T wakeup);
  229. void USART_EnableMuteMode(USART_T* usart);
  230. void USART_DisableMuteMode(USART_T* usart);
  231. /** LIN mode */
  232. void USART_ConfigLINBreakDetectLength(USART_T* usart, USART_LBDL_T length);
  233. void USART_EnableLIN(USART_T* usart);
  234. void USART_DisableLIN(USART_T* usart);
  235. /** Transmit and receive */
  236. void USART_EnableTx(USART_T* usart);
  237. void USART_DisableTx(USART_T* usart);
  238. void USART_EnableRx(USART_T* usart);
  239. void USART_DisableRx(USART_T* usart);
  240. void USART_TxData(USART_T* usart, uint16_t data);
  241. uint16_t USART_RxData(USART_T* usart);
  242. void USART_TxBreak(USART_T* usart);
  243. /** Smartcard mode */
  244. void USART_ConfigGuardTime(USART_T* usart, uint8_t guardTime);
  245. void USART_ConfigPrescaler(USART_T* usart, uint8_t div);
  246. void USART_EnableSmartCard(USART_T* usart);
  247. void USART_DisableSmartCard(USART_T* usart);
  248. void USART_EnableSmartCardNACK(USART_T* usart);
  249. void USART_DisableSmartCardNACK(USART_T* usart);
  250. /** Half-duplex mode */
  251. void USART_EnableHalfDuplex(USART_T* usart);
  252. void USART_DisableHalfDuplex(USART_T* usart);
  253. /** IrDA mode */
  254. void USART_ConfigIrDA(USART_T* usart, USART_IRDALP_T IrDAMode);
  255. void USART_EnableIrDA(USART_T* usart);
  256. void USART_DisableIrDA(USART_T* usart);
  257. /** Interrupt and flag */
  258. void USART_EnableInterrupt(USART_T* usart, USART_INT_T interrupt);
  259. void USART_DisableInterrupt(USART_T* usart, USART_INT_T interrupt);
  260. uint8_t USART_ReadStatusFlag(USART_T* usart, USART_FLAG_T flag);
  261. void USART_ClearStatusFlag(USART_T* usart, USART_FLAG_T flag);
  262. uint8_t USART_ReadIntFlag(USART_T* usart, USART_INT_T flag);
  263. void USART_ClearIntFlag(USART_T* usart, USART_INT_T flag);
  264. /**@} end of group USART_Fuctions*/
  265. /**@} end of group USART_Driver*/
  266. /**@} end of group Peripherals_Library*/
  267. #ifdef __cplusplus
  268. }
  269. #endif
  270. #endif /* __APM32F10X_USART_H */