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