1 /** 2 ****************************************************************************** 3 * @file stm32c0xx_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) 2022 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 STM32C0xx_HAL_IRDA_EX_H 21 #define STM32C0xx_HAL_IRDA_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32c0xx_hal_def.h" 29 30 /** @addtogroup STM32C0xx_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 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 77 { \ 78 case RCC_USART1CLKSOURCE_PCLK1: \ 79 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 80 break; \ 81 case RCC_USART1CLKSOURCE_HSIKER: \ 82 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 83 break; \ 84 case RCC_USART1CLKSOURCE_SYSCLK: \ 85 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 86 break; \ 87 case RCC_USART1CLKSOURCE_LSE: \ 88 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 89 break; \ 90 default: \ 91 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 92 break; \ 93 } \ 94 } \ 95 else if((__HANDLE__)->Instance == USART2) \ 96 { \ 97 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 98 } \ 99 else \ 100 { \ 101 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 102 } \ 103 } while(0U) 104 105 /** @brief Compute the mask to apply to retrieve the received data 106 * according to the word length and to the parity bits activation. 107 * @param __HANDLE__ specifies the IRDA Handle. 108 * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field. 109 */ 110 #define IRDA_MASK_COMPUTATION(__HANDLE__) \ 111 do { \ 112 if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B) \ 113 { \ 114 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 115 { \ 116 (__HANDLE__)->Mask = 0x01FFU ; \ 117 } \ 118 else \ 119 { \ 120 (__HANDLE__)->Mask = 0x00FFU ; \ 121 } \ 122 } \ 123 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B) \ 124 { \ 125 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 126 { \ 127 (__HANDLE__)->Mask = 0x00FFU ; \ 128 } \ 129 else \ 130 { \ 131 (__HANDLE__)->Mask = 0x007FU ; \ 132 } \ 133 } \ 134 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B) \ 135 { \ 136 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 137 { \ 138 (__HANDLE__)->Mask = 0x007FU ; \ 139 } \ 140 else \ 141 { \ 142 (__HANDLE__)->Mask = 0x003FU ; \ 143 } \ 144 } \ 145 else \ 146 { \ 147 (__HANDLE__)->Mask = 0x0000U; \ 148 } \ 149 } while(0U) 150 151 /** @brief Ensure that IRDA frame length is valid. 152 * @param __LENGTH__ IRDA frame length. 153 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid) 154 */ 155 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \ 156 ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \ 157 ((__LENGTH__) == IRDA_WORDLENGTH_9B)) 158 /** 159 * @} 160 */ 161 162 /* Exported functions --------------------------------------------------------*/ 163 164 /** 165 * @} 166 */ 167 168 /** 169 * @} 170 */ 171 172 #ifdef __cplusplus 173 } 174 #endif 175 176 #endif /* STM32C0xx_HAL_IRDA_EX_H */ 177 178