ch32v00X_usart.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v00X_usart.h
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2024/01/01
  6. * Description : This file contains all the functions prototypes for the
  7. * USART firmware library.
  8. *********************************************************************************
  9. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  10. * Attention: This software (modified or not) and binary are used for
  11. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  12. *******************************************************************************/
  13. #ifndef __CH32V00X_USART_H
  14. #define __CH32V00X_USART_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <ch32v00X.h>
  19. /* USART Init Structure definition */
  20. typedef struct
  21. {
  22. uint32_t USART_BaudRate; /* This member configures the USART communication baud rate.
  23. The baud rate is computed using the following formula:
  24. - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate)))
  25. - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5 */
  26. uint16_t USART_WordLength; /* Specifies the number of data bits transmitted or received in a frame.
  27. This parameter can be a value of @ref USART_Word_Length */
  28. uint16_t USART_StopBits; /* Specifies the number of stop bits transmitted.
  29. This parameter can be a value of @ref USART_Stop_Bits */
  30. uint16_t USART_Parity; /* Specifies the parity mode.
  31. This parameter can be a value of @ref USART_Parity
  32. @note When parity is enabled, the computed parity is inserted
  33. at the MSB position of the transmitted data (9th bit when
  34. the word length is set to 9 data bits; 8th bit when the
  35. word length is set to 8 data bits). */
  36. uint16_t USART_Mode; /* Specifies wether the Receive or Transmit mode is enabled or disabled.
  37. This parameter can be a value of @ref USART_Mode */
  38. uint16_t USART_HardwareFlowControl; /* Specifies wether the hardware flow control mode is enabled
  39. or disabled.
  40. This parameter can be a value of @ref USART_Hardware_Flow_Control */
  41. } USART_InitTypeDef;
  42. /* USART_Word_Length */
  43. #define USART_WordLength_8b ((uint16_t)0x0000)
  44. #define USART_WordLength_9b ((uint16_t)0x1000)
  45. /* USART_Stop_Bits */
  46. #define USART_StopBits_1 ((uint16_t)0x0000)
  47. #define USART_StopBits_0_5 ((uint16_t)0x1000)
  48. #define USART_StopBits_2 ((uint16_t)0x2000)
  49. #define USART_StopBits_1_5 ((uint16_t)0x3000)
  50. /* USART_Parity */
  51. #define USART_Parity_No ((uint16_t)0x0000)
  52. #define USART_Parity_Even ((uint16_t)0x0400)
  53. #define USART_Parity_Odd ((uint16_t)0x0600)
  54. /* USART_Mode */
  55. #define USART_Mode_Rx ((uint16_t)0x0004)
  56. #define USART_Mode_Tx ((uint16_t)0x0008)
  57. /* USART_Hardware_Flow_Control */
  58. #define USART_HardwareFlowControl_None ((uint16_t)0x0000)
  59. #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100)
  60. #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200)
  61. #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300)
  62. /* USART_Interrupt_definition */
  63. #define USART_IT_PE ((uint16_t)0x0028)
  64. #define USART_IT_TXE ((uint16_t)0x0727)
  65. #define USART_IT_TC ((uint16_t)0x0626)
  66. #define USART_IT_RXNE ((uint16_t)0x0525)
  67. #define USART_IT_ORE_RX ((uint16_t)0x0325)
  68. #define USART_IT_IDLE ((uint16_t)0x0424)
  69. #define USART_IT_LBD ((uint16_t)0x0846)
  70. #define USART_IT_CTS ((uint16_t)0x096A)
  71. #define USART_IT_ERR ((uint16_t)0x0060)
  72. #define USART_IT_ORE_ER ((uint16_t)0x0360)
  73. #define USART_IT_NE ((uint16_t)0x0260)
  74. #define USART_IT_FE ((uint16_t)0x0160)
  75. #define USART_IT_ORE USART_IT_ORE_ER
  76. /* USART_DMA_Requests */
  77. #define USART_DMAReq_Tx ((uint16_t)0x0080)
  78. #define USART_DMAReq_Rx ((uint16_t)0x0040)
  79. /* USART_WakeUp_methods */
  80. #define USART_WakeUp_IdleLine ((uint16_t)0x0000)
  81. #define USART_WakeUp_AddressMark ((uint16_t)0x0800)
  82. /* USART_LIN_Break_Detection_Length */
  83. #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000)
  84. #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020)
  85. /* USART_IrDA_Low_Power */
  86. #define USART_IrDAMode_LowPower ((uint16_t)0x0004)
  87. #define USART_IrDAMode_Normal ((uint16_t)0x0000)
  88. /* USART_Flags */
  89. #define USART_FLAG_CTS ((uint16_t)0x0200)
  90. #define USART_FLAG_LBD ((uint16_t)0x0100)
  91. #define USART_FLAG_TXE ((uint16_t)0x0080)
  92. #define USART_FLAG_TC ((uint16_t)0x0040)
  93. #define USART_FLAG_RXNE ((uint16_t)0x0020)
  94. #define USART_FLAG_IDLE ((uint16_t)0x0010)
  95. #define USART_FLAG_ORE ((uint16_t)0x0008)
  96. #define USART_FLAG_NE ((uint16_t)0x0004)
  97. #define USART_FLAG_FE ((uint16_t)0x0002)
  98. #define USART_FLAG_PE ((uint16_t)0x0001)
  99. void USART_DeInit(USART_TypeDef *USARTx);
  100. void USART_Init(USART_TypeDef *USARTx, USART_InitTypeDef *USART_InitStruct);
  101. void USART_StructInit(USART_InitTypeDef *USART_InitStruct);
  102. void USART_Cmd(USART_TypeDef *USARTx, FunctionalState NewState);
  103. void USART_ITConfig(USART_TypeDef *USARTx, uint16_t USART_IT, FunctionalState NewState);
  104. void USART_DMACmd(USART_TypeDef *USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
  105. void USART_SetAddress(USART_TypeDef *USARTx, uint8_t USART_Address);
  106. void USART_WakeUpConfig(USART_TypeDef *USARTx, uint16_t USART_WakeUp);
  107. void USART_ReceiverWakeUpCmd(USART_TypeDef *USARTx, FunctionalState NewState);
  108. void USART_LINBreakDetectLengthConfig(USART_TypeDef *USARTx, uint16_t USART_LINBreakDetectLength);
  109. void USART_LINCmd(USART_TypeDef *USARTx, FunctionalState NewState);
  110. void USART_SendData(USART_TypeDef *USARTx, uint16_t Data);
  111. uint16_t USART_ReceiveData(USART_TypeDef *USARTx);
  112. void USART_SendBreak(USART_TypeDef *USARTx);
  113. void USART_SetPrescaler(USART_TypeDef *USARTx, uint8_t USART_Prescaler);
  114. void USART_HalfDuplexCmd(USART_TypeDef *USARTx, FunctionalState NewState);
  115. void USART_IrDAConfig(USART_TypeDef *USARTx, uint16_t USART_IrDAMode);
  116. void USART_IrDACmd(USART_TypeDef *USARTx, FunctionalState NewState);
  117. FlagStatus USART_GetFlagStatus(USART_TypeDef *USARTx, uint16_t USART_FLAG);
  118. void USART_ClearFlag(USART_TypeDef *USARTx, uint16_t USART_FLAG);
  119. ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint16_t USART_IT);
  120. void USART_ClearITPendingBit(USART_TypeDef *USARTx, uint16_t USART_IT);
  121. #ifdef __cplusplus
  122. }
  123. #endif
  124. #endif /* __CH32V00X_USART_H */