]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_smartcard.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_smartcard.h
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_smartcard.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    19-June-2014
7   * @brief   Header file of SMARTCARD HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
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.
23   *
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.
34   *
35   ******************************************************************************
36   */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_SMARTCARD_H
40 #define __STM32F4xx_HAL_SMARTCARD_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
48
49 /** @addtogroup STM32F4xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup SMARTCARD
54   * @{
55   */
56
57 /* Exported types ------------------------------------------------------------*/
58 /** 
59   * @brief SMARTCARD Init Structure definition
60   */
61 typedef struct
62 {
63   uint32_t BaudRate;                  /*!< This member configures the SmartCard communication baud rate.
64                                            The baud rate is computed using the following formula:
65                                            - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
66                                            - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
67
68   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
69                                            This parameter can be a value of @ref SMARTCARD_Word_Length */
70
71   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
72                                            This parameter can be a value of @ref SMARTCARD_Stop_Bits */
73
74   uint32_t Parity;                   /*!< Specifies the parity mode.
75                                            This parameter can be a value of @ref SMARTCARD_Parity
76                                            @note When parity is enabled, the computed parity is inserted
77                                                  at the MSB position of the transmitted data (9th bit when
78                                                  the word length is set to 9 data bits; 8th bit when the
79                                                  word length is set to 8 data bits).*/
80
81   uint32_t Mode;                      /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
82                                            This parameter can be a value of @ref SMARTCARD_Mode */
83
84   uint32_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
85                                            This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
86
87   uint32_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
88                                            This parameter can be a value of @ref SMARTCARD_Clock_Phase */
89
90   uint32_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
91                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
92                                            This parameter can be a value of @ref SMARTCARD_Last_Bit */
93
94   uint32_t  Prescaler;                 /*!< Specifies the SmartCard Prescaler. 
95                                            This parameter must be a number between Min_Data = 0 and Max_Data = 255 */
96
97   uint32_t  GuardTime;                 /*!< Specifies the SmartCard Guard Time. 
98                                             This parameter must be a number between Min_Data = 0 and Max_Data = 255 */
99
100   uint32_t NACKState;                 /*!< Specifies the SmartCard NACK Transmission state.
101                                            This parameter can be a value of @ref SmartCard_NACK_State */
102 }SMARTCARD_InitTypeDef;
103
104 /** 
105   * @brief HAL State structures definition
106   */
107 typedef enum
108 {
109   HAL_SMARTCARD_STATE_RESET             = 0x00,    /*!< Peripheral is not yet Initialized                  */
110   HAL_SMARTCARD_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use           */
111   HAL_SMARTCARD_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing                     */
112   HAL_SMARTCARD_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing               */
113   HAL_SMARTCARD_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing                  */
114   HAL_SMARTCARD_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission and Reception process is ongoing */ 
115   HAL_SMARTCARD_STATE_TIMEOUT           = 0x03,    /*!< Timeout state                                      */
116   HAL_SMARTCARD_STATE_ERROR             = 0x04     /*!< Error                                              */
117 }HAL_SMARTCARD_StateTypeDef;
118
119 /** 
120   * @brief  HAL SMARTCARD Error Code structure definition
121   */
122 typedef enum
123 {
124   HAL_SMARTCARD_ERROR_NONE      = 0x00,    /*!< No error            */
125   HAL_SMARTCARD_ERROR_PE        = 0x01,    /*!< Parity error        */
126   HAL_SMARTCARD_ERROR_NE        = 0x02,    /*!< Noise error         */
127   HAL_SMARTCARD_ERROR_FE        = 0x04,    /*!< frame error         */
128   HAL_SMARTCARD_ERROR_ORE       = 0x08,    /*!< Overrun error       */
129   HAL_SMARTCARD_ERROR_DMA       = 0x10     /*!< DMA transfer error  */
130 }HAL_SMARTCARD_ErrorTypeDef;
131
132 /** 
133   * @brief  SMARTCARD handle Structure definition
134   */
135 typedef struct
136 {
137   USART_TypeDef                    *Instance;        /* USART registers base address */
138
139   SMARTCARD_InitTypeDef            Init;            /* SmartCard communication parameters */
140
141   uint8_t                          *pTxBuffPtr;      /* Pointer to SmartCard Tx transfer Buffer */
142
143   uint16_t                         TxXferSize;       /* SmartCard Tx Transfer size */
144
145   uint16_t                         TxXferCount;      /* SmartCard Tx Transfer Counter */
146
147   uint8_t                          *pRxBuffPtr;      /* Pointer to SmartCard Rx transfer Buffer */
148
149   uint16_t                         RxXferSize;       /* SmartCard Rx Transfer size */
150
151   uint16_t                         RxXferCount;      /* SmartCard Rx Transfer Counter */
152
153   DMA_HandleTypeDef                *hdmatx;          /* SmartCard Tx DMA Handle parameters */
154
155   DMA_HandleTypeDef                *hdmarx;          /* SmartCard Rx DMA Handle parameters */
156
157   HAL_LockTypeDef                  Lock;            /* Locking object */
158
159   __IO HAL_SMARTCARD_StateTypeDef  State;           /* SmartCard communication state */
160
161   __IO HAL_SMARTCARD_ErrorTypeDef  ErrorCode;       /* SMARTCARD Error code */
162 }SMARTCARD_HandleTypeDef;
163
164 /* Exported constants --------------------------------------------------------*/
165 /** @defgroup SMARTCARD_Exported_Constants
166   * @{
167   */
168
169 /** @defgroup SMARTCARD_Word_Length 
170   * @{
171   */
172 #define SMARTCARD_WORDLENGTH_8B                  ((uint32_t)0x00000000)
173 #define SMARTCARD_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
174 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) (((LENGTH) == SMARTCARD_WORDLENGTH_8B) || \
175                                           ((LENGTH) == SMARTCARD_WORDLENGTH_9B))
176 /**
177   * @}
178   */
179
180 /** @defgroup SMARTCARD_Stop_Bits 
181   * @{
182   */
183 #define SMARTCARD_STOPBITS_1                     ((uint32_t)0x00000000)
184 #define SMARTCARD_STOPBITS_0_5                   ((uint32_t)USART_CR2_STOP_0)
185 #define SMARTCARD_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
186 #define SMARTCARD_STOPBITS_1_5                   ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
187 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_1) || \
188                                          ((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
189                                          ((STOPBITS) == SMARTCARD_STOPBITS_1_5) || \
190                                          ((STOPBITS) == SMARTCARD_STOPBITS_2))
191 /**
192   * @}
193   */
194
195 /** @defgroup SMARTCARD_Parity 
196   * @{
197   */
198 #define SMARTCARD_PARITY_NONE                    ((uint32_t)0x00000000)
199 #define SMARTCARD_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
200 #define SMARTCARD_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 
201 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_NONE) || \
202                                      ((PARITY) == SMARTCARD_PARITY_EVEN) || \
203                                      ((PARITY) == SMARTCARD_PARITY_ODD))
204 /**
205   * @}
206   */
207
208 /** @defgroup SMARTCARD_Mode 
209   * @{
210   */
211 #define SMARTCARD_MODE_RX                        ((uint32_t)USART_CR1_RE)
212 #define SMARTCARD_MODE_TX                        ((uint32_t)USART_CR1_TE)
213 #define SMARTCARD_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
214 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & (uint32_t)0x0000FFF3) == 0x00) && ((MODE) != (uint32_t)0x000000))
215 /**
216   * @}
217   */
218
219 /** @defgroup SMARTCARD_Clock_Polarity 
220   * @{
221   */
222 #define SMARTCARD_POLARITY_LOW                   ((uint32_t)0x00000000)
223 #define SMARTCARD_POLARITY_HIGH                  ((uint32_t)USART_CR2_CPOL)
224 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
225 /**
226   * @}
227   */ 
228
229 /** @defgroup SMARTCARD_Clock_Phase
230   * @{
231   */
232 #define SMARTCARD_PHASE_1EDGE                    ((uint32_t)0x00000000)
233 #define SMARTCARD_PHASE_2EDGE                    ((uint32_t)USART_CR2_CPHA)
234 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
235 /**
236   * @}
237   */
238
239 /** @defgroup SMARTCARD_Last_Bit
240   * @{
241   */
242 #define SMARTCARD_LASTBIT_DISABLE                ((uint32_t)0x00000000)
243 #define SMARTCARD_LASTBIT_ENABLE                 ((uint32_t)USART_CR2_LBCL)
244 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
245                                        ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
246 /**
247   * @}
248   */
249
250 /** @defgroup SmartCard_NACK_State 
251   * @{
252   */
253 #define SMARTCARD_NACK_ENABLED                  ((uint32_t)USART_CR3_NACK)
254 #define SMARTCARD_NACK_DISABLED                 ((uint32_t)0x00000000)
255 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLED) || \
256                                        ((NACK) == SMARTCARD_NACK_DISABLED))
257 /**
258   * @}
259   */
260
261 /** @defgroup SmartCard_DMA_Requests 
262   * @{
263   */
264
265 #define SMARTCARD_DMAREQ_TX                    ((uint32_t)USART_CR3_DMAT)
266 #define SMARTCARD_DMAREQ_RX                    ((uint32_t)USART_CR3_DMAR)
267
268 /**
269   * @}
270   */
271
272 /** @defgroup SmartCard_Flags 
273   *        Elements values convention: 0xXXXX
274   *           - 0xXXXX  : Flag mask in the SR register
275   * @{
276   */
277
278 #define SMARTCARD_FLAG_TXE                       ((uint32_t)0x00000080)
279 #define SMARTCARD_FLAG_TC                        ((uint32_t)0x00000040)
280 #define SMARTCARD_FLAG_RXNE                      ((uint32_t)0x00000020)
281 #define SMARTCARD_FLAG_IDLE                      ((uint32_t)0x00000010)
282 #define SMARTCARD_FLAG_ORE                       ((uint32_t)0x00000008)
283 #define SMARTCARD_FLAG_NE                        ((uint32_t)0x00000004)
284 #define SMARTCARD_FLAG_FE                        ((uint32_t)0x00000002)
285 #define SMARTCARD_FLAG_PE                        ((uint32_t)0x00000001)
286 /**
287   * @}
288   */
289
290 /** @defgroup SmartCard_Interrupt_definition 
291   *        Elements values convention: 0xY000XXXX
292   *           - XXXX  : Interrupt mask in the XX register
293   *           - Y  : Interrupt source register (2bits)
294   *                 - 01: CR1 register
295   *                 - 10: CR3 register
296
297   *
298   * @{
299   */
300 #define SMARTCARD_IT_PE                          ((uint32_t)0x10000100)
301 #define SMARTCARD_IT_TXE                         ((uint32_t)0x10000080)
302 #define SMARTCARD_IT_TC                          ((uint32_t)0x10000040)
303 #define SMARTCARD_IT_RXNE                        ((uint32_t)0x10000020)
304 #define SMARTCARD_IT_IDLE                        ((uint32_t)0x10000010)
305 #define SMARTCARD_IT_ERR                         ((uint32_t)0x20000001)
306
307 /**
308   * @}
309   */
310
311 /**
312   * @}
313   */
314   
315 /* Exported macro ------------------------------------------------------------*/
316
317 /** @brief Reset SMARTCARD handle state
318   * @param  __HANDLE__: specifies the SMARTCARD Handle.
319   * @retval None
320   */
321 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMARTCARD_STATE_RESET)
322
323 /** @brief  Flushs the Smartcard DR register 
324   * @param  __HANDLE__: specifies the SMARTCARD Handle.
325   */
326 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
327     
328 /** @brief  Checks whether the specified Smartcard flag is set or not.
329   * @param  __HANDLE__: specifies the SMARTCARD Handle.
330   * @param  __FLAG__: specifies the flag to check.
331   *        This parameter can be one of the following values:
332   *            @arg SMARTCARD_FLAG_TXE:  Transmit data register empty flag
333   *            @arg SMARTCARD_FLAG_TC:   Transmission Complete flag
334   *            @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
335   *            @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag
336   *            @arg SMARTCARD_FLAG_ORE:  OverRun Error flag
337   *            @arg SMARTCARD_FLAG_NE:   Noise Error flag
338   *            @arg SMARTCARD_FLAG_FE:   Framing Error flag
339   *            @arg SMARTCARD_FLAG_PE:   Parity Error flag
340   * @retval The new state of __FLAG__ (TRUE or FALSE).
341   */
342 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
343
344 /** @brief  Clears the specified Smartcard pending flags.
345   * @param  __HANDLE__: specifies the SMARTCARD Handle.
346   * @param  __FLAG__: specifies the flag to check.
347   *          This parameter can be any combination of the following values:
348   *            @arg SMARTCARD_FLAG_TC:   Transmission Complete flag.
349   *            @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag.
350   *   
351   * @note   PE (Parity error), FE (Framing error), NE (Noise error) and ORE (OverRun 
352   *          error) flags are cleared by software sequence: a read operation to 
353   *          USART_SR register followed by a read operation to USART_DR register.
354   * @note   RXNE flag can be also cleared by a read to the USART_DR register.
355   * @note   TC flag can be also cleared by software sequence: a read operation to 
356   *          USART_SR register followed by a write operation to USART_DR register.
357   * @note   TXE flag is cleared only by a write to the USART_DR register.
358   */
359 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
360
361 /** @brief  Clear the SMARTCARD PE pending flag.
362   * @param  __HANDLE__: specifies the USART Handle.
363   *         This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
364   *         UART peripheral.
365   * @retval None
366   */
367 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) do{(__HANDLE__)->Instance->SR;\
368                                                (__HANDLE__)->Instance->DR;}while(0)
369 /** @brief  Clear the SMARTCARD FE pending flag.
370   * @param  __HANDLE__: specifies the USART Handle.
371   *         This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
372   *         UART peripheral.
373   * @retval None
374   */
375 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
376
377 /** @brief  Clear the SMARTCARD NE pending flag.
378   * @param  __HANDLE__: specifies the USART Handle.
379   *         This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
380   *         UART peripheral.
381   * @retval None
382   */
383 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
384
385 /** @brief  Clear the SMARTCARD ORE pending flag.
386   * @param  __HANDLE__: specifies the USART Handle.
387   *         This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
388   *         UART peripheral.
389   * @retval None
390   */
391 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
392
393 /** @brief  Clear the SMARTCARD IDLE pending flag.
394   * @param  __HANDLE__: specifies the USART Handle.
395   *         This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
396   *         UART peripheral.
397   * @retval None
398   */
399 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
400
401
402 /** @brief  Enables or disables the specified SmartCard interrupts.
403   * @param  __HANDLE__: specifies the SMARTCARD Handle.
404   * @param  __INTERRUPT__: specifies the SMARTCARD interrupt source to check.
405   *          This parameter can be one of the following values:
406   *            @arg SMARTCARD_IT_TXE:  Transmit Data Register empty interrupt
407   *            @arg SMARTCARD_IT_TC:   Transmission complete interrupt
408   *            @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
409   *            @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
410   *            @arg SMARTCARD_IT_PE:   Parity Error interrupt
411   *            @arg SMARTCARD_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
412   */
413 #define SMARTCARD_IT_MASK  ((uint32_t)0x0000FFFF)
414 #define __SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
415                                                              ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
416 #define __SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
417                                                              ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
418
419 /** @brief  Checks whether the specified SmartCard interrupt has occurred or not.
420   * @param  __HANDLE__: specifies the SmartCard Handle.
421   * @param  __IT__: specifies the SMARTCARD interrupt source to check.
422   *          This parameter can be one of the following values:
423   *            @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
424   *            @arg SMARTCARD_IT_TC:  Transmission complete interrupt
425   *            @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
426   *            @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
427   *            @arg SMARTCARD_IT_ERR: Error interrupt
428   *            @arg SMARTCARD_IT_PE: Parity Error interrupt
429   * @retval The new state of __IT__ (TRUE or FALSE).
430   */
431 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == 1)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
432
433 /** @brief  Macros to enable or disable the SmartCard interface.
434   * @param  __HANDLE__: specifies the SmartCard Handle.
435   */
436 #define __SMARTCARD_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
437 #define __SMARTCARD_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
438
439 /** @brief  Macros to enable or disable the SmartCard DMA request.
440   * @param  __HANDLE__: specifies the SmartCard Handle.
441   * @param  __REQUEST__: specifies the SmartCard DMA request.
442   *          This parameter can be one of the following values:
443   *            @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
444   *            @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
445   */
446 #define __SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__)    ((__HANDLE__)->Instance->CR3 |=  (__REQUEST__))
447 #define __SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__)   ((__HANDLE__)->Instance->CR3 &=  ~(__REQUEST__))
448
449 #define __DIV(_PCLK_, _BAUD_)                        (((_PCLK_)*25)/(4*(_BAUD_)))
450 #define __DIVMANT(_PCLK_, _BAUD_)                    (__DIV((_PCLK_), (_BAUD_))/100)
451 #define __DIVFRAQ(_PCLK_, _BAUD_)                    (((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
452 #define __SMARTCARD_BRR(_PCLK_, _BAUD_)              ((__DIVMANT((_PCLK_), (_BAUD_)) << 4)|(__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F))
453
454 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001)
455
456 /* Exported functions --------------------------------------------------------*/
457 /* Initialization/de-initialization functions  **********************************/
458 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
459 HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc);
460 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
461 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
462 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
463 /* IO operation functions *******************************************************/
464 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
465 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
466 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
467 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
468 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
469 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
470 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
471 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
472 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
473 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
474
475 /* Peripheral State functions  **************************************************/
476 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
477 uint32_t                   HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
478
479 /**
480   * @}
481   */ 
482
483 /**
484   * @}
485   */
486
487 #ifdef __cplusplus
488 }
489 #endif
490
491 #endif /* __STM32F4xx_HAL_SMARTCARD_H */
492
493 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/