py32f0xx_hal_irda.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_hal_irda.h
  4. * @author MCU Application Team
  5. * @brief Header file of IRDA HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F0xx_HAL_IRDA_H
  32. #define __PY32F0xx_HAL_IRDA_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx_hal_def.h"
  38. /** @addtogroup PY32F0xx_HAL_Driver
  39. * @{
  40. */
  41. /** @addtogroup IRDA
  42. * @{
  43. */
  44. /* Exported types ------------------------------------------------------------*/
  45. /** @defgroup IRDA_Exported_Types IRDA Exported Types
  46. * @{
  47. */
  48. /**
  49. * @brief IRDA Init Structure definition
  50. */
  51. typedef struct
  52. {
  53. uint32_t BaudRate; /*!< This member configures the IRDA communication baud rate.
  54. The baud rate is computed using the following formula:
  55. - IntegerDivider = ((PCLKx) / (16 * (hirda->Init.BaudRate)))
  56. - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */
  57. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  58. This parameter can be a value of @ref IRDA_Word_Length */
  59. uint32_t Parity; /*!< Specifies the parity mode.
  60. This parameter can be a value of @ref IRDA_Parity
  61. @note When parity is enabled, the computed parity is inserted
  62. at the MSB position of the transmitted data (9th bit when
  63. the word length is set to 9 data bits; 8th bit when the
  64. word length is set to 8 data bits). */
  65. uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  66. This parameter can be a value of @ref IRDA_Mode */
  67. uint8_t Prescaler; /*!< Specifies the Prescaler value to be programmed
  68. in the IrDA low-power Baud Register, for defining pulse width on which
  69. burst acceptance/rejection will be decided. This value is used as divisor
  70. of system clock to achieve required pulse width. */
  71. uint32_t IrDAMode; /*!< Specifies the IrDA mode
  72. This parameter can be a value of @ref IRDA_Low_Power */
  73. } IRDA_InitTypeDef;
  74. /**
  75. * @brief HAL IRDA State structures definition
  76. * @note HAL IRDA State value is a combination of 2 different substates: gState and RxState.
  77. * - gState contains IRDA state information related to global Handle management
  78. * and also information related to Tx operations.
  79. * gState value coding follow below described bitmap :
  80. * b7-b6 Error information
  81. * 00 : No Error
  82. * 01 : (Not Used)
  83. * 10 : Timeout
  84. * 11 : Error
  85. * b5 IP initilisation status
  86. * 0 : Reset (IP not initialized)
  87. * 1 : Init done (IP not initialized. HAL IRDA Init function already called)
  88. * b4-b3 (not used)
  89. * xx : Should be set to 00
  90. * b2 Intrinsic process state
  91. * 0 : Ready
  92. * 1 : Busy (IP busy with some configuration or internal operations)
  93. * b1 (not used)
  94. * x : Should be set to 0
  95. * b0 Tx state
  96. * 0 : Ready (no Tx operation ongoing)
  97. * 1 : Busy (Tx operation ongoing)
  98. * - RxState contains information related to Rx operations.
  99. * RxState value coding follow below described bitmap :
  100. * b7-b6 (not used)
  101. * xx : Should be set to 00
  102. * b5 IP initilisation status
  103. * 0 : Reset (IP not initialized)
  104. * 1 : Init done (IP not initialized)
  105. * b4-b2 (not used)
  106. * xxx : Should be set to 000
  107. * b1 Rx state
  108. * 0 : Ready (no Rx operation ongoing)
  109. * 1 : Busy (Rx operation ongoing)
  110. * b0 (not used)
  111. * x : Should be set to 0.
  112. */
  113. typedef enum
  114. {
  115. HAL_IRDA_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized
  116. Value is allowed for gState and RxState */
  117. HAL_IRDA_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
  118. Value is allowed for gState and RxState */
  119. HAL_IRDA_STATE_BUSY = 0x24U, /*!< An internal process is ongoing
  120. Value is allowed for gState only */
  121. HAL_IRDA_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
  122. Value is allowed for gState only */
  123. HAL_IRDA_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
  124. Value is allowed for RxState only */
  125. HAL_IRDA_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
  126. Not to be used for neither gState nor RxState.
  127. Value is result of combination (Or) between gState and RxState values */
  128. HAL_IRDA_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
  129. Value is allowed for gState only */
  130. HAL_IRDA_STATE_ERROR = 0xE0U /*!< Error
  131. Value is allowed for gState only */
  132. } HAL_IRDA_StateTypeDef;
  133. /**
  134. * @brief IRDA handle Structure definition
  135. */
  136. #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
  137. typedef struct __IRDA_HandleTypeDef
  138. #else
  139. typedef struct
  140. #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
  141. {
  142. USART_TypeDef *Instance; /*!< USART registers base address */
  143. IRDA_InitTypeDef Init; /*!< IRDA communication parameters */
  144. uint8_t *pTxBuffPtr; /*!< Pointer to IRDA Tx transfer Buffer */
  145. uint16_t TxXferSize; /*!< IRDA Tx Transfer size */
  146. __IO uint16_t TxXferCount; /*!< IRDA Tx Transfer Counter */
  147. uint8_t *pRxBuffPtr; /*!< Pointer to IRDA Rx transfer Buffer */
  148. uint16_t RxXferSize; /*!< IRDA Rx Transfer size */
  149. __IO uint16_t RxXferCount; /*!< IRDA Rx Transfer Counter */
  150. DMA_HandleTypeDef *hdmatx; /*!< IRDA Tx DMA Handle parameters */
  151. DMA_HandleTypeDef *hdmarx; /*!< IRDA Rx DMA Handle parameters */
  152. HAL_LockTypeDef Lock; /*!< Locking object */
  153. __IO HAL_IRDA_StateTypeDef gState; /*!< IRDA state information related to global Handle management
  154. and also related to Tx operations.
  155. This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
  156. __IO HAL_IRDA_StateTypeDef RxState; /*!< IRDA state information related to Rx operations.
  157. This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
  158. __IO uint32_t ErrorCode; /*!< IRDA Error code */
  159. #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
  160. void (* TxHalfCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Tx Half Complete Callback */
  161. void (* TxCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Tx Complete Callback */
  162. void (* RxHalfCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Rx Half Complete Callback */
  163. void (* RxCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Rx Complete Callback */
  164. void (* ErrorCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Error Callback */
  165. void (* AbortCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Abort Complete Callback */
  166. void (* AbortTransmitCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Abort Transmit Complete Callback */
  167. void (* AbortReceiveCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Abort Receive Complete Callback */
  168. void (* MspInitCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Msp Init callback */
  169. void (* MspDeInitCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Msp DeInit callback */
  170. #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
  171. } IRDA_HandleTypeDef;
  172. #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
  173. /**
  174. * @brief HAL IRDA Callback ID enumeration definition
  175. */
  176. typedef enum
  177. {
  178. HAL_IRDA_TX_HALFCOMPLETE_CB_ID = 0x00U, /*!< IRDA Tx Half Complete Callback ID */
  179. HAL_IRDA_TX_COMPLETE_CB_ID = 0x01U, /*!< IRDA Tx Complete Callback ID */
  180. HAL_IRDA_RX_HALFCOMPLETE_CB_ID = 0x02U, /*!< IRDA Rx Half Complete Callback ID */
  181. HAL_IRDA_RX_COMPLETE_CB_ID = 0x03U, /*!< IRDA Rx Complete Callback ID */
  182. HAL_IRDA_ERROR_CB_ID = 0x04U, /*!< IRDA Error Callback ID */
  183. HAL_IRDA_ABORT_COMPLETE_CB_ID = 0x05U, /*!< IRDA Abort Complete Callback ID */
  184. HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U, /*!< IRDA Abort Transmit Complete Callback ID */
  185. HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID = 0x07U, /*!< IRDA Abort Receive Complete Callback ID */
  186. HAL_IRDA_MSPINIT_CB_ID = 0x08U, /*!< IRDA MspInit callback ID */
  187. HAL_IRDA_MSPDEINIT_CB_ID = 0x09U /*!< IRDA MspDeInit callback ID */
  188. } HAL_IRDA_CallbackIDTypeDef;
  189. /**
  190. * @brief HAL IRDA Callback pointer definition
  191. */
  192. typedef void (*pIRDA_CallbackTypeDef)(IRDA_HandleTypeDef *hirda); /*!< pointer to an IRDA callback function */
  193. #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
  194. /**
  195. * @}
  196. */
  197. /* Exported constants --------------------------------------------------------*/
  198. /** @defgroup IRDA_Exported_Constants IRDA Exported constants
  199. * @{
  200. */
  201. /** @defgroup IRDA_Error_Code IRDA Error Code
  202. * @{
  203. */
  204. #define HAL_IRDA_ERROR_NONE 0x00000000U /*!< No error */
  205. #define HAL_IRDA_ERROR_PE 0x00000001U /*!< Parity error */
  206. #define HAL_IRDA_ERROR_NE 0x00000002U /*!< Noise error */
  207. #define HAL_IRDA_ERROR_FE 0x00000004U /*!< Frame error */
  208. #define HAL_IRDA_ERROR_ORE 0x00000008U /*!< Overrun error */
  209. #define HAL_IRDA_ERROR_DMA 0x00000010U /*!< DMA transfer error */
  210. #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
  211. #define HAL_IRDA_ERROR_INVALID_CALLBACK ((uint32_t)0x00000020U) /*!< Invalid Callback error */
  212. #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
  213. /**
  214. * @}
  215. */
  216. /** @defgroup IRDA_Word_Length IRDA Word Length
  217. * @{
  218. */
  219. #define IRDA_WORDLENGTH_8B 0x00000000U
  220. #define IRDA_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
  221. /**
  222. * @}
  223. */
  224. /** @defgroup IRDA_Parity IRDA Parity
  225. * @{
  226. */
  227. #define IRDA_PARITY_NONE 0x00000000U
  228. #define IRDA_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
  229. #define IRDA_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
  230. /**
  231. * @}
  232. */
  233. /** @defgroup IRDA_Mode IRDA Transfer Mode
  234. * @{
  235. */
  236. #define IRDA_MODE_RX ((uint32_t)USART_CR1_RE)
  237. #define IRDA_MODE_TX ((uint32_t)USART_CR1_TE)
  238. #define IRDA_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
  239. /**
  240. * @}
  241. */
  242. /** @defgroup IRDA_Low_Power IRDA Low Power
  243. * @{
  244. */
  245. #define IRDA_POWERMODE_LOWPOWER ((uint32_t)USART_CR3_IRLP)
  246. #define IRDA_POWERMODE_NORMAL 0x00000000U
  247. /**
  248. * @}
  249. */
  250. /** @defgroup IRDA_Flags IRDA Flags
  251. * Elements values convention: 0xXXXX
  252. * - 0xXXXX : Flag mask in the SR register
  253. * @{
  254. */
  255. #define IRDA_FLAG_TXE ((uint32_t)USART_SR_TXE)
  256. #define IRDA_FLAG_TC ((uint32_t)USART_SR_TC)
  257. #define IRDA_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
  258. #define IRDA_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
  259. #define IRDA_FLAG_ORE ((uint32_t)USART_SR_ORE)
  260. #define IRDA_FLAG_NE ((uint32_t)USART_SR_NE)
  261. #define IRDA_FLAG_FE ((uint32_t)USART_SR_FE)
  262. #define IRDA_FLAG_PE ((uint32_t)USART_SR_PE)
  263. /**
  264. * @}
  265. */
  266. /** @defgroup IRDA_Interrupt_definition IRDA Interrupt Definitions
  267. * Elements values convention: 0xY000XXXX
  268. * - XXXX : Interrupt mask in the XX register
  269. * - Y : Interrupt source register (2bits)
  270. * - 01: CR1 register
  271. * - 10: CR2 register
  272. * - 11: CR3 register
  273. * @{
  274. */
  275. #define IRDA_IT_PE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
  276. #define IRDA_IT_TXE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
  277. #define IRDA_IT_TC ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
  278. #define IRDA_IT_RXNE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
  279. #define IRDA_IT_IDLE ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
  280. #define IRDA_IT_LBD ((uint32_t)(IRDA_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
  281. #define IRDA_IT_CTS ((uint32_t)(IRDA_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
  282. #define IRDA_IT_ERR ((uint32_t)(IRDA_CR3_REG_INDEX << 28U | USART_CR3_EIE))
  283. /**
  284. * @}
  285. */
  286. /**
  287. * @}
  288. */
  289. /* Exported macro ------------------------------------------------------------*/
  290. /** @defgroup IRDA_Exported_Macros IRDA Exported Macros
  291. * @{
  292. */
  293. /** @brief Reset IRDA handle gstate & RxState
  294. * @param __HANDLE__ specifies the IRDA Handle.
  295. * IRDA Handle selects the USARTx or UARTy peripheral
  296. * (USART,UART availability and x,y values depending on device).
  297. * @retval None
  298. */
  299. #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
  300. #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__) do{ \
  301. (__HANDLE__)->gState = HAL_IRDA_STATE_RESET; \
  302. (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET; \
  303. (__HANDLE__)->MspInitCallback = NULL; \
  304. (__HANDLE__)->MspDeInitCallback = NULL; \
  305. } while(0U)
  306. #else
  307. #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__) do{ \
  308. (__HANDLE__)->gState = HAL_IRDA_STATE_RESET; \
  309. (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET; \
  310. } while(0U)
  311. #endif /*USE_HAL_IRDA_REGISTER_CALLBACKS */
  312. /** @brief Flush the IRDA DR register
  313. * @param __HANDLE__ specifies the IRDA Handle.
  314. * IRDA Handle selects the USARTx or UARTy peripheral
  315. * (USART,UART availability and x,y values depending on device).
  316. * @retval None
  317. */
  318. #define __HAL_IRDA_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
  319. /** @brief Check whether the specified IRDA flag is set or not.
  320. * @param __HANDLE__ specifies the IRDA Handle.
  321. * IRDA Handle selects the USARTx or UARTy peripheral
  322. * (USART,UART availability and x,y values depending on device).
  323. * @param __FLAG__ specifies the flag to check.
  324. * This parameter can be one of the following values:
  325. * @arg IRDA_FLAG_TXE: Transmit data register empty flag
  326. * @arg IRDA_FLAG_TC: Transmission Complete flag
  327. * @arg IRDA_FLAG_RXNE: Receive data register not empty flag
  328. * @arg IRDA_FLAG_IDLE: Idle Line detection flag
  329. * @arg IRDA_FLAG_ORE: OverRun Error flag
  330. * @arg IRDA_FLAG_NE: Noise Error flag
  331. * @arg IRDA_FLAG_FE: Framing Error flag
  332. * @arg IRDA_FLAG_PE: Parity Error flag
  333. * @retval The new state of __FLAG__ (TRUE or FALSE).
  334. */
  335. #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  336. /** @brief Clear the specified IRDA pending flag.
  337. * @param __HANDLE__ specifies the IRDA Handle.
  338. * IRDA Handle selects the USARTx or UARTy peripheral
  339. * (USART,UART availability and x,y values depending on device).
  340. * @param __FLAG__ specifies the flag to check.
  341. * This parameter can be any combination of the following values:
  342. * @arg IRDA_FLAG_TC: Transmission Complete flag.
  343. * @arg IRDA_FLAG_RXNE: Receive data register not empty flag.
  344. *
  345. * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
  346. * error) and IDLE (Idle line detected) flags are cleared by software
  347. * sequence: a read operation to USART_SR register followed by a read
  348. * operation to USART_DR register.
  349. * @note RXNE flag can be also cleared by a read to the USART_DR register.
  350. * @note TC flag can be also cleared by software sequence: a read operation to
  351. * USART_SR register followed by a write operation to USART_DR register.
  352. * @note TXE flag is cleared only by a write to the USART_DR register.
  353. * @retval None
  354. */
  355. #define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  356. /** @brief Clear the IRDA PE pending flag.
  357. * @param __HANDLE__ specifies the IRDA Handle.
  358. * IRDA Handle selects the USARTx or UARTy peripheral
  359. * (USART,UART availability and x,y values depending on device).
  360. * @retval None
  361. */
  362. #define __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__) \
  363. do{ \
  364. __IO uint32_t tmpreg = 0x00U; \
  365. tmpreg = (__HANDLE__)->Instance->SR; \
  366. tmpreg = (__HANDLE__)->Instance->DR; \
  367. UNUSED(tmpreg); \
  368. } while(0U)
  369. /** @brief Clear the IRDA FE pending flag.
  370. * @param __HANDLE__ specifies the IRDA Handle.
  371. * IRDA Handle selects the USARTx or UARTy peripheral
  372. * (USART,UART availability and x,y values depending on device).
  373. * @retval None
  374. */
  375. #define __HAL_IRDA_CLEAR_FEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  376. /** @brief Clear the IRDA NE pending flag.
  377. * @param __HANDLE__ specifies the IRDA Handle.
  378. * IRDA Handle selects the USARTx or UARTy peripheral
  379. * (USART,UART availability and x,y values depending on device).
  380. * @retval None
  381. */
  382. #define __HAL_IRDA_CLEAR_NEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  383. /** @brief Clear the IRDA ORE pending flag.
  384. * @param __HANDLE__ specifies the IRDA Handle.
  385. * IRDA Handle selects the USARTx or UARTy peripheral
  386. * (USART,UART availability and x,y values depending on device).
  387. * @retval None
  388. */
  389. #define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  390. /** @brief Clear the IRDA IDLE pending flag.
  391. * @param __HANDLE__ specifies the IRDA Handle.
  392. * IRDA Handle selects the USARTx or UARTy peripheral
  393. * (USART,UART availability and x,y values depending on device).
  394. * @retval None
  395. */
  396. #define __HAL_IRDA_CLEAR_IDLEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  397. /** @brief Enable the specified IRDA interrupt.
  398. * @param __HANDLE__ specifies the IRDA Handle.
  399. * IRDA Handle selects the USARTx or UARTy peripheral
  400. * (USART,UART availability and x,y values depending on device).
  401. * @param __INTERRUPT__ specifies the IRDA interrupt source to enable.
  402. * This parameter can be one of the following values:
  403. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  404. * @arg IRDA_IT_TC: Transmission complete interrupt
  405. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  406. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  407. * @arg IRDA_IT_PE: Parity Error interrupt
  408. * @arg IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  409. * @retval None
  410. */
  411. #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
  412. (((__INTERRUPT__) >> 28U) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
  413. ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & IRDA_IT_MASK)))
  414. /** @brief Disable the specified IRDA interrupt.
  415. * @param __HANDLE__ specifies the IRDA Handle.
  416. * IRDA Handle selects the USARTx or UARTy peripheral
  417. * (USART,UART availability and x,y values depending on device).
  418. * @param __INTERRUPT__ specifies the IRDA interrupt source to disable.
  419. * This parameter can be one of the following values:
  420. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  421. * @arg IRDA_IT_TC: Transmission complete interrupt
  422. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  423. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  424. * @arg IRDA_IT_PE: Parity Error interrupt
  425. * @arg IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  426. * @retval None
  427. */
  428. #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
  429. (((__INTERRUPT__) >> 28U) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
  430. ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & IRDA_IT_MASK)))
  431. /** @brief Check whether the specified IRDA interrupt has occurred or not.
  432. * @param __HANDLE__ specifies the IRDA Handle.
  433. * IRDA Handle selects the USARTx or UARTy peripheral
  434. * (USART,UART availability and x,y values depending on device).
  435. * @param __IT__ specifies the IRDA interrupt source to check.
  436. * This parameter can be one of the following values:
  437. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  438. * @arg IRDA_IT_TC: Transmission complete interrupt
  439. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  440. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  441. * @arg IRDA_IT_ERR: Error interrupt
  442. * @arg IRDA_IT_PE: Parity Error interrupt
  443. * @retval The new state of __IT__ (TRUE or FALSE).
  444. */
  445. #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == IRDA_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == IRDA_CR2_REG_INDEX)? \
  446. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & IRDA_IT_MASK))
  447. /** @brief Enable UART/USART associated to IRDA Handle
  448. * @param __HANDLE__ specifies the IRDA Handle.
  449. * IRDA Handle selects the USARTx or UARTy peripheral
  450. * (USART,UART availability and x,y values depending on device).
  451. * @retval None
  452. */
  453. #define __HAL_IRDA_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
  454. /** @brief Disable UART/USART associated to IRDA Handle
  455. * @param __HANDLE__ specifies the IRDA Handle.
  456. * IRDA Handle selects the USARTx or UARTy peripheral
  457. * (USART,UART availability and x,y values depending on device).
  458. * @retval None
  459. */
  460. #define __HAL_IRDA_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
  461. /**
  462. * @}
  463. */
  464. /* Exported functions --------------------------------------------------------*/
  465. /** @addtogroup IRDA_Exported_Functions
  466. * @{
  467. */
  468. /** @addtogroup IRDA_Exported_Functions_Group1
  469. * @{
  470. */
  471. /* Initialization/de-initialization functions **********************************/
  472. HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda);
  473. HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda);
  474. void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda);
  475. void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda);
  476. #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
  477. /* Callbacks Register/UnRegister functions ***********************************/
  478. HAL_StatusTypeDef HAL_IRDA_RegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID, pIRDA_CallbackTypeDef pCallback);
  479. HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID);
  480. #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
  481. /**
  482. * @}
  483. */
  484. /** @addtogroup IRDA_Exported_Functions_Group2
  485. * @{
  486. */
  487. /* IO operation functions *******************************************************/
  488. HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  489. HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  490. HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  491. HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  492. HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  493. HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  494. HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda);
  495. HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda);
  496. HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda);
  497. /* Transfer Abort functions */
  498. HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda);
  499. HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda);
  500. HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda);
  501. HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda);
  502. HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda);
  503. HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda);
  504. void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda);
  505. void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda);
  506. void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda);
  507. void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
  508. void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
  509. void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda);
  510. void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda);
  511. void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda);
  512. void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda);
  513. /**
  514. * @}
  515. */
  516. /** @addtogroup IRDA_Exported_Functions_Group3
  517. * @{
  518. */
  519. /* Peripheral State functions **************************************************/
  520. HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda);
  521. uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda);
  522. /**
  523. * @}
  524. */
  525. /**
  526. * @}
  527. */
  528. /* Private types -------------------------------------------------------------*/
  529. /* Private variables ---------------------------------------------------------*/
  530. /* Private constants ---------------------------------------------------------*/
  531. /** @defgroup IRDA_Private_Constants IRDA Private Constants
  532. * @{
  533. */
  534. /** @brief IRDA interruptions flag mask
  535. *
  536. */
  537. #define IRDA_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
  538. USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
  539. #define IRDA_CR1_REG_INDEX 1U
  540. #define IRDA_CR2_REG_INDEX 2U
  541. #define IRDA_CR3_REG_INDEX 3U
  542. /**
  543. * @}
  544. */
  545. /* Private macros --------------------------------------------------------*/
  546. /** @defgroup IRDA_Private_Macros IRDA Private Macros
  547. * @{
  548. */
  549. #define IS_IRDA_WORD_LENGTH(LENGTH) (((LENGTH) == IRDA_WORDLENGTH_8B) || \
  550. ((LENGTH) == IRDA_WORDLENGTH_9B))
  551. #define IS_IRDA_PARITY(PARITY) (((PARITY) == IRDA_PARITY_NONE) || \
  552. ((PARITY) == IRDA_PARITY_EVEN) || \
  553. ((PARITY) == IRDA_PARITY_ODD))
  554. #define IS_IRDA_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00000000U))
  555. #define IS_IRDA_POWERMODE(MODE) (((MODE) == IRDA_POWERMODE_LOWPOWER) || \
  556. ((MODE) == IRDA_POWERMODE_NORMAL))
  557. #define IS_IRDA_BAUDRATE(BAUDRATE) ((BAUDRATE) < 115201U)
  558. #define IRDA_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_)))
  559. #define IRDA_DIVMANT(_PCLK_, _BAUD_) (IRDA_DIV((_PCLK_), (_BAUD_))/100U)
  560. #define IRDA_DIVFRAQ(_PCLK_, _BAUD_) (((IRDA_DIV((_PCLK_), (_BAUD_)) - (IRDA_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
  561. /* UART BRR = mantissa + overflow + fraction
  562. = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */
  563. #define IRDA_BRR(_PCLK_, _BAUD_) (((IRDA_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
  564. (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
  565. (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
  566. /**
  567. * @}
  568. */
  569. /* Private functions ---------------------------------------------------------*/
  570. /** @defgroup IRDA_Private_Functions IRDA Private Functions
  571. * @{
  572. */
  573. /**
  574. * @}
  575. */
  576. /**
  577. * @}
  578. */
  579. /**
  580. * @}
  581. */
  582. #ifdef __cplusplus
  583. }
  584. #endif
  585. #endif /* __PY32F0xx_HAL_IRDA_H */
  586. /************************ (C) COPYRIGHT Puya *****END OF FILE****/