TUKS MCU Introductory course / TUKS-COURSE-2-LED
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_irda.h Source File

stm32l4xx_hal_irda.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_irda.h
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   Header file of IRDA HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_HAL_IRDA_H
00040 #define __STM32L4xx_HAL_IRDA_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx_hal_def.h"
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup IRDA
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/
00058 /** @defgroup IRDA_Exported_Types IRDA Exported Types
00059   * @{
00060   */
00061 
00062 /**
00063   * @brief IRDA Init Structure definition
00064   */
00065 typedef struct
00066 {
00067   uint32_t BaudRate;                  /*!< This member configures the IRDA communication baud rate.
00068                                            The baud rate register is computed using the following formula:
00069                                               Baud Rate Register = ((PCLKx) / ((hirda->Init.BaudRate))) */
00070 
00071   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
00072                                            This parameter can be a value of @ref IRDA_Word_Length */
00073 
00074   uint32_t Parity;                    /*!< Specifies the parity mode.
00075                                            This parameter can be a value of @ref IRDA_Parity
00076                                            @note When parity is enabled, the computed parity is inserted
00077                                                  at the MSB position of the transmitted data (9th bit when
00078                                                  the word length is set to 9 data bits; 8th bit when the
00079                                                  word length is set to 8 data bits). */
00080 
00081   uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
00082                                            This parameter can be a value of @ref IRDA_Transfer_Mode */
00083 
00084   uint8_t  Prescaler;                 /*!< Specifies the Prescaler value for dividing the UART/USART source clock
00085                                            to achieve low-power frequency.
00086                                            @note Prescaler value 0 is forbidden */
00087 
00088   uint16_t PowerMode;                 /*!< Specifies the IRDA power mode.
00089                                            This parameter can be a value of @ref IRDA_Low_Power */
00090 }IRDA_InitTypeDef;
00091 
00092 /**
00093   * @brief HAL IRDA State structures definition
00094   * @note  HAL IRDA State value is a combination of 2 different substates: gState and RxState.
00095   *        - gState contains IRDA state information related to global Handle management 
00096   *          and also information related to Tx operations.
00097   *          gState value coding follow below described bitmap :
00098   *          b7-b6  Error information 
00099   *             00 : No Error
00100   *             01 : (Not Used)
00101   *             10 : Timeout
00102   *             11 : Error
00103   *          b5     IP initilisation status
00104   *             0  : Reset (IP not initialized)
00105   *             1  : Init done (IP not initialized. HAL IRDA Init function already called)
00106   *          b4-b3  (not used)
00107   *             xx : Should be set to 00
00108   *          b2     Intrinsic process state
00109   *             0  : Ready
00110   *             1  : Busy (IP busy with some configuration or internal operations)
00111   *          b1     (not used)
00112   *             x  : Should be set to 0
00113   *          b0     Tx state
00114   *             0  : Ready (no Tx operation ongoing)
00115   *             1  : Busy (Tx operation ongoing)
00116   *        - RxState contains information related to Rx operations.
00117   *          RxState value coding follow below described bitmap :
00118   *          b7-b6  (not used)
00119   *             xx : Should be set to 00
00120   *          b5     IP initilisation status
00121   *             0  : Reset (IP not initialized)
00122   *             1  : Init done (IP not initialized)
00123   *          b4-b2  (not used)
00124   *            xxx : Should be set to 000
00125   *          b1     Rx state
00126   *             0  : Ready (no Rx operation ongoing)
00127   *             1  : Busy (Rx operation ongoing)
00128   *          b0     (not used)
00129   *             x  : Should be set to 0.
00130   */
00131 typedef enum
00132 {
00133   HAL_IRDA_STATE_RESET             = 0x00U,   /*!< Peripheral is not initialized
00134                                                    Value is allowed for gState and RxState */
00135   HAL_IRDA_STATE_READY             = 0x20U,   /*!< Peripheral Initialized and ready for use
00136                                                    Value is allowed for gState and RxState */
00137   HAL_IRDA_STATE_BUSY              = 0x24U,   /*!< an internal process is ongoing 
00138                                                    Value is allowed for gState only */
00139   HAL_IRDA_STATE_BUSY_TX           = 0x21U,   /*!< Data Transmission process is ongoing
00140                                                    Value is allowed for gState only */
00141   HAL_IRDA_STATE_BUSY_RX           = 0x22U,   /*!< Data Reception process is ongoing
00142                                                    Value is allowed for RxState only */
00143   HAL_IRDA_STATE_BUSY_TX_RX        = 0x23U,   /*!< Data Transmission and Reception process is ongoing
00144                                                    Not to be used for neither gState nor RxState.
00145                                                    Value is result of combination (Or) between gState and RxState values */
00146   HAL_IRDA_STATE_TIMEOUT           = 0xA0U,   /*!< Timeout state
00147                                                    Value is allowed for gState only */
00148   HAL_IRDA_STATE_ERROR             = 0xE0U    /*!< Error
00149                                                    Value is allowed for gState only */
00150 }HAL_IRDA_StateTypeDef;
00151 
00152 /**
00153   * @brief  HAL IRDA Error Code structure definition
00154   */
00155 typedef enum
00156 {
00157   HAL_IRDA_ERROR_NONE      = 0x00,    /*!< No error            */
00158   HAL_IRDA_ERROR_PE        = 0x01,    /*!< Parity error        */
00159   HAL_IRDA_ERROR_NE        = 0x02,    /*!< Noise error         */
00160   HAL_IRDA_ERROR_FE        = 0x04,    /*!< frame error         */
00161   HAL_IRDA_ERROR_ORE       = 0x08,    /*!< Overrun error       */
00162   HAL_IRDA_ERROR_DMA       = 0x10     /*!< DMA transfer error  */
00163 }HAL_IRDA_ErrorTypeDef;
00164 
00165 /**
00166   * @brief IRDA clock sources definition
00167   */
00168 typedef enum
00169 {
00170   IRDA_CLOCKSOURCE_PCLK1      = 0x00,    /*!< PCLK1 clock source     */
00171   IRDA_CLOCKSOURCE_PCLK2      = 0x01,    /*!< PCLK2 clock source     */
00172   IRDA_CLOCKSOURCE_HSI        = 0x02,    /*!< HSI clock source       */
00173   IRDA_CLOCKSOURCE_SYSCLK     = 0x04,    /*!< SYSCLK clock source    */
00174   IRDA_CLOCKSOURCE_LSE        = 0x08,    /*!< LSE clock source       */
00175   IRDA_CLOCKSOURCE_UNDEFINED  = 0x10     /*!< Undefined clock source */
00176 }IRDA_ClockSourceTypeDef;
00177 
00178 /**
00179   * @brief  IRDA handle Structure definition
00180   */
00181 typedef struct
00182 {
00183   USART_TypeDef            *Instance;        /*!< USART registers base address       */
00184 
00185   IRDA_InitTypeDef         Init;             /*!< IRDA communication parameters      */
00186 
00187   uint8_t                  *pTxBuffPtr;      /*!< Pointer to IRDA Tx transfer Buffer */
00188 
00189   uint16_t                 TxXferSize;       /*!< IRDA Tx Transfer size              */
00190 
00191   uint16_t                 TxXferCount;      /* !<IRDA Tx Transfer Counter           */
00192 
00193   uint8_t                  *pRxBuffPtr;      /*!< Pointer to IRDA Rx transfer Buffer */
00194 
00195   uint16_t                 RxXferSize;       /*!< IRDA Rx Transfer size              */
00196 
00197   uint16_t                 RxXferCount;      /*!< IRDA Rx Transfer Counter           */
00198 
00199   uint16_t                 Mask;             /*!< USART RX RDR register mask         */
00200 
00201   DMA_HandleTypeDef        *hdmatx;          /*!< IRDA Tx DMA Handle parameters      */
00202 
00203   DMA_HandleTypeDef        *hdmarx;          /*!< IRDA Rx DMA Handle parameters      */
00204 
00205   HAL_LockTypeDef          Lock;             /*!< Locking object                     */
00206 
00207   __IO HAL_IRDA_StateTypeDef    gState;      /*!< IRDA state information related to global Handle management 
00208                                                   and also related to Tx operations.
00209                                                   This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
00210 
00211   __IO HAL_IRDA_StateTypeDef    RxState;     /*!< IRDA state information related to Rx operations.
00212                                                   This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
00213 
00214   uint32_t                 ErrorCode;        /*!< IRDA Error code                    */
00215 
00216 }IRDA_HandleTypeDef;
00217 
00218 /**
00219   * @brief  IRDA Configuration enumeration values definition
00220   */
00221 typedef enum
00222 {
00223   IRDA_BAUDRATE        = 0x00,     /*!< IRDA Baud rate          */
00224   IRDA_PARITY          = 0x01,     /*!< IRDA frame parity       */
00225   IRDA_WORDLENGTH      = 0x02,     /*!< IRDA frame length       */
00226   IRDA_MODE            = 0x03,     /*!< IRDA communication mode */
00227   IRDA_PRESCALER       = 0x04,     /*!< IRDA prescaling         */
00228   IRDA_POWERMODE       = 0x05      /*!< IRDA power mode         */
00229 }IRDA_ControlTypeDef;
00230 
00231 /**
00232   * @}
00233   */
00234 
00235 /* Exported constants --------------------------------------------------------*/
00236 /** @defgroup IRDA_Exported_Constants IRDA Exported Constants
00237   * @{
00238   */
00239 
00240 /** @defgroup IRDA_Word_Length IRDA Word Length
00241   * @{
00242   */
00243 #define IRDA_WORDLENGTH_7B                  ((uint32_t)USART_CR1_M1)   /*!< 7-bit long frame */
00244 #define IRDA_WORDLENGTH_8B                  ((uint32_t)0x00000000)     /*!< 8-bit long frame */
00245 #define IRDA_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M0)   /*!< 9-bit long frame */
00246 /**
00247   * @}
00248   */
00249 
00250 /** @defgroup IRDA_Parity IRDA Parity
00251   * @{
00252   */
00253 #define IRDA_PARITY_NONE                    ((uint32_t)0x00000000)                      /*!< No parity   */
00254 #define IRDA_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)                   /*!< Even parity */
00255 #define IRDA_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))  /*!< Odd parity  */
00256 /**
00257   * @}
00258   */
00259 
00260 /** @defgroup IRDA_Transfer_Mode IRDA Transfer Mode
00261   * @{
00262   */
00263 #define IRDA_MODE_RX                        ((uint32_t)USART_CR1_RE)                   /*!< RX mode        */
00264 #define IRDA_MODE_TX                        ((uint32_t)USART_CR1_TE)                   /*!< TX mode        */
00265 #define IRDA_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))   /*!< RX and TX mode */
00266 /**
00267   * @}
00268   */
00269 
00270 /** @defgroup IRDA_Low_Power IRDA Low Power
00271   * @{
00272   */
00273 #define IRDA_POWERMODE_NORMAL               ((uint32_t)0x00000000)       /*!< IRDA normal power mode */ 
00274 #define IRDA_POWERMODE_LOWPOWER             ((uint32_t)USART_CR3_IRLP)   /*!< IRDA low power mode    */ 
00275 /**
00276   * @}
00277   */
00278 
00279 /** @defgroup IRDA_State IRDA State
00280   * @{
00281   */
00282 #define IRDA_STATE_DISABLE                  ((uint32_t)0x00000000)     /*!< IRDA disabled  */ 
00283 #define IRDA_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)   /*!< IRDA enabled   */ 
00284 /**
00285   * @}
00286   */
00287 
00288 /** @defgroup IRDA_Mode  IRDA Mode
00289   * @{
00290   */
00291 #define IRDA_MODE_DISABLE                   ((uint32_t)0x00000000)      /*!< Associated UART disabled in IRDA mode */
00292 #define IRDA_MODE_ENABLE                    ((uint32_t)USART_CR3_IREN)  /*!< Associated UART enabled in IRDA mode  */
00293 /**
00294   * @}
00295   */
00296 
00297 /** @defgroup IRDA_One_Bit  IRDA One Bit Sampling
00298   * @{
00299   */
00300 #define IRDA_ONE_BIT_SAMPLE_DISABLE         ((uint32_t)0x00000000)       /*!< One-bit sampling disabled */
00301 #define IRDA_ONE_BIT_SAMPLE_ENABLE          ((uint32_t)USART_CR3_ONEBIT) /*!< One-bit sampling enabled  */
00302 /**
00303   * @}
00304   */
00305 
00306 /** @defgroup IRDA_DMA_Tx IRDA DMA Tx
00307   * @{
00308   */
00309 #define IRDA_DMA_TX_DISABLE                 ((uint32_t)0x00000000)       /*!< IRDA DMA TX disabled */ 
00310 #define IRDA_DMA_TX_ENABLE                  ((uint32_t)USART_CR3_DMAT)   /*!< IRDA DMA TX enabled  */ 
00311 /**
00312   * @}
00313   */
00314 
00315 /** @defgroup IRDA_DMA_Rx  IRDA DMA Rx
00316   * @{
00317   */
00318 #define IRDA_DMA_RX_DISABLE                 ((uint32_t)0x00000000)       /*!< IRDA DMA RX disabled */
00319 #define IRDA_DMA_RX_ENABLE                  ((uint32_t)USART_CR3_DMAR)   /*!< IRDA DMA RX enabled  */
00320 /**
00321   * @}
00322   */
00323 
00324 /** @defgroup IRDA_Request_Parameters IRDA Request Parameters
00325   * @{
00326   */
00327 #define IRDA_AUTOBAUD_REQUEST            ((uint16_t)USART_RQR_ABRRQ)        /*!< Auto-Baud Rate Request      */
00328 #define IRDA_RXDATA_FLUSH_REQUEST        ((uint16_t)USART_RQR_RXFRQ)        /*!< Receive Data flush Request  */
00329 #define IRDA_TXDATA_FLUSH_REQUEST        ((uint16_t)USART_RQR_TXFRQ)        /*!< Transmit data flush Request */
00330 /**
00331   * @}
00332   */
00333 
00334 /** @defgroup IRDA_Flags IRDA Flags
00335   *        Elements values convention: 0xXXXX
00336   *           - 0xXXXX  : Flag mask in the ISR register
00337   * @{
00338   */
00339 #define IRDA_FLAG_REACK                     ((uint32_t)0x00400000)    /*!< IRDA Receive enable acknowledge flag  */ 
00340 #define IRDA_FLAG_TEACK                     ((uint32_t)0x00200000)    /*!< IRDA Transmit enable acknowledge flag */ 
00341 #define IRDA_FLAG_BUSY                      ((uint32_t)0x00010000)    /*!< IRDA Busy flag                        */  
00342 #define IRDA_FLAG_ABRF                      ((uint32_t)0x00008000)    /*!< IRDA Auto baud rate flag              */
00343 #define IRDA_FLAG_ABRE                      ((uint32_t)0x00004000)    /*!< IRDA Auto baud rate error             */  
00344 #define IRDA_FLAG_TXE                       ((uint32_t)0x00000080)    /*!< IRDA Transmit data register empty     */
00345 #define IRDA_FLAG_TC                        ((uint32_t)0x00000040)    /*!< IRDA Transmission complete            */  
00346 #define IRDA_FLAG_RXNE                      ((uint32_t)0x00000020)    /*!< IRDA Read data register not empty     */
00347 #define IRDA_FLAG_ORE                       ((uint32_t)0x00000008)    /*!< IRDA Overrun error                    */  
00348 #define IRDA_FLAG_NE                        ((uint32_t)0x00000004)    /*!< IRDA Noise error                      */
00349 #define IRDA_FLAG_FE                        ((uint32_t)0x00000002)    /*!< IRDA Noise error                      */  
00350 #define IRDA_FLAG_PE                        ((uint32_t)0x00000001)    /*!< IRDA Parity error                     */
00351 /**
00352   * @}
00353   */
00354 
00355 /** @defgroup IRDA_Interrupt_definition IRDA Interrupts Definition
00356   *        Elements values convention: 0000ZZZZ0XXYYYYYb
00357   *           - YYYYY  : Interrupt source position in the XX register (5bits)
00358   *           - XX  : Interrupt source register (2bits)
00359   *                 - 01: CR1 register
00360   *                 - 10: CR2 register
00361   *                 - 11: CR3 register
00362   *           - ZZZZ  : Flag position in the ISR register(4bits)
00363   * @{
00364   */
00365 #define IRDA_IT_PE                          ((uint16_t)0x0028)     /*!< IRDA Parity error interruption                 */
00366 #define IRDA_IT_TXE                         ((uint16_t)0x0727)     /*!< IRDA Transmit data register empty interruption */
00367 #define IRDA_IT_TC                          ((uint16_t)0x0626)     /*!< IRDA Transmission complete interruption        */
00368 #define IRDA_IT_RXNE                        ((uint16_t)0x0525)     /*!< IRDA Read data register not empty interruption */
00369 #define IRDA_IT_IDLE                        ((uint16_t)0x0424)     /*!< IRDA Idle interruption                         */
00370 
00371 /*       Elements values convention: 000000000XXYYYYYb
00372              - YYYYY  : Interrupt source position in the XX register (5bits)
00373              - XX  : Interrupt source register (2bits)
00374                    - 01: CR1 register
00375                    - 10: CR2 register
00376                    - 11: CR3 register */
00377 #define IRDA_IT_ERR                         ((uint16_t)0x0060)       /*!< IRDA Error interruption        */
00378 
00379 /*       Elements values convention: 0000ZZZZ00000000b
00380              - ZZZZ  : Flag position in the ISR register(4bits) */
00381 #define IRDA_IT_ORE                         ((uint16_t)0x0300)      /*!< IRDA Overrun error interruption */
00382 #define IRDA_IT_NE                          ((uint16_t)0x0200)      /*!< IRDA Noise error interruption   */
00383 #define IRDA_IT_FE                          ((uint16_t)0x0100)      /*!< IRDA Frame error interruption   */
00384 /**
00385   * @}
00386   */
00387 
00388 /** @defgroup IRDA_IT_CLEAR_Flags   IRDA Interruption Clear Flags
00389   * @{
00390   */
00391 #define IRDA_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag          */
00392 #define IRDA_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag         */
00393 #define IRDA_CLEAR_NEF                       USART_ICR_NCF             /*!< Noise detected Clear Flag        */
00394 #define IRDA_CLEAR_OREF                      USART_ICR_ORECF           /*!< OverRun Error Clear Flag         */
00395 #define IRDA_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< IDLE line detected Clear Flag    */
00396 #define IRDA_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag */
00397 /**
00398   * @}
00399   */
00400 
00401 /** @defgroup IRDA_Interruption_Mask    IRDA interruptions flags mask
00402   * @{
00403   */
00404 #define IRDA_IT_MASK  ((uint16_t)0x001F)                             /*!< IRDA Interruptions flags mask */
00405 /**
00406   * @}
00407   */
00408 
00409 /**
00410  * @}
00411  */
00412 
00413 
00414 /* Exported macros -----------------------------------------------------------*/
00415 /** @defgroup IRDA_Exported_Macros IRDA Exported Macros
00416   * @{
00417   */
00418 
00419 /** @brief  Reset IRDA handle state.
00420   * @param  __HANDLE__: IRDA handle.
00421   * @retval None
00422   */
00423 #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
00424                                                        (__HANDLE__)->gState = HAL_IRDA_STATE_RESET;      \
00425                                                        (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET;     \
00426                                                      } while(0)
00427 
00428 /** @brief  Flush the IRDA DR register.
00429   * @param  __HANDLE__: specifies the IRDA Handle.
00430   * @retval None
00431   */
00432 #define __HAL_IRDA_FLUSH_DRREGISTER(__HANDLE__)                            \
00433     do{                                                                    \
00434          SET_BIT((__HANDLE__)->Instance->RQR, IRDA_RXDATA_FLUSH_REQUEST); \
00435          SET_BIT((__HANDLE__)->Instance->RQR, IRDA_TXDATA_FLUSH_REQUEST); \
00436       } while(0)
00437 
00438 /** @brief  Clear the specified IRDA pending flag.
00439   * @param  __HANDLE__: specifies the IRDA Handle.
00440   * @param  __FLAG__: specifies the flag to check.
00441   *          This parameter can be any combination of the following values:
00442   *            @arg @ref IRDA_CLEAR_PEF
00443   *            @arg @ref IRDA_CLEAR_FEF
00444   *            @arg @ref IRDA_CLEAR_NEF
00445   *            @arg @ref IRDA_CLEAR_OREF
00446   *            @arg @ref IRDA_CLEAR_TCF
00447   *            @arg @ref IRDA_CLEAR_IDLEF
00448   * @retval None
00449   */
00450 #define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
00451 
00452 /** @brief  Clear the IRDA PE pending flag.
00453   * @param  __HANDLE__: specifies the IRDA Handle.
00454   * @retval None
00455   */
00456 #define __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_PEF)
00457 
00458 
00459 /** @brief  Clear the IRDA FE pending flag.
00460   * @param  __HANDLE__: specifies the IRDA Handle.
00461   * @retval None
00462   */
00463 #define __HAL_IRDA_CLEAR_FEFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_FEF)
00464 
00465 /** @brief  Clear the IRDA NE pending flag.
00466   * @param  __HANDLE__: specifies the IRDA Handle.
00467   * @retval None
00468   */
00469 #define __HAL_IRDA_CLEAR_NEFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_NEF)
00470 
00471 /** @brief  Clear the IRDA ORE pending flag.
00472   * @param  __HANDLE__: specifies the IRDA Handle.
00473   * @retval None
00474   */
00475 #define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__)    __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_OREF)
00476 
00477 /** @brief  Clear the IRDA IDLE pending flag.
00478   * @param  __HANDLE__: specifies the IRDA Handle.
00479   * @retval None
00480   */
00481 #define __HAL_IRDA_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_IRDA_CLEAR_FLAG((__HANDLE__), IRDA_CLEAR_IDLEF)
00482 
00483 /** @brief  Check whether the specified IRDA flag is set or not.
00484   * @param  __HANDLE__: specifies the IRDA Handle.
00485   * @param  __FLAG__: specifies the flag to check.
00486   *        This parameter can be one of the following values:
00487   *            @arg @ref IRDA_FLAG_REACK Receive enable acknowledge flag
00488   *            @arg @ref IRDA_FLAG_TEACK Transmit enable acknowledge flag
00489   *            @arg @ref IRDA_FLAG_BUSY  Busy flag
00490   *            @arg @ref IRDA_FLAG_ABRF  Auto Baud rate detection flag
00491   *            @arg @ref IRDA_FLAG_ABRE  Auto Baud rate detection error flag
00492   *            @arg @ref IRDA_FLAG_TXE   Transmit data register empty flag
00493   *            @arg @ref IRDA_FLAG_TC    Transmission Complete flag
00494   *            @arg @ref IRDA_FLAG_RXNE  Receive data register not empty flag
00495   *            @arg @ref IRDA_FLAG_ORE   OverRun Error flag
00496   *            @arg @ref IRDA_FLAG_NE    Noise Error flag
00497   *            @arg @ref IRDA_FLAG_FE    Framing Error flag
00498   *            @arg @ref IRDA_FLAG_PE    Parity Error flag
00499   * @retval The new state of __FLAG__ (TRUE or FALSE).
00500   */
00501 #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
00502 
00503 
00504 /** @brief  Enable the specified IRDA interrupt.
00505   * @param  __HANDLE__: specifies the IRDA Handle.
00506   * @param  __INTERRUPT__: specifies the IRDA interrupt source to enable.
00507   *          This parameter can be one of the following values:
00508   *            @arg @ref IRDA_IT_TXE  Transmit Data Register empty interrupt
00509   *            @arg @ref IRDA_IT_TC   Transmission complete interrupt
00510   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
00511   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
00512   *            @arg @ref IRDA_IT_PE   Parity Error interrupt
00513   *            @arg @ref IRDA_IT_ERR  Error interrupt(Frame error, noise error, overrun error)
00514   * @retval None
00515   */
00516 #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
00517                                                            ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
00518                                                            ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & IRDA_IT_MASK))))
00519 
00520 /** @brief  Disable the specified IRDA interrupt.
00521   * @param  __HANDLE__: specifies the IRDA Handle.
00522   * @param  __INTERRUPT__: specifies the IRDA interrupt source to disable.
00523   *          This parameter can be one of the following values:
00524   *            @arg @ref IRDA_IT_TXE  Transmit Data Register empty interrupt
00525   *            @arg @ref IRDA_IT_TC   Transmission complete interrupt
00526   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
00527   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
00528   *            @arg @ref IRDA_IT_PE   Parity Error interrupt
00529   *            @arg @ref IRDA_IT_ERR  Error interrupt(Frame error, noise error, overrun error)
00530   * @retval None
00531   */
00532 #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
00533                                                            ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & IRDA_IT_MASK))): \
00534                                                            ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & IRDA_IT_MASK))))
00535 
00536 
00537 /** @brief  Check whether the specified IRDA interrupt has occurred or not.
00538   * @param  __HANDLE__: specifies the IRDA Handle.
00539   * @param  __IT__: specifies the IRDA interrupt source to check.
00540   *          This parameter can be one of the following values:
00541   *            @arg @ref IRDA_IT_TXE Transmit Data Register empty interrupt
00542   *            @arg @ref IRDA_IT_TC  Transmission complete interrupt
00543   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
00544   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
00545   *            @arg @ref IRDA_IT_ORE OverRun Error interrupt
00546   *            @arg @ref IRDA_IT_NE Noise Error interrupt
00547   *            @arg @ref IRDA_IT_FE Framing Error interrupt
00548   *            @arg @ref IRDA_IT_PE Parity Error interrupt
00549   * @retval The new state of __IT__ (TRUE or FALSE).
00550   */
00551 #define __HAL_IRDA_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1U << ((__IT__)>> 0x08)))
00552 
00553 /** @brief  Check whether the specified IRDA interrupt source is enabled or not.
00554   * @param  __HANDLE__: specifies the IRDA Handle.
00555   * @param  __IT__: specifies the IRDA interrupt source to check.
00556   *          This parameter can be one of the following values:
00557   *            @arg @ref IRDA_IT_TXE Transmit Data Register empty interrupt
00558   *            @arg @ref IRDA_IT_TC  Transmission complete interrupt
00559   *            @arg @ref IRDA_IT_RXNE Receive Data register not empty interrupt
00560   *            @arg @ref IRDA_IT_IDLE Idle line detection interrupt
00561   *            @arg @ref IRDA_IT_ERR Framing, overrun or noise error interrupt
00562   *            @arg @ref IRDA_IT_PE Parity Error interrupt
00563   * @retval The new state of __IT__ (TRUE or FALSE).
00564   */
00565 #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \
00566                                                        (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & IRDA_IT_MASK)))
00567 
00568 
00569 /** @brief  Clear the specified IRDA ISR flag, in setting the proper ICR register flag.
00570   * @param  __HANDLE__: specifies the IRDA Handle.
00571   * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
00572   *                       to clear the corresponding interrupt
00573   *          This parameter can be one of the following values:
00574   *            @arg @ref IRDA_CLEAR_PEF Parity Error Clear Flag
00575   *            @arg @ref IRDA_CLEAR_FEF Framing Error Clear Flag
00576   *            @arg @ref IRDA_CLEAR_NEF Noise detected Clear Flag
00577   *            @arg @ref IRDA_CLEAR_OREF OverRun Error Clear Flag
00578   *            @arg @ref IRDA_CLEAR_TCF Transmission Complete Clear Flag
00579   * @retval None
00580   */
00581 #define __HAL_IRDA_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
00582 
00583 
00584 /** @brief  Set a specific IRDA request flag.
00585   * @param  __HANDLE__: specifies the IRDA Handle.
00586   * @param  __REQ__: specifies the request flag to set
00587   *          This parameter can be one of the following values:
00588   *            @arg @ref IRDA_AUTOBAUD_REQUEST Auto-Baud Rate Request
00589   *            @arg @ref IRDA_RXDATA_FLUSH_REQUEST Receive Data flush Request
00590   *            @arg @ref IRDA_TXDATA_FLUSH_REQUEST Transmit data flush Request
00591   *
00592   * @retval None
00593   */
00594 #define __HAL_IRDA_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
00595 
00596 /** @brief  Enable the IRDA one bit sample method.
00597   * @param  __HANDLE__: specifies the IRDA Handle.  
00598   * @retval None
00599   */     
00600 #define __HAL_IRDA_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
00601 
00602 /** @brief  Disable the IRDA one bit sample method.
00603   * @param  __HANDLE__: specifies the IRDA Handle.  
00604   * @retval None
00605   */      
00606 #define __HAL_IRDA_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
00607 
00608 /** @brief  Enable UART/USART associated to IRDA Handle.
00609   * @param  __HANDLE__: specifies the IRDA Handle.
00610   * @retval None
00611   */
00612 #define __HAL_IRDA_ENABLE(__HANDLE__)                   ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
00613 
00614 /** @brief  Disable UART/USART associated to IRDA Handle.
00615   * @param  __HANDLE__: specifies the IRDA Handle.
00616   * @retval None
00617   */
00618 #define __HAL_IRDA_DISABLE(__HANDLE__)                  ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
00619 
00620 /**
00621   * @}
00622   */
00623 
00624 /* Private macros --------------------------------------------------------*/
00625 /** @defgroup IRDA_Private_Macros   IRDA Private Macros
00626   * @{
00627   */
00628 
00629 /** @brief  Compute the mask to apply to retrieve the received data
00630   *         according to the word length and to the parity bits activation.
00631   * @param  __HANDLE__: specifies the IRDA Handle.
00632   * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field.
00633   */
00634 #define IRDA_MASK_COMPUTATION(__HANDLE__)                             \
00635   do {                                                                \
00636   if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B)            \
00637   {                                                                   \
00638      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
00639      {                                                                \
00640         (__HANDLE__)->Mask = 0x01FF ;                                 \
00641      }                                                                \
00642      else                                                             \
00643      {                                                                \
00644         (__HANDLE__)->Mask = 0x00FF ;                                 \
00645      }                                                                \
00646   }                                                                   \
00647   else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B)       \
00648   {                                                                   \
00649      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
00650      {                                                                \
00651         (__HANDLE__)->Mask = 0x00FF ;                                 \
00652      }                                                                \
00653      else                                                             \
00654      {                                                                \
00655         (__HANDLE__)->Mask = 0x007F ;                                 \
00656      }                                                                \
00657   }                                                                   \
00658   else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B)       \
00659   {                                                                   \
00660      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
00661      {                                                                \
00662         (__HANDLE__)->Mask = 0x007F ;                                 \
00663      }                                                                \
00664      else                                                             \
00665      {                                                                \
00666         (__HANDLE__)->Mask = 0x003F ;                                 \
00667      }                                                                \
00668   }                                                                   \
00669 } while(0)
00670 
00671 /** @brief  Ensure that IRDA Baud rate is less or equal to maximum value.
00672   * @param  __BAUDRATE__: specifies the IRDA Baudrate set by the user.
00673   * @retval True or False
00674   */
00675 #define IS_IRDA_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 115201)
00676 
00677 /** @brief  Ensure that IRDA prescaler value is strictly larger than 0.
00678   * @param  __PRESCALER__: specifies the IRDA prescaler value set by the user.
00679   * @retval True or False
00680   */
00681 #define IS_IRDA_PRESCALER(__PRESCALER__) ((__PRESCALER__) > 0)
00682 
00683 /**
00684   * @brief Ensure that IRDA frame length is valid.
00685   * @param __LENGTH__: IRDA frame length. 
00686   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
00687   */ 
00688 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \
00689                                          ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \
00690                                          ((__LENGTH__) == IRDA_WORDLENGTH_9B))
00691 
00692 /**
00693   * @brief Ensure that IRDA frame parity is valid.
00694   * @param __PARITY__: IRDA frame parity. 
00695   * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
00696   */ 
00697 #define IS_IRDA_PARITY(__PARITY__) (((__PARITY__) == IRDA_PARITY_NONE) || \
00698                                     ((__PARITY__) == IRDA_PARITY_EVEN) || \
00699                                     ((__PARITY__) == IRDA_PARITY_ODD))
00700 
00701 /**
00702   * @brief Ensure that IRDA communication mode is valid.
00703   * @param __MODE__: IRDA communication mode. 
00704   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
00705   */ 
00706 #define IS_IRDA_TX_RX_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(IRDA_MODE_TX_RX)))) == (uint32_t)0x00) && ((__MODE__) != (uint32_t)0x00))
00707 
00708 /**
00709   * @brief Ensure that IRDA power mode is valid.
00710   * @param __MODE__: IRDA power mode. 
00711   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
00712   */ 
00713 #define IS_IRDA_POWERMODE(__MODE__) (((__MODE__) == IRDA_POWERMODE_LOWPOWER) || \
00714                                      ((__MODE__) == IRDA_POWERMODE_NORMAL))
00715 
00716 /**
00717   * @brief Ensure that IRDA state is valid.
00718   * @param __STATE__: IRDA state mode. 
00719   * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
00720   */ 
00721 #define IS_IRDA_STATE(__STATE__) (((__STATE__) == IRDA_STATE_DISABLE) || \
00722                                   ((__STATE__) == IRDA_STATE_ENABLE))
00723 
00724 /**
00725   * @brief Ensure that IRDA associated UART/USART mode is valid.
00726   * @param __MODE__: IRDA associated UART/USART mode. 
00727   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
00728   */ 
00729 #define IS_IRDA_MODE(__MODE__)  (((__MODE__) == IRDA_MODE_DISABLE) || \
00730                                  ((__MODE__) == IRDA_MODE_ENABLE))
00731 
00732 /**
00733   * @brief Ensure that IRDA sampling rate is valid.
00734   * @param __ONEBIT__: IRDA sampling rate. 
00735   * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
00736   */ 
00737 #define IS_IRDA_ONE_BIT_SAMPLE(__ONEBIT__)      (((__ONEBIT__) == IRDA_ONE_BIT_SAMPLE_DISABLE) || \
00738                                                  ((__ONEBIT__) == IRDA_ONE_BIT_SAMPLE_ENABLE))
00739 
00740 /**
00741   * @brief Ensure that IRDA DMA TX mode is valid.
00742   * @param __DMATX__: IRDA DMA TX mode. 
00743   * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
00744   */ 
00745 #define IS_IRDA_DMA_TX(__DMATX__)     (((__DMATX__) == IRDA_DMA_TX_DISABLE) || \
00746                                        ((__DMATX__) == IRDA_DMA_TX_ENABLE))
00747 
00748 /**
00749   * @brief Ensure that IRDA DMA RX mode is valid.
00750   * @param __DMARX__: IRDA DMA RX mode. 
00751   * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
00752   */ 
00753 #define IS_IRDA_DMA_RX(__DMARX__) (((__DMARX__) == IRDA_DMA_RX_DISABLE) || \
00754                                    ((__DMARX__) == IRDA_DMA_RX_ENABLE))
00755 
00756 /**
00757   * @brief Ensure that IRDA request is valid.
00758   * @param __PARAM__: IRDA request. 
00759   * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
00760   */ 
00761 #define IS_IRDA_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == IRDA_AUTOBAUD_REQUEST) || \
00762                                               ((__PARAM__) == IRDA_RXDATA_FLUSH_REQUEST) || \
00763                                               ((__PARAM__) == IRDA_TXDATA_FLUSH_REQUEST))
00764 /**
00765  * @}
00766  */
00767 
00768 /* Include IRDA HAL Extended module */
00769 #include "stm32l4xx_hal_irda_ex.h"
00770 
00771 /* Exported functions --------------------------------------------------------*/
00772 /** @addtogroup IRDA_Exported_Functions IRDA Exported Functions
00773   * @{
00774   */
00775 
00776 /** @addtogroup IRDA_Exported_Functions_Group1 Initialization and de-initialization functions
00777   * @{
00778   */
00779 
00780 /* Initialization and de-initialization functions  ****************************/
00781 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda);
00782 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda);
00783 void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda);
00784 void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda);
00785 
00786 /**
00787   * @}
00788   */
00789 
00790 /** @addtogroup IRDA_Exported_Functions_Group2 IO operation functions
00791   * @{
00792   */
00793 
00794 /* IO operation functions *****************************************************/
00795 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00796 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00797 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00798 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00799 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00800 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00801 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda);
00802 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda);
00803 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda);
00804 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda);
00805 void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda);
00806 void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda);
00807 void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
00808 void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
00809 void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda);
00810 
00811 /**
00812   * @}
00813   */
00814 
00815 /* Peripheral Control functions  ************************************************/
00816 
00817 /** @addtogroup IRDA_Exported_Functions_Group4 Peripheral State and Error functions
00818   * @{
00819   */
00820 
00821 /* Peripheral State and Error functions ***************************************/
00822 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda);
00823 uint32_t              HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda);
00824 
00825 /**
00826   * @}
00827   */
00828 
00829 /**
00830   * @}
00831   */
00832 
00833 /**
00834   * @}
00835   */
00836 
00837 /**
00838   * @}
00839   */
00840 
00841 #ifdef __cplusplus
00842 }
00843 #endif
00844 
00845 #endif /* __STM32L4xx_HAL_IRDA_H */
00846 
00847 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/