1 /**
2   ******************************************************************************
3   * @file    stm32f7xx_hal_smartcard_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of SMARTCARD 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_SMARTCARD_EX_H
21 #define STM32F7xx_HAL_SMARTCARD_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 SMARTCARDEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /* Exported constants --------------------------------------------------------*/
40 
41 /** @addtogroup SMARTCARDEx_Exported_Constants  SMARTCARD Extended Exported Constants
42   * @{
43   */
44 
45 /** @defgroup SMARTCARDEx_Transmission_Completion_Indication SMARTCARD Transmission Completion Indication
46   * @{
47   */
48 #if defined(USART_TCBGT_SUPPORT)
49 #define SMARTCARD_TCBGT      SMARTCARD_IT_TCBGT /*!< SMARTCARD transmission complete before guard time */
50 #endif /* USART_TCBGT_SUPPORT */
51 #define SMARTCARD_TC         SMARTCARD_IT_TC    /*!< SMARTCARD transmission complete (flag raised when guard time has elapsed) */
52 /**
53   * @}
54   */
55 
56 /** @defgroup SMARTCARDEx_Advanced_Features_Initialization_Type SMARTCARD advanced feature initialization type
57   * @{
58   */
59 #define SMARTCARD_ADVFEATURE_NO_INIT                 0x00000000U    /*!< No advanced feature initialization                  */
60 #define SMARTCARD_ADVFEATURE_TXINVERT_INIT           0x00000001U    /*!< TX pin active level inversion                       */
61 #define SMARTCARD_ADVFEATURE_RXINVERT_INIT           0x00000002U    /*!< RX pin active level inversion                       */
62 #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT         0x00000004U    /*!< Binary data inversion                               */
63 #define SMARTCARD_ADVFEATURE_SWAP_INIT               0x00000008U    /*!< TX/RX pins swap                                     */
64 #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT   0x00000010U    /*!< RX overrun disable                                  */
65 #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT  0x00000020U    /*!< DMA disable on Reception Error                      */
66 #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT           0x00000080U    /*!< Most significant bit sent/received first            */
67 #if defined(USART_TCBGT_SUPPORT)
68 #define SMARTCARD_ADVFEATURE_TXCOMPLETION            0x00000100U    /*!< TX completion indication before of after guard time */
69 #endif /* USART_TCBGT_SUPPORT */
70 /**
71   * @}
72   */
73 
74 /** @defgroup SMARTCARDEx_Flags SMARTCARD Flags
75   *        Elements values convention: 0xXXXX
76   *           - 0xXXXX  : Flag mask in the ISR register
77   * @{
78   */
79 #if defined(USART_TCBGT_SUPPORT)
80 #define SMARTCARD_FLAG_TCBGT          USART_ISR_TCBGT         /*!< SMARTCARD transmission complete before guard time completion */
81 #endif /* USART_TCBGT_SUPPORT */
82 #if defined(USART_ISR_REACK)
83 #define SMARTCARD_FLAG_REACK          USART_ISR_REACK         /*!< SMARTCARD receive enable acknowledge flag  */
84 #endif /* USART_ISR_REACK */
85 #define SMARTCARD_FLAG_TEACK          USART_ISR_TEACK         /*!< SMARTCARD transmit enable acknowledge flag */
86 #define SMARTCARD_FLAG_BUSY           USART_ISR_BUSY          /*!< SMARTCARD busy flag                        */
87 #define SMARTCARD_FLAG_EOBF           USART_ISR_EOBF          /*!< SMARTCARD end of block flag                */
88 #define SMARTCARD_FLAG_RTOF           USART_ISR_RTOF          /*!< SMARTCARD receiver timeout flag            */
89 #define SMARTCARD_FLAG_TXE            USART_ISR_TXE           /*!< SMARTCARD transmit data register empty     */
90 #define SMARTCARD_FLAG_TC             USART_ISR_TC            /*!< SMARTCARD transmission complete            */
91 #define SMARTCARD_FLAG_RXNE           USART_ISR_RXNE          /*!< SMARTCARD read data register not empty     */
92 #define SMARTCARD_FLAG_IDLE           USART_ISR_IDLE          /*!< SMARTCARD idle line detection              */
93 #define SMARTCARD_FLAG_ORE            USART_ISR_ORE           /*!< SMARTCARD overrun error                    */
94 #define SMARTCARD_FLAG_NE             USART_ISR_NE            /*!< SMARTCARD noise error                      */
95 #define SMARTCARD_FLAG_FE             USART_ISR_FE            /*!< SMARTCARD frame error                      */
96 #define SMARTCARD_FLAG_PE             USART_ISR_PE            /*!< SMARTCARD parity error                     */
97 /**
98   * @}
99   */
100 
101 /** @defgroup SMARTCARDEx_Interrupt_definition SMARTCARD Interrupts Definition
102   *        Elements values convention: 000ZZZZZ0XXYYYYYb
103   *           - YYYYY  : Interrupt source position in the XX register (5 bits)
104   *           - XX  : Interrupt source register (2 bits)
105   *                 - 01: CR1 register
106   *                 - 10: CR2 register
107   *                 - 11: CR3 register
108   *           - ZZZZZ  : Flag position in the ISR register(5 bits)
109   * @{
110   */
111 #define SMARTCARD_IT_PE                     0x0028U           /*!< SMARTCARD parity error interruption                 */
112 #define SMARTCARD_IT_TXE                    0x0727U           /*!< SMARTCARD transmit data register empty interruption */
113 #define SMARTCARD_IT_TC                     0x0626U           /*!< SMARTCARD transmission complete interruption        */
114 #define SMARTCARD_IT_RXNE                   0x0525U           /*!< SMARTCARD read data register not empty interruption */
115 #define SMARTCARD_IT_IDLE                   0x0424U           /*!< SMARTCARD idle line detection interruption          */
116 
117 #define SMARTCARD_IT_ERR                    0x0060U           /*!< SMARTCARD error interruption         */
118 #define SMARTCARD_IT_ORE                    0x0300U           /*!< SMARTCARD overrun error interruption */
119 #define SMARTCARD_IT_NE                     0x0200U           /*!< SMARTCARD noise error interruption   */
120 #define SMARTCARD_IT_FE                     0x0100U           /*!< SMARTCARD frame error interruption   */
121 
122 #define SMARTCARD_IT_EOB                    0x0C3BU           /*!< SMARTCARD end of block interruption     */
123 #define SMARTCARD_IT_RTO                    0x0B3AU           /*!< SMARTCARD receiver timeout interruption */
124 #if defined(USART_TCBGT_SUPPORT)
125 #define SMARTCARD_IT_TCBGT                  0x1978U           /*!< SMARTCARD transmission complete before guard time completion interruption */
126 #endif /* USART_TCBGT_SUPPORT */
127 
128 /**
129   * @}
130   */
131 
132 /** @defgroup SMARTCARDEx_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags
133   * @{
134   */
135 #define SMARTCARD_CLEAR_PEF                 USART_ICR_PECF    /*!< SMARTCARD parity error clear flag          */
136 #define SMARTCARD_CLEAR_FEF                 USART_ICR_FECF    /*!< SMARTCARD framing error clear flag         */
137 #define SMARTCARD_CLEAR_NEF                 USART_ICR_NCF    /*!< SMARTCARD noise error detected clear flag  */
138 #define SMARTCARD_CLEAR_OREF                USART_ICR_ORECF   /*!< SMARTCARD overrun error clear flag         */
139 #define SMARTCARD_CLEAR_IDLEF               USART_ICR_IDLECF  /*!< SMARTCARD idle line detected clear flag    */
140 #define SMARTCARD_CLEAR_TCF                 USART_ICR_TCCF    /*!< SMARTCARD transmission complete clear flag */
141 #if defined(USART_TCBGT_SUPPORT)
142 #define SMARTCARD_CLEAR_TCBGTF              USART_ICR_TCBGTCF /*!< SMARTCARD transmission complete before guard time completion clear flag */
143 #endif /* USART_TCBGT_SUPPORT */
144 #define SMARTCARD_CLEAR_RTOF                USART_ICR_RTOCF   /*!< SMARTCARD receiver time out clear flag     */
145 #define SMARTCARD_CLEAR_EOBF                USART_ICR_EOBCF   /*!< SMARTCARD end of block clear flag          */
146 /**
147   * @}
148   */
149 
150 /**
151   * @}
152   */
153 /* Exported macros -----------------------------------------------------------*/
154 /* Private macros ------------------------------------------------------------*/
155 /** @defgroup SMARTCARDEx_Private_Macros SMARTCARD Extended Private Macros
156   * @{
157   */
158 
159 /** @brief  Set the Transmission Completion flag
160   * @param  __HANDLE__ specifies the SMARTCARD Handle.
161   * @note  If TCBGT (Transmission Complete Before Guard Time) flag is not available or if
162   *        AdvancedInit.TxCompletionIndication is not already filled, the latter is forced
163   *        to SMARTCARD_TC (transmission completion indication when guard time has elapsed).
164   * @retval None
165   */
166 #if defined(USART_TCBGT_SUPPORT)
167 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__)                                                \
168   do {                                                                                                       \
169     if (HAL_IS_BIT_CLR((__HANDLE__)->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXCOMPLETION))        \
170     {                                                                                                        \
171       (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC;                                      \
172     }                                                                                                        \
173     else                                                                                                     \
174     {                                                                                                        \
175       assert_param(IS_SMARTCARD_TRANSMISSION_COMPLETION((__HANDLE__)->AdvancedInit.TxCompletionIndication)); \
176     }                                                                                                        \
177   } while(0U)
178 #else
179 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__)         \
180   do {                                                                \
181     (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \
182   } while(0U)
183 #endif /* USART_TCBGT_SUPPORT */
184 
185 /** @brief  Return the transmission completion flag.
186   * @param  __HANDLE__ specifies the SMARTCARD Handle.
187   * @note  Based on AdvancedInit.TxCompletionIndication setting, return TC or TCBGT flag.
188   *        When TCBGT flag (Transmission Complete Before Guard Time) is not available, TC flag is
189   *        reported.
190   * @retval Transmission completion flag
191   */
192 #if defined(USART_TCBGT_SUPPORT)
193 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__)  \
194   (((__HANDLE__)->AdvancedInit.TxCompletionIndication == SMARTCARD_TC) ? (SMARTCARD_FLAG_TC) :  (SMARTCARD_FLAG_TCBGT))
195 #else
196 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__)    (SMARTCARD_FLAG_TC)
197 #endif /* USART_TCBGT_SUPPORT */
198 
199 
200 /** @brief Ensure that SMARTCARD frame transmission completion used flag is valid.
201   * @param __TXCOMPLETE__ SMARTCARD frame transmission completion used flag.
202   * @retval SET (__TXCOMPLETE__ is valid) or RESET (__TXCOMPLETE__ is invalid)
203   */
204 #if defined(USART_TCBGT_SUPPORT)
205 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) (((__TXCOMPLETE__) == SMARTCARD_TCBGT) || \
206                                                               ((__TXCOMPLETE__) == SMARTCARD_TC))
207 #else
208 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) ((__TXCOMPLETE__) == SMARTCARD_TC)
209 #endif /* USART_TCBGT_SUPPORT */
210 
211 /**
212   * @}
213   */
214 
215 /* Exported functions --------------------------------------------------------*/
216 /** @addtogroup SMARTCARDEx_Exported_Functions
217   * @{
218   */
219 
220 /* Initialization and de-initialization functions  ****************************/
221 /* IO operation methods *******************************************************/
222 
223 /** @addtogroup SMARTCARDEx_Exported_Functions_Group1
224   * @{
225   */
226 
227 /* Peripheral Control functions ***********************************************/
228 void              HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength);
229 void              HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue);
230 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
231 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
232 
233 /**
234   * @}
235   */
236 
237 /* Exported functions --------------------------------------------------------*/
238 /** @addtogroup SMARTCARDEx_Exported_Functions_Group2
239   * @{
240   */
241 
242 /* IO operation functions *****************************************************/
243 
244 /**
245   * @}
246   */
247 
248 
249 /**
250   * @}
251   */
252 
253 /* Private functions ---------------------------------------------------------*/
254 
255 /**
256   * @}
257   */
258 
259 /**
260   * @}
261   */
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* STM32F7xx_HAL_SMARTCARD_EX_H */
268 
269