1 /** 2 ****************************************************************************** 3 * @file stm32u0xx_hal_irda_ex.h 4 * @author MCD Application Team 5 * @brief Header file of IRDA HAL Extended module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2023 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 STM32U0xx_HAL_IRDA_EX_H 21 #define STM32U0xx_HAL_IRDA_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32u0xx_hal_def.h" 29 30 /** @addtogroup STM32U0xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @defgroup IRDAEx IRDAEx 35 * @brief IRDA Extended HAL module driver 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /* Exported constants --------------------------------------------------------*/ 41 /** @defgroup IRDAEx_Extended_Exported_Constants IRDAEx Extended Exported Constants 42 * @{ 43 */ 44 45 /** @defgroup IRDAEx_Word_Length IRDAEx Word Length 46 * @{ 47 */ 48 #define IRDA_WORDLENGTH_7B USART_CR1_M1 /*!< 7-bit long frame */ 49 #define IRDA_WORDLENGTH_8B 0x00000000U /*!< 8-bit long frame */ 50 #define IRDA_WORDLENGTH_9B USART_CR1_M0 /*!< 9-bit long frame */ 51 /** 52 * @} 53 */ 54 55 /** 56 * @} 57 */ 58 59 /* Exported macros -----------------------------------------------------------*/ 60 61 /* Private macros ------------------------------------------------------------*/ 62 63 /** @defgroup IRDAEx_Private_Macros IRDAEx Private Macros 64 * @{ 65 */ 66 67 /** @brief Report the IRDA clock source. 68 * @param __HANDLE__ specifies the IRDA Handle. 69 * @param __CLOCKSOURCE__ output variable. 70 * @retval IRDA clocking source, written in __CLOCKSOURCE__. 71 */ 72 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 73 do { \ 74 if((__HANDLE__)->Instance == USART1) \ 75 { \ 76 (__CLOCKSOURCE__) = (uint32_t)RCC_PERIPHCLK_USART1; \ 77 } \ 78 else if((__HANDLE__)->Instance == USART2) \ 79 { \ 80 (__CLOCKSOURCE__) = (uint32_t)RCC_PERIPHCLK_USART2; \ 81 } \ 82 else \ 83 { \ 84 (__CLOCKSOURCE__) = 0U; \ 85 } \ 86 } while(0U) 87 88 89 /** @brief Compute the mask to apply to retrieve the received data 90 * according to the word length and to the parity bits activation. 91 * @param __HANDLE__ specifies the IRDA Handle. 92 * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field. 93 */ 94 #define IRDA_MASK_COMPUTATION(__HANDLE__) \ 95 do { \ 96 if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B) \ 97 { \ 98 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 99 { \ 100 (__HANDLE__)->Mask = 0x01FFU ; \ 101 } \ 102 else \ 103 { \ 104 (__HANDLE__)->Mask = 0x00FFU ; \ 105 } \ 106 } \ 107 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B) \ 108 { \ 109 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 110 { \ 111 (__HANDLE__)->Mask = 0x00FFU ; \ 112 } \ 113 else \ 114 { \ 115 (__HANDLE__)->Mask = 0x007FU ; \ 116 } \ 117 } \ 118 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B) \ 119 { \ 120 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 121 { \ 122 (__HANDLE__)->Mask = 0x007FU ; \ 123 } \ 124 else \ 125 { \ 126 (__HANDLE__)->Mask = 0x003FU ; \ 127 } \ 128 } \ 129 else \ 130 { \ 131 (__HANDLE__)->Mask = 0x0000U; \ 132 } \ 133 } while(0U) 134 135 /** @brief Ensure that IRDA frame length is valid. 136 * @param __LENGTH__ IRDA frame length. 137 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid) 138 */ 139 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \ 140 ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \ 141 ((__LENGTH__) == IRDA_WORDLENGTH_9B)) 142 /** 143 * @} 144 */ 145 146 /* Exported functions --------------------------------------------------------*/ 147 148 /** 149 * @} 150 */ 151 152 /** 153 * @} 154 */ 155 156 #ifdef __cplusplus 157 } 158 #endif 159 160 #endif /* STM32U0xx_HAL_IRDA_EX_H */ 161 162