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