STM32F479xx HAL User Manual
stm32f4xx_hal_irda.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_irda.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of IRDA HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef __STM32F4xx_HAL_IRDA_H
00022 #define __STM32F4xx_HAL_IRDA_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f4xx_hal_def.h"
00030 
00031 /** @addtogroup STM32F4xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup IRDA
00036   * @{
00037   */
00038 
00039 /* Exported types ------------------------------------------------------------*/
00040 /** @defgroup IRDA_Exported_Types IRDA Exported Types
00041   * @{
00042   */
00043 /**
00044   * @brief IRDA Init Structure definition
00045   */
00046 typedef struct
00047 {
00048   uint32_t BaudRate;                  /*!< This member configures the IRDA communication baud rate.
00049                                            The baud rate is computed using the following formula:
00050                                            - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
00051                                            - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
00052 
00053   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
00054                                            This parameter can be a value of @ref IRDA_Word_Length */
00055 
00056   uint32_t Parity;                    /*!< Specifies the parity mode.
00057                                            This parameter can be a value of @ref IRDA_Parity
00058                                            @note When parity is enabled, the computed parity is inserted
00059                                                  at the MSB position of the transmitted data (9th bit when
00060                                                  the word length is set to 9 data bits; 8th bit when the
00061                                                  word length is set to 8 data bits). */
00062 
00063   uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
00064                                            This parameter can be a value of @ref IRDA_Mode */
00065 
00066   uint8_t  Prescaler;                 /*!< Specifies the Prescaler value to be programmed
00067                                            in the IrDA low-power Baud Register, for defining pulse width on which
00068                                            burst acceptance/rejection will be decided. This value is used as divisor
00069                                            of system clock to achieve required pulse width. */
00070 
00071   uint32_t IrDAMode;                  /*!< Specifies the IrDA mode
00072                                            This parameter can be a value of @ref IRDA_Low_Power */
00073 } IRDA_InitTypeDef;
00074 
00075 /**
00076   * @brief HAL IRDA State structures definition
00077   * @note  HAL IRDA State value is a combination of 2 different substates: gState and RxState.
00078   *        - gState contains IRDA state information related to global Handle management
00079   *          and also information related to Tx operations.
00080   *          gState value coding follow below described bitmap :
00081   *          b7-b6  Error information
00082   *             00 : No Error
00083   *             01 : (Not Used)
00084   *             10 : Timeout
00085   *             11 : Error
00086   *          b5     IP initialisation status
00087   *             0  : Reset (IP not initialized)
00088   *             1  : Init done (IP initialized. HAL IRDA Init function already called)
00089   *          b4-b3  (not used)
00090   *             xx : Should be set to 00
00091   *          b2     Intrinsic process state
00092   *             0  : Ready
00093   *             1  : Busy (IP busy with some configuration or internal operations)
00094   *          b1     (not used)
00095   *             x  : Should be set to 0
00096   *          b0     Tx state
00097   *             0  : Ready (no Tx operation ongoing)
00098   *             1  : Busy (Tx operation ongoing)
00099   *        - RxState contains information related to Rx operations.
00100   *          RxState value coding follow below described bitmap :
00101   *          b7-b6  (not used)
00102   *             xx : Should be set to 00
00103   *          b5     IP initialisation status
00104   *             0  : Reset (IP not initialized)
00105   *             1  : Init done (IP initialized)
00106   *          b4-b2  (not used)
00107   *            xxx : Should be set to 000
00108   *          b1     Rx state
00109   *             0  : Ready (no Rx operation ongoing)
00110   *             1  : Busy (Rx operation ongoing)
00111   *          b0     (not used)
00112   *             x  : Should be set to 0.
00113   */
00114 typedef enum
00115 {
00116   HAL_IRDA_STATE_RESET             = 0x00U,    /*!< Peripheral is not yet Initialized
00117                                                    Value is allowed for gState and RxState */
00118   HAL_IRDA_STATE_READY             = 0x20U,    /*!< Peripheral Initialized and ready for use
00119                                                    Value is allowed for gState and RxState */
00120   HAL_IRDA_STATE_BUSY              = 0x24U,    /*!< An internal process is ongoing
00121                                                    Value is allowed for gState only */
00122   HAL_IRDA_STATE_BUSY_TX           = 0x21U,    /*!< Data Transmission process is ongoing
00123                                                    Value is allowed for gState only */
00124   HAL_IRDA_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing
00125                                                    Value is allowed for RxState only */
00126   HAL_IRDA_STATE_BUSY_TX_RX        = 0x23U,    /*!< Data Transmission and Reception process is ongoing
00127                                                    Not to be used for neither gState nor RxState.
00128                                                    Value is result of combination (Or) between gState and RxState values */
00129   HAL_IRDA_STATE_TIMEOUT           = 0xA0U,    /*!< Timeout state
00130                                                    Value is allowed for gState only */
00131   HAL_IRDA_STATE_ERROR             = 0xE0U     /*!< Error
00132                                                    Value is allowed for gState only */
00133 } HAL_IRDA_StateTypeDef;
00134 
00135 /**
00136   * @brief IRDA handle Structure definition
00137   */
00138 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
00139 typedef struct __IRDA_HandleTypeDef
00140 #else
00141 typedef struct
00142 #endif  /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00143 {
00144   USART_TypeDef               *Instance;        /*!<  USART registers base address       */
00145 
00146   IRDA_InitTypeDef            Init;             /*!<  IRDA communication parameters      */
00147 
00148   uint8_t                     *pTxBuffPtr;      /*!<  Pointer to IRDA Tx transfer Buffer */
00149 
00150   uint16_t                    TxXferSize;       /*!<  IRDA Tx Transfer size              */
00151 
00152   __IO uint16_t               TxXferCount;      /*!<  IRDA Tx Transfer Counter           */
00153 
00154   uint8_t                     *pRxBuffPtr;      /*!<  Pointer to IRDA Rx transfer Buffer */
00155 
00156   uint16_t                    RxXferSize;       /*!<  IRDA Rx Transfer size              */
00157 
00158   __IO uint16_t               RxXferCount;      /*!<  IRDA Rx Transfer Counter           */
00159 
00160   DMA_HandleTypeDef           *hdmatx;          /*!<  IRDA Tx DMA Handle parameters      */
00161 
00162   DMA_HandleTypeDef           *hdmarx;          /*!<  IRDA Rx DMA Handle parameters      */
00163 
00164   HAL_LockTypeDef             Lock;             /*!<  Locking object                     */
00165 
00166   __IO HAL_IRDA_StateTypeDef  gState;           /*!<  IRDA state information related to global Handle management
00167                                                    and also related to Tx operations.
00168                                                    This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
00169 
00170   __IO HAL_IRDA_StateTypeDef  RxState;          /*!<  IRDA state information related to Rx operations.
00171                                                    This parameter can be a value of @ref HAL_IRDA_StateTypeDef */
00172 
00173   __IO uint32_t               ErrorCode;        /*!< IRDA Error code                    */
00174 
00175 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
00176   void (* TxHalfCpltCallback)(struct __IRDA_HandleTypeDef *hirda);        /*!< IRDA Tx Half Complete Callback        */
00177 
00178   void (* TxCpltCallback)(struct __IRDA_HandleTypeDef *hirda);            /*!< IRDA Tx Complete Callback             */
00179 
00180   void (* RxHalfCpltCallback)(struct __IRDA_HandleTypeDef *hirda);        /*!< IRDA Rx Half Complete Callback        */
00181 
00182   void (* RxCpltCallback)(struct __IRDA_HandleTypeDef *hirda);            /*!< IRDA Rx Complete Callback             */
00183 
00184   void (* ErrorCallback)(struct __IRDA_HandleTypeDef *hirda);             /*!< IRDA Error Callback                   */
00185 
00186   void (* AbortCpltCallback)(struct __IRDA_HandleTypeDef *hirda);         /*!< IRDA Abort Complete Callback          */
00187 
00188   void (* AbortTransmitCpltCallback)(struct __IRDA_HandleTypeDef *hirda); /*!< IRDA Abort Transmit Complete Callback */
00189 
00190   void (* AbortReceiveCpltCallback)(struct __IRDA_HandleTypeDef *hirda);  /*!< IRDA Abort Receive Complete Callback  */
00191 
00192 
00193   void (* MspInitCallback)(struct __IRDA_HandleTypeDef *hirda);           /*!< IRDA Msp Init callback                */
00194 
00195   void (* MspDeInitCallback)(struct __IRDA_HandleTypeDef *hirda);         /*!< IRDA Msp DeInit callback              */
00196 #endif  /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00197 
00198 } IRDA_HandleTypeDef;
00199 
00200 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
00201 /**
00202   * @brief  HAL IRDA Callback ID enumeration definition
00203   */
00204 typedef enum
00205 {
00206   HAL_IRDA_TX_HALFCOMPLETE_CB_ID         = 0x00U,    /*!< IRDA Tx Half Complete Callback ID        */
00207   HAL_IRDA_TX_COMPLETE_CB_ID             = 0x01U,    /*!< IRDA Tx Complete Callback ID             */
00208   HAL_IRDA_RX_HALFCOMPLETE_CB_ID         = 0x02U,    /*!< IRDA Rx Half Complete Callback ID        */
00209   HAL_IRDA_RX_COMPLETE_CB_ID             = 0x03U,    /*!< IRDA Rx Complete Callback ID             */
00210   HAL_IRDA_ERROR_CB_ID                   = 0x04U,    /*!< IRDA Error Callback ID                   */
00211   HAL_IRDA_ABORT_COMPLETE_CB_ID          = 0x05U,    /*!< IRDA Abort Complete Callback ID          */
00212   HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U,    /*!< IRDA Abort Transmit Complete Callback ID */
00213   HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID  = 0x07U,    /*!< IRDA Abort Receive Complete Callback ID  */
00214 
00215   HAL_IRDA_MSPINIT_CB_ID                 = 0x08U,    /*!< IRDA MspInit callback ID                 */
00216   HAL_IRDA_MSPDEINIT_CB_ID               = 0x09U     /*!< IRDA MspDeInit callback ID               */
00217 
00218 } HAL_IRDA_CallbackIDTypeDef;
00219 
00220 /**
00221   * @brief  HAL IRDA Callback pointer definition
00222   */
00223 typedef  void (*pIRDA_CallbackTypeDef)(IRDA_HandleTypeDef *hirda);  /*!< pointer to an IRDA callback function */
00224 
00225 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00226 
00227 /**
00228   * @}
00229   */
00230 
00231 /* Exported constants --------------------------------------------------------*/
00232 /** @defgroup IRDA_Exported_Constants IRDA Exported constants
00233   * @{
00234   */
00235 /** @defgroup IRDA_Error_Code IRDA Error Code
00236   * @{
00237   */
00238 #define HAL_IRDA_ERROR_NONE        0x00000000U   /*!< No error            */
00239 #define HAL_IRDA_ERROR_PE          0x00000001U   /*!< Parity error        */
00240 #define HAL_IRDA_ERROR_NE          0x00000002U   /*!< Noise error         */
00241 #define HAL_IRDA_ERROR_FE          0x00000004U   /*!< Frame error         */
00242 #define HAL_IRDA_ERROR_ORE         0x00000008U   /*!< Overrun error       */
00243 #define HAL_IRDA_ERROR_DMA         0x00000010U   /*!< DMA transfer error  */
00244 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
00245 #define HAL_IRDA_ERROR_INVALID_CALLBACK   ((uint32_t)0x00000020U)   /*!< Invalid Callback error  */
00246 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00247 /**
00248   * @}
00249   */
00250 
00251 /** @defgroup IRDA_Word_Length IRDA Word Length
00252   * @{
00253   */
00254 #define IRDA_WORDLENGTH_8B         0x00000000U
00255 #define IRDA_WORDLENGTH_9B         ((uint32_t)USART_CR1_M)
00256 /**
00257   * @}
00258   */
00259 
00260 /** @defgroup IRDA_Parity  IRDA Parity
00261   * @{
00262   */
00263 #define IRDA_PARITY_NONE           0x00000000U
00264 #define IRDA_PARITY_EVEN           ((uint32_t)USART_CR1_PCE)
00265 #define IRDA_PARITY_ODD            ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
00266 /**
00267   * @}
00268   */
00269 
00270 /** @defgroup IRDA_Mode IRDA Transfer Mode
00271   * @{
00272   */
00273 #define IRDA_MODE_RX               ((uint32_t)USART_CR1_RE)
00274 #define IRDA_MODE_TX               ((uint32_t)USART_CR1_TE)
00275 #define IRDA_MODE_TX_RX            ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
00276 /**
00277   * @}
00278   */
00279 
00280 /** @defgroup IRDA_Low_Power IRDA Low Power
00281   * @{
00282   */
00283 #define IRDA_POWERMODE_LOWPOWER    ((uint32_t)USART_CR3_IRLP)
00284 #define IRDA_POWERMODE_NORMAL      0x00000000U
00285 /**
00286   * @}
00287   */
00288 
00289 /** @defgroup IRDA_Flags IRDA Flags
00290   *        Elements values convention: 0xXXXX
00291   *           - 0xXXXX  : Flag mask in the SR register
00292   * @{
00293   */
00294 #define IRDA_FLAG_TXE              ((uint32_t)USART_SR_TXE)
00295 #define IRDA_FLAG_TC               ((uint32_t)USART_SR_TC)
00296 #define IRDA_FLAG_RXNE             ((uint32_t)USART_SR_RXNE)
00297 #define IRDA_FLAG_IDLE             ((uint32_t)USART_SR_IDLE)
00298 #define IRDA_FLAG_ORE              ((uint32_t)USART_SR_ORE)
00299 #define IRDA_FLAG_NE               ((uint32_t)USART_SR_NE)
00300 #define IRDA_FLAG_FE               ((uint32_t)USART_SR_FE)
00301 #define IRDA_FLAG_PE               ((uint32_t)USART_SR_PE)
00302 /**
00303   * @}
00304   */
00305 
00306 /** @defgroup IRDA_Interrupt_definition IRDA Interrupt Definitions
00307   *        Elements values convention: 0xY000XXXX
00308   *           - XXXX  : Interrupt mask in the XX register
00309   *           - Y  : Interrupt source register (2bits)
00310   *                 - 01: CR1 register
00311   *                 - 10: CR2 register
00312   *                 - 11: CR3 register
00313   * @{
00314   */
00315 #define IRDA_IT_PE                 ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
00316 #define IRDA_IT_TXE                ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
00317 #define IRDA_IT_TC                 ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
00318 #define IRDA_IT_RXNE               ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
00319 #define IRDA_IT_IDLE               ((uint32_t)(IRDA_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
00320 
00321 #define IRDA_IT_LBD                ((uint32_t)(IRDA_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
00322 
00323 #define IRDA_IT_CTS                ((uint32_t)(IRDA_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
00324 #define IRDA_IT_ERR                ((uint32_t)(IRDA_CR3_REG_INDEX << 28U | USART_CR3_EIE))
00325 /**
00326   * @}
00327   */
00328 
00329 /**
00330   * @}
00331   */
00332 
00333 /* Exported macro ------------------------------------------------------------*/
00334 /** @defgroup IRDA_Exported_Macros IRDA Exported Macros
00335   * @{
00336   */
00337 
00338 /** @brief Reset IRDA handle gstate & RxState
00339   * @param  __HANDLE__ specifies the IRDA Handle.
00340   *         IRDA Handle selects the USARTx or UARTy peripheral
00341   *         (USART,UART availability and x,y values depending on device).
00342   * @retval None
00343   */
00344 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
00345 #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
00346                                                        (__HANDLE__)->gState = HAL_IRDA_STATE_RESET;      \
00347                                                        (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET;     \
00348                                                        (__HANDLE__)->MspInitCallback = NULL;             \
00349                                                        (__HANDLE__)->MspDeInitCallback = NULL;           \
00350                                                      } while(0U)
00351 #else
00352 #define __HAL_IRDA_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
00353                                                        (__HANDLE__)->gState = HAL_IRDA_STATE_RESET;      \
00354                                                        (__HANDLE__)->RxState = HAL_IRDA_STATE_RESET;     \
00355                                                      } while(0U)
00356 #endif /*USE_HAL_IRDA_REGISTER_CALLBACKS  */
00357 
00358 /** @brief  Flush the IRDA DR register
00359   * @param  __HANDLE__ specifies the IRDA Handle.
00360   *         IRDA Handle selects the USARTx or UARTy peripheral
00361   *         (USART,UART availability and x,y values depending on device).
00362   * @retval None
00363   */
00364 #define __HAL_IRDA_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
00365 
00366 /** @brief  Check whether the specified IRDA flag is set or not.
00367   * @param  __HANDLE__ specifies the IRDA Handle.
00368   *         IRDA Handle selects the USARTx or UARTy peripheral
00369   *         (USART,UART availability and x,y values depending on device).
00370   * @param  __FLAG__ specifies the flag to check.
00371   *        This parameter can be one of the following values:
00372   *            @arg IRDA_FLAG_TXE:  Transmit data register empty flag
00373   *            @arg IRDA_FLAG_TC:   Transmission Complete flag
00374   *            @arg IRDA_FLAG_RXNE: Receive data register not empty flag
00375   *            @arg IRDA_FLAG_IDLE: Idle Line detection flag
00376   *            @arg IRDA_FLAG_ORE:  OverRun Error flag
00377   *            @arg IRDA_FLAG_NE:   Noise Error flag
00378   *            @arg IRDA_FLAG_FE:   Framing Error flag
00379   *            @arg IRDA_FLAG_PE:   Parity Error flag
00380   * @retval The new state of __FLAG__ (TRUE or FALSE).
00381   */
00382 #define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
00383 
00384 /** @brief  Clear the specified IRDA pending flag.
00385   * @param  __HANDLE__ specifies the IRDA Handle.
00386   *         IRDA Handle selects the USARTx or UARTy peripheral
00387   *         (USART,UART availability and x,y values depending on device).
00388   * @param  __FLAG__ specifies the flag to check.
00389   *          This parameter can be any combination of the following values:
00390   *            @arg IRDA_FLAG_TC:   Transmission Complete flag.
00391   *            @arg IRDA_FLAG_RXNE: Receive data register not empty flag.
00392   *
00393   * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
00394   *          error) and IDLE (Idle line detected) flags are cleared by software
00395   *          sequence: a read operation to USART_SR register followed by a read
00396   *          operation to USART_DR register.
00397   * @note   RXNE flag can be also cleared by a read to the USART_DR register.
00398   * @note   TC flag can be also cleared by software sequence: a read operation to
00399   *          USART_SR register followed by a write operation to USART_DR register.
00400   * @note   TXE flag is cleared only by a write to the USART_DR register.
00401   * @retval None
00402   */
00403 #define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
00404 
00405 /** @brief  Clear the IRDA PE pending flag.
00406   * @param  __HANDLE__ specifies the IRDA Handle.
00407   *         IRDA Handle selects the USARTx or UARTy peripheral
00408   *         (USART,UART availability and x,y values depending on device).
00409   * @retval None
00410   */
00411 #define __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)     \
00412   do{                                           \
00413     __IO uint32_t tmpreg = 0x00U;               \
00414     tmpreg = (__HANDLE__)->Instance->SR;        \
00415     tmpreg = (__HANDLE__)->Instance->DR;        \
00416     UNUSED(tmpreg);                             \
00417   } while(0U)
00418 
00419 /** @brief  Clear the IRDA FE pending flag.
00420   * @param  __HANDLE__ specifies the IRDA Handle.
00421   *         IRDA Handle selects the USARTx or UARTy peripheral
00422   *         (USART,UART availability and x,y values depending on device).
00423   * @retval None
00424   */
00425 #define __HAL_IRDA_CLEAR_FEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
00426 
00427 /** @brief  Clear the IRDA NE pending flag.
00428   * @param  __HANDLE__ specifies the IRDA Handle.
00429   *         IRDA Handle selects the USARTx or UARTy peripheral
00430   *         (USART,UART availability and x,y values depending on device).
00431   * @retval None
00432   */
00433 #define __HAL_IRDA_CLEAR_NEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
00434 
00435 /** @brief  Clear the IRDA ORE pending flag.
00436   * @param  __HANDLE__ specifies the IRDA Handle.
00437   *         IRDA Handle selects the USARTx or UARTy peripheral
00438   *         (USART,UART availability and x,y values depending on device).
00439   * @retval None
00440   */
00441 #define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
00442 
00443 /** @brief  Clear the IRDA IDLE pending flag.
00444   * @param  __HANDLE__ specifies the IRDA Handle.
00445   *         IRDA Handle selects the USARTx or UARTy peripheral
00446   *         (USART,UART availability and x,y values depending on device).
00447   * @retval None
00448   */
00449 #define __HAL_IRDA_CLEAR_IDLEFLAG(__HANDLE__) __HAL_IRDA_CLEAR_PEFLAG(__HANDLE__)
00450 
00451 /** @brief  Enable the specified IRDA interrupt.
00452   * @param  __HANDLE__ specifies the IRDA Handle.
00453   *         IRDA Handle selects the USARTx or UARTy peripheral
00454   *         (USART,UART availability and x,y values depending on device).
00455   * @param  __INTERRUPT__ specifies the IRDA interrupt source to enable.
00456   *          This parameter can be one of the following values:
00457   *            @arg IRDA_IT_TXE:  Transmit Data Register empty interrupt
00458   *            @arg IRDA_IT_TC:   Transmission complete interrupt
00459   *            @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
00460   *            @arg IRDA_IT_IDLE: Idle line detection interrupt
00461   *            @arg IRDA_IT_PE:   Parity Error interrupt
00462   *            @arg IRDA_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
00463   * @retval None
00464   */
00465 #define __HAL_IRDA_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28U) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & IRDA_IT_MASK)): \
00466                                                            (((__INTERRUPT__) >> 28U) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & IRDA_IT_MASK)): \
00467                                                             ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & IRDA_IT_MASK)))
00468 /** @brief  Disable the specified IRDA interrupt.
00469   * @param  __HANDLE__ specifies the IRDA Handle.
00470   *         IRDA Handle selects the USARTx or UARTy peripheral
00471   *         (USART,UART availability and x,y values depending on device).
00472   * @param  __INTERRUPT__ specifies the IRDA interrupt source to disable.
00473   *          This parameter can be one of the following values:
00474   *            @arg IRDA_IT_TXE:  Transmit Data Register empty interrupt
00475   *            @arg IRDA_IT_TC:   Transmission complete interrupt
00476   *            @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
00477   *            @arg IRDA_IT_IDLE: Idle line detection interrupt
00478   *            @arg IRDA_IT_PE:   Parity Error interrupt
00479   *            @arg IRDA_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
00480   * @retval None
00481   */
00482 #define __HAL_IRDA_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28U) == IRDA_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
00483                                                            (((__INTERRUPT__) >> 28U) == IRDA_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & IRDA_IT_MASK)): \
00484                                                            ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & IRDA_IT_MASK)))
00485 
00486 /** @brief  Check whether the specified IRDA interrupt has occurred or not.
00487   * @param  __HANDLE__ specifies the IRDA Handle.
00488   *         IRDA Handle selects the USARTx or UARTy peripheral
00489   *         (USART,UART availability and x,y values depending on device).
00490   * @param  __IT__ specifies the IRDA interrupt source to check.
00491   *          This parameter can be one of the following values:
00492   *            @arg IRDA_IT_TXE: Transmit Data Register empty interrupt
00493   *            @arg IRDA_IT_TC:  Transmission complete interrupt
00494   *            @arg IRDA_IT_RXNE: Receive Data register not empty interrupt
00495   *            @arg IRDA_IT_IDLE: Idle line detection interrupt
00496   *            @arg IRDA_IT_ERR: Error interrupt
00497   *            @arg IRDA_IT_PE: Parity Error interrupt
00498   * @retval The new state of __IT__ (TRUE or FALSE).
00499   */
00500 #define __HAL_IRDA_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == IRDA_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == IRDA_CR2_REG_INDEX)? \
00501                                                       (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & IRDA_IT_MASK))
00502 
00503 /** @brief  Macro to enable the IRDA's one bit sample method
00504   * @param  __HANDLE__ specifies the IRDA Handle.
00505   * @retval None
00506   */
00507 #define __HAL_IRDA_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 |= USART_CR3_ONEBIT)
00508 
00509 /** @brief  Macro to disable the IRDA's one bit sample method
00510   * @param  __HANDLE__ specifies the IRDA Handle.
00511   * @retval None
00512   */
00513 #define __HAL_IRDA_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
00514 
00515 /** @brief  Enable UART/USART associated to IRDA Handle
00516   * @param  __HANDLE__ specifies the IRDA Handle.
00517   *         IRDA Handle selects the USARTx or UARTy peripheral
00518   *         (USART,UART availability and x,y values depending on device).
00519   * @retval None
00520   */
00521 #define __HAL_IRDA_ENABLE(__HANDLE__)                   (SET_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
00522 
00523 /** @brief  Disable UART/USART associated to IRDA Handle
00524   * @param  __HANDLE__ specifies the IRDA Handle.
00525   *         IRDA Handle selects the USARTx or UARTy peripheral
00526   *         (USART,UART availability and x,y values depending on device).
00527   * @retval None
00528   */
00529 #define __HAL_IRDA_DISABLE(__HANDLE__)                  (CLEAR_BIT((__HANDLE__)->Instance->CR1, USART_CR1_UE))
00530 
00531 /**
00532   * @}
00533   */
00534 
00535 /* Exported functions --------------------------------------------------------*/
00536 /** @addtogroup IRDA_Exported_Functions
00537   * @{
00538   */
00539 
00540 /** @addtogroup IRDA_Exported_Functions_Group1
00541   * @{
00542   */
00543 /* Initialization/de-initialization functions  **********************************/
00544 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda);
00545 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda);
00546 void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda);
00547 void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda);
00548 
00549 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
00550 /* Callbacks Register/UnRegister functions  ***********************************/
00551 HAL_StatusTypeDef HAL_IRDA_RegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID, pIRDA_CallbackTypeDef pCallback);
00552 HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID);
00553 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00554 
00555 /**
00556   * @}
00557   */
00558 
00559 /** @addtogroup IRDA_Exported_Functions_Group2
00560   * @{
00561   */
00562 /* IO operation functions *******************************************************/
00563 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00564 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00565 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00566 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00567 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00568 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size);
00569 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda);
00570 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda);
00571 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda);
00572 /* Transfer Abort functions */
00573 HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda);
00574 HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda);
00575 HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda);
00576 HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda);
00577 HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda);
00578 HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda);
00579 
00580 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda);
00581 void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda);
00582 void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda);
00583 void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
00584 void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda);
00585 void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda);
00586 void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda);
00587 void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda);
00588 void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda);
00589 /**
00590   * @}
00591   */
00592 
00593 /** @addtogroup IRDA_Exported_Functions_Group3
00594   * @{
00595   */
00596 /* Peripheral State functions  **************************************************/
00597 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda);
00598 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda);
00599 /**
00600   * @}
00601   */
00602 
00603 /**
00604   * @}
00605   */
00606 
00607 /* Private types -------------------------------------------------------------*/
00608 /* Private variables ---------------------------------------------------------*/
00609 /* Private constants ---------------------------------------------------------*/
00610 /** @defgroup IRDA_Private_Constants IRDA Private Constants
00611   * @{
00612   */
00613 
00614 /** @brief IRDA interruptions flag mask
00615   *
00616   */
00617 #define IRDA_IT_MASK  ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
00618                                   USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
00619 
00620 #define IRDA_CR1_REG_INDEX         1U
00621 #define IRDA_CR2_REG_INDEX         2U
00622 #define IRDA_CR3_REG_INDEX         3U
00623 /**
00624   * @}
00625   */
00626 
00627 /* Private macros --------------------------------------------------------*/
00628 /** @defgroup IRDA_Private_Macros   IRDA Private Macros
00629   * @{
00630   */
00631 #define IS_IRDA_WORD_LENGTH(LENGTH)   (((LENGTH) == IRDA_WORDLENGTH_8B) || \
00632                                        ((LENGTH) == IRDA_WORDLENGTH_9B))
00633 
00634 #define IS_IRDA_PARITY(PARITY)        (((PARITY) == IRDA_PARITY_NONE) || \
00635                                        ((PARITY) == IRDA_PARITY_EVEN) || \
00636                                        ((PARITY) == IRDA_PARITY_ODD))
00637 
00638 #define IS_IRDA_MODE(MODE)            ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00000000U))
00639 
00640 #define IS_IRDA_POWERMODE(MODE)       (((MODE) == IRDA_POWERMODE_LOWPOWER) || \
00641                                        ((MODE) == IRDA_POWERMODE_NORMAL))
00642 
00643 #define IS_IRDA_BAUDRATE(BAUDRATE)    ((BAUDRATE) < 115201U)
00644 
00645 #define IRDA_DIV(_PCLK_, _BAUD_)      ((uint32_t)((((uint64_t)(_PCLK_))*25U)/(4U*(((uint64_t)(_BAUD_))))))
00646 
00647 #define IRDA_DIVMANT(_PCLK_, _BAUD_)  (IRDA_DIV((_PCLK_), (_BAUD_))/100U)
00648 
00649 #define IRDA_DIVFRAQ(_PCLK_, _BAUD_)  ((((IRDA_DIV((_PCLK_), (_BAUD_)) - (IRDA_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U)
00650 
00651 /* UART BRR = mantissa + overflow + fraction
00652             = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */
00653 #define IRDA_BRR(_PCLK_, _BAUD_)      (((IRDA_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
00654                                         (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
00655                                         (IRDA_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
00656 
00657 /**
00658   * @}
00659   */
00660 
00661 /* Private functions ---------------------------------------------------------*/
00662 /** @defgroup IRDA_Private_Functions IRDA Private Functions
00663   * @{
00664   */
00665 
00666 /**
00667   * @}
00668   */
00669 
00670 /**
00671   * @}
00672   */
00673 
00674 /**
00675   * @}
00676   */
00677 
00678 #ifdef __cplusplus
00679 }
00680 #endif
00681 
00682 #endif /* __STM32F4xx_HAL_IRDA_H */
00683 
00684 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/