1 /* Define to prevent recursive inclusion -------------------------------------*/ 2 #ifndef __AIR32F10x_USART_H 3 #define __AIR32F10x_USART_H 4 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 /* Includes ------------------------------------------------------------------*/ 10 #include "air32f10x.h" 11 12 /** @addtogroup air32f10x_StdPeriph_Driver 13 * @{ 14 */ 15 16 /** @addtogroup USART 17 * @{ 18 */ 19 20 /** @defgroup USART_Exported_Types 21 * @{ 22 */ 23 24 /** 25 * @brief USART Init Structure definition 26 */ 27 28 typedef struct 29 { 30 uint32_t USART_BaudRate; /*!< This member configures the USART communication baud rate. 31 The baud rate is computed using the following formula: 32 - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate))) 33 - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5 */ 34 35 uint16_t USART_WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. 36 This parameter can be a value of @ref USART_Word_Length */ 37 38 uint16_t USART_StopBits; /*!< Specifies the number of stop bits transmitted. 39 This parameter can be a value of @ref USART_Stop_Bits */ 40 41 uint16_t USART_Parity; /*!< Specifies the parity mode. 42 This parameter can be a value of @ref USART_Parity 43 @note When parity is enabled, the computed parity is inserted 44 at the MSB position of the transmitted data (9th bit when 45 the word length is set to 9 data bits; 8th bit when the 46 word length is set to 8 data bits). */ 47 48 uint16_t USART_Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled. 49 This parameter can be a value of @ref USART_Mode */ 50 51 uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled 52 or disabled. 53 This parameter can be a value of @ref USART_Hardware_Flow_Control */ 54 } USART_InitTypeDef; 55 56 /** 57 * @brief USART Clock Init Structure definition 58 */ 59 60 typedef struct 61 { 62 63 uint16_t USART_Clock; /*!< Specifies whether the USART clock is enabled or disabled. 64 This parameter can be a value of @ref USART_Clock */ 65 66 uint16_t USART_CPOL; /*!< Specifies the steady state value of the serial clock. 67 This parameter can be a value of @ref USART_Clock_Polarity */ 68 69 uint16_t USART_CPHA; /*!< Specifies the clock transition on which the bit capture is made. 70 This parameter can be a value of @ref USART_Clock_Phase */ 71 72 uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted 73 data bit (MSB) has to be output on the SCLK pin in synchronous mode. 74 This parameter can be a value of @ref USART_Last_Bit */ 75 } USART_ClockInitTypeDef; 76 77 /** 78 * @} 79 */ 80 81 /** @defgroup USART_Exported_Constants 82 * @{ 83 */ 84 85 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 86 ((PERIPH) == USART2) || \ 87 ((PERIPH) == USART3) || \ 88 ((PERIPH) == UART4) || \ 89 ((PERIPH) == UART5)) 90 91 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 92 ((PERIPH) == USART2) || \ 93 ((PERIPH) == USART3)) 94 95 #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 96 ((PERIPH) == USART2) || \ 97 ((PERIPH) == USART3) || \ 98 ((PERIPH) == UART4)) 99 /** @defgroup USART_Word_Length 100 * @{ 101 */ 102 103 #define USART_WordLength_8b ((uint16_t)0x0000) 104 #define USART_WordLength_9b ((uint16_t)0x1000) 105 106 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \ 107 ((LENGTH) == USART_WordLength_9b)) 108 /** 109 * @} 110 */ 111 112 /** @defgroup USART_Stop_Bits 113 * @{ 114 */ 115 116 #define USART_StopBits_1 ((uint16_t)0x0000) 117 #define USART_StopBits_0_5 ((uint16_t)0x1000) 118 #define USART_StopBits_2 ((uint16_t)0x2000) 119 #define USART_StopBits_1_5 ((uint16_t)0x3000) 120 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \ 121 ((STOPBITS) == USART_StopBits_0_5) || \ 122 ((STOPBITS) == USART_StopBits_2) || \ 123 ((STOPBITS) == USART_StopBits_1_5)) 124 /** 125 * @} 126 */ 127 128 /** @defgroup USART_Parity 129 * @{ 130 */ 131 132 #define USART_Parity_No ((uint16_t)0x0000) 133 #define USART_Parity_Even ((uint16_t)0x0400) 134 #define USART_Parity_Odd ((uint16_t)0x0600) 135 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \ 136 ((PARITY) == USART_Parity_Even) || \ 137 ((PARITY) == USART_Parity_Odd)) 138 /** 139 * @} 140 */ 141 142 /** @defgroup USART_Mode 143 * @{ 144 */ 145 146 #define USART_Mode_Rx ((uint16_t)0x0004) 147 #define USART_Mode_Tx ((uint16_t)0x0008) 148 #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00)) 149 /** 150 * @} 151 */ 152 153 /** @defgroup USART_Hardware_Flow_Control 154 * @{ 155 */ 156 #define USART_HardwareFlowControl_None ((uint16_t)0x0000) 157 #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100) 158 #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200) 159 #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300) 160 #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\ 161 (((CONTROL) == USART_HardwareFlowControl_None) || \ 162 ((CONTROL) == USART_HardwareFlowControl_RTS) || \ 163 ((CONTROL) == USART_HardwareFlowControl_CTS) || \ 164 ((CONTROL) == USART_HardwareFlowControl_RTS_CTS)) 165 /** 166 * @} 167 */ 168 169 /** @defgroup USART_Clock 170 * @{ 171 */ 172 #define USART_Clock_Disable ((uint16_t)0x0000) 173 #define USART_Clock_Enable ((uint16_t)0x0800) 174 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \ 175 ((CLOCK) == USART_Clock_Enable)) 176 /** 177 * @} 178 */ 179 180 /** @defgroup USART_Clock_Polarity 181 * @{ 182 */ 183 184 #define USART_CPOL_Low ((uint16_t)0x0000) 185 #define USART_CPOL_High ((uint16_t)0x0400) 186 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High)) 187 188 /** 189 * @} 190 */ 191 192 /** @defgroup USART_Clock_Phase 193 * @{ 194 */ 195 196 #define USART_CPHA_1Edge ((uint16_t)0x0000) 197 #define USART_CPHA_2Edge ((uint16_t)0x0200) 198 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge)) 199 200 /** 201 * @} 202 */ 203 204 /** @defgroup USART_Last_Bit 205 * @{ 206 */ 207 208 #define USART_LastBit_Disable ((uint16_t)0x0000) 209 #define USART_LastBit_Enable ((uint16_t)0x0100) 210 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \ 211 ((LASTBIT) == USART_LastBit_Enable)) 212 /** 213 * @} 214 */ 215 216 /** @defgroup USART_Interrupt_definition 217 * @{ 218 */ 219 220 #define USART_IT_PE ((uint16_t)0x0028) 221 #define USART_IT_TXE ((uint16_t)0x0727) 222 #define USART_IT_TC ((uint16_t)0x0626) 223 #define USART_IT_RXNE ((uint16_t)0x0525) 224 #define USART_IT_IDLE ((uint16_t)0x0424) 225 #define USART_IT_LBD ((uint16_t)0x0846) 226 #define USART_IT_CTS ((uint16_t)0x096A) 227 #define USART_IT_ERR ((uint16_t)0x0060) 228 #define USART_IT_ORE ((uint16_t)0x0360) 229 #define USART_IT_NE ((uint16_t)0x0260) 230 #define USART_IT_FE ((uint16_t)0x0160) 231 #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 232 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 233 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 234 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR)) 235 #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 236 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 237 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 238 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \ 239 ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE)) 240 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 241 ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS)) 242 /** 243 * @} 244 */ 245 246 /** @defgroup USART_DMA_Requests 247 * @{ 248 */ 249 250 #define USART_DMAReq_Tx ((uint16_t)0x0080) 251 #define USART_DMAReq_Rx ((uint16_t)0x0040) 252 #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00)) 253 254 /** 255 * @} 256 */ 257 258 /** @defgroup USART_WakeUp_methods 259 * @{ 260 */ 261 262 #define USART_WakeUp_IdleLine ((uint16_t)0x0000) 263 #define USART_WakeUp_AddressMark ((uint16_t)0x0800) 264 #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \ 265 ((WAKEUP) == USART_WakeUp_AddressMark)) 266 /** 267 * @} 268 */ 269 270 /** @defgroup USART_LIN_Break_Detection_Length 271 * @{ 272 */ 273 274 #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000) 275 #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020) 276 #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \ 277 (((LENGTH) == USART_LINBreakDetectLength_10b) || \ 278 ((LENGTH) == USART_LINBreakDetectLength_11b)) 279 /** 280 * @} 281 */ 282 283 /** @defgroup USART_IrDA_Low_Power 284 * @{ 285 */ 286 287 #define USART_IrDAMode_LowPower ((uint16_t)0x0004) 288 #define USART_IrDAMode_Normal ((uint16_t)0x0000) 289 #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \ 290 ((MODE) == USART_IrDAMode_Normal)) 291 /** 292 * @} 293 */ 294 295 /** @defgroup USART_Flags 296 * @{ 297 */ 298 299 #define USART_FLAG_CTS ((uint16_t)0x0200) 300 #define USART_FLAG_LBD ((uint16_t)0x0100) 301 #define USART_FLAG_TXE ((uint16_t)0x0080) 302 #define USART_FLAG_TC ((uint16_t)0x0040) 303 #define USART_FLAG_RXNE ((uint16_t)0x0020) 304 #define USART_FLAG_IDLE ((uint16_t)0x0010) 305 #define USART_FLAG_ORE ((uint16_t)0x0008) 306 #define USART_FLAG_NE ((uint16_t)0x0004) 307 #define USART_FLAG_FE ((uint16_t)0x0002) 308 #define USART_FLAG_PE ((uint16_t)0x0001) 309 #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \ 310 ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \ 311 ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \ 312 ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \ 313 ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE)) 314 315 #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00)) 316 #define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) &&\ 317 ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \ 318 || ((USART_FLAG) != USART_FLAG_CTS)) 319 #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0044AA21)) 320 #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF) 321 #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF) 322 323 /** 324 * @} 325 */ 326 327 /** 328 * @} 329 */ 330 331 /** @defgroup USART_Exported_Macros 332 * @{ 333 */ 334 335 /** 336 * @} 337 */ 338 339 /** @defgroup USART_Exported_Functions 340 * @{ 341 */ 342 343 void USART_DeInit(USART_TypeDef* USARTx); 344 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct); 345 void USART_StructInit(USART_InitTypeDef* USART_InitStruct); 346 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct); 347 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct); 348 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState); 349 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState); 350 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState); 351 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address); 352 void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp); 353 void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState); 354 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength); 355 void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState); 356 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data); 357 uint16_t USART_ReceiveData(USART_TypeDef* USARTx); 358 void USART_SendBreak(USART_TypeDef* USARTx); 359 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime); 360 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler); 361 void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState); 362 void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState); 363 void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState); 364 void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState); 365 void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState); 366 void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode); 367 void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState); 368 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG); 369 void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG); 370 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT); 371 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT); 372 373 #ifdef __cplusplus 374 } 375 #endif 376 377 #endif /* __AIR32F10x_USART_H */ 378 /** 379 * @} 380 */ 381 382 /** 383 * @} 384 */ 385 386 /** 387 * @} 388 */ 389 390