QuakeGod
2022-09-29 e1f35018c4dec304b00f50d9dbe12204fd57a623
提交 | 用户 | age
bfc108 1 /**
Q 2   ******************************************************************************
3   * @file    stm32f0xx_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 __STM32F0xx_HAL_IRDA_EX_H
38 #define __STM32F0xx_HAL_IRDA_EX_H
39
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43
44 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) 
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f0xx_hal_def.h"
48
49 /** @addtogroup STM32F0xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup IRDAEx
54   * @{
55   */
56
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup IRDAEx_Exported_Constants IRDAEx Exported Constants
60   * @{
61   */
62   
63 /** @defgroup IRDAEx_Word_Length IRDA Word Length
64   * @{
65   */
66 #if defined (STM32F042x6) || defined (STM32F048xx) || \
67     defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
68     defined (STM32F091xC) || defined (STM32F098xx)
69 #define IRDA_WORDLENGTH_7B                  ((uint32_t)USART_CR1_M1)   /*!< 7-bit long frame */
70 #define IRDA_WORDLENGTH_8B                  (0x00000000U)              /*!< 8-bit long frame */
71 #define IRDA_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M0)   /*!< 9-bit long frame */
72 #else
73 #define IRDA_WORDLENGTH_8B                  (0x00000000U)              /*!< 8-bit long frame */
74 #define IRDA_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)    /*!< 9-bit long frame */
75 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || \
76           defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
77           defined (STM32F091xC) || defined (STM32F098xx)*/
78 /**
79   * @}
80   */
81     
82 /**
83   * @}
84   */  
85
86 /* Exported macros -----------------------------------------------------------*/
87 /* Exported functions --------------------------------------------------------*/
88
89 /* Private macros ------------------------------------------------------------*/
90
91 /** @defgroup IRDAEx_Private_Macros IRDAEx Private Macros
92   * @{
93   */
94
95 /** @brief  Report the IRDA clock source.
96   * @param  __HANDLE__ specifies the IRDA Handle.
97   * @param  __CLOCKSOURCE__ output variable.
98   * @retval IRDA clocking source, written in __CLOCKSOURCE__.
99   */
100
101 #if defined(STM32F031x6) || defined(STM32F038xx)
102 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
103   do {                                                        \
104      switch(__HAL_RCC_GET_USART1_SOURCE())                    \
105      {                                                        \
106       case RCC_USART1CLKSOURCE_PCLK1:                         \
107         (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;           \
108         break;                                                \
109       case RCC_USART1CLKSOURCE_HSI:                           \
110         (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;             \
111         break;                                                \
112       case RCC_USART1CLKSOURCE_SYSCLK:                        \
113         (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;          \
114         break;                                                \
115       case RCC_USART1CLKSOURCE_LSE:                           \
116         (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;             \
117         break;                                                \
118       default:                                                \
119         (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;       \
120         break;                                                \
121      }                                                        \
122   } while(0)
123 #elif defined (STM32F042x6) || defined (STM32F048xx) ||       \
124       defined (STM32F051x8) || defined (STM32F058xx)
125 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
126   do {                                                        \
127     if((__HANDLE__)->Instance == USART1)                      \
128     {                                                         \
129        switch(__HAL_RCC_GET_USART1_SOURCE())                  \
130        {                                                      \
131         case RCC_USART1CLKSOURCE_PCLK1:                       \
132           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
133           break;                                              \
134         case RCC_USART1CLKSOURCE_HSI:                         \
135           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
136           break;                                              \
137         case RCC_USART1CLKSOURCE_SYSCLK:                      \
138           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
139           break;                                              \
140         case RCC_USART1CLKSOURCE_LSE:                         \
141           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
142           break;                                              \
143         default:                                              \
144           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
145           break;                                              \
146        }                                                      \
147     }                                                         \
148     else if((__HANDLE__)->Instance == USART2)                 \
149     {                                                         \
150       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
151     }                                                         \
152     else                                                      \
153     {                                                         \
154       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;         \
155     }                                                         \
156   } while(0)
157 #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
158 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
159   do {                                                        \
160     if((__HANDLE__)->Instance == USART1)                      \
161     {                                                         \
162        switch(__HAL_RCC_GET_USART1_SOURCE())                  \
163        {                                                      \
164         case RCC_USART1CLKSOURCE_PCLK1:                       \
165           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
166           break;                                              \
167         case RCC_USART1CLKSOURCE_HSI:                         \
168           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
169           break;                                              \
170         case RCC_USART1CLKSOURCE_SYSCLK:                      \
171           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
172           break;                                              \
173         case RCC_USART1CLKSOURCE_LSE:                         \
174           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
175           break;                                              \
176         default:                                              \
177           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
178           break;                                              \
179        }                                                      \
180     }                                                         \
181     else if((__HANDLE__)->Instance == USART2)                 \
182     {                                                         \
183        switch(__HAL_RCC_GET_USART2_SOURCE())                  \
184        {                                                      \
185         case RCC_USART2CLKSOURCE_PCLK1:                       \
186           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
187           break;                                              \
188         case RCC_USART2CLKSOURCE_HSI:                         \
189           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
190           break;                                              \
191         case RCC_USART2CLKSOURCE_SYSCLK:                      \
192           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
193           break;                                              \
194         case RCC_USART2CLKSOURCE_LSE:                         \
195           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
196           break;                                              \
197         default:                                              \
198           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
199           break;                                              \
200        }                                                      \
201     }                                                         \
202     else if((__HANDLE__)->Instance == USART3)                 \
203     {                                                         \
204       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
205     }                                                         \
206     else if((__HANDLE__)->Instance == USART4)                 \
207     {                                                         \
208       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
209     }                                                         \
210     else                                                      \
211     {                                                         \
212       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;         \
213     }                                                         \
214   } while(0)
215 #elif defined(STM32F091xC) || defined(STM32F098xx)
216 #define IRDA_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)       \
217   do {                                                        \
218     if((__HANDLE__)->Instance == USART1)                      \
219     {                                                         \
220        switch(__HAL_RCC_GET_USART1_SOURCE())                  \
221        {                                                      \
222         case RCC_USART1CLKSOURCE_PCLK1:                       \
223           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
224           break;                                              \
225         case RCC_USART1CLKSOURCE_HSI:                         \
226           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
227           break;                                              \
228         case RCC_USART1CLKSOURCE_SYSCLK:                      \
229           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
230           break;                                              \
231         case RCC_USART1CLKSOURCE_LSE:                         \
232           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
233           break;                                              \
234         default:                                              \
235           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
236           break;                                              \
237        }                                                      \
238     }                                                         \
239     else if((__HANDLE__)->Instance == USART2)                 \
240     {                                                         \
241        switch(__HAL_RCC_GET_USART2_SOURCE())                  \
242        {                                                      \
243         case RCC_USART2CLKSOURCE_PCLK1:                       \
244           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
245           break;                                              \
246         case RCC_USART2CLKSOURCE_HSI:                         \
247           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
248           break;                                              \
249         case RCC_USART2CLKSOURCE_SYSCLK:                      \
250           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
251           break;                                              \
252         case RCC_USART2CLKSOURCE_LSE:                         \
253           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
254           break;                                              \
255         default:                                              \
256           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
257           break;                                              \
258        }                                                      \
259     }                                                         \
260     else if((__HANDLE__)->Instance == USART3)                 \
261     {                                                         \
262        switch(__HAL_RCC_GET_USART3_SOURCE())                  \
263        {                                                      \
264         case RCC_USART3CLKSOURCE_PCLK1:                       \
265           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;         \
266           break;                                              \
267         case RCC_USART3CLKSOURCE_HSI:                         \
268           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_HSI;           \
269           break;                                              \
270         case RCC_USART3CLKSOURCE_SYSCLK:                      \
271           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_SYSCLK;        \
272           break;                                              \
273         case RCC_USART3CLKSOURCE_LSE:                         \
274           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_LSE;           \
275           break;                                              \
276         default:                                              \
277           (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;     \
278           break;                                              \
279        }                                                      \
280     }                                                         \
281     else if((__HANDLE__)->Instance == USART4)                 \
282     {                                                         \
283       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
284     }                                                         \
285     else if((__HANDLE__)->Instance == USART5)                 \
286     {                                                         \
287       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
288     }                                                         \
289     else if((__HANDLE__)->Instance == USART6)                 \
290     {                                                         \
291       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
292     }                                                         \
293     else if((__HANDLE__)->Instance == USART7)                 \
294     {                                                         \
295       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
296     }                                                         \
297     else if((__HANDLE__)->Instance == USART8)                 \
298     {                                                         \
299       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_PCLK1;             \
300     }                                                         \
301     else                                                      \
302     {                                                         \
303       (__CLOCKSOURCE__) = IRDA_CLOCKSOURCE_UNDEFINED;         \
304     }                                                         \
305   } while(0)
306
307 #endif /* defined(STM32F031x6) || defined(STM32F038xx) */
308
309
310 /** @brief  Compute the mask to apply to retrieve the received data
311   *         according to the word length and to the parity bits activation.
312   * @note   If PCE = 1, the parity bit is not included in the data extracted
313   *         by the reception API().
314   *         This masking operation is not carried out in the case of
315   *         DMA transfers.
316   * @param  __HANDLE__ specifies the IRDA Handle.
317   * @retval None, the mask to apply to the associated UART RDR register is stored in (__HANDLE__)->Mask field.
318   */
319 #if defined (STM32F042x6) || defined (STM32F048xx) || \
320     defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
321     defined (STM32F091xC) || defined (STM32F098xx)
322 #define IRDA_MASK_COMPUTATION(__HANDLE__)                             \
323   do {                                                                \
324   if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B)            \
325   {                                                                   \
326      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
327      {                                                                \
328         (__HANDLE__)->Mask = 0x01FFU ;                                \
329      }                                                                \
330      else                                                             \
331      {                                                                \
332         (__HANDLE__)->Mask = 0x00FFU ;                                \
333      }                                                                \
334   }                                                                   \
335   else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B)       \
336   {                                                                   \
337      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
338      {                                                                \
339         (__HANDLE__)->Mask = 0x00FFU ;                                \
340      }                                                                \
341      else                                                             \
342      {                                                                \
343         (__HANDLE__)->Mask = 0x007FU ;                                \
344      }                                                                \
345   }                                                                   \
346   else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_7B)       \
347   {                                                                   \
348      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
349      {                                                                \
350         (__HANDLE__)->Mask = 0x007FU ;                                \
351      }                                                                \
352      else                                                             \
353      {                                                                \
354         (__HANDLE__)->Mask = 0x003FU ;                                \
355      }                                                                \
356   }                                                                   \
357 } while(0)
358 #else
359 #define IRDA_MASK_COMPUTATION(__HANDLE__)                             \
360   do {                                                                \
361   if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_9B)            \
362   {                                                                   \
363      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
364      {                                                                \
365         (__HANDLE__)->Mask = 0x01FFU ;                                \
366      }                                                                \
367      else                                                             \
368      {                                                                \
369         (__HANDLE__)->Mask = 0x00FFU ;                                \
370      }                                                                \
371   }                                                                   \
372   else if ((__HANDLE__)->Init.WordLength == IRDA_WORDLENGTH_8B)       \
373   {                                                                   \
374      if ((__HANDLE__)->Init.Parity == IRDA_PARITY_NONE)               \
375      {                                                                \
376         (__HANDLE__)->Mask = 0x00FFU ;                                \
377      }                                                                \
378      else                                                             \
379      {                                                                \
380         (__HANDLE__)->Mask = 0x007FU ;                                \
381      }                                                                \
382   }                                                                   \
383 } while(0)
384 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || \
385           defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
386           defined (STM32F091xC) || defined(STM32F098xx) */
387
388 /**
389   * @brief Ensure that IRDA frame length is valid.
390   * @param __LENGTH__ IRDA frame length. 
391   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
392   */ 
393 #if defined (STM32F042x6) || defined (STM32F048xx) || \
394     defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
395     defined (STM32F091xC) || defined (STM32F098xx)
396 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_7B) || \
397                                          ((__LENGTH__) == IRDA_WORDLENGTH_8B) || \
398                                          ((__LENGTH__) == IRDA_WORDLENGTH_9B))
399 #else
400 #define IS_IRDA_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == IRDA_WORDLENGTH_8B) || \
401                                          ((__LENGTH__) == IRDA_WORDLENGTH_9B))
402 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || \
403           defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
404           defined (STM32F091xC) || defined (STM32F098xx)*/
405
406 /**
407   * @}
408   */
409
410 /* Exported functions --------------------------------------------------------*/
411
412 /**
413   * @}
414   */
415
416 /**
417   * @}
418   */
419
420 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)  */
421   
422 #ifdef __cplusplus
423 }
424 #endif
425
426 #endif /* __STM32F0xx_HAL_IRDA_EX_H */
427
428 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
429