训练营PLSR题目
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

683 righe
31 KiB

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