2 ******************************************************************************
3 * @file stm32l0xx_hal_irda_ex.h
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief Header file of IRDA HAL Extension module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2013 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L0xx_HAL_IRDA_EX_H
40 #define __STM32L0xx_HAL_IRDA_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l0xx_hal_def.h"
49 /** @addtogroup STM32L0xx_HAL_Driver
53 /** @addtogroup IRDAEx
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup IRDAEx_Extended_Exported_Constants IRDA Extended Exported Constants
63 /** @defgroup IRDAEx_Word_Length IRDAEx Word length
66 #define IRDA_WORDLENGTH_7B ((uint32_t)USART_CR1_M_1)
67 #define IRDA_WORDLENGTH_8B ((uint32_t)0x00000000)
68 #define IRDA_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0)
69 #define IS_IRDA_WORD_LENGTH(LENGTH) (((LENGTH) == IRDA_WORDLENGTH_7B) || \
70 ((LENGTH) == IRDA_WORDLENGTH_8B) || \
71 ((LENGTH) == IRDA_WORDLENGTH_9B))
81 /* Exported macro ------------------------------------------------------------*/
83 /** @defgroup IRDAEx_Extended_Exported_Macros IRDA Extended Exported Macros
86 /** @brief Reports the IRDA clock source.
87 * @param __HANDLE__: specifies the UART Handle
88 * @param __CLOCKSOURCE__ : output variable
89 * @retval IRDA clocking source, written in __CLOCKSOURCE__.
91 #if defined (STM32L031xx) || defined (STM32L041xx)
92 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
94 if((__HANDLE__)->Instance == USART2) \
96 switch(__HAL_RCC_GET_USART2_SOURCE()) \
98 case RCC_USART2CLKSOURCE_PCLK1: \
99 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
101 case RCC_USART2CLKSOURCE_HSI: \
102 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
104 case RCC_USART2CLKSOURCE_SYSCLK: \
105 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
107 case RCC_USART2CLKSOURCE_LSE: \
108 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
114 else if((__HANDLE__)->Instance == LPUART1) \
116 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
118 case RCC_LPUART1CLKSOURCE_PCLK1: \
119 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
121 case RCC_LPUART1CLKSOURCE_HSI: \
122 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
124 case RCC_LPUART1CLKSOURCE_SYSCLK: \
125 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
127 case RCC_LPUART1CLKSOURCE_LSE: \
128 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
136 #else /* (STM32L031xx) || defined (STM32L041xx) */
138 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
140 if((__HANDLE__)->Instance == USART1) \
142 switch(__HAL_RCC_GET_USART1_SOURCE()) \
144 case RCC_USART1CLKSOURCE_PCLK2: \
145 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK2; \
147 case RCC_USART1CLKSOURCE_HSI: \
148 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
150 case RCC_USART1CLKSOURCE_SYSCLK: \
151 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
153 case RCC_USART1CLKSOURCE_LSE: \
154 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
160 else if((__HANDLE__)->Instance == USART2) \
162 switch(__HAL_RCC_GET_USART2_SOURCE()) \
164 case RCC_USART2CLKSOURCE_PCLK1: \
165 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
167 case RCC_USART2CLKSOURCE_HSI: \
168 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
170 case RCC_USART2CLKSOURCE_SYSCLK: \
171 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
173 case RCC_USART2CLKSOURCE_LSE: \
174 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
180 else if((__HANDLE__)->Instance == LPUART1) \
182 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
184 case RCC_LPUART1CLKSOURCE_PCLK1: \
185 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1; \
187 case RCC_LPUART1CLKSOURCE_HSI: \
188 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI; \
190 case RCC_LPUART1CLKSOURCE_SYSCLK: \
191 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK; \
193 case RCC_LPUART1CLKSOURCE_LSE: \
194 (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE; \
201 #endif /* (STM32L031xx) || (STM32L041xx) */
203 /** @brief Reports the mask to apply to retrieve the received data
204 * according to the word length and to the parity bits activation.
205 * @param __HANDLE__: specifies the IRDA Handle
206 * @retval mask to apply to USART RDR register value.
208 #define IRDA_MASK_COMPUTATION(__HANDLE__) \
210 if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B) \
212 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
214 (__HANDLE__)->Mask = 0x01FF ; \
218 (__HANDLE__)->Mask = 0x00FF ; \
221 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B) \
223 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
225 (__HANDLE__)->Mask = 0x00FF ; \
229 (__HANDLE__)->Mask = 0x007F ; \
232 else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B) \
234 if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE) \
236 (__HANDLE__)->Mask = 0x007F ; \
240 (__HANDLE__)->Mask = 0x003F ; \
248 /* Exported functions --------------------------------------------------------*/
249 /* Initialization/de-initialization methods **********************************/
250 /* IO operation methods *******************************************************/
251 /* Peripheral Control methods ************************************************/
252 /* Peripheral State methods **************************************************/
267 #endif /* __STM32L0xx_HAL_IRDA_EX_H */
269 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/