stm32f7xx_hal_irda.h 32 KB

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