1 /**
2   ******************************************************************************
3   * @file    stm32f7xx_hal_usart_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of USART 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 STM32F7xx_HAL_USART_EX_H
21 #define STM32F7xx_HAL_USART_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f7xx_hal_def.h"
29 
30 /** @addtogroup STM32F7xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup USARTEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /* Exported constants --------------------------------------------------------*/
40 /** @defgroup USARTEx_Exported_Constants USARTEx Exported Constants
41   * @{
42   */
43 
44 /** @defgroup USARTEx_Word_Length USARTEx Word Length
45   * @{
46   */
47 #define USART_WORDLENGTH_7B                  (USART_CR1_M1)   /*!< 7-bit long USART frame */
48 #define USART_WORDLENGTH_8B                  (0x00000000U)              /*!< 8-bit long USART frame */
49 #define USART_WORDLENGTH_9B                  (USART_CR1_M0)   /*!< 9-bit long USART frame */
50 /**
51   * @}
52   */
53 
54 
55 /**
56   * @}
57   */
58 
59 /* Private macros ------------------------------------------------------------*/
60 /** @defgroup USARTEx_Private_Macros USARTEx Private Macros
61   * @{
62   */
63 
64 /** @brief  Compute the USART mask to apply to retrieve the received data
65   *         according to the word length and to the parity bits activation.
66   * @note   If PCE = 1, the parity bit is not included in the data extracted
67   *         by the reception API().
68   *         This masking operation is not carried out in the case of
69   *         DMA transfers.
70   * @param  __HANDLE__ specifies the USART Handle.
71   * @retval None, the mask to apply to USART RDR register is stored in (__HANDLE__)->Mask field.
72   */
73 #define USART_MASK_COMPUTATION(__HANDLE__)                            \
74   do {                                                                \
75     if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B)         \
76     {                                                                 \
77       if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)             \
78       {                                                               \
79         (__HANDLE__)->Mask = 0x01FFU;                                 \
80       }                                                               \
81       else                                                            \
82       {                                                               \
83         (__HANDLE__)->Mask = 0x00FFU;                                 \
84       }                                                               \
85     }                                                                 \
86     else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B)    \
87     {                                                                 \
88       if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)             \
89       {                                                               \
90         (__HANDLE__)->Mask = 0x00FFU;                                 \
91       }                                                               \
92       else                                                            \
93       {                                                               \
94         (__HANDLE__)->Mask = 0x007FU;                                 \
95       }                                                               \
96     }                                                                 \
97     else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B)    \
98     {                                                                 \
99       if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE)             \
100       {                                                               \
101         (__HANDLE__)->Mask = 0x007FU;                                 \
102       }                                                               \
103       else                                                            \
104       {                                                               \
105         (__HANDLE__)->Mask = 0x003FU;                                 \
106       }                                                               \
107     }                                                                 \
108     else                                                              \
109     {                                                                 \
110       (__HANDLE__)->Mask = 0x0000U;                                   \
111     }                                                                 \
112   } while(0U)
113 
114 /**
115   * @brief Ensure that USART frame length is valid.
116   * @param __LENGTH__ USART frame length.
117   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
118   */
119 #define IS_USART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == USART_WORDLENGTH_7B) || \
120                                           ((__LENGTH__) == USART_WORDLENGTH_8B) || \
121                                           ((__LENGTH__) == USART_WORDLENGTH_9B))
122 
123 
124 /**
125   * @}
126   */
127 
128 /* Exported functions --------------------------------------------------------*/
129 /** @addtogroup USARTEx_Exported_Functions
130   * @{
131   */
132 
133 /** @addtogroup USARTEx_Exported_Functions_Group1
134   * @{
135   */
136 
137 /* IO operation functions *****************************************************/
138 
139 /**
140   * @}
141   */
142 
143 /** @addtogroup USARTEx_Exported_Functions_Group2
144   * @{
145   */
146 
147 /* Peripheral Control functions ***********************************************/
148 
149 /**
150   * @}
151   */
152 
153 /**
154   * @}
155   */
156 
157 /**
158   * @}
159   */
160 
161 /**
162   * @}
163   */
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* STM32F7xx_HAL_USART_EX_H */
170 
171