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 
37 /* Define to prevent recursive inclusion -------------------------------------*/
38 #ifndef __STM32L1xx_HAL_IRDA_H
39 #define __STM32L1xx_HAL_IRDA_H
40 
41 #ifdef __cplusplus
42  extern "C" {
43 #endif
44 
45 /* Includes ------------------------------------------------------------------*/
46 #include "stm32l1xx_hal_def.h"
47 
48 /** @addtogroup STM32L1xx_HAL_Driver
49   * @{
50   */
51 
52 /** @addtogroup IRDA
53   * @{
54   */
55 
56 /* Exported types ------------------------------------------------------------*/
57 /** @defgroup IRDA_Exported_Types IRDA Exported Types
58   * @{
59   */
60 
61 /**
62   * @brief IRDA Init Structure definition
63   */
64 typedef struct
65 {
66   uint32_t BaudRate;                  /*!< This member configures the IRDA communication baud rate.
67                                            The baud rate is computed using the following formula:
68                                            - IntegerDivider = ((PCLKx) / (16 * (hirda->Init.BaudRate)))
69                                            - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */
70 
71   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
72                                            This parameter can be a value of @ref IRDA_Word_Length */
73 
74 
75   uint32_t Parity;                    /*!< Specifies the parity mode.
76                                            This parameter can be a value of @ref IRDA_Parity
77                                            @note When parity is enabled, the computed parity is inserted
78                                                  at the MSB position of the transmitted data (9th bit when
79                                                  the word length is set to 9 data bits; 8th bit when the
80                                                  word length is set to 8 data bits). */
81 
82   uint32_t Mode;                      /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
83                                            This parameter can be a value of @ref IRDA_Transfer_Mode */
84 
85   uint8_t  Prescaler;                 /*!< Specifies the Prescaler value prescaler value to be programmed
86                                            in the IrDA low-power Baud Register, for defining pulse width on which
87                                            burst acceptance/rejection will be decided. This value is used as divisor
88                                            of system clock to achieve required pulse width. */
89 
90   uint32_t IrDAMode;                  /*!< Specifies the IrDA mode
91                                            This parameter can be a value of @ref IRDA_Low_Power */
92 }IRDA_InitTypeDef;
93 
94 /**
95   * @brief HAL IRDA State structures definition
96   */
97 typedef enum
98 {
99   HAL_IRDA_STATE_RESET             = 0x00,    /*!< Peripheral is not initialized */
100   HAL_IRDA_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use */
101   HAL_IRDA_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing */
102   HAL_IRDA_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing */
103   HAL_IRDA_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing */
104   HAL_IRDA_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission and Reception process is ongoing */
105   HAL_IRDA_STATE_TIMEOUT           = 0x03,    /*!< Timeout state */
106   HAL_IRDA_STATE_ERROR             = 0x04     /*!< Error */
107 }HAL_IRDA_StateTypeDef;
108 
109 
110 /**
111   * @brief  IRDA handle Structure definition
112   */
113 typedef struct
114 {
115   USART_TypeDef               *Instance;        /*!< USART registers base address       */
116 
117   IRDA_InitTypeDef            Init;             /*!< IRDA communication parameters      */
118 
119   uint8_t                     *pTxBuffPtr;      /*!< Pointer to IRDA Tx transfer Buffer */
120 
121   uint16_t                    TxXferSize;       /*!< IRDA Tx Transfer size              */
122 
123   uint16_t                    TxXferCount;      /*!< IRDA Tx Transfer Counter           */
124 
125   uint8_t                     *pRxBuffPtr;      /*!< Pointer to IRDA Rx transfer Buffer */
126 
127   uint16_t                    RxXferSize;       /*!< IRDA Rx Transfer size              */
128 
129   uint16_t                    RxXferCount;      /*!< IRDA Rx Transfer Counter           */
130 
131   DMA_HandleTypeDef           *hdmatx;          /*!< IRDA Tx DMA Handle parameters      */
132 
133   DMA_HandleTypeDef           *hdmarx;          /*!< IRDA Rx DMA Handle parameters      */
134 
135   HAL_LockTypeDef             Lock;             /*!< Locking object                     */
136 
137   __IO HAL_IRDA_StateTypeDef  State;            /*!< IRDA communication state           */
138 
139   __IO uint32_t               ErrorCode;        /*!< IRDA Error code                    */
140 
141 }IRDA_HandleTypeDef;
142 
143 /**
144   * @}
145   */
146 
147 /* Exported constants --------------------------------------------------------*/
148 /** @defgroup IRDA_Exported_Constants IRDA Exported constants
149   * @{
150   */
151 
152 /** @defgroup IRDA_Error_Codes IRDA Error Codes
153   * @{
154   */
155 #define HAL_IRDA_ERROR_NONE      (0x00U)    /*!< No error            */
156 #define HAL_IRDA_ERROR_PE        (0x01U)    /*!< Parity error        */
157 #define HAL_IRDA_ERROR_NE        (0x02U)    /*!< Noise error         */
158 #define HAL_IRDA_ERROR_FE        (0x04U)    /*!< frame error         */
159 #define HAL_IRDA_ERROR_ORE       (0x08U)    /*!< Overrun error       */
160 #define HAL_IRDA_ERROR_DMA       (0x10U)    /*!< DMA transfer error  */
161 
162 /**
163   * @}
164   */
165 
166 
167 /** @defgroup IRDA_Word_Length IRDA Word Length
168   * @{
169   */
170 #define IRDA_WORDLENGTH_8B                  (0x00000000U)
171 #define IRDA_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
172 /**
173   * @}
174   */
175 
176 /** @defgroup IRDA_Parity IRDA Parity
177   * @{
178   */
179 #define IRDA_PARITY_NONE                    (0x00000000U)
180 #define IRDA_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
181 #define IRDA_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
182 /**
183   * @}
184   */
185 
186 /** @defgroup IRDA_Transfer_Mode IRDA Transfer Mode
187   * @{
188   */
189 #define IRDA_MODE_RX                        ((uint32_t)USART_CR1_RE)
190 #define IRDA_MODE_TX                        ((uint32_t)USART_CR1_TE)
191 #define IRDA_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
192 /**
193   * @}
194   */
195 
196 /** @defgroup IRDA_Low_Power IRDA Low Power
197   * @{
198   */
199 #define IRDA_POWERMODE_LOWPOWER             ((uint32_t)USART_CR3_IRLP)
200 #define IRDA_POWERMODE_NORMAL               (0x00000000U)
201 /**
202   * @}
203   */
204 
205 /** @defgroup IRDA_One_Bit  IRDA One Bit Sampling
206   * @{
207   */
208 #define IRDA_ONE_BIT_SAMPLE_DISABLE         (0x00000000U)
209 #define IRDA_ONE_BIT_SAMPLE_ENABLE          ((uint32_t)USART_CR3_ONEBIT)
210 /**
211   * @}
212   */
213 
214 /** @defgroup IRDA_Flags IRDA Flags
215   *        Elements values convention: 0xXXXX
216   *           - 0xXXXX  : Flag mask in the SR register
217   * @{
218   */
219 #define IRDA_FLAG_TXE                       ((uint32_t)USART_SR_TXE)
220 #define IRDA_FLAG_TC                        ((uint32_t)USART_SR_TC)
221 #define IRDA_FLAG_RXNE                      ((uint32_t)USART_SR_RXNE)
222 #define IRDA_FLAG_IDLE                      ((uint32_t)USART_SR_IDLE)
223 #define IRDA_FLAG_ORE                       ((uint32_t)USART_SR_ORE)
224 #define IRDA_FLAG_NE                        ((uint32_t)USART_SR_NE)
225 #define IRDA_FLAG_FE                        ((uint32_t)USART_SR_FE)
226 #define IRDA_FLAG_PE                        ((uint32_t)USART_SR_PE)
227 /**
228   * @}
229   */
230 
231 /** @defgroup IRDA_Interrupt_definition IRDA Interrupt Definitions
232   *        Elements values convention: 0xY000XXXX
233   *           - XXXX  : Interrupt mask (16 bits) in the Y register
234   *           - Y  : Interrupt source register (4 bits)
235   *                 - 0001: CR1 register
236   *                 - 0010: CR2 register
237   *                 - 0011: CR3 register
238   *
239   * @{
240   */
241 
242 #define IRDA_IT_PE                          ((uint32_t)(IRDA_CR1_REG_INDEX << 28 | USART_CR1_PEIE))
243 #define IRDA_IT_TXE                         ((uint32_t)(IRDA_CR1_REG_INDEX << 28 | USART_CR1_TXEIE))
244 #define IRDA_IT_TC                          ((uint32_t)(IRDA_CR1_REG_INDEX << 28 | USART_CR1_TCIE))
245 #define IRDA_IT_RXNE                        ((uint32_t)(IRDA_CR1_REG_INDEX << 28 | USART_CR1_RXNEIE))
246 #define IRDA_IT_IDLE                        ((uint32_t)(IRDA_CR1_REG_INDEX << 28 | USART_CR1_IDLEIE))
247 
248 #define IRDA_IT_LBD                         ((uint32_t)(IRDA_CR2_REG_INDEX << 28 | USART_CR2_LBDIE))
249 
250 #define IRDA_IT_CTS                         ((uint32_t)(IRDA_CR3_REG_INDEX << 28 | USART_CR3_CTSIE))
251 #define IRDA_IT_ERR                         ((uint32_t)(IRDA_CR3_REG_INDEX << 28 | USART_CR3_EIE))
252 
253 /**
254   * @}
255   */
256 
257 /**
258   * @}
259   */
260 
261 
262 /* Exported macro ------------------------------------------------------------*/
263 /** @defgroup IRDA_Exported_Macros IRDA Exported Macros
264   * @{
265   */
266 
267 /** @brief Reset IRDA handle state
268   * @param  __HANDLE__: specifies the IRDA Handle.
269   *         IRDA Handle selects the USARTx or UARTy peripheral
270   *         (USART,UART availability and x,y values depending on device).
271   * @retval None
272   */
273 #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_IRDA_STATE_RESET)
274 
275 /** @brief  Flush the IRDA DR register
276   * @param  __HANDLE__: specifies the USART Handle.
277   *         IRDA Handle selects the USARTx or UARTy peripheral
278   *         (USART,UART availability and x,y values depending on device).
279   */
280 #define __HAL_IRDA_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
281 
282 /** @brief  Check whether the specified IRDA flag is set or not.
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   * @param  __FLAG__: specifies the flag to check.
287   *        This parameter can be one of the following values:
288   *            @arg IRDA_FLAG_TXE:  Transmit data register empty flag
289   *            @arg IRDA_FLAG_TC:   Transmission Complete flag
290   *            @arg IRDA_FLAG_RXNE: Receive data register not empty flag
291   *            @arg IRDA_FLAG_IDLE: Idle Line detection flag
292   *            @arg IRDA_FLAG_ORE:  OverRun Error flag
293   *            @arg IRDA_FLAG_NE:   Noise Error flag
294   *            @arg IRDA_FLAG_FE:   Framing Error flag
295   *            @arg IRDA_FLAG_PE:   Parity Error flag
296   * @retval The new state of __FLAG__ (TRUE or FALSE).
297   */
298 #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
299 
300 /** @brief  Clear the specified IRDA pending flag.
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   * @param  __FLAG__: specifies the flag to check.
305   *          This parameter can be any combination of the following values:
306   *            @arg IRDA_FLAG_TC:   Transmission Complete flag.
307   *            @arg IRDA_FLAG_RXNE: Receive data register not empty flag.
308   *
309   * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
310   *          error) and IDLE (Idle line detected) flags are cleared by software
311   *          sequence: a read operation to USART_SR register followed by a read
312   *          operation to USART_DR register.
313   * @note   RXNE flag can be also cleared by a read to the USART_DR register.
314   * @note   TC flag can be also cleared by software sequence: a read operation to
315   *          USART_SR register followed by a write operation to USART_DR register.
316   * @note   TXE flag is cleared only by a write to the USART_DR register.
317   *
318   * @retval None
319   */
320 #define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
321 
322 /** @brief  Clear the IRDA PE pending flag.
323   * @param  __HANDLE__: specifies the IRDA Handle.
324   *         IRDA Handle selects the USARTx or UARTy peripheral
325   *         (USART,UART availability and x,y values depending on device).
326   * @retval None
327   */
328 #define __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__) \
329 do{                                         \
330   __IO uint32_t tmpreg;                     \
331   tmpreg = (__HANDLE__)->Instance->SR;      \
332   tmpreg = (__HANDLE__)->Instance->DR;      \
333   UNUSED(tmpreg);                           \
334   }while(0)                                 \
335 
336 /** @brief  Clear the IRDA FE pending flag.
337   * @param  __HANDLE__: specifies the IRDA Handle.
338   *         IRDA Handle selects the USARTx or UARTy peripheral
339   *         (USART,UART availability and x,y values depending on device).
340   * @retval None
341   */
342 #define __HAL_IRDA_CLEAR_FEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
343 
344 /** @brief  Clear the IRDA NE 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_NEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
351 
352 /** @brief  Clear the IRDA ORE pending flag.
353   * @param  __HANDLE__: specifies the IRDA Handle.
354   *         IRDA Handle selects the USARTx or UARTy peripheral
355   *         (USART,UART availability and x,y values depending on device).
356   * @retval None
357   */
358 #define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
359 
360 /** @brief  Clear the IRDA IDLE pending flag.
361   * @param  __HANDLE__: specifies the IRDA Handle.
362   *         IRDA Handle selects the USARTx or UARTy peripheral
363   *         (USART,UART availability and x,y values depending on device).
364   * @retval None
365   */
366 #define __HAL_IRDA_CLEAR_IDLEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
367 
368 /** @brief  Enable the specified IRDA interrupt.
369   * @param  __HANDLE__: specifies the IRDA Handle.
370   *         IRDA Handle selects the USARTx or UARTy peripheral
371   *         (USART,UART availability and x,y values depending on device).
372   * @param  __INTERRUPT__: specifies the IRDA interrupt source to enable.
373   *          This parameter can be one of the following values:
374   *            @arg IRDA_IT_TXE:  Transmit Data Register empty interrupt
375   *            @arg IRDA_IT_TC:   Transmission complete interrupt
376   *            @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
377   *            @arg IRDA_IT_IDLE: Idle line detection interrupt
378   *            @arg IRDA_IT_PE:   Parity Error interrupt
379   *            @arg IRDA_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
380   * @retval None
381   */
382 #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
383                                                            (((__INTERRUPT__) >> 28) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & IRDA_IT_MASK)): \
384                                                            ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & IRDA_IT_MASK)))
385 
386 /** @brief  Disable the specified IRDA interrupt.
387   * @param  __HANDLE__: specifies the IRDA Handle.
388   *         IRDA Handle selects the USARTx or UARTy peripheral
389   *         (USART,UART availability and x,y values depending on device).
390   * @param  __INTERRUPT__: specifies the IRDA interrupt source to disable.
391   *          This parameter can be one of the following values:
392   *            @arg IRDA_IT_TXE:  Transmit Data Register empty interrupt
393   *            @arg IRDA_IT_TC:   Transmission complete interrupt
394   *            @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
395   *            @arg IRDA_IT_IDLE: Idle line detection interrupt
396   *            @arg IRDA_IT_PE:   Parity Error interrupt
397   *            @arg IRDA_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
398   * @retval None
399   */
400 #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
401                                                            (((__INTERRUPT__) >> 28) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
402                                                            ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & IRDA_IT_MASK)))
403 
404 /** @brief  Check whether the specified IRDA interrupt has occurred or not.
405   * @param  __HANDLE__: specifies the IRDA Handle.
406   *         IRDA Handle selects the USARTx or UARTy peripheral
407   *         (USART,UART availability and x,y values depending on device).
408   * @param  __IT__: specifies the IRDA interrupt source to check.
409   *          This parameter can be one of the following values:
410   *            @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
411   *            @arg IRDA_IT_TC:  Transmission complete interrupt
412   *            @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
413   *            @arg IRDA_IT_IDLE: Idle line detection interrupt
414   *            @arg IRDA_IT_ERR: Error interrupt
415   *            @arg IRDA_IT_PE: Parity Error interrupt
416   * @retval The new state of __IT__ (TRUE or FALSE).
417   */
418 #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == IRDA_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:((((__IT__) >> 28) == IRDA_CR2_REG_INDEX)? \
419                                                       (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & IRDA_IT_MASK))
420 
421 /** @brief  Enables the IRDA one bit sample method
422   * @param  __HANDLE__: specifies the IRDA Handle.
423   * @retval None
424   */
425 #define __HAL_IRDA_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR3, (USART_CR3_ONEBIT)))
426 
427 /** @brief  Disables the IRDA one bit sample method
428   * @param  __HANDLE__: specifies the IRDA Handle.
429   * @retval None
430   */
431 #define __HAL_IRDA_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR3, (USART_CR3_ONEBIT)))
432 
433 /** @brief  Enable UART/USART associated to IRDA Handle
434   * @param  __HANDLE__: specifies the IRDA Handle.
435   *         IRDA Handle selects the USARTx or UARTy peripheral
436   *         (USART,UART availability and x,y values depending on device).
437   * @retval None
438   */
439 #define __HAL_IRDA_ENABLE(__HANDLE__)                   (SET_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
440 
441 /** @brief  Disable UART/USART associated to IRDA Handle
442   * @param  __HANDLE__: specifies the IRDA Handle.
443   *         IRDA Handle selects the USARTx or UARTy peripheral
444   *         (USART,UART availability and x,y values depending on device).
445   * @retval None
446   */
447 #define __HAL_IRDA_DISABLE(__HANDLE__)                  (CLEAR_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
448 
449 /**
450   * @}
451   */
452 
453 /* Private macros --------------------------------------------------------*/
454 /** @defgroup IRDA_Private_Macros   IRDA Private Macros
455   * @{
456   */
457 
458 #define IRDA_CR1_REG_INDEX                  1
459 #define IRDA_CR2_REG_INDEX                  2
460 #define IRDA_CR3_REG_INDEX                  3
461 
462 #define IRDA_DIV(__PCLK__, __BAUD__)                    (((__PCLK__)*25)/(4*(__BAUD__)))
463 #define IRDA_DIVMANT(__PCLK__, __BAUD__)                (IRDA_DIV((__PCLK__), (__BAUD__))/100)
464 #define IRDA_DIVFRAQ(__PCLK__, __BAUD__)                (((IRDA_DIV((__PCLK__), (__BAUD__)) - (IRDA_DIVMANT((__PCLK__), (__BAUD__)) * 100)) * 16 + 50) / 100)
465 /* UART BRR = mantissa + overflow + fraction
466             = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0F) */
467 #define IRDA_BRR(_PCLK_, _BAUD_)            (((IRDA_DIVMANT((_PCLK_), (_BAUD_)) << 4) + \
468                                              (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0)) + \
469                                              (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F))
470 
471 /** Ensure that IRDA Baud rate is less or equal to maximum value
472   *    __BAUDRATE__: specifies the IRDA Baudrate set by the user.
473   *                  The maximum Baud Rate is 115200bps
474   * Returns : True or False
475   */
476 #define IS_IRDA_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 115201)
477 
478 #define IS_IRDA_WORD_LENGTH(LENGTH)    (((LENGTH) == IRDA_WORDLENGTH_8B) || \
479                                         ((LENGTH) == IRDA_WORDLENGTH_9B))
480 
481 #define IS_IRDA_PARITY(PARITY)         (((PARITY) == IRDA_PARITY_NONE) || \
482                                         ((PARITY) == IRDA_PARITY_EVEN) || \
483                                         ((PARITY) == IRDA_PARITY_ODD))
484 
485 #define IS_IRDA_MODE(MODE)             ((((MODE) & (~((uint32_t)IRDA_MODE_TX_RX))) == 0x00) && \
486                                         ((MODE) != 0x00000000U))
487 
488 #define IS_IRDA_POWERMODE(MODE)        (((MODE) == IRDA_POWERMODE_LOWPOWER) || \
489                                         ((MODE) == IRDA_POWERMODE_NORMAL))
490 
491 /** IRDA interruptions flag mask
492   *
493   */
494 #define IRDA_IT_MASK  ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
495                                   USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
496 
497 /**
498   * @}
499   */
500 
501 
502 /* Exported functions --------------------------------------------------------*/
503 
504 /** @addtogroup IRDA_Exported_Functions IRDA Exported Functions
505   * @{
506   */
507 
508 /** @addtogroup IRDA_Exported_Functions_Group1 Initialization and de-initialization functions
509   * @{
510   */
511 
512 /* Initialization and de-initialization functions  ****************************/
513 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda);
514 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda);
515 void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda);
516 void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda);
517 
518 /**
519   * @}
520   */
521 
522 /** @addtogroup IRDA_Exported_Functions_Group2 IO operation functions
523   * @{
524   */
525 
526 /* IO operation functions *****************************************************/
527 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
528 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
529 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
530 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
531 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
532 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
533 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda);
534 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda);
535 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda);
536 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda);
537 void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda);
538 void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda);
539 void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
540 void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
541 void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda);
542 
543 /**
544   * @}
545   */
546 
547 /** @addtogroup IRDA_Exported_Functions_Group3 Peripheral State and Errors functions
548   * @{
549   */
550 
551 /* Peripheral State and Error functions ***************************************/
552 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda);
553 uint32_t              HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda);
554 
555 /**
556   * @}
557   */
558 
559 /**
560   * @}
561   */
562 
563 /**
564   * @}
565   */
566 
567 /**
568   * @}
569   */
570 
571 #ifdef __cplusplus
572 }
573 #endif
574 
575 #endif /* __STM32L1xx_HAL_IRDA_H */
576 
577 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
578