stm32f1xx_hal_irda.h 28 KB

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