1 /**
2   ******************************************************************************
3   * @file    stm32h7xx_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 STM32H7xx_HAL_IRDA_EX_H
21 #define STM32H7xx_HAL_IRDA_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h7xx_hal_def.h"
29 
30 /** @addtogroup STM32H7xx_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(UART9) && defined(USART10)
73 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
74   do {                                                        \
75     if((__HANDLE__)->Instance == USART1)                      \
76     {                                                         \
77       switch(__HAL_RCC_GET_USART1_SOURCE())                   \
78       {                                                       \
79         case RCC_USART1CLKSOURCE_D2PCLK2:                     \
80           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2;       \
81           break;                                              \
82         case RCC_USART1CLKSOURCE_PLL2:                        \
83           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
84           break;                                              \
85         case RCC_USART1CLKSOURCE_PLL3:                        \
86           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
87           break;                                              \
88         case RCC_USART1CLKSOURCE_HSI:                         \
89           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
90           break;                                              \
91         case RCC_USART1CLKSOURCE_CSI:                         \
92           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
93           break;                                              \
94         case RCC_USART1CLKSOURCE_LSE:                         \
95           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
96           break;                                              \
97         default:                                              \
98           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
99           break;                                              \
100       }                                                       \
101     }                                                         \
102     else if((__HANDLE__)->Instance == USART2)                 \
103     {                                                         \
104       switch(__HAL_RCC_GET_USART2_SOURCE())                   \
105       {                                                       \
106         case RCC_USART2CLKSOURCE_D2PCLK1:                     \
107           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
108           break;                                              \
109         case RCC_USART2CLKSOURCE_PLL2:                        \
110           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
111           break;                                              \
112         case RCC_USART2CLKSOURCE_PLL3:                        \
113           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
114           break;                                              \
115         case RCC_USART2CLKSOURCE_HSI:                         \
116           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
117           break;                                              \
118         case RCC_USART2CLKSOURCE_CSI:                         \
119           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
120           break;                                              \
121         case RCC_USART2CLKSOURCE_LSE:                         \
122           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
123           break;                                              \
124         default:                                              \
125           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
126           break;                                              \
127       }                                                       \
128     }                                                         \
129     else if((__HANDLE__)->Instance == USART3)                 \
130     {                                                         \
131       switch(__HAL_RCC_GET_USART3_SOURCE())                   \
132       {                                                       \
133         case RCC_USART3CLKSOURCE_D2PCLK1:                     \
134           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
135           break;                                              \
136         case RCC_USART3CLKSOURCE_PLL2:                        \
137           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
138           break;                                              \
139         case RCC_USART3CLKSOURCE_PLL3:                        \
140           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
141           break;                                              \
142         case RCC_USART3CLKSOURCE_HSI:                         \
143           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
144           break;                                              \
145         case RCC_USART3CLKSOURCE_CSI:                         \
146           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
147           break;                                              \
148         case RCC_USART3CLKSOURCE_LSE:                         \
149           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
150           break;                                              \
151         default:                                              \
152           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
153           break;                                              \
154       }                                                       \
155     }                                                         \
156     else if((__HANDLE__)->Instance == UART4)                  \
157     {                                                         \
158       switch(__HAL_RCC_GET_UART4_SOURCE())                    \
159       {                                                       \
160         case RCC_UART4CLKSOURCE_D2PCLK1:                      \
161           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
162           break;                                              \
163         case RCC_UART4CLKSOURCE_PLL2:                         \
164           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
165           break;                                              \
166         case RCC_UART4CLKSOURCE_PLL3:                         \
167           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
168           break;                                              \
169         case RCC_UART4CLKSOURCE_HSI:                          \
170           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
171           break;                                              \
172         case RCC_UART4CLKSOURCE_CSI:                          \
173           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
174           break;                                              \
175         case RCC_UART4CLKSOURCE_LSE:                          \
176           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
177           break;                                              \
178         default:                                              \
179           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
180           break;                                              \
181       }                                                       \
182     }                                                         \
183     else if ((__HANDLE__)->Instance == UART5)                 \
184     {                                                         \
185       switch(__HAL_RCC_GET_UART5_SOURCE())                    \
186       {                                                       \
187         case RCC_UART5CLKSOURCE_D2PCLK1:                      \
188           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
189           break;                                              \
190         case RCC_UART5CLKSOURCE_PLL2:                         \
191           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
192           break;                                              \
193         case RCC_UART5CLKSOURCE_PLL3:                         \
194           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
195           break;                                              \
196         case RCC_UART5CLKSOURCE_HSI:                          \
197           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
198           break;                                              \
199         case RCC_UART5CLKSOURCE_CSI:                          \
200           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
201           break;                                              \
202         case RCC_UART5CLKSOURCE_LSE:                          \
203           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
204           break;                                              \
205         default:                                              \
206           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
207           break;                                              \
208       }                                                       \
209     }                                                         \
210     else if((__HANDLE__)->Instance == USART6)                 \
211     {                                                         \
212       switch(__HAL_RCC_GET_USART6_SOURCE())                   \
213       {                                                       \
214         case RCC_USART6CLKSOURCE_D2PCLK2:                     \
215           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2;       \
216           break;                                              \
217         case RCC_USART6CLKSOURCE_PLL2:                        \
218           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
219           break;                                              \
220         case RCC_USART6CLKSOURCE_PLL3:                        \
221           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
222           break;                                              \
223         case RCC_USART6CLKSOURCE_HSI:                         \
224           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
225           break;                                              \
226         case RCC_USART6CLKSOURCE_CSI:                         \
227           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
228           break;                                              \
229         case RCC_USART6CLKSOURCE_LSE:                         \
230           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
231           break;                                              \
232         default:                                              \
233           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
234           break;                                              \
235       }                                                       \
236     }                                                         \
237     else if((__HANDLE__)->Instance == UART7)                  \
238     {                                                         \
239       switch(__HAL_RCC_GET_UART7_SOURCE())                    \
240       {                                                       \
241         case RCC_UART7CLKSOURCE_D2PCLK1:                      \
242           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
243           break;                                              \
244         case RCC_UART7CLKSOURCE_PLL2:                         \
245           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
246           break;                                              \
247         case RCC_UART7CLKSOURCE_PLL3:                         \
248           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
249           break;                                              \
250         case RCC_UART7CLKSOURCE_HSI:                          \
251           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
252           break;                                              \
253         case RCC_UART7CLKSOURCE_CSI:                          \
254           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
255           break;                                              \
256         case RCC_UART7CLKSOURCE_LSE:                          \
257           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
258           break;                                              \
259         default:                                              \
260           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
261           break;                                              \
262       }                                                       \
263     }                                                         \
264     else if((__HANDLE__)->Instance == UART8)                  \
265     {                                                         \
266       switch(__HAL_RCC_GET_UART8_SOURCE())                    \
267       {                                                       \
268         case RCC_UART8CLKSOURCE_D2PCLK1:                      \
269           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
270           break;                                              \
271         case RCC_UART8CLKSOURCE_PLL2:                         \
272           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
273           break;                                              \
274         case RCC_UART8CLKSOURCE_PLL3:                         \
275           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
276           break;                                              \
277         case RCC_UART8CLKSOURCE_HSI:                          \
278           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
279           break;                                              \
280         case RCC_UART8CLKSOURCE_CSI:                          \
281           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
282           break;                                              \
283         case RCC_UART8CLKSOURCE_LSE:                          \
284           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
285           break;                                              \
286         default:                                              \
287           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
288           break;                                              \
289       }                                                       \
290     }                                                         \
291     else if((__HANDLE__)->Instance == UART9)                  \
292     {                                                         \
293       switch(__HAL_RCC_GET_UART9_SOURCE())                    \
294       {                                                       \
295         case RCC_UART9CLKSOURCE_D2PCLK2:                      \
296           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2;       \
297           break;                                              \
298         case RCC_UART9CLKSOURCE_PLL2:                         \
299           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
300           break;                                              \
301         case RCC_UART9CLKSOURCE_PLL3:                         \
302           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
303           break;                                              \
304         case RCC_UART9CLKSOURCE_HSI:                          \
305           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
306           break;                                              \
307         case RCC_UART9CLKSOURCE_CSI:                          \
308           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
309           break;                                              \
310         case RCC_UART9CLKSOURCE_LSE:                          \
311           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
312           break;                                              \
313         default:                                              \
314           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
315           break;                                              \
316       }                                                       \
317     }                                                         \
318     else if((__HANDLE__)->Instance == USART10)                \
319     {                                                         \
320       switch(__HAL_RCC_GET_USART10_SOURCE())                  \
321       {                                                       \
322         case RCC_USART10CLKSOURCE_D2PCLK2:                    \
323           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2;       \
324           break;                                              \
325         case RCC_USART10CLKSOURCE_PLL2:                       \
326           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
327           break;                                              \
328         case RCC_USART10CLKSOURCE_PLL3:                       \
329           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
330           break;                                              \
331         case RCC_USART10CLKSOURCE_HSI:                        \
332           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
333           break;                                              \
334         case RCC_USART10CLKSOURCE_CSI:                        \
335           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
336           break;                                              \
337         case RCC_USART10CLKSOURCE_LSE:                        \
338           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
339           break;                                              \
340         default:                                              \
341           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
342           break;                                              \
343       }                                                       \
344     }                                                         \
345     else                                                      \
346     {                                                         \
347       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;         \
348     }                                                         \
349   } while(0U)
350 #else
351 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
352   do {                                                        \
353     if((__HANDLE__)->Instance == USART1)                      \
354     {                                                         \
355       switch(__HAL_RCC_GET_USART1_SOURCE())                   \
356       {                                                       \
357         case RCC_USART1CLKSOURCE_D2PCLK2:                     \
358           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2;       \
359           break;                                              \
360         case RCC_USART1CLKSOURCE_PLL2:                        \
361           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
362           break;                                              \
363         case RCC_USART1CLKSOURCE_PLL3:                        \
364           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
365           break;                                              \
366         case RCC_USART1CLKSOURCE_HSI:                         \
367           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
368           break;                                              \
369         case RCC_USART1CLKSOURCE_CSI:                         \
370           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
371           break;                                              \
372         case RCC_USART1CLKSOURCE_LSE:                         \
373           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
374           break;                                              \
375         default:                                              \
376           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
377           break;                                              \
378       }                                                       \
379     }                                                         \
380     else if((__HANDLE__)->Instance == USART2)                 \
381     {                                                         \
382       switch(__HAL_RCC_GET_USART2_SOURCE())                   \
383       {                                                       \
384         case RCC_USART2CLKSOURCE_D2PCLK1:                     \
385           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
386           break;                                              \
387         case RCC_USART2CLKSOURCE_PLL2:                        \
388           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
389           break;                                              \
390         case RCC_USART2CLKSOURCE_PLL3:                        \
391           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
392           break;                                              \
393         case RCC_USART2CLKSOURCE_HSI:                         \
394           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
395           break;                                              \
396         case RCC_USART2CLKSOURCE_CSI:                         \
397           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
398           break;                                              \
399         case RCC_USART2CLKSOURCE_LSE:                         \
400           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
401           break;                                              \
402         default:                                              \
403           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
404           break;                                              \
405       }                                                       \
406     }                                                         \
407     else if((__HANDLE__)->Instance == USART3)                 \
408     {                                                         \
409       switch(__HAL_RCC_GET_USART3_SOURCE())                   \
410       {                                                       \
411         case RCC_USART3CLKSOURCE_D2PCLK1:                     \
412           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
413           break;                                              \
414         case RCC_USART3CLKSOURCE_PLL2:                        \
415           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
416           break;                                              \
417         case RCC_USART3CLKSOURCE_PLL3:                        \
418           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
419           break;                                              \
420         case RCC_USART3CLKSOURCE_HSI:                         \
421           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
422           break;                                              \
423         case RCC_USART3CLKSOURCE_CSI:                         \
424           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
425           break;                                              \
426         case RCC_USART3CLKSOURCE_LSE:                         \
427           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
428           break;                                              \
429         default:                                              \
430           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
431           break;                                              \
432       }                                                       \
433     }                                                         \
434     else if((__HANDLE__)->Instance == UART4)                  \
435     {                                                         \
436       switch(__HAL_RCC_GET_UART4_SOURCE())                    \
437       {                                                       \
438         case RCC_UART4CLKSOURCE_D2PCLK1:                      \
439           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
440           break;                                              \
441         case RCC_UART4CLKSOURCE_PLL2:                         \
442           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
443           break;                                              \
444         case RCC_UART4CLKSOURCE_PLL3:                         \
445           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
446           break;                                              \
447         case RCC_UART4CLKSOURCE_HSI:                          \
448           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
449           break;                                              \
450         case RCC_UART4CLKSOURCE_CSI:                          \
451           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
452           break;                                              \
453         case RCC_UART4CLKSOURCE_LSE:                          \
454           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
455           break;                                              \
456         default:                                              \
457           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
458           break;                                              \
459       }                                                       \
460     }                                                         \
461     else if ((__HANDLE__)->Instance == UART5)                 \
462     {                                                         \
463       switch(__HAL_RCC_GET_UART5_SOURCE())                    \
464       {                                                       \
465         case RCC_UART5CLKSOURCE_D2PCLK1:                      \
466           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
467           break;                                              \
468         case RCC_UART5CLKSOURCE_PLL2:                         \
469           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
470           break;                                              \
471         case RCC_UART5CLKSOURCE_PLL3:                         \
472           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
473           break;                                              \
474         case RCC_UART5CLKSOURCE_HSI:                          \
475           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
476           break;                                              \
477         case RCC_UART5CLKSOURCE_CSI:                          \
478           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
479           break;                                              \
480         case RCC_UART5CLKSOURCE_LSE:                          \
481           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
482           break;                                              \
483         default:                                              \
484           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
485           break;                                              \
486       }                                                       \
487     }                                                         \
488     else if((__HANDLE__)->Instance == USART6)                 \
489     {                                                         \
490       switch(__HAL_RCC_GET_USART6_SOURCE())                   \
491       {                                                       \
492         case RCC_USART6CLKSOURCE_D2PCLK2:                     \
493           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK2;       \
494           break;                                              \
495         case RCC_USART6CLKSOURCE_PLL2:                        \
496           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
497           break;                                              \
498         case RCC_USART6CLKSOURCE_PLL3:                        \
499           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
500           break;                                              \
501         case RCC_USART6CLKSOURCE_HSI:                         \
502           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
503           break;                                              \
504         case RCC_USART6CLKSOURCE_CSI:                         \
505           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
506           break;                                              \
507         case RCC_USART6CLKSOURCE_LSE:                         \
508           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
509           break;                                              \
510         default:                                              \
511           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
512           break;                                              \
513       }                                                       \
514     }                                                         \
515     else if((__HANDLE__)->Instance == UART7)                  \
516     {                                                         \
517       switch(__HAL_RCC_GET_UART7_SOURCE())                    \
518       {                                                       \
519         case RCC_UART7CLKSOURCE_D2PCLK1:                      \
520           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
521           break;                                              \
522         case RCC_UART7CLKSOURCE_PLL2:                         \
523           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
524           break;                                              \
525         case RCC_UART7CLKSOURCE_PLL3:                         \
526           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
527           break;                                              \
528         case RCC_UART7CLKSOURCE_HSI:                          \
529           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
530           break;                                              \
531         case RCC_UART7CLKSOURCE_CSI:                          \
532           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
533           break;                                              \
534         case RCC_UART7CLKSOURCE_LSE:                          \
535           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
536           break;                                              \
537         default:                                              \
538           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
539           break;                                              \
540       }                                                       \
541     }                                                         \
542     else if((__HANDLE__)->Instance == UART8)                  \
543     {                                                         \
544       switch(__HAL_RCC_GET_UART8_SOURCE())                    \
545       {                                                       \
546         case RCC_UART8CLKSOURCE_D2PCLK1:                      \
547           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_D2PCLK1;       \
548           break;                                              \
549         case RCC_UART8CLKSOURCE_PLL2:                         \
550           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL2Q;         \
551           break;                                              \
552         case RCC_UART8CLKSOURCE_PLL3:                         \
553           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PLL3Q;         \
554           break;                                              \
555         case RCC_UART8CLKSOURCE_HSI:                          \
556           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
557           break;                                              \
558         case RCC_UART8CLKSOURCE_CSI:                          \
559           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_CSI;           \
560           break;                                              \
561         case RCC_UART8CLKSOURCE_LSE:                          \
562           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
563           break;                                              \
564         default:                                              \
565           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
566           break;                                              \
567       }                                                       \
568     }                                                         \
569     else                                                      \
570     {                                                         \
571       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;         \
572     }                                                         \
573   } while(0U)
574 #endif /* UART9 && USART10 */
575 
576 /** @brief  Compute the mask to apply to retrieve the received data
577   *         according to the word length and to the parity bits activation.
578   * @param  __HANDLE__ specifies the IRDA Handle.
579   * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field.
580   */
581 #define IRDA_MASK_COMPUTATION(__HANDLE__)                             \
582   do {                                                                \
583     if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B)          \
584     {                                                                 \
585       if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)              \
586       {                                                               \
587         (__HANDLE__)->Mask = 0x01FFU ;                                \
588       }                                                               \
589       else                                                            \
590       {                                                               \
591         (__HANDLE__)->Mask = 0x00FFU ;                                \
592       }                                                               \
593     }                                                                 \
594     else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B)     \
595     {                                                                 \
596       if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)              \
597       {                                                               \
598         (__HANDLE__)->Mask = 0x00FFU ;                                \
599       }                                                               \
600       else                                                            \
601       {                                                               \
602         (__HANDLE__)->Mask = 0x007FU ;                                \
603       }                                                               \
604     }                                                                 \
605     else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B)     \
606     {                                                                 \
607       if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)              \
608       {                                                               \
609         (__HANDLE__)->Mask = 0x007FU ;                                \
610       }                                                               \
611       else                                                            \
612       {                                                               \
613         (__HANDLE__)->Mask = 0x003FU ;                                \
614       }                                                               \
615     }                                                                 \
616     else                                                              \
617     {                                                                 \
618       (__HANDLE__)->Mask = 0x0000U;                                   \
619     }                                                                 \
620   } while(0U)
621 
622 /** @brief Ensure that IRDA frame length is valid.
623   * @param __LENGTH__ IRDA frame length.
624   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
625   */
626 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \
627                                          ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \
628                                          ((__LENGTH__) == IRDA_WORDLENGTH_9B))
629 /**
630   * @}
631   */
632 
633 /* Exported functions --------------------------------------------------------*/
634 
635 /**
636   * @}
637   */
638 
639 /**
640   * @}
641   */
642 
643 #ifdef __cplusplus
644 }
645 #endif
646 
647 #endif /* STM32H7xx_HAL_IRDA_EX_H */
648 
649