1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_irda_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of IRDA HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35 
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32L0xx_HAL_IRDA_EX_H
38 #define __STM32L0xx_HAL_IRDA_EX_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32l0xx_hal_def.h"
46 
47 /** @addtogroup STM32L0xx_HAL_Driver
48   * @{
49   */
50 
51 /** @addtogroup IRDAEx
52   * @{
53   */
54 
55 /* Exported types ------------------------------------------------------------*/
56 /* Exported constants --------------------------------------------------------*/
57 /* Exported macros -----------------------------------------------------------*/
58 /* Exported functions --------------------------------------------------------*/
59 
60 /* Private macros ------------------------------------------------------------*/
61 
62 /** @defgroup IRDAEx_Private_Macros IRDAEx Private Macros
63   * @{
64   */
65 
66 /** @brief  Report the IRDA clock source.
67   * @param  __HANDLE__: specifies the IRDA Handle.
68   * @param  __CLOCKSOURCE__: output variable.
69   * @retval IRDA clocking source, written in __CLOCKSOURCE__.
70   */
71 #if defined (STM32L031xx) || defined (STM32L041xx) || defined (STM32L011xx) || defined (STM32L021xx)
72 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
73   do {                                                        \
74     if((__HANDLE__)->Instance == USART2)                      \
75     {                                                         \
76        switch(__HAL_RCC_GET_USART2_SOURCE())                  \
77        {                                                      \
78         case RCC_USART2CLKSOURCE_PCLK1:                       \
79           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
80           break;                                              \
81         case RCC_USART2CLKSOURCE_HSI:                         \
82           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
83           break;                                              \
84         case RCC_USART2CLKSOURCE_SYSCLK:                      \
85           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
86           break;                                              \
87         case RCC_USART2CLKSOURCE_LSE:                         \
88           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
89           break;                                              \
90         default:                                              \
91           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
92           break;                                              \
93        }                                                      \
94     }                                                         \
95     else if((__HANDLE__)->Instance == LPUART1)                \
96     {                                                         \
97        switch(__HAL_RCC_GET_LPUART1_SOURCE())                 \
98        {                                                      \
99         case RCC_LPUART1CLKSOURCE_PCLK1:                      \
100           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
101           break;                                              \
102         case RCC_LPUART1CLKSOURCE_HSI:                        \
103           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
104           break;                                              \
105         case RCC_LPUART1CLKSOURCE_SYSCLK:                     \
106           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
107           break;                                              \
108         case RCC_LPUART1CLKSOURCE_LSE:                        \
109           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
110           break;                                              \
111         default:                                              \
112           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
113           break;                                              \
114        }                                                      \
115     }                                                         \
116   } while(0)
117 
118 #else /* (STM32L031xx) || defined (STM32L041xx) || (STM32L011xx) || defined (STM32L021xx) */
119 
120 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
121   do {                                                        \
122     if((__HANDLE__)->Instance == USART1)                      \
123     {                                                         \
124        switch(__HAL_RCC_GET_USART1_SOURCE())                  \
125        {                                                      \
126         case RCC_USART1CLKSOURCE_PCLK2:                       \
127           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2;         \
128           break;                                              \
129         case RCC_USART1CLKSOURCE_HSI:                         \
130           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
131           break;                                              \
132         case RCC_USART1CLKSOURCE_SYSCLK:                      \
133           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
134           break;                                              \
135         case RCC_USART1CLKSOURCE_LSE:                         \
136           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
137           break;                                              \
138         default:                                              \
139           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
140           break;                                              \
141        }                                                      \
142     }                                                         \
143     else if((__HANDLE__)->Instance == USART2)                 \
144     {                                                         \
145        switch(__HAL_RCC_GET_USART2_SOURCE())                  \
146        {                                                      \
147         case RCC_USART2CLKSOURCE_PCLK1:                       \
148           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
149           break;                                              \
150         case RCC_USART2CLKSOURCE_HSI:                         \
151           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
152           break;                                              \
153         case RCC_USART2CLKSOURCE_SYSCLK:                      \
154           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
155           break;                                              \
156         case RCC_USART2CLKSOURCE_LSE:                         \
157           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
158           break;                                              \
159         default:                                              \
160           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
161           break;                                              \
162        }                                                      \
163     }                                                         \
164     else if((__HANDLE__)->Instance == LPUART1)                \
165     {                                                         \
166        switch(__HAL_RCC_GET_LPUART1_SOURCE())                 \
167        {                                                      \
168         case RCC_LPUART1CLKSOURCE_PCLK1:                      \
169           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
170           break;                                              \
171         case RCC_LPUART1CLKSOURCE_HSI:                        \
172           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
173           break;                                              \
174         case RCC_LPUART1CLKSOURCE_SYSCLK:                     \
175           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
176           break;                                              \
177         case RCC_LPUART1CLKSOURCE_LSE:                        \
178           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
179           break;                                              \
180         default:                                              \
181           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
182           break;                                              \
183        }                                                      \
184     }                                                         \
185   } while(0)
186 #endif /* (STM32L031xx) || (STM32L041xx) || (STM32L011xx) || (STM32L021xx) */
187 
188 /**
189   * @}
190   */
191 
192 /* Exported functions --------------------------------------------------------*/
193 
194 /**
195   * @}
196   */
197 
198 /**
199   * @}
200   */
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #endif /* __STM32L0xx_HAL_IRDA_EX_H */
207 
208 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
209 
210