stm32f7xx_hal_irda.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_irda.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of IRDA HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_IRDA_H
  39. #define __STM32F7xx_HAL_IRDA_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup IRDA
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup IRDA_Exported_Types IRDA Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief IRDA Init Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t BaudRate; /*!< This member configures the IRDA communication baud rate.
  61. The baud rate register is computed using the following formula:
  62. Baud Rate Register = ((PCLKx) / ((hirda->Init.BaudRate))) */
  63. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  64. This parameter can be a value of @ref IRDAEx_Word_Length */
  65. uint32_t Parity; /*!< Specifies the parity mode.
  66. This parameter can be a value of @ref IRDA_Parity
  67. @note When parity is enabled, the computed parity is inserted
  68. at the MSB position of the transmitted data (9th bit when
  69. the word length is set to 9 data bits; 8th bit when the
  70. word length is set to 8 data bits). */
  71. uint16_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  72. This parameter can be a value of @ref IRDA_Transfer_Mode */
  73. uint8_t Prescaler; /*!< Specifies the Prescaler value for dividing the UART/USART source clock
  74. to achieve low-power frequency.
  75. @note Prescaler value 0 is forbidden */
  76. uint16_t PowerMode; /*!< Specifies the IRDA power mode.
  77. This parameter can be a value of @ref IRDA_Low_Power */
  78. }IRDA_InitTypeDef;
  79. /**
  80. * @brief HAL State structures definition
  81. */
  82. typedef enum
  83. {
  84. HAL_IRDA_STATE_RESET = 0x00, /*!< Peripheral is not yet Initialized */
  85. HAL_IRDA_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
  86. HAL_IRDA_STATE_BUSY = 0x02, /*!< An internal process is ongoing */
  87. HAL_IRDA_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
  88. HAL_IRDA_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
  89. HAL_IRDA_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
  90. HAL_IRDA_STATE_TIMEOUT = 0x03, /*!< Timeout state */
  91. HAL_IRDA_STATE_ERROR = 0x04 /*!< Error */
  92. }HAL_IRDA_StateTypeDef;
  93. /**
  94. * @brief IRDA clock sources definition
  95. */
  96. typedef enum
  97. {
  98. IRDA_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
  99. IRDA_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
  100. IRDA_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
  101. IRDA_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
  102. IRDA_CLOCKSOURCE_LSE = 0x08 /*!< LSE clock source */
  103. }IRDA_ClockSourceTypeDef;
  104. /**
  105. * @brief IRDA handle Structure definition
  106. */
  107. typedef struct
  108. {
  109. USART_TypeDef *Instance; /* IRDA registers base address */
  110. IRDA_InitTypeDef Init; /* IRDA communication parameters */
  111. uint8_t *pTxBuffPtr; /* Pointer to IRDA Tx transfer Buffer */
  112. uint16_t TxXferSize; /* IRDA Tx Transfer size */
  113. uint16_t TxXferCount; /* IRDA Tx Transfer Counter */
  114. uint8_t *pRxBuffPtr; /* Pointer to IRDA Rx transfer Buffer */
  115. uint16_t RxXferSize; /* IRDA Rx Transfer size */
  116. uint16_t RxXferCount; /* IRDA Rx Transfer Counter */
  117. uint16_t Mask; /* IRDA RX RDR register mask */
  118. DMA_HandleTypeDef *hdmatx; /* IRDA Tx DMA Handle parameters */
  119. DMA_HandleTypeDef *hdmarx; /* IRDA Rx DMA Handle parameters */
  120. HAL_LockTypeDef Lock; /* Locking object */
  121. __IO HAL_IRDA_StateTypeDef State; /* IRDA communication state */
  122. __IO uint32_t ErrorCode; /* IRDA Error code */
  123. }IRDA_HandleTypeDef;
  124. /**
  125. * @}
  126. */
  127. /**
  128. * @brief IRDA Configuration enumeration values definition
  129. */
  130. /* Exported constants --------------------------------------------------------*/
  131. /** @defgroup IRDA_Exported_Constants IRDA Exported constants
  132. * @{
  133. */
  134. /** @defgroup IRDA_Error_Code IRDA Error Code
  135. * @brief IRDA Error Code
  136. * @{
  137. */
  138. #define HAL_IRDA_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
  139. #define HAL_IRDA_ERROR_PE ((uint32_t)0x00000001) /*!< Parity error */
  140. #define HAL_IRDA_ERROR_NE ((uint32_t)0x00000002) /*!< Noise error */
  141. #define HAL_IRDA_ERROR_FE ((uint32_t)0x00000004) /*!< frame error */
  142. #define HAL_IRDA_ERROR_ORE ((uint32_t)0x00000008) /*!< Overrun error */
  143. #define HAL_IRDA_ERROR_DMA ((uint32_t)0x00000010) /*!< DMA transfer error */
  144. /**
  145. * @}
  146. */
  147. /** @defgroup IRDA_Parity IRDA Parity
  148. * @{
  149. */
  150. #define IRDA_PARITY_NONE ((uint32_t)0x0000)
  151. #define IRDA_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
  152. #define IRDA_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
  153. /**
  154. * @}
  155. */
  156. /** @defgroup IRDA_Transfer_Mode IRDA Transfer Mode
  157. * @{
  158. */
  159. #define IRDA_MODE_RX ((uint32_t)USART_CR1_RE)
  160. #define IRDA_MODE_TX ((uint32_t)USART_CR1_TE)
  161. #define IRDA_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
  162. /**
  163. * @}
  164. */
  165. /** @defgroup IRDA_Low_Power IRDA Low Power
  166. * @{
  167. */
  168. #define IRDA_POWERMODE_NORMAL ((uint32_t)0x0000)
  169. #define IRDA_POWERMODE_LOWPOWER ((uint32_t)USART_CR3_IRLP)
  170. /**
  171. * @}
  172. */
  173. /** @defgroup IRDA_State IRDA State
  174. * @{
  175. */
  176. #define IRDA_STATE_DISABLE ((uint32_t)0x0000)
  177. #define IRDA_STATE_ENABLE ((uint32_t)USART_CR1_UE)
  178. /**
  179. * @}
  180. */
  181. /** @defgroup IRDA_Mode IRDA Mode
  182. * @{
  183. */
  184. #define IRDA_MODE_DISABLE ((uint32_t)0x0000)
  185. #define IRDA_MODE_ENABLE ((uint32_t)USART_CR3_IREN)
  186. /**
  187. * @}
  188. */
  189. /** @defgroup IRDA_One_Bit IRDA One Bit
  190. * @{
  191. */
  192. #define IRDA_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x00000000)
  193. #define IRDA_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT)
  194. /**
  195. * @}
  196. */
  197. /** @defgroup IRDA_DMA_Tx IRDA DMA Tx
  198. * @{
  199. */
  200. #define IRDA_DMA_TX_DISABLE ((uint32_t)0x00000000)
  201. #define IRDA_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT)
  202. /**
  203. * @}
  204. */
  205. /** @defgroup IRDA_DMA_Rx IRDA DMA Rx
  206. * @{
  207. */
  208. #define IRDA_DMA_RX_DISABLE ((uint32_t)0x0000)
  209. #define IRDA_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR)
  210. /**
  211. * @}
  212. */
  213. /** @defgroup IRDA_Flags IRDA Flags
  214. * Elements values convention: 0xXXXX
  215. * - 0xXXXX : Flag mask in the ISR register
  216. * @{
  217. */
  218. #define IRDA_FLAG_REACK ((uint32_t)0x00400000)
  219. #define IRDA_FLAG_TEACK ((uint32_t)0x00200000)
  220. #define IRDA_FLAG_BUSY ((uint32_t)0x00010000)
  221. #define IRDA_FLAG_ABRF ((uint32_t)0x00008000)
  222. #define IRDA_FLAG_ABRE ((uint32_t)0x00004000)
  223. #define IRDA_FLAG_TXE ((uint32_t)0x00000080)
  224. #define IRDA_FLAG_TC ((uint32_t)0x00000040)
  225. #define IRDA_FLAG_RXNE ((uint32_t)0x00000020)
  226. #define IRDA_FLAG_ORE ((uint32_t)0x00000008)
  227. #define IRDA_FLAG_NE ((uint32_t)0x00000004)
  228. #define IRDA_FLAG_FE ((uint32_t)0x00000002)
  229. #define IRDA_FLAG_PE ((uint32_t)0x00000001)
  230. /**
  231. * @}
  232. */
  233. /** @defgroup IRDA_Interrupt_definition IRDA Interrupt definition
  234. * Elements values convention: 0000ZZZZ0XXYYYYYb
  235. * - YYYYY : Interrupt source position in the XX register (5bits)
  236. * - XX : Interrupt source register (2bits)
  237. * - 01: CR1 register
  238. * - 10: CR2 register
  239. * - 11: CR3 register
  240. * - ZZZZ : Flag position in the ISR register(4bits)
  241. * @{
  242. */
  243. #define IRDA_IT_PE ((uint16_t)0x0028)
  244. #define IRDA_IT_TXE ((uint16_t)0x0727)
  245. #define IRDA_IT_TC ((uint16_t)0x0626)
  246. #define IRDA_IT_RXNE ((uint16_t)0x0525)
  247. #define IRDA_IT_IDLE ((uint16_t)0x0424)
  248. /** Elements values convention: 000000000XXYYYYYb
  249. * - YYYYY : Interrupt source position in the XX register (5bits)
  250. * - XX : Interrupt source register (2bits)
  251. * - 01: CR1 register
  252. * - 10: CR2 register
  253. * - 11: CR3 register
  254. */
  255. #define IRDA_IT_ERR ((uint16_t)0x0060)
  256. /** Elements values convention: 0000ZZZZ00000000b
  257. * - ZZZZ : Flag position in the ISR register(4bits)
  258. */
  259. #define IRDA_IT_ORE ((uint16_t)0x0300)
  260. #define IRDA_IT_NE ((uint16_t)0x0200)
  261. #define IRDA_IT_FE ((uint16_t)0x0100)
  262. /**
  263. * @}
  264. */
  265. /** @defgroup IRDA_IT_CLEAR_Flags IRDA IT CLEAR Flags
  266. * @{
  267. */
  268. #define IRDA_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  269. #define IRDA_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  270. #define IRDA_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
  271. #define IRDA_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
  272. #define IRDA_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  273. /**
  274. * @}
  275. */
  276. /** @defgroup IRDA_Request_Parameters IRDA Request Parameters
  277. * @{
  278. */
  279. #define IRDA_AUTOBAUD_REQUEST ((uint16_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
  280. #define IRDA_RXDATA_FLUSH_REQUEST ((uint16_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  281. #define IRDA_TXDATA_FLUSH_REQUEST ((uint16_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. /* Exported macro ------------------------------------------------------------*/
  289. /** @defgroup IRDA_Exported_Macros IRDA Exported Macros
  290. * @{
  291. */
  292. /** @brief Reset IRDA handle state
  293. * @param __HANDLE__: specifies the IRDA Handle.
  294. * The Handle Instance which can be USART1 or USART2.
  295. * @retval None
  296. */
  297. #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_IRDA_STATE_RESET)
  298. /** @brief Check whether the specified IRDA flag is set or not.
  299. * @param __HANDLE__: specifies the IRDA Handle.
  300. * The Handle Instance which can be USART1 or USART2.
  301. * UART peripheral
  302. * @param __FLAG__: specifies the flag to check.
  303. * This parameter can be one of the following values:
  304. * @arg IRDA_FLAG_REACK: Receive enable acknowledge flag
  305. * @arg IRDA_FLAG_TEACK: Transmit enable acknowledge flag
  306. * @arg IRDA_FLAG_BUSY: Busy flag
  307. * @arg IRDA_FLAG_ABRF: Auto Baud rate detection flag
  308. * @arg IRDA_FLAG_ABRE: Auto Baud rate detection error flag
  309. * @arg IRDA_FLAG_TXE: Transmit data register empty flag
  310. * @arg IRDA_FLAG_TC: Transmission Complete flag
  311. * @arg IRDA_FLAG_RXNE: Receive data register not empty flag
  312. * @arg IRDA_FLAG_IDLE: Idle Line detection flag
  313. * @arg IRDA_FLAG_ORE: OverRun Error flag
  314. * @arg IRDA_FLAG_NE: Noise Error flag
  315. * @arg IRDA_FLAG_FE: Framing Error flag
  316. * @arg IRDA_FLAG_PE: Parity Error flag
  317. * @retval The new state of __FLAG__ (TRUE or FALSE).
  318. */
  319. #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  320. /** @brief Enable the specified IRDA interrupt.
  321. * @param __HANDLE__: specifies the IRDA Handle.
  322. * The Handle Instance which can be USART1 or USART2.
  323. * UART peripheral
  324. * @param __INTERRUPT__: specifies the IRDA interrupt source to enable.
  325. * This parameter can be one of the following values:
  326. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  327. * @arg IRDA_IT_TC: Transmission complete interrupt
  328. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  329. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  330. * @arg IRDA_IT_PE: Parity Error interrupt
  331. * @arg IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  332. * @retval None
  333. */
  334. #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 |= (1 << ((__INTERRUPT__) & IRDA_IT_MASK))): \
  335. ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 |= (1 << ((__INTERRUPT__) & IRDA_IT_MASK))): \
  336. ((__HANDLE__)->Instance->CR3 |= (1 << ((__INTERRUPT__) & IRDA_IT_MASK))))
  337. /** @brief Disable the specified IRDA interrupt.
  338. * @param __HANDLE__: specifies the IRDA Handle.
  339. * The Handle Instance which can be USART1 or USART2.
  340. * @param __INTERRUPT__: specifies the IRDA interrupt source to disable.
  341. * This parameter can be one of the following values:
  342. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  343. * @arg IRDA_IT_TC: Transmission complete interrupt
  344. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  345. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  346. * @arg IRDA_IT_PE: Parity Error interrupt
  347. * @arg IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  348. * @retval None
  349. */
  350. #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & IRDA_IT_MASK))): \
  351. ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & IRDA_IT_MASK))): \
  352. ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & IRDA_IT_MASK))))
  353. /** @brief Check whether the specified IRDA interrupt has occurred or not.
  354. * @param __HANDLE__: specifies the IRDA Handle.
  355. * The Handle Instance which can be USART1 or USART2.
  356. * @param __IT__: specifies the IRDA interrupt source to check.
  357. * This parameter can be one of the following values:
  358. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  359. * @arg IRDA_IT_TC: Transmission complete interrupt
  360. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  361. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  362. * @arg IRDA_IT_ORE: OverRun Error interrupt
  363. * @arg IRDA_IT_NE: Noise Error interrupt
  364. * @arg IRDA_IT_FE: Framing Error interrupt
  365. * @arg IRDA_IT_PE: Parity Error interrupt
  366. * @retval The new state of __IT__ (TRUE or FALSE).
  367. */
  368. #define __HAL_IRDA_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
  369. /** @brief Check whether the specified IRDA interrupt source is enabled.
  370. * @param __HANDLE__: specifies the IRDA Handle.
  371. * The Handle Instance which can be USART1 or USART2.
  372. * @param __IT__: specifies the IRDA interrupt source to check.
  373. * This parameter can be one of the following values:
  374. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  375. * @arg IRDA_IT_TC: Transmission complete interrupt
  376. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  377. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  378. * @arg IRDA_IT_ORE: OverRun Error interrupt
  379. * @arg IRDA_IT_NE: Noise Error interrupt
  380. * @arg IRDA_IT_FE: Framing Error interrupt
  381. * @arg IRDA_IT_PE: Parity Error interrupt
  382. * @retval The new state of __IT__ (TRUE or FALSE).
  383. */
  384. #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
  385. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & IRDA_IT_MASK)))
  386. /** @brief Clear the specified IRDA ISR flag, in setting the proper ICR register flag.
  387. * @param __HANDLE__: specifies the IRDA Handle.
  388. * The Handle Instance which can be USART1 or USART2.
  389. * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
  390. * to clear the corresponding interrupt
  391. * This parameter can be one of the following values:
  392. * @arg IRDA_CLEAR_PEF: Parity Error Clear Flag
  393. * @arg IRDA_CLEAR_FEF: Framing Error Clear Flag
  394. * @arg IRDA_CLEAR_NEF: Noise detected Clear Flag
  395. * @arg IRDA_CLEAR_OREF: OverRun Error Clear Flag
  396. * @arg IRDA_CLEAR_TCF: Transmission Complete Clear Flag
  397. * @retval None
  398. */
  399. #define __HAL_IRDA_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR |= (uint32_t)(__IT_CLEAR__))
  400. /** @brief Set a specific IRDA request flag.
  401. * @param __HANDLE__: specifies the IRDA Handle.
  402. * The Handle Instance which can be USART1 or USART2.
  403. * @param __REQ__: specifies the request flag to set
  404. * This parameter can be one of the following values:
  405. * @arg IRDA_AUTOBAUD_REQUEST: Auto-Baud Rate Request
  406. * @arg IRDA_RXDATA_FLUSH_REQUEST: Receive Data flush Request
  407. * @arg IRDA_TXDATA_FLUSH_REQUEST: Transmit data flush Request
  408. *
  409. * @retval None
  410. */
  411. #define __HAL_IRDA_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
  412. /** @brief Enable UART/USART associated to IRDA Handle
  413. * @param __HANDLE__: specifies the IRDA Handle.
  414. * The Handle Instance which can be USART1 or USART2.
  415. * @retval None
  416. */
  417. #define __HAL_IRDA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  418. /** @brief Disable UART/USART associated to IRDA Handle
  419. * @param __HANDLE__: specifies the IRDA Handle.
  420. * The Handle Instance which can be USART1 or USART2.
  421. * @retval None
  422. */
  423. #define __HAL_IRDA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  424. /**
  425. * @}
  426. */
  427. /* Include IRDA HAL Extension module */
  428. #include "stm32f7xx_hal_irda_ex.h"
  429. /* Exported functions --------------------------------------------------------*/
  430. /** @addtogroup IRDA_Exported_Functions IrDA Exported Functions
  431. * @{
  432. */
  433. /** @addtogroup IRDA_Exported_Functions_Group1 IrDA Initialization and de-initialization functions
  434. * @{
  435. */
  436. /* Initialization and de-initialization functions ****************************/
  437. HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda);
  438. HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda);
  439. void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda);
  440. void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda);
  441. /**
  442. * @}
  443. */
  444. /** @addtogroup IRDA_Exported_Functions_Group2 IO operation functions
  445. * @{
  446. */
  447. /* IO operation functions *****************************************************/
  448. HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  449. HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  450. HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  451. HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  452. HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  453. HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  454. HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda);
  455. HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda);
  456. HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda);
  457. void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda);
  458. void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda);
  459. void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda);
  460. void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
  461. void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
  462. void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda);
  463. /**
  464. * @}
  465. */
  466. /** @addtogroup IRDA_Exported_Functions_Group3 Peripheral Control functions
  467. * @{
  468. */
  469. /* Peripheral State methods **************************************************/
  470. HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda);
  471. uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda);
  472. /**
  473. * @}
  474. */
  475. /**
  476. * @}
  477. */
  478. /* Private types -------------------------------------------------------------*/
  479. /* Private variables ---------------------------------------------------------*/
  480. /* Private constants ---------------------------------------------------------*/
  481. /** @defgroup IRDA_Private_Constants IRDA Private Constants
  482. * @{
  483. */
  484. /** @defgroup IRDA_Interruption_Mask IRDA Interruption Mask
  485. * @{
  486. */
  487. #define IRDA_IT_MASK ((uint16_t)0x001F)
  488. /**
  489. * @}
  490. */
  491. /**
  492. * @}
  493. */
  494. /* Private macros --------------------------------------------------------*/
  495. /** @defgroup IRDA_Private_Macros IRDA Private Macros
  496. * @{
  497. */
  498. /** @brief Ensure that IRDA Baud rate is less or equal to maximum value
  499. * @param __BAUDRATE__: specifies the IRDA Baudrate set by the user.
  500. * @retval True or False
  501. */
  502. #define IS_IRDA_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 115201)
  503. /** @brief Ensure that IRDA prescaler value is strictly larger than 0
  504. * @param __PRESCALER__: specifies the IRDA prescaler value set by the user.
  505. * @retval True or False
  506. */
  507. #define IS_IRDA_PRESCALER(__PRESCALER__) ((__PRESCALER__) > 0)
  508. #define IS_IRDA_PARITY(__PARITY__) (((__PARITY__) == IRDA_PARITY_NONE) || \
  509. ((__PARITY__) == IRDA_PARITY_EVEN) || \
  510. ((__PARITY__) == IRDA_PARITY_ODD))
  511. #define IS_IRDA_TX_RX_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(IRDA_MODE_TX_RX)))) == (uint32_t)0x00) && ((__MODE__) != (uint32_t)0x00))
  512. #define IS_IRDA_POWERMODE(__MODE__) (((__MODE__) == IRDA_POWERMODE_LOWPOWER) || \
  513. ((__MODE__) == IRDA_POWERMODE_NORMAL))
  514. #define IS_IRDA_STATE(__STATE__) (((__STATE__) == IRDA_STATE_DISABLE) || \
  515. ((__STATE__) == IRDA_STATE_ENABLE))
  516. #define IS_IRDA_MODE(__STATE__) (((__STATE__) == IRDA_MODE_DISABLE) || \
  517. ((__STATE__) == IRDA_MODE_ENABLE))
  518. #define IS_IRDA_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == IRDA_ONE_BIT_SAMPLE_DISABLE) || \
  519. ((__ONEBIT__) == IRDA_ONE_BIT_SAMPLE_ENABLE))
  520. #define IS_IRDA_DMA_TX(__DMATX__) (((__DMATX__) == IRDA_DMA_TX_DISABLE) || \
  521. ((__DMATX__) == IRDA_DMA_TX_ENABLE))
  522. #define IS_IRDA_DMA_RX(__DMARX__) (((__DMARX__) == IRDA_DMA_RX_DISABLE) || \
  523. ((__DMARX__) == IRDA_DMA_RX_ENABLE))
  524. #define IS_IRDA_REQUEST_PARAMETER(PARAM) (((PARAM) == IRDA_AUTOBAUD_REQUEST) || \
  525. ((PARAM) == IRDA_SENDBREAK_REQUEST) || \
  526. ((PARAM) == IRDA_MUTE_MODE_REQUEST) || \
  527. ((PARAM) == IRDA_RXDATA_FLUSH_REQUEST) || \
  528. ((PARAM) == IRDA_TXDATA_FLUSH_REQUEST))
  529. /**
  530. * @}
  531. */
  532. /* Private functions ---------------------------------------------------------*/
  533. /** @defgroup IRDA_Private_Functions IRDA Private Functions
  534. * @{
  535. */
  536. /**
  537. * @}
  538. */
  539. /**
  540. * @}
  541. */
  542. /**
  543. * @}
  544. */
  545. #ifdef __cplusplus
  546. }
  547. #endif
  548. #endif /* __STM32F7xx_HAL_IRDA_H */
  549. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/