stm32l1xx_hal_irda.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_irda.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 5-September-2014
  7. * @brief This file contains all the functions prototypes for the IRDA
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  13. *
  14. * Redistribution and use in source and binary forms, with or without modification,
  15. * are permitted provided that the following conditions are met:
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ******************************************************************************
  37. */
  38. /* Define to prevent recursive inclusion -------------------------------------*/
  39. #ifndef __STM32L1xx_HAL_IRDA_H
  40. #define __STM32L1xx_HAL_IRDA_H
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /* Includes ------------------------------------------------------------------*/
  45. #include "stm32l1xx_hal_def.h"
  46. /** @addtogroup STM32L1xx_HAL_Driver
  47. * @{
  48. */
  49. /** @addtogroup IRDA
  50. * @{
  51. */
  52. /* Exported types ------------------------------------------------------------*/
  53. /** @defgroup IRDA_Exported_Types IRDA Exported Types
  54. * @{
  55. */
  56. /**
  57. * @brief IRDA Init Structure definition
  58. */
  59. typedef struct
  60. {
  61. uint32_t BaudRate; /*!< This member configures the IRDA communication baud rate.
  62. The baud rate is computed using the following formula:
  63. - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
  64. - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
  65. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  66. This parameter can be a value of @ref IRDA_Word_Length */
  67. uint32_t Parity; /*!< Specifies the parity mode.
  68. This parameter can be a value of @ref IRDA_Parity
  69. @note When parity is enabled, the computed parity is inserted
  70. at the MSB position of the transmitted data (9th bit when
  71. the word length is set to 9 data bits; 8th bit when the
  72. word length is set to 8 data bits). */
  73. uint32_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
  74. This parameter can be a value of @ref IRDA_Transfer_Mode */
  75. uint8_t Prescaler; /*!< Specifies the Prescaler */
  76. uint32_t IrDAMode; /*!< Specifies the IrDA mode
  77. This parameter can be a value of @ref IRDA_Low_Power */
  78. }IRDA_InitTypeDef;
  79. /**
  80. * @brief HAL IRDA State structures definition
  81. */
  82. typedef enum
  83. {
  84. HAL_IRDA_STATE_RESET = 0x00, /*!< Peripheral is not 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 HAL IRDA Error Code structure definition
  95. */
  96. typedef enum
  97. {
  98. HAL_IRDA_ERROR_NONE = 0x00, /*!< No error */
  99. HAL_IRDA_ERROR_PE = 0x01, /*!< Parity error */
  100. HAL_IRDA_ERROR_NE = 0x02, /*!< Noise error */
  101. HAL_IRDA_ERROR_FE = 0x04, /*!< frame error */
  102. HAL_IRDA_ERROR_ORE = 0x08, /*!< Overrun error */
  103. HAL_IRDA_ERROR_DMA = 0x10 /*!< DMA transfer error */
  104. }HAL_IRDA_ErrorTypeDef;
  105. /**
  106. * @brief IRDA handle Structure definition
  107. */
  108. typedef struct
  109. {
  110. USART_TypeDef *Instance; /* USART registers base address */
  111. IRDA_InitTypeDef Init; /* IRDA communication parameters */
  112. uint8_t *pTxBuffPtr; /* Pointer to IRDA Tx transfer Buffer */
  113. uint16_t TxXferSize; /* IRDA Tx Transfer size */
  114. uint16_t TxXferCount; /* IRDA Tx Transfer Counter */
  115. uint8_t *pRxBuffPtr; /* Pointer to IRDA Rx transfer Buffer */
  116. uint16_t RxXferSize; /* IRDA Rx Transfer size */
  117. uint16_t RxXferCount; /* IRDA Rx Transfer Counter */
  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 HAL_IRDA_ErrorTypeDef ErrorCode; /* IRDA Error code */
  123. }IRDA_HandleTypeDef;
  124. /**
  125. * @}
  126. */
  127. /* Exported constants --------------------------------------------------------*/
  128. /** @defgroup IRDA_Exported_Constants IRDA Exported constants
  129. * @{
  130. */
  131. /** @defgroup IRDA_Word_Length IRDA Word Length
  132. * @{
  133. */
  134. #define IRDA_WORDLENGTH_8B ((uint32_t)0x00000000)
  135. #define IRDA_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
  136. #define IS_IRDA_WORD_LENGTH(LENGTH) (((LENGTH) == IRDA_WORDLENGTH_8B) || \
  137. ((LENGTH) == IRDA_WORDLENGTH_9B))
  138. /**
  139. * @}
  140. */
  141. /** @defgroup IRDA_Parity IRDA Parity
  142. * @{
  143. */
  144. #define IRDA_PARITY_NONE ((uint32_t)0x00000000)
  145. #define IRDA_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
  146. #define IRDA_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
  147. #define IS_IRDA_PARITY(PARITY) (((PARITY) == IRDA_PARITY_NONE) || \
  148. ((PARITY) == IRDA_PARITY_EVEN) || \
  149. ((PARITY) == IRDA_PARITY_ODD))
  150. /**
  151. * @}
  152. */
  153. /** @defgroup IRDA_Transfer_Mode IRDA Transfer Mode
  154. * @{
  155. */
  156. #define IRDA_MODE_RX ((uint32_t)USART_CR1_RE)
  157. #define IRDA_MODE_TX ((uint32_t)USART_CR1_TE)
  158. #define IRDA_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
  159. #define IS_IRDA_MODE(MODE) ((((MODE) & (uint32_t)0x0000FFF3) == 0x00) && ((MODE) != (uint32_t)0x000000))
  160. /**
  161. * @}
  162. */
  163. /** @defgroup IRDA_Low_Power IRDA Low Power
  164. * @{
  165. */
  166. #define IRDA_POWERMODE_LOWPOWER ((uint32_t)USART_CR3_IRLP)
  167. #define IRDA_POWERMODE_NORMAL ((uint32_t)0x00000000)
  168. #define IS_IRDA_POWERMODE(MODE) (((MODE) == IRDA_POWERMODE_LOWPOWER) || \
  169. ((MODE) == IRDA_POWERMODE_NORMAL))
  170. /**
  171. * @}
  172. */
  173. /** @defgroup IRDA_Flags IRDA Flags
  174. * Elements values convention: 0xXXXX
  175. * - 0xXXXX : Flag mask in the SR register
  176. * @{
  177. */
  178. #define IRDA_FLAG_TXE ((uint32_t)USART_SR_TXE)
  179. #define IRDA_FLAG_TC ((uint32_t)USART_SR_TC)
  180. #define IRDA_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
  181. #define IRDA_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
  182. #define IRDA_FLAG_ORE ((uint32_t)USART_SR_ORE)
  183. #define IRDA_FLAG_NE ((uint32_t)USART_SR_NE)
  184. #define IRDA_FLAG_FE ((uint32_t)USART_SR_FE)
  185. #define IRDA_FLAG_PE ((uint32_t)USART_SR_PE)
  186. /**
  187. * @}
  188. */
  189. /** @defgroup IRDA_Interrupt_definition IRDA Interrupt Definitions
  190. * Elements values convention: 0xY000XXXX
  191. * - XXXX : Interrupt mask in the XX register
  192. * - Y : Interrupt source register (4 bits)
  193. * - 01: CR1 register
  194. * - 10: CR2 register
  195. * - 11: CR3 register
  196. *
  197. * @{
  198. */
  199. #define IRDA_IT_PE ((uint32_t)0x10000100)
  200. #define IRDA_IT_TXE ((uint32_t)0x10000080)
  201. #define IRDA_IT_TC ((uint32_t)0x10000040)
  202. #define IRDA_IT_RXNE ((uint32_t)0x10000020)
  203. #define IRDA_IT_IDLE ((uint32_t)0x10000010)
  204. #define IRDA_IT_LBD ((uint32_t)0x20000040)
  205. #define IRDA_IT_CTS ((uint32_t)0x30000400)
  206. #define IRDA_IT_ERR ((uint32_t)0x30000001)
  207. /**
  208. * @}
  209. */
  210. /** @defgroup IRDA_Interruption_Mask IRDA interruptions flag mask
  211. * @{
  212. */
  213. #define IRDA_IT_MASK ((uint32_t)0x0000FFFF)
  214. /**
  215. * @}
  216. */
  217. /**
  218. * @}
  219. */
  220. /* Exported macro ------------------------------------------------------------*/
  221. /** @defgroup IRDA_Exported_Macros IRDA Exported Macros
  222. * @{
  223. */
  224. /** @brief Reset IRDA handle state
  225. * @param __HANDLE__: specifies the IRDA Handle.
  226. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  227. * UART peripheral (availability depending on device for UARTy).
  228. * @retval None
  229. */
  230. #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_IRDA_STATE_RESET)
  231. /** @brief Flushs the IRDA DR register
  232. * @param __HANDLE__: specifies the USART Handle.
  233. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  234. * UART peripheral (availability depending on device for UARTy).
  235. */
  236. #define __HAL_IRDA_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
  237. /** @brief Checks whether the specified IRDA flag is set or not.
  238. * @param __HANDLE__: specifies the IRDA Handle.
  239. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  240. * UART peripheral (availability depending on device for UARTy).
  241. * @param __FLAG__: specifies the flag to check.
  242. * This parameter can be one of the following values:
  243. * @arg IRDA_FLAG_TXE: Transmit data register empty flag
  244. * @arg IRDA_FLAG_TC: Transmission Complete flag
  245. * @arg IRDA_FLAG_RXNE: Receive data register not empty flag
  246. * @arg IRDA_FLAG_IDLE: Idle Line detection flag
  247. * @arg IRDA_FLAG_ORE: OverRun Error flag
  248. * @arg IRDA_FLAG_NE: Noise Error flag
  249. * @arg IRDA_FLAG_FE: Framing Error flag
  250. * @arg IRDA_FLAG_PE: Parity Error flag
  251. * @retval The new state of __FLAG__ (TRUE or FALSE).
  252. */
  253. #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  254. /** @brief Clears the specified IRDA pending flag.
  255. * @param __HANDLE__: specifies the IRDA Handle.
  256. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  257. * UART peripheral (availability depending on device for UARTy).
  258. * @param __FLAG__: specifies the flag to check.
  259. * This parameter can be any combination of the following values:
  260. * @arg IRDA_FLAG_TC: Transmission Complete flag.
  261. * @arg IRDA_FLAG_RXNE: Receive data register not empty flag.
  262. *
  263. * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
  264. * error) and IDLE (Idle line detected) flags are cleared by software
  265. * sequence: a read operation to USART_SR register followed by a read
  266. * operation to USART_DR register.
  267. * @note RXNE flag can be also cleared by a read to the USART_DR register.
  268. * @note TC flag can be also cleared by software sequence: a read operation to
  269. * USART_SR register followed by a write operation to USART_DR register.
  270. * @note TXE flag is cleared only by a write to the USART_DR register.
  271. *
  272. * @retval None
  273. */
  274. #define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  275. /** @brief Clear the IRDA PE pending flag.
  276. * @param __HANDLE__: specifies the IRDA Handle.
  277. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  278. * UART peripheral (availability depending on device for UARTy).
  279. * @retval None
  280. */
  281. #define __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__) do{(__HANDLE__)->Instance->SR;\
  282. (__HANDLE__)->Instance->DR;}while(0)
  283. /** @brief Clear the IRDA FE pending flag.
  284. * @param __HANDLE__: specifies the IRDA Handle.
  285. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  286. * UART peripheral (availability depending on device for UARTy).
  287. * @retval None
  288. */
  289. #define __HAL_IRDA_CLEAR_FEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  290. /** @brief Clear the IRDA NE pending flag.
  291. * @param __HANDLE__: specifies the IRDA Handle.
  292. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  293. * UART peripheral (availability depending on device for UARTy).
  294. * @retval None
  295. */
  296. #define __HAL_IRDA_CLEAR_NEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  297. /** @brief Clear the IRDA ORE pending flag.
  298. * @param __HANDLE__: specifies the IRDA Handle.
  299. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  300. * UART peripheral (availability depending on device for UARTy).
  301. * @retval None
  302. */
  303. #define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  304. /** @brief Clear the IRDA IDLE pending flag.
  305. * @param __HANDLE__: specifies the IRDA Handle.
  306. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  307. * UART peripheral (availability depending on device for UARTy).
  308. * @retval None
  309. */
  310. #define __HAL_IRDA_CLEAR_IDLEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
  311. /** @brief Enables the specified IRDA interrupt.
  312. * @param __HANDLE__: specifies the IRDA Handle.
  313. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  314. * UART peripheral (availability depending on device for UARTy).
  315. * @param __INTERRUPT__: specifies the IRDA interrupt source to enable.
  316. * This parameter can be one of the following values:
  317. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  318. * @arg IRDA_IT_TC: Transmission complete interrupt
  319. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  320. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  321. * @arg IRDA_IT_PE: Parity Error interrupt
  322. * @arg IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  323. * @retval None
  324. */
  325. #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
  326. (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
  327. ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & IRDA_IT_MASK)))
  328. /** @brief Disables the specified IRDA interrupt.
  329. * @param __HANDLE__: specifies the IRDA Handle.
  330. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  331. * UART peripheral (availability depending on device for UARTy).
  332. * @param __INTERRUPT__: specifies the IRDA interrupt source to disable.
  333. * This parameter can be one of the following values:
  334. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  335. * @arg IRDA_IT_TC: Transmission complete interrupt
  336. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  337. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  338. * @arg IRDA_IT_PE: Parity Error interrupt
  339. * @arg IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  340. * @retval None
  341. */
  342. #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
  343. (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
  344. ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & IRDA_IT_MASK)))
  345. /** @brief Checks whether the specified IRDA interrupt has occurred or not.
  346. * @param __HANDLE__: specifies the IRDA Handle.
  347. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  348. * UART peripheral (availability depending on device for UARTy).
  349. * @param __IT__: specifies the IRDA interrupt source to check.
  350. * This parameter can be one of the following values:
  351. * @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
  352. * @arg IRDA_IT_TC: Transmission complete interrupt
  353. * @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
  354. * @arg IRDA_IT_IDLE: Idle line detection interrupt
  355. * @arg USART_IT_ERR: Error interrupt
  356. * @arg IRDA_IT_PE: Parity Error interrupt
  357. * @retval The new state of __IT__ (TRUE or FALSE).
  358. */
  359. #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == 1)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28) == 2)? \
  360. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & IRDA_IT_MASK))
  361. /** @brief Enable UART/USART associated to IRDA Handle
  362. * @param __HANDLE__: specifies the IRDA Handle.
  363. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  364. * UART peripheral (availability depending on device for UARTy).
  365. * @retval None
  366. */
  367. #define __HAL_IRDA_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
  368. /** @brief Disable UART/USART associated to IRDA Handle
  369. * @param __HANDLE__: specifies the IRDA Handle.
  370. * This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
  371. * UART peripheral (availability depending on device for UARTy).
  372. * @retval None
  373. */
  374. #define __HAL_IRDA_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
  375. /**
  376. * @}
  377. */
  378. /* Private macros --------------------------------------------------------*/
  379. /** @defgroup IRDA_Private_Macros IRDA Private Macros
  380. * @{
  381. */
  382. #define IRDA_DIV(__PCLK__, __BAUD__) (((__PCLK__)*25)/(4*(__BAUD__)))
  383. #define IRDA_DIVMANT(__PCLK__, __BAUD__) (IRDA_DIV((__PCLK__), (__BAUD__))/100)
  384. #define IRDA_DIVFRAQ(__PCLK__, __BAUD__) (((IRDA_DIV((__PCLK__), (__BAUD__)) - (IRDA_DIVMANT((__PCLK__), (__BAUD__)) * 100)) * 16 + 50) / 100)
  385. #define IRDA_BRR(__PCLK__, __BAUD__) ((IRDA_DIVMANT((__PCLK__), (__BAUD__)) << 4)|(IRDA_DIVFRAQ((__PCLK__), (__BAUD__)) & 0x0F))
  386. /** @brief Ensure that IRDA Baud rate is less or equal to maximum value
  387. * @param __BAUDRATE__: specifies the IRDA Baudrate set by the user.
  388. * @retval True or False
  389. */
  390. #define IS_IRDA_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 115201)
  391. /**
  392. * @}
  393. */
  394. /* Exported functions --------------------------------------------------------*/
  395. /** @addtogroup IRDA_Exported_Functions IRDA Exported Functions
  396. * @{
  397. */
  398. /** @addtogroup IRDA_Exported_Functions_Group1 IrDA Initialization and de-initialization functions
  399. * @{
  400. */
  401. /* Initialization and de-initialization functions ****************************/
  402. HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda);
  403. HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda);
  404. void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda);
  405. void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda);
  406. /**
  407. * @}
  408. */
  409. /** @addtogroup IRDA_Exported_Functions_Group2 IO operation functions
  410. * @{
  411. */
  412. /* IO operation functions *****************************************************/
  413. HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  414. HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  415. HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  416. HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  417. HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  418. HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
  419. HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda);
  420. HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda);
  421. HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda);
  422. void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda);
  423. void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda);
  424. void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda);
  425. void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
  426. void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
  427. void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda);
  428. /**
  429. * @}
  430. */
  431. /** @addtogroup IRDA_Exported_Functions_Group3 Peripheral State and Errors functions
  432. * @{
  433. */
  434. /* Peripheral State and Error functions ***************************************/
  435. HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda);
  436. uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda);
  437. /**
  438. * @}
  439. */
  440. /**
  441. * @}
  442. */
  443. /**
  444. * @}
  445. */
  446. /**
  447. * @}
  448. */
  449. #ifdef __cplusplus
  450. }
  451. #endif
  452. #endif /* __STM32L1xx_HAL_IRDA_H */
  453. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/