1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_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) 2017 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 STM32L4xx_HAL_IRDA_EX_H 21 #define STM32L4xx_HAL_IRDA_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l4xx_hal_def.h" 29 30 /** @addtogroup STM32L4xx_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 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) \ 73 || defined (STM32L496xx) || defined (STM32L4A6xx) \ 74 || defined (STM32L4P5xx) || defined (STM32L4Q5xx) \ 75 || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 76 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 77 do { \ 78 if((__HANDLE__)->Instance == USART1) \ 79 { \ 80 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 81 { \ 82 case RCC_USART1CLKSOURCE_PCLK2: \ 83 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \ 84 break; \ 85 case RCC_USART1CLKSOURCE_HSI: \ 86 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 87 break; \ 88 case RCC_USART1CLKSOURCE_SYSCLK: \ 89 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 90 break; \ 91 case RCC_USART1CLKSOURCE_LSE: \ 92 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 93 break; \ 94 default: \ 95 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 96 break; \ 97 } \ 98 } \ 99 else if((__HANDLE__)->Instance == USART2) \ 100 { \ 101 switch(__HAL_RCC_GET_USART2_SOURCE()) \ 102 { \ 103 case RCC_USART2CLKSOURCE_PCLK1: \ 104 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 105 break; \ 106 case RCC_USART2CLKSOURCE_HSI: \ 107 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 108 break; \ 109 case RCC_USART2CLKSOURCE_SYSCLK: \ 110 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 111 break; \ 112 case RCC_USART2CLKSOURCE_LSE: \ 113 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 114 break; \ 115 default: \ 116 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 117 break; \ 118 } \ 119 } \ 120 else if((__HANDLE__)->Instance == USART3) \ 121 { \ 122 switch(__HAL_RCC_GET_USART3_SOURCE()) \ 123 { \ 124 case RCC_USART3CLKSOURCE_PCLK1: \ 125 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 126 break; \ 127 case RCC_USART3CLKSOURCE_HSI: \ 128 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 129 break; \ 130 case RCC_USART3CLKSOURCE_SYSCLK: \ 131 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 132 break; \ 133 case RCC_USART3CLKSOURCE_LSE: \ 134 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 135 break; \ 136 default: \ 137 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 138 break; \ 139 } \ 140 } \ 141 else if((__HANDLE__)->Instance == UART4) \ 142 { \ 143 switch(__HAL_RCC_GET_UART4_SOURCE()) \ 144 { \ 145 case RCC_UART4CLKSOURCE_PCLK1: \ 146 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 147 break; \ 148 case RCC_UART4CLKSOURCE_HSI: \ 149 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 150 break; \ 151 case RCC_UART4CLKSOURCE_SYSCLK: \ 152 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 153 break; \ 154 case RCC_UART4CLKSOURCE_LSE: \ 155 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 156 break; \ 157 default: \ 158 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 159 break; \ 160 } \ 161 } \ 162 else if ((__HANDLE__)->Instance == UART5) \ 163 { \ 164 switch(__HAL_RCC_GET_UART5_SOURCE()) \ 165 { \ 166 case RCC_UART5CLKSOURCE_PCLK1: \ 167 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 168 break; \ 169 case RCC_UART5CLKSOURCE_HSI: \ 170 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 171 break; \ 172 case RCC_UART5CLKSOURCE_SYSCLK: \ 173 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 174 break; \ 175 case RCC_UART5CLKSOURCE_LSE: \ 176 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 177 break; \ 178 default: \ 179 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 180 break; \ 181 } \ 182 } \ 183 else \ 184 { \ 185 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 186 } \ 187 } while(0) 188 #elif defined (STM32L412xx) || defined (STM32L422xx) || defined (STM32L431xx) || defined (STM32L433xx) || defined (STM32L443xx) 189 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 190 do { \ 191 if((__HANDLE__)->Instance == USART1) \ 192 { \ 193 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 194 { \ 195 case RCC_USART1CLKSOURCE_PCLK2: \ 196 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \ 197 break; \ 198 case RCC_USART1CLKSOURCE_HSI: \ 199 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 200 break; \ 201 case RCC_USART1CLKSOURCE_SYSCLK: \ 202 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 203 break; \ 204 case RCC_USART1CLKSOURCE_LSE: \ 205 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 206 break; \ 207 default: \ 208 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 209 break; \ 210 } \ 211 } \ 212 else if((__HANDLE__)->Instance == USART2) \ 213 { \ 214 switch(__HAL_RCC_GET_USART2_SOURCE()) \ 215 { \ 216 case RCC_USART2CLKSOURCE_PCLK1: \ 217 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 218 break; \ 219 case RCC_USART2CLKSOURCE_HSI: \ 220 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 221 break; \ 222 case RCC_USART2CLKSOURCE_SYSCLK: \ 223 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 224 break; \ 225 case RCC_USART2CLKSOURCE_LSE: \ 226 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 227 break; \ 228 default: \ 229 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 230 break; \ 231 } \ 232 } \ 233 else if((__HANDLE__)->Instance == USART3) \ 234 { \ 235 switch(__HAL_RCC_GET_USART3_SOURCE()) \ 236 { \ 237 case RCC_USART3CLKSOURCE_PCLK1: \ 238 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 239 break; \ 240 case RCC_USART3CLKSOURCE_HSI: \ 241 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 242 break; \ 243 case RCC_USART3CLKSOURCE_SYSCLK: \ 244 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 245 break; \ 246 case RCC_USART3CLKSOURCE_LSE: \ 247 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 248 break; \ 249 default: \ 250 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 251 break; \ 252 } \ 253 } \ 254 else \ 255 { \ 256 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 257 } \ 258 } while(0) 259 #elif defined (STM32L432xx) || defined (STM32L442xx) 260 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 261 do { \ 262 if((__HANDLE__)->Instance == USART1) \ 263 { \ 264 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 265 { \ 266 case RCC_USART1CLKSOURCE_PCLK2: \ 267 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \ 268 break; \ 269 case RCC_USART1CLKSOURCE_HSI: \ 270 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 271 break; \ 272 case RCC_USART1CLKSOURCE_SYSCLK: \ 273 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 274 break; \ 275 case RCC_USART1CLKSOURCE_LSE: \ 276 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 277 break; \ 278 default: \ 279 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 280 break; \ 281 } \ 282 } \ 283 else if((__HANDLE__)->Instance == USART2) \ 284 { \ 285 switch(__HAL_RCC_GET_USART2_SOURCE()) \ 286 { \ 287 case RCC_USART2CLKSOURCE_PCLK1: \ 288 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 289 break; \ 290 case RCC_USART2CLKSOURCE_HSI: \ 291 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 292 break; \ 293 case RCC_USART2CLKSOURCE_SYSCLK: \ 294 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 295 break; \ 296 case RCC_USART2CLKSOURCE_LSE: \ 297 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 298 break; \ 299 default: \ 300 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 301 break; \ 302 } \ 303 } \ 304 else \ 305 { \ 306 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 307 } \ 308 } while(0) 309 #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) 310 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 311 do { \ 312 if((__HANDLE__)->Instance == USART1) \ 313 { \ 314 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 315 { \ 316 case RCC_USART1CLKSOURCE_PCLK2: \ 317 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \ 318 break; \ 319 case RCC_USART1CLKSOURCE_HSI: \ 320 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 321 break; \ 322 case RCC_USART1CLKSOURCE_SYSCLK: \ 323 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 324 break; \ 325 case RCC_USART1CLKSOURCE_LSE: \ 326 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 327 break; \ 328 default: \ 329 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 330 break; \ 331 } \ 332 } \ 333 else if((__HANDLE__)->Instance == USART2) \ 334 { \ 335 switch(__HAL_RCC_GET_USART2_SOURCE()) \ 336 { \ 337 case RCC_USART2CLKSOURCE_PCLK1: \ 338 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 339 break; \ 340 case RCC_USART2CLKSOURCE_HSI: \ 341 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 342 break; \ 343 case RCC_USART2CLKSOURCE_SYSCLK: \ 344 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 345 break; \ 346 case RCC_USART2CLKSOURCE_LSE: \ 347 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 348 break; \ 349 default: \ 350 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 351 break; \ 352 } \ 353 } \ 354 else if((__HANDLE__)->Instance == USART3) \ 355 { \ 356 switch(__HAL_RCC_GET_USART3_SOURCE()) \ 357 { \ 358 case RCC_USART3CLKSOURCE_PCLK1: \ 359 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 360 break; \ 361 case RCC_USART3CLKSOURCE_HSI: \ 362 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 363 break; \ 364 case RCC_USART3CLKSOURCE_SYSCLK: \ 365 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 366 break; \ 367 case RCC_USART3CLKSOURCE_LSE: \ 368 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 369 break; \ 370 default: \ 371 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 372 break; \ 373 } \ 374 } \ 375 else if((__HANDLE__)->Instance == UART4) \ 376 { \ 377 switch(__HAL_RCC_GET_UART4_SOURCE()) \ 378 { \ 379 case RCC_UART4CLKSOURCE_PCLK1: \ 380 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \ 381 break; \ 382 case RCC_UART4CLKSOURCE_HSI: \ 383 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \ 384 break; \ 385 case RCC_UART4CLKSOURCE_SYSCLK: \ 386 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \ 387 break; \ 388 case RCC_UART4CLKSOURCE_LSE: \ 389 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \ 390 break; \ 391 default: \ 392 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 393 break; \ 394 } \ 395 } \ 396 else \ 397 { \ 398 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED; \ 399 } \ 400 } while(0) 401 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || 402 * STM32L496xx || STM32L4A6xx || 403 * STM32L4P5xx || STM32L4Q5xx || 404 * STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx 405 */ 406 407 /** @brief Compute the mask to apply to retrieve the received data 408 * according to the word length and to the parity bits activation. 409 * @param __HANDLE__ specifies the IRDA Handle. 410 * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field. 411 */ 412 #define IRDA_MASK_COMPUTATION(__HANDLE__) \ 413 do { \ 414 if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B) \ 415 { \ 416 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 417 { \ 418 (__HANDLE__)->Mask = 0x01FFU ; \ 419 } \ 420 else \ 421 { \ 422 (__HANDLE__)->Mask = 0x00FFU ; \ 423 } \ 424 } \ 425 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B) \ 426 { \ 427 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 428 { \ 429 (__HANDLE__)->Mask = 0x00FFU ; \ 430 } \ 431 else \ 432 { \ 433 (__HANDLE__)->Mask = 0x007FU ; \ 434 } \ 435 } \ 436 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B) \ 437 { \ 438 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \ 439 { \ 440 (__HANDLE__)->Mask = 0x007FU ; \ 441 } \ 442 else \ 443 { \ 444 (__HANDLE__)->Mask = 0x003FU ; \ 445 } \ 446 } \ 447 else \ 448 { \ 449 (__HANDLE__)->Mask = 0x0000U; \ 450 } \ 451 } while(0U) 452 453 /** @brief Ensure that IRDA frame length is valid. 454 * @param __LENGTH__ IRDA frame length. 455 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid) 456 */ 457 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \ 458 ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \ 459 ((__LENGTH__) == IRDA_WORDLENGTH_9B)) 460 /** 461 * @} 462 */ 463 464 /* Exported functions --------------------------------------------------------*/ 465 466 /** 467 * @} 468 */ 469 470 /** 471 * @} 472 */ 473 474 #ifdef __cplusplus 475 } 476 #endif 477 478 #endif /* STM32L4xx_HAL_IRDA_EX_H */ 479 480