1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_irda.h
4   * @author  MCD Application Team
5   * @brief   Header file of IRDA HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35 
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32L0xx_HAL_IRDA_H
38 #define __STM32L0xx_HAL_IRDA_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32l0xx_hal_def.h"
46 
47 /** @addtogroup STM32L0xx_HAL_Driver
48   * @{
49   */
50 
51 /** @addtogroup IRDA
52   * @{
53   */
54 
55 /* Exported types ------------------------------------------------------------*/
56 /** @defgroup IRDA_Exported_Types IRDA Exported Types
57   * @{
58   */
59 
60 /**
61   * @brief IRDA Init Structure definition
62   */
63 typedef struct
64 {
65   uint32_t BaudRate;                  /*!< This member configures the IRDA communication baud rate.
66                                            The baud rate register is computed using the following formula:
67                                               Baud Rate Register = ((PCLKx) / ((hirda->Init.BaudRate))) */
68 
69   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
70                                            This parameter can be a value of @ref IRDA_Word_Length */
71 
72   uint32_t Parity;                    /*!< Specifies the parity mode.
73                                            This parameter can be a value of @ref IRDA_Parity
74                                            @note When parity is enabled, the computed parity is inserted
75                                                  at the MSB position of the transmitted data (9th bit when
76                                                  the word length is set to 9 data bits; 8th bit when the
77                                                  word length is set to 8 data bits). */
78 
79   uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
80                                            This parameter can be a value of @ref IRDA_Transfer_Mode */
81 
82   uint8_t  Prescaler;                 /*!< Specifies the Prescaler value for dividing the UART/USART source clock
83                                            to achieve low-power frequency.
84                                            @note Prescaler value 0 is forbidden */
85 
86   uint16_t PowerMode;                 /*!< Specifies the IRDA power mode.
87                                            This parameter can be a value of @ref IRDA_Low_Power */
88 }IRDA_InitTypeDef;
89 
90 /**
91   * @brief HAL IRDA State structures definition
92   * @note  HAL IRDA State value is a combination of 2 different substates: gState and RxState.
93   *        - gState contains IRDA state information related to global Handle management
94   *          and also information related to Tx operations.
95   *          gState value coding follow below described bitmap :
96   *          b7-b6  Error information
97   *             00 : No Error
98   *             01 : (Not Used)
99   *             10 : Timeout
100   *             11 : Error
101   *          b5     IP initilisation status
102   *             0  : Reset (IP not initialized)
103   *             1  : Init done (IP not initialized. HAL IRDA Init function already called)
104   *          b4-b3  (not used)
105   *             xx : Should be set to 00
106   *          b2     Intrinsic process state
107   *             0  : Ready
108   *             1  : Busy (IP busy with some configuration or internal operations)
109   *          b1     (not used)
110   *             x  : Should be set to 0
111   *          b0     Tx state
112   *             0  : Ready (no Tx operation ongoing)
113   *             1  : Busy (Tx operation ongoing)
114   *        - RxState contains information related to Rx operations.
115   *          RxState value coding follow below described bitmap :
116   *          b7-b6  (not used)
117   *             xx : Should be set to 00
118   *          b5     IP initilisation status
119   *             0  : Reset (IP not initialized)
120   *             1  : Init done (IP not initialized)
121   *          b4-b2  (not used)
122   *            xxx : Should be set to 000
123   *          b1     Rx state
124   *             0  : Ready (no Rx operation ongoing)
125   *             1  : Busy (Rx operation ongoing)
126   *          b0     (not used)
127   *             x  : Should be set to 0.
128   */
129 typedef enum
130 {
131   HAL_IRDA_STATE_RESET             = 0x00U,   /*!< Peripheral is not initialized
132                                                    Value is allowed for gState and RxState */
133   HAL_IRDA_STATE_READY             = 0x20U,   /*!< Peripheral Initialized and ready for use
134                                                    Value is allowed for gState and RxState */
135   HAL_IRDA_STATE_BUSY              = 0x24U,   /*!< an internal process is ongoing
136                                                    Value is allowed for gState only */
137   HAL_IRDA_STATE_BUSY_TX           = 0x21U,   /*!< Data Transmission process is ongoing
138                                                    Value is allowed for gState only */
139   HAL_IRDA_STATE_BUSY_RX           = 0x22U,   /*!< Data Reception process is ongoing
140                                                    Value is allowed for RxState only */
141   HAL_IRDA_STATE_BUSY_TX_RX        = 0x23U,   /*!< Data Transmission and Reception process is ongoing
142                                                    Not to be used for neither gState nor RxState.
143                                                    Value is result of combination (Or) between gState and RxState values */
144   HAL_IRDA_STATE_TIMEOUT           = 0xA0U,   /*!< Timeout state
145                                                    Value is allowed for gState only */
146   HAL_IRDA_STATE_ERROR             = 0xE0U    /*!< Error
147                                                    Value is allowed for gState only */
148 }HAL_IRDA_StateTypeDef;
149 
150 /**
151   * @brief  HAL IRDA Error Code structure definition
152   */
153 
154 #define  HAL_IRDA_ERROR_NONE      ((uint32_t)0x00U)    /*!< No error            */
155 #define  HAL_IRDA_ERROR_PE        ((uint32_t)0x01U)    /*!< Parity error        */
156 #define  HAL_IRDA_ERROR_NE        ((uint32_t)0x02U)    /*!< Noise error         */
157 #define  HAL_IRDA_ERROR_FE        ((uint32_t)0x04U)    /*!< frame error         */
158 #define  HAL_IRDA_ERROR_ORE       ((uint32_t)0x08U)    /*!< Overrun error       */
159 #define  HAL_IRDA_ERROR_DMA       ((uint32_t)0x10U)    /*!< DMA transfer error  */
160 
161 /**
162   * @brief IRDA clock sources definition
163   */
164 typedef enum
165 {
166   IRDA_CLOCKSOURCE_PCLK1      = 0x00U,    /*!< PCLK1 clock source     */
167   IRDA_CLOCKSOURCE_PCLK2      = 0x01U,    /*!< PCLK2 clock source     */
168   IRDA_CLOCKSOURCE_HSI        = 0x02U,    /*!< HSI clock source       */
169   IRDA_CLOCKSOURCE_SYSCLK     = 0x04U,    /*!< SYSCLK clock source    */
170   IRDA_CLOCKSOURCE_LSE        = 0x08U,    /*!< LSE clock source       */
171   IRDA_CLOCKSOURCE_UNDEFINED  = 0x10U     /*!< Undefined clock source */
172 }IRDA_ClockSourceTypeDef;
173 
174 /**
175   * @brief  IRDA handle Structure definition
176   */
177 typedef struct
178 {
179   USART_TypeDef            *Instance;        /*!< IRDA registers base address        */
180 
181   IRDA_InitTypeDef         Init;             /*!< IRDA communication parameters      */
182 
183   uint8_t                  *pTxBuffPtr;      /*!< Pointer to IRDA Tx transfer Buffer */
184 
185   uint16_t                 TxXferSize;       /*!< IRDA Tx Transfer size              */
186 
187   __IO uint16_t            TxXferCount;      /*!< IRDA Tx Transfer Counter           */
188 
189   uint8_t                  *pRxBuffPtr;      /*!< Pointer to IRDA Rx transfer Buffer */
190 
191   uint16_t                 RxXferSize;       /*!< IRDA Rx Transfer size              */
192 
193   __IO uint16_t            RxXferCount;      /*!< IRDA Rx Transfer Counter           */
194 
195   uint16_t                 Mask;             /*!< IRDA RX RDR register mask          */
196 
197   DMA_HandleTypeDef        *hdmatx;          /*!< IRDA Tx DMA Handle parameters      */
198 
199   DMA_HandleTypeDef        *hdmarx;          /*!< IRDA Rx DMA Handle parameters      */
200 
201   HAL_LockTypeDef          Lock;             /*!< Locking object                     */
202 
203   __IO HAL_IRDA_StateTypeDef    gState;      /*!< IRDA state information related to global Handle management
204                                                   and also related to Tx operations.
205                                                   This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
206 
207   __IO HAL_IRDA_StateTypeDef    RxState;     /*!< IRDA state information related to Rx operations.
208                                                   This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
209 
210   __IO uint32_t           ErrorCode;        /*!< IRDA Error code                    */
211 
212 }IRDA_HandleTypeDef;
213 
214 /**
215   * @}
216   */
217 
218 /* Exported constants --------------------------------------------------------*/
219 /** @defgroup IRDA_Exported_Constants IRDA Exported Constants
220   * @{
221   */
222 
223 /** @defgroup IRDA_Word_Length IRDA Word Length
224   * @{
225   */
226 #define IRDA_WORDLENGTH_7B                  ((uint32_t)USART_CR1_M1)   /*!< 7-bit long frame */
227 #define IRDA_WORDLENGTH_8B                  ((uint32_t)0x00000000)     /*!< 8-bit long frame */
228 #define IRDA_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M0)   /*!< 9-bit long frame */
229 /**
230   * @}
231   */
232 
233 /** @defgroup IRDA_Parity IRDA Parity
234   * @{
235   */
236 #define IRDA_PARITY_NONE                    ((uint32_t)0x00000000U)                     /*!< No parity   */
237 #define IRDA_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)                   /*!< Even parity */
238 #define IRDA_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))  /*!< Odd parity  */
239 /**
240   * @}
241   */
242 
243 /** @defgroup IRDA_Transfer_Mode IRDA Transfer Mode
244   * @{
245   */
246 #define IRDA_MODE_RX                        ((uint32_t)USART_CR1_RE)                   /*!< RX mode        */
247 #define IRDA_MODE_TX                        ((uint32_t)USART_CR1_TE)                   /*!< TX mode        */
248 #define IRDA_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))   /*!< RX and TX mode */
249 /**
250   * @}
251   */
252 
253 /** @defgroup IRDA_Low_Power IRDA Low Power
254   * @{
255   */
256 #define IRDA_POWERMODE_NORMAL               ((uint32_t)0x00000000U)      /*!< IRDA normal power mode */
257 #define IRDA_POWERMODE_LOWPOWER             ((uint32_t)USART_CR3_IRLP)   /*!< IRDA low power mode    */
258 /**
259   * @}
260   */
261 
262 /** @defgroup IRDA_State IRDA State
263   * @{
264   */
265 #define IRDA_STATE_DISABLE                  ((uint32_t)0x00000000U)    /*!< IRDA disabled  */
266 #define IRDA_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)   /*!< IRDA enabled   */
267 /**
268   * @}
269   */
270 
271 /** @defgroup IRDA_Mode IRDA Mode
272   * @{
273   */
274 #define IRDA_MODE_DISABLE                   ((uint32_t)0x00000000U)     /*!< Associated UART disabled in IRDA mode */
275 #define IRDA_MODE_ENABLE                    ((uint32_t)USART_CR3_IREN)  /*!< Associated UART enabled in IRDA mode  */
276 /**
277   * @}
278   */
279 
280 /** @defgroup IRDA_One_Bit  IRDA One Bit Sampling
281   * @{
282   */
283 #define IRDA_ONE_BIT_SAMPLE_DISABLE         ((uint32_t)0x00000000U)      /*!< One-bit sampling disabled */
284 #define IRDA_ONE_BIT_SAMPLE_ENABLE          ((uint32_t)USART_CR3_ONEBIT) /*!< One-bit sampling enabled  */
285 /**
286   * @}
287   */
288 
289 /** @defgroup IRDA_DMA_Tx IRDA DMA Tx
290   * @{
291   */
292 #define IRDA_DMA_TX_DISABLE                 ((uint32_t)0x00000000U)      /*!< IRDA DMA TX disabled */
293 #define IRDA_DMA_TX_ENABLE                  ((uint32_t)USART_CR3_DMAT)   /*!< IRDA DMA TX enabled  */
294 /**
295   * @}
296   */
297 
298 /** @defgroup IRDA_DMA_Rx  IRDA DMA Rx
299   * @{
300   */
301 #define IRDA_DMA_RX_DISABLE                 ((uint32_t)0x00000000)       /*!< IRDA DMA RX disabled */
302 #define IRDA_DMA_RX_ENABLE                  ((uint32_t)USART_CR3_DMAR)   /*!< IRDA DMA RX enabled  */
303 /**
304   * @}
305   */
306 
307 /** @defgroup IRDA_Request_Parameters IRDA Request Parameters
308   * @{
309   */
310 #define IRDA_AUTOBAUD_REQUEST            ((uint16_t)USART_RQR_ABRRQ)        /*!< Auto-Baud Rate Request      */
311 #define IRDA_RXDATA_FLUSH_REQUEST        ((uint16_t)USART_RQR_RXFRQ)        /*!< Receive Data flush Request  */
312 #define IRDA_TXDATA_FLUSH_REQUEST        ((uint16_t)USART_RQR_TXFRQ)        /*!< Transmit data flush Request */
313 /**
314   * @}
315   */
316 
317 /** @defgroup IRDA_Flags IRDA Flags
318   *        Elements values convention: 0xXXXX
319   *           - 0xXXXX  : Flag mask in the ISR register
320   * @{
321   */
322 #define IRDA_FLAG_REACK                     USART_ISR_REACK  /*!< IRDA Receive enable acknowledge flag  */
323 #define IRDA_FLAG_TEACK                     USART_ISR_TEACK  /*!< IRDA Transmit enable acknowledge flag */
324 #define IRDA_FLAG_BUSY                      USART_ISR_BUSY   /*!< IRDA Busy flag                        */
325 #define IRDA_FLAG_ABRF                      USART_ISR_ABRF   /*!< IRDA Auto baud rate flag              */
326 #define IRDA_FLAG_ABRE                      USART_ISR_ABRE   /*!< IRDA Auto baud rate error             */
327 #define IRDA_FLAG_TXE                       USART_ISR_TXE    /*!< IRDA Transmit data register empty     */
328 #define IRDA_FLAG_TC                        USART_ISR_TC     /*!< IRDA Transmission complete            */
329 #define IRDA_FLAG_RXNE                      USART_ISR_RXNE   /*!< IRDA Read data register not empty     */
330 #define IRDA_FLAG_ORE                       USART_ISR_ORE    /*!< IRDA Overrun error                    */
331 #define IRDA_FLAG_NE                        USART_ISR_NE     /*!< IRDA Noise error                      */
332 #define IRDA_FLAG_FE                        USART_ISR_FE     /*!< IRDA Framing error                    */
333 #define IRDA_FLAG_PE                        USART_ISR_PE     /*!< IRDA Parity error                     */
334 /**
335   * @}
336   */
337 
338 /** @defgroup IRDA_Interrupt_definition IRDA Interrupts Definition
339   *        Elements values convention: 0000ZZZZ0XXYYYYYb
340   *           - YYYYY  : Interrupt source position in the XX register (5bits)
341   *           - XX  : Interrupt source register (2bits)
342   *                 - 01: CR1 register
343   *                 - 10: CR2 register
344   *                 - 11: CR3 register
345   *           - ZZZZ  : Flag position in the ISR register(4bits)
346   * @{
347   */
348 #define IRDA_IT_PE                          ((uint16_t)0x0028U)     /*!< IRDA Parity error interruption                 */
349 #define IRDA_IT_TXE                         ((uint16_t)0x0727U)     /*!< IRDA Transmit data register empty interruption */
350 #define IRDA_IT_TC                          ((uint16_t)0x0626U)     /*!< IRDA Transmission complete interruption        */
351 #define IRDA_IT_RXNE                        ((uint16_t)0x0525U)     /*!< IRDA Read data register not empty interruption */
352 #define IRDA_IT_IDLE                        ((uint16_t)0x0424U)     /*!< IRDA Idle interruption                         */
353 
354 /**       Elements values convention: 000000000XXYYYYYb
355   *           - YYYYY  : Interrupt source position in the XX register (5bits)
356   *           - XX  : Interrupt source register (2bits)
357   *                 - 01: CR1 register
358   *                 - 10: CR2 register
359   *                 - 11: CR3 register
360   */
361 #define IRDA_IT_ERR                         ((uint16_t)0x0060U)       /*!< IRDA Error interruption        */
362 
363 /**       Elements values convention: 0000ZZZZ00000000b
364   *           - ZZZZ  : Flag position in the ISR register(4bits)
365   */
366 #define IRDA_IT_ORE                         ((uint16_t)0x0300U)      /*!< IRDA Overrun error interruption */
367 #define IRDA_IT_NE                          ((uint16_t)0x0200U)      /*!< IRDA Noise error interruption   */
368 #define IRDA_IT_FE                          ((uint16_t)0x0100U)      /*!< IRDA Frame error interruption   */
369 /**
370   * @}
371   */
372 
373 /** @defgroup IRDA_IT_CLEAR_Flags   IRDA Interruption Clear Flags
374   * @{
375   */
376 #define IRDA_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag          */
377 #define IRDA_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag         */
378 #define IRDA_CLEAR_NEF                       USART_ICR_NCF             /*!< Noise detected Clear Flag        */
379 #define IRDA_CLEAR_OREF                      USART_ICR_ORECF           /*!< OverRun Error Clear Flag         */
380 #define IRDA_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< IDLE line detected Clear Flag    */
381 #define IRDA_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag */
382 /**
383   * @}
384   */
385 
386 /** @defgroup IRDA_Interruption_Mask    IRDA interruptions flags mask
387   * @{
388   */
389 #define IRDA_IT_MASK  ((uint16_t)0x001FU)                             /*!< IRDA Interruptions flags mask */
390 /**
391   * @}
392   */
393 
394 /**
395  * @}
396  */
397 
398 
399 /* Exported macros -----------------------------------------------------------*/
400 /** @defgroup IRDA_Exported_Macros IRDA Exported Macros
401   * @{
402   */
403 
404 /** @brief  Reset IRDA handle state.
405   * @param  __HANDLE__: IRDA handle.
406   * @retval None
407   */
408 #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
409                                                        (__HANDLE__)->gState = HAL_IRDA_STATE_RESET;      \
410                                                        (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET;     \
411                                                      } while(0)
412 
413 /** @brief  Flush the IRDA DR register.
414   * @param  __HANDLE__: specifies the IRDA Handle.
415   * @retval None
416   */
417 #define __HAL_IRDA_FLUSH_DRREGISTER(__HANDLE__)                            \
418     do{                                                                    \
419          SET_BIT((__HANDLE__)->Instance->RQR, IRDA_RXDATA_FLUSH_REQUEST); \
420          SET_BIT((__HANDLE__)->Instance->RQR, IRDA_TXDATA_FLUSH_REQUEST); \
421       } while(0)
422 
423 /** @brief  Clear the specified IRDA pending flag.
424   * @param  __HANDLE__: specifies the IRDA Handle.
425   * @param  __FLAG__: specifies the flag to check.
426   *          This parameter can be any combination of the following values:
427   *            @arg @ref IRDA_CLEAR_PEF
428   *            @arg @ref IRDA_CLEAR_FEF
429   *            @arg @ref IRDA_CLEAR_NEF
430   *            @arg @ref IRDA_CLEAR_OREF
431   *            @arg @ref IRDA_CLEAR_TCF
432   *            @arg @ref IRDA_CLEAR_IDLEF
433   * @retval None
434   */
435 #define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
436 
437 /** @brief  Clear the IRDA PE pending flag.
438   * @param  __HANDLE__: specifies the IRDA Handle.
439   * @retval None
440   */
441 #define __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_PEF)
442 
443 
444 /** @brief  Clear the IRDA FE pending flag.
445   * @param  __HANDLE__: specifies the IRDA Handle.
446   * @retval None
447   */
448 #define __HAL_IRDA_CLEAR_FEFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_FEF)
449 
450 /** @brief  Clear the IRDA NE pending flag.
451   * @param  __HANDLE__: specifies the IRDA Handle.
452   * @retval None
453   */
454 #define __HAL_IRDA_CLEAR_NEFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_NEF)
455 
456 /** @brief  Clear the IRDA ORE pending flag.
457   * @param  __HANDLE__: specifies the IRDA Handle.
458   * @retval None
459   */
460 #define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_OREF)
461 
462 /** @brief  Clear the IRDA IDLE pending flag.
463   * @param  __HANDLE__: specifies the IRDA Handle.
464   * @retval None
465   */
466 #define __HAL_IRDA_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_IDLEF)
467 
468 /** @brief  Check whether the specified IRDA flag is set or not.
469   * @param  __HANDLE__: specifies the IRDA Handle.
470   * @param  __FLAG__: specifies the flag to check.
471   *        This parameter can be one of the following values:
472   *            @arg @ref IRDA_FLAG_REACK Receive enable acknowledge flag
473   *            @arg @ref IRDA_FLAG_TEACK Transmit enable acknowledge flag
474   *            @arg @ref IRDA_FLAG_BUSY  Busy flag
475   *            @arg @ref IRDA_FLAG_ABRF  Auto Baud rate detection flag
476   *            @arg @ref IRDA_FLAG_ABRE  Auto Baud rate detection error flag
477   *            @arg @ref IRDA_FLAG_TXE   Transmit data register empty flag
478   *            @arg @ref IRDA_FLAG_TC    Transmission Complete flag
479   *            @arg @ref IRDA_FLAG_RXNE  Receive data register not empty flag
480   *            @arg @ref IRDA_FLAG_ORE   OverRun Error flag
481   *            @arg @ref IRDA_FLAG_NE    Noise Error flag
482   *            @arg @ref IRDA_FLAG_FE    Framing Error flag
483   *            @arg @ref IRDA_FLAG_PE    Parity Error flag
484   * @retval The new state of __FLAG__ (TRUE or FALSE).
485   */
486 #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
487 
488 
489 /** @brief  Enable the specified IRDA interrupt.
490   * @param  __HANDLE__: specifies the IRDA Handle.
491   * @param  __INTERRUPT__: specifies the IRDA interrupt source to enable.
492   *          This parameter can be one of the following values:
493   *            @arg @ref IRDA_IT_TXE  Transmit Data Register empty interrupt
494   *            @arg @ref IRDA_IT_TC   Transmission complete interrupt
495   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
496   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
497   *            @arg @ref IRDA_IT_PE   Parity Error interrupt
498   *            @arg @ref IRDA_IT_ERR  Error interrupt(Frame error, noise error, overrun error)
499   * @retval None
500   */
501 #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
502                                                            ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
503                                                            ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & IRDA_IT_MASK))))
504 
505 /** @brief  Disable the specified IRDA interrupt.
506   * @param  __HANDLE__: specifies the IRDA Handle.
507   * @param  __INTERRUPT__: specifies the IRDA interrupt source to disable.
508   *          This parameter can be one of the following values:
509   *            @arg @ref IRDA_IT_TXE  Transmit Data Register empty interrupt
510   *            @arg @ref IRDA_IT_TC   Transmission complete interrupt
511   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
512   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
513   *            @arg @ref IRDA_IT_PE   Parity Error interrupt
514   *            @arg @ref IRDA_IT_ERR  Error interrupt(Frame error, noise error, overrun error)
515   * @retval None
516   */
517 #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
518                                                            ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
519                                                            ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & IRDA_IT_MASK))))
520 
521 
522 /** @brief  Check whether the specified IRDA interrupt has occurred or not.
523   * @param  __HANDLE__: specifies the IRDA Handle.
524   * @param  __IT__: specifies the IRDA interrupt source to check.
525   *          This parameter can be one of the following values:
526   *            @arg @ref IRDA_IT_TXE Transmit Data Register empty interrupt
527   *            @arg @ref IRDA_IT_TC  Transmission complete interrupt
528   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
529   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
530   *            @arg @ref IRDA_IT_ORE OverRun Error interrupt
531   *            @arg @ref IRDA_IT_NE Noise Error interrupt
532   *            @arg @ref IRDA_IT_FE Framing Error interrupt
533   *            @arg @ref IRDA_IT_PE Parity Error interrupt
534   * @retval The new state of __IT__ (TRUE or FALSE).
535   */
536 #define __HAL_IRDA_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1U << ((__IT__)>> 0x08U)))
537 
538 /** @brief  Check whether the specified IRDA interrupt source is enabled or not.
539   * @param  __HANDLE__: specifies the IRDA Handle.
540   * @param  __IT__: specifies the IRDA interrupt source to check.
541   *          This parameter can be one of the following values:
542   *            @arg @ref IRDA_IT_TXE Transmit Data Register empty interrupt
543   *            @arg @ref IRDA_IT_TC  Transmission complete interrupt
544   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
545   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
546   *            @arg @ref IRDA_IT_ERR Framing, overrun or noise error interrupt
547   *            @arg @ref IRDA_IT_PE Parity Error interrupt
548   * @retval The new state of __IT__ (TRUE or FALSE).
549   */
550 #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2U)? \
551                                                        (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1U << (((uint16_t)(__IT__)) & IRDA_IT_MASK)))
552 
553 /** @brief  Clear the specified IRDA ISR flag, in setting the proper ICR register flag.
554   * @param  __HANDLE__: specifies the IRDA Handle.
555   * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
556   *                       to clear the corresponding interrupt
557   *          This parameter can be one of the following values:
558   *            @arg @ref IRDA_CLEAR_PEF Parity Error Clear Flag
559   *            @arg @ref IRDA_CLEAR_FEF Framing Error Clear Flag
560   *            @arg @ref IRDA_CLEAR_NEF Noise detected Clear Flag
561   *            @arg @ref IRDA_CLEAR_OREF OverRun Error Clear Flag
562   *            @arg @ref IRDA_CLEAR_TCF Transmission Complete Clear Flag
563   * @retval None
564   */
565 #define __HAL_IRDA_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
566 
567 
568 /** @brief  Set a specific IRDA request flag.
569   * @param  __HANDLE__: specifies the IRDA Handle.
570   * @param  __REQ__: specifies the request flag to set
571   *          This parameter can be one of the following values:
572   *            @arg @ref IRDA_AUTOBAUD_REQUEST Auto-Baud Rate Request
573   *            @arg @ref IRDA_RXDATA_FLUSH_REQUEST Receive Data flush Request
574   *            @arg @ref IRDA_TXDATA_FLUSH_REQUEST Transmit data flush Request
575   *
576   * @retval None
577   */
578 #define __HAL_IRDA_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
579 
580 /** @brief  Enable the IRDA one bit sample method.
581   * @param  __HANDLE__: specifies the IRDA Handle.
582   * @retval None
583   */
584 #define __HAL_IRDA_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
585 
586 /** @brief  Disable the IRDA one bit sample method.
587   * @param  __HANDLE__: specifies the IRDA Handle.
588   * @retval None
589   */
590 #define __HAL_IRDA_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
591 
592 /** @brief  Enable UART/USART associated to IRDA Handle.
593   * @param  __HANDLE__: specifies the IRDA Handle.
594   * @retval None
595   */
596 #define __HAL_IRDA_ENABLE(__HANDLE__)                   ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
597 
598 /** @brief  Disable UART/USART associated to IRDA Handle.
599   * @param  __HANDLE__: specifies the IRDA Handle.
600   * @retval None
601   */
602 #define __HAL_IRDA_DISABLE(__HANDLE__)                  ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
603 
604 /**
605   * @}
606   */
607 
608 /* Private macros --------------------------------------------------------*/
609 /** @defgroup IRDA_Private_Macros   IRDA Private Macros
610   * @{
611   */
612 
613 /** @brief  Compute the mask to apply to retrieve the received data
614   *         according to the word length and to the parity bits activation.
615   * @param  __HANDLE__: specifies the IRDA Handle.
616   * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field.
617   */
618 #define IRDA_MASK_COMPUTATION(__HANDLE__)                             \
619   do {                                                                \
620   if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B)            \
621   {                                                                   \
622      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
623      {                                                                \
624         (__HANDLE__)->Mask = 0x01FFU ;                                \
625      }                                                                \
626      else                                                             \
627      {                                                                \
628         (__HANDLE__)->Mask = 0x00FFU ;                                \
629      }                                                                \
630   }                                                                   \
631   else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B)       \
632   {                                                                   \
633      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
634      {                                                                \
635         (__HANDLE__)->Mask = 0x00FFU ;                                \
636      }                                                                \
637      else                                                             \
638      {                                                                \
639         (__HANDLE__)->Mask = 0x007FU ;                                \
640      }                                                                \
641   }                                                                   \
642   else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B)       \
643   {                                                                   \
644      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
645      {                                                                \
646         (__HANDLE__)->Mask = 0x007FU ;                                \
647      }                                                                \
648      else                                                             \
649      {                                                                \
650         (__HANDLE__)->Mask = 0x003FU ;                                \
651      }                                                                \
652   }                                                                   \
653 } while(0)
654 
655 /** @brief  Ensure that IRDA Baud rate is less or equal to maximum value.
656   * @param  __BAUDRATE__: specifies the IRDA Baudrate set by the user.
657   * @retval True or False
658   */
659 #define IS_IRDA_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 115201U)
660 
661 /** @brief  Ensure that IRDA prescaler value is strictly larger than 0.
662   * @param  __PRESCALER__: specifies the IRDA prescaler value set by the user.
663   * @retval True or False
664   */
665 #define IS_IRDA_PRESCALER(__PRESCALER__) ((__PRESCALER__) > 0U)
666 
667 /**
668   * @brief Ensure that IRDA frame length is valid.
669   * @param __LENGTH__: IRDA frame length.
670   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
671   */
672 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \
673                                          ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \
674                                          ((__LENGTH__) == IRDA_WORDLENGTH_9B))
675 
676 /**
677   * @brief Ensure that IRDA frame parity is valid.
678   * @param __PARITY__: IRDA frame parity.
679   * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
680   */
681 #define IS_IRDA_PARITY(__PARITY__) (((__PARITY__) == IRDA_PARITY_NONE) || \
682                                     ((__PARITY__) == IRDA_PARITY_EVEN) || \
683                                     ((__PARITY__) == IRDA_PARITY_ODD))
684 
685 /**
686   * @brief Ensure that IRDA communication mode is valid.
687   * @param __MODE__: IRDA communication mode.
688   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
689   */
690 #define IS_IRDA_TX_RX_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(IRDA_MODE_TX_RX)))) == (uint32_t)0x00) && ((__MODE__) != (uint32_t)0x00))
691 
692 /**
693   * @brief Ensure that IRDA power mode is valid.
694   * @param __MODE__: IRDA power mode.
695   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
696   */
697 #define IS_IRDA_POWERMODE(__MODE__) (((__MODE__) == IRDA_POWERMODE_LOWPOWER) || \
698                                      ((__MODE__) == IRDA_POWERMODE_NORMAL))
699 
700 /**
701   * @brief Ensure that IRDA state is valid.
702   * @param __STATE__: IRDA state mode.
703   * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
704   */
705 #define IS_IRDA_STATE(__STATE__) (((__STATE__) == IRDA_STATE_DISABLE) || \
706                                   ((__STATE__) == IRDA_STATE_ENABLE))
707 
708 /**
709   * @brief Ensure that IRDA associated UART/USART mode is valid.
710   * @param __MODE__: IRDA associated UART/USART mode.
711   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
712   */
713 #define IS_IRDA_MODE(__MODE__)  (((__MODE__) == IRDA_MODE_DISABLE) || \
714                                  ((__MODE__) == IRDA_MODE_ENABLE))
715 
716 /**
717   * @brief Ensure that IRDA sampling rate is valid.
718   * @param __ONEBIT__: IRDA sampling rate.
719   * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
720   */
721 #define IS_IRDA_ONE_BIT_SAMPLE(__ONEBIT__)      (((__ONEBIT__) == IRDA_ONE_BIT_SAMPLE_DISABLE) || \
722                                                  ((__ONEBIT__) == IRDA_ONE_BIT_SAMPLE_ENABLE))
723 
724 /**
725   * @brief Ensure that IRDA DMA TX mode is valid.
726   * @param __DMATX__: IRDA DMA TX mode.
727   * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
728   */
729 #define IS_IRDA_DMA_TX(__DMATX__)     (((__DMATX__) == IRDA_DMA_TX_DISABLE) || \
730                                        ((__DMATX__) == IRDA_DMA_TX_ENABLE))
731 
732 /**
733   * @brief Ensure that IRDA DMA RX mode is valid.
734   * @param __DMARX__: IRDA DMA RX mode.
735   * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
736   */
737 #define IS_IRDA_DMA_RX(__DMARX__) (((__DMARX__) == IRDA_DMA_RX_DISABLE) || \
738                                    ((__DMARX__) == IRDA_DMA_RX_ENABLE))
739 
740 /**
741   * @brief Ensure that IRDA request is valid.
742   * @param __PARAM__: IRDA request.
743   * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
744   */
745 #define IS_IRDA_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == IRDA_AUTOBAUD_REQUEST) || \
746                                               ((__PARAM__) == IRDA_RXDATA_FLUSH_REQUEST) || \
747                                               ((__PARAM__) == IRDA_TXDATA_FLUSH_REQUEST))
748 /**
749  * @}
750  */
751 
752 /* Include IRDA HAL Extended module */
753 #include "stm32l0xx_hal_irda_ex.h"
754 
755 /* Exported functions --------------------------------------------------------*/
756 /** @addtogroup IRDA_Exported_Functions IRDA Exported Functions
757   * @{
758   */
759 
760 /** @addtogroup IRDA_Exported_Functions_Group1 Initialization and de-initialization functions
761   * @{
762   */
763 
764 /* Initialization and de-initialization functions  ****************************/
765 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda);
766 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda);
767 void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda);
768 void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda);
769 
770 /**
771   * @}
772   */
773 
774 /** @addtogroup IRDA_Exported_Functions_Group2 IO operation functions
775   * @{
776   */
777 
778 /* IO operation functions *****************************************************/
779 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
780 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
781 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
782 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
783 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
784 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
785 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda);
786 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda);
787 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda);
788 /* Transfer Abort functions */
789 HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda);
790 HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda);
791 HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda);
792 HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda);
793 HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda);
794 HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda);
795 
796 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda);
797 void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda);
798 void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda);
799 void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
800 void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
801 void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda);
802 void HAL_IRDA_AbortCpltCallback (IRDA_HandleTypeDef *hirda);
803 void HAL_IRDA_AbortTransmitCpltCallback (IRDA_HandleTypeDef *hirda);
804 void HAL_IRDA_AbortReceiveCpltCallback (IRDA_HandleTypeDef *hirda);
805 
806 /**
807   * @}
808   */
809 
810 /* Peripheral Control functions  ************************************************/
811 
812 /** @addtogroup IRDA_Exported_Functions_Group4 Peripheral State and Error functions
813   * @{
814   */
815 
816 /* Peripheral State and Error functions ***************************************/
817 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda);
818 uint32_t              HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda);
819 
820 /**
821   * @}
822   */
823 
824 /**
825   * @}
826   */
827 
828 /**
829   * @}
830   */
831 
832 /**
833   * @}
834   */
835 
836 #ifdef __cplusplus
837 }
838 #endif
839 
840 #endif /* __STM32L0xx_HAL_IRDA_H */
841 
842 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
843 
844