stm32l1xx_hal_irda.h 25 KB

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