Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /**
sahilmgandhi 18:6a4db94011d3 2 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 3 * @file stm32f2xx_hal_smartcard.h
sahilmgandhi 18:6a4db94011d3 4 * @author MCD Application Team
sahilmgandhi 18:6a4db94011d3 5 * @version V1.1.3
sahilmgandhi 18:6a4db94011d3 6 * @date 29-June-2016
sahilmgandhi 18:6a4db94011d3 7 * @brief Header file of SMARTCARD HAL module.
sahilmgandhi 18:6a4db94011d3 8 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 9 * @attention
sahilmgandhi 18:6a4db94011d3 10 *
sahilmgandhi 18:6a4db94011d3 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
sahilmgandhi 18:6a4db94011d3 12 *
sahilmgandhi 18:6a4db94011d3 13 * Redistribution and use in source and binary forms, with or without modification,
sahilmgandhi 18:6a4db94011d3 14 * are permitted provided that the following conditions are met:
sahilmgandhi 18:6a4db94011d3 15 * 1. Redistributions of source code must retain the above copyright notice,
sahilmgandhi 18:6a4db94011d3 16 * this list of conditions and the following disclaimer.
sahilmgandhi 18:6a4db94011d3 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
sahilmgandhi 18:6a4db94011d3 18 * this list of conditions and the following disclaimer in the documentation
sahilmgandhi 18:6a4db94011d3 19 * and/or other materials provided with the distribution.
sahilmgandhi 18:6a4db94011d3 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
sahilmgandhi 18:6a4db94011d3 21 * may be used to endorse or promote products derived from this software
sahilmgandhi 18:6a4db94011d3 22 * without specific prior written permission.
sahilmgandhi 18:6a4db94011d3 23 *
sahilmgandhi 18:6a4db94011d3 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
sahilmgandhi 18:6a4db94011d3 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sahilmgandhi 18:6a4db94011d3 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
sahilmgandhi 18:6a4db94011d3 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
sahilmgandhi 18:6a4db94011d3 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sahilmgandhi 18:6a4db94011d3 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
sahilmgandhi 18:6a4db94011d3 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
sahilmgandhi 18:6a4db94011d3 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
sahilmgandhi 18:6a4db94011d3 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
sahilmgandhi 18:6a4db94011d3 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sahilmgandhi 18:6a4db94011d3 34 *
sahilmgandhi 18:6a4db94011d3 35 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 36 */
sahilmgandhi 18:6a4db94011d3 37
sahilmgandhi 18:6a4db94011d3 38 /* Define to prevent recursive inclusion -------------------------------------*/
sahilmgandhi 18:6a4db94011d3 39 #ifndef __STM32F2xx_HAL_SMARTCARD_H
sahilmgandhi 18:6a4db94011d3 40 #define __STM32F2xx_HAL_SMARTCARD_H
sahilmgandhi 18:6a4db94011d3 41
sahilmgandhi 18:6a4db94011d3 42 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 43 extern "C" {
sahilmgandhi 18:6a4db94011d3 44 #endif
sahilmgandhi 18:6a4db94011d3 45
sahilmgandhi 18:6a4db94011d3 46 /* Includes ------------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 47 #include "stm32f2xx_hal_def.h"
sahilmgandhi 18:6a4db94011d3 48
sahilmgandhi 18:6a4db94011d3 49 /** @addtogroup STM32F2xx_HAL_Driver
sahilmgandhi 18:6a4db94011d3 50 * @{
sahilmgandhi 18:6a4db94011d3 51 */
sahilmgandhi 18:6a4db94011d3 52
sahilmgandhi 18:6a4db94011d3 53 /** @addtogroup SMARTCARD
sahilmgandhi 18:6a4db94011d3 54 * @{
sahilmgandhi 18:6a4db94011d3 55 */
sahilmgandhi 18:6a4db94011d3 56
sahilmgandhi 18:6a4db94011d3 57 /* Exported types ------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 58 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
sahilmgandhi 18:6a4db94011d3 59 * @{
sahilmgandhi 18:6a4db94011d3 60 */
sahilmgandhi 18:6a4db94011d3 61
sahilmgandhi 18:6a4db94011d3 62 /**
sahilmgandhi 18:6a4db94011d3 63 * @brief SMARTCARD Init Structure definition
sahilmgandhi 18:6a4db94011d3 64 */
sahilmgandhi 18:6a4db94011d3 65 typedef struct
sahilmgandhi 18:6a4db94011d3 66 {
sahilmgandhi 18:6a4db94011d3 67 uint32_t BaudRate; /*!< This member configures the SmartCard communication baud rate.
sahilmgandhi 18:6a4db94011d3 68 The baud rate is computed using the following formula:
sahilmgandhi 18:6a4db94011d3 69 - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
sahilmgandhi 18:6a4db94011d3 70 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
sahilmgandhi 18:6a4db94011d3 71
sahilmgandhi 18:6a4db94011d3 72 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
sahilmgandhi 18:6a4db94011d3 73 This parameter can be a value of @ref SMARTCARD_Word_Length */
sahilmgandhi 18:6a4db94011d3 74
sahilmgandhi 18:6a4db94011d3 75 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
sahilmgandhi 18:6a4db94011d3 76 This parameter can be a value of @ref SMARTCARD_Stop_Bits */
sahilmgandhi 18:6a4db94011d3 77
sahilmgandhi 18:6a4db94011d3 78 uint32_t Parity; /*!< Specifies the parity mode.
sahilmgandhi 18:6a4db94011d3 79 This parameter can be a value of @ref SMARTCARD_Parity
sahilmgandhi 18:6a4db94011d3 80 @note When parity is enabled, the computed parity is inserted
sahilmgandhi 18:6a4db94011d3 81 at the MSB position of the transmitted data (9th bit when
sahilmgandhi 18:6a4db94011d3 82 the word length is set to 9 data bits; 8th bit when the
sahilmgandhi 18:6a4db94011d3 83 word length is set to 8 data bits).*/
sahilmgandhi 18:6a4db94011d3 84
sahilmgandhi 18:6a4db94011d3 85 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
sahilmgandhi 18:6a4db94011d3 86 This parameter can be a value of @ref SMARTCARD_Mode */
sahilmgandhi 18:6a4db94011d3 87
sahilmgandhi 18:6a4db94011d3 88 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
sahilmgandhi 18:6a4db94011d3 89 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
sahilmgandhi 18:6a4db94011d3 90
sahilmgandhi 18:6a4db94011d3 91 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
sahilmgandhi 18:6a4db94011d3 92 This parameter can be a value of @ref SMARTCARD_Clock_Phase */
sahilmgandhi 18:6a4db94011d3 93
sahilmgandhi 18:6a4db94011d3 94 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
sahilmgandhi 18:6a4db94011d3 95 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
sahilmgandhi 18:6a4db94011d3 96 This parameter can be a value of @ref SMARTCARD_Last_Bit */
sahilmgandhi 18:6a4db94011d3 97
sahilmgandhi 18:6a4db94011d3 98 uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler value used for dividing the system clock
sahilmgandhi 18:6a4db94011d3 99 to provide the smartcard clock. The value given in the register (5 significant bits)
sahilmgandhi 18:6a4db94011d3 100 is multiplied by 2 to give the division factor of the source clock frequency.
sahilmgandhi 18:6a4db94011d3 101 This parameter can be a value of @ref SMARTCARD_Prescaler */
sahilmgandhi 18:6a4db94011d3 102
sahilmgandhi 18:6a4db94011d3 103 uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time value in terms of number of baud clocks */
sahilmgandhi 18:6a4db94011d3 104
sahilmgandhi 18:6a4db94011d3 105 uint32_t NACKState; /*!< Specifies the SmartCard NACK Transmission state.
sahilmgandhi 18:6a4db94011d3 106 This parameter can be a value of @ref SMARTCARD_NACK_State */
sahilmgandhi 18:6a4db94011d3 107 }SMARTCARD_InitTypeDef;
sahilmgandhi 18:6a4db94011d3 108
sahilmgandhi 18:6a4db94011d3 109 /**
sahilmgandhi 18:6a4db94011d3 110 * @brief HAL SMARTCARD State structures definition
sahilmgandhi 18:6a4db94011d3 111 * @note HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState.
sahilmgandhi 18:6a4db94011d3 112 * - gState contains SMARTCARD state information related to global Handle management
sahilmgandhi 18:6a4db94011d3 113 * and also information related to Tx operations.
sahilmgandhi 18:6a4db94011d3 114 * gState value coding follow below described bitmap :
sahilmgandhi 18:6a4db94011d3 115 * b7-b6 Error information
sahilmgandhi 18:6a4db94011d3 116 * 00 : No Error
sahilmgandhi 18:6a4db94011d3 117 * 01 : (Not Used)
sahilmgandhi 18:6a4db94011d3 118 * 10 : Timeout
sahilmgandhi 18:6a4db94011d3 119 * 11 : Error
sahilmgandhi 18:6a4db94011d3 120 * b5 IP initilisation status
sahilmgandhi 18:6a4db94011d3 121 * 0 : Reset (IP not initialized)
sahilmgandhi 18:6a4db94011d3 122 * 1 : Init done (IP not initialized. HAL SMARTCARD Init function already called)
sahilmgandhi 18:6a4db94011d3 123 * b4-b3 (not used)
sahilmgandhi 18:6a4db94011d3 124 * xx : Should be set to 00
sahilmgandhi 18:6a4db94011d3 125 * b2 Intrinsic process state
sahilmgandhi 18:6a4db94011d3 126 * 0 : Ready
sahilmgandhi 18:6a4db94011d3 127 * 1 : Busy (IP busy with some configuration or internal operations)
sahilmgandhi 18:6a4db94011d3 128 * b1 (not used)
sahilmgandhi 18:6a4db94011d3 129 * x : Should be set to 0
sahilmgandhi 18:6a4db94011d3 130 * b0 Tx state
sahilmgandhi 18:6a4db94011d3 131 * 0 : Ready (no Tx operation ongoing)
sahilmgandhi 18:6a4db94011d3 132 * 1 : Busy (Tx operation ongoing)
sahilmgandhi 18:6a4db94011d3 133 * - RxState contains information related to Rx operations.
sahilmgandhi 18:6a4db94011d3 134 * RxState value coding follow below described bitmap :
sahilmgandhi 18:6a4db94011d3 135 * b7-b6 (not used)
sahilmgandhi 18:6a4db94011d3 136 * xx : Should be set to 00
sahilmgandhi 18:6a4db94011d3 137 * b5 IP initilisation status
sahilmgandhi 18:6a4db94011d3 138 * 0 : Reset (IP not initialized)
sahilmgandhi 18:6a4db94011d3 139 * 1 : Init done (IP not initialized)
sahilmgandhi 18:6a4db94011d3 140 * b4-b2 (not used)
sahilmgandhi 18:6a4db94011d3 141 * xxx : Should be set to 000
sahilmgandhi 18:6a4db94011d3 142 * b1 Rx state
sahilmgandhi 18:6a4db94011d3 143 * 0 : Ready (no Rx operation ongoing)
sahilmgandhi 18:6a4db94011d3 144 * 1 : Busy (Rx operation ongoing)
sahilmgandhi 18:6a4db94011d3 145 * b0 (not used)
sahilmgandhi 18:6a4db94011d3 146 * x : Should be set to 0.
sahilmgandhi 18:6a4db94011d3 147 */
sahilmgandhi 18:6a4db94011d3 148 typedef enum
sahilmgandhi 18:6a4db94011d3 149 {
sahilmgandhi 18:6a4db94011d3 150 HAL_SMARTCARD_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized
sahilmgandhi 18:6a4db94011d3 151 Value is allowed for gState and RxState */
sahilmgandhi 18:6a4db94011d3 152 HAL_SMARTCARD_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
sahilmgandhi 18:6a4db94011d3 153 Value is allowed for gState and RxState */
sahilmgandhi 18:6a4db94011d3 154 HAL_SMARTCARD_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
sahilmgandhi 18:6a4db94011d3 155 Value is allowed for gState only */
sahilmgandhi 18:6a4db94011d3 156 HAL_SMARTCARD_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
sahilmgandhi 18:6a4db94011d3 157 Value is allowed for gState only */
sahilmgandhi 18:6a4db94011d3 158 HAL_SMARTCARD_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
sahilmgandhi 18:6a4db94011d3 159 Value is allowed for RxState only */
sahilmgandhi 18:6a4db94011d3 160 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
sahilmgandhi 18:6a4db94011d3 161 Not to be used for neither gState nor RxState.
sahilmgandhi 18:6a4db94011d3 162 Value is result of combination (Or) between gState and RxState values */
sahilmgandhi 18:6a4db94011d3 163 HAL_SMARTCARD_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
sahilmgandhi 18:6a4db94011d3 164 Value is allowed for gState only */
sahilmgandhi 18:6a4db94011d3 165 HAL_SMARTCARD_STATE_ERROR = 0xE0U /*!< Error
sahilmgandhi 18:6a4db94011d3 166 Value is allowed for gState only */
sahilmgandhi 18:6a4db94011d3 167 }HAL_SMARTCARD_StateTypeDef;
sahilmgandhi 18:6a4db94011d3 168
sahilmgandhi 18:6a4db94011d3 169 /**
sahilmgandhi 18:6a4db94011d3 170 * @brief SMARTCARD handle Structure definition
sahilmgandhi 18:6a4db94011d3 171 */
sahilmgandhi 18:6a4db94011d3 172 typedef struct
sahilmgandhi 18:6a4db94011d3 173 {
sahilmgandhi 18:6a4db94011d3 174 USART_TypeDef *Instance; /* USART registers base address */
sahilmgandhi 18:6a4db94011d3 175
sahilmgandhi 18:6a4db94011d3 176 SMARTCARD_InitTypeDef Init; /* SmartCard communication parameters */
sahilmgandhi 18:6a4db94011d3 177
sahilmgandhi 18:6a4db94011d3 178 uint8_t *pTxBuffPtr; /* Pointer to SmartCard Tx transfer Buffer */
sahilmgandhi 18:6a4db94011d3 179
sahilmgandhi 18:6a4db94011d3 180 uint16_t TxXferSize; /* SmartCard Tx Transfer size */
sahilmgandhi 18:6a4db94011d3 181
sahilmgandhi 18:6a4db94011d3 182 __IO uint16_t TxXferCount; /* SmartCard Tx Transfer Counter */
sahilmgandhi 18:6a4db94011d3 183
sahilmgandhi 18:6a4db94011d3 184 uint8_t *pRxBuffPtr; /* Pointer to SmartCard Rx transfer Buffer */
sahilmgandhi 18:6a4db94011d3 185
sahilmgandhi 18:6a4db94011d3 186 uint16_t RxXferSize; /* SmartCard Rx Transfer size */
sahilmgandhi 18:6a4db94011d3 187
sahilmgandhi 18:6a4db94011d3 188 __IO uint16_t RxXferCount; /* SmartCard Rx Transfer Counter */
sahilmgandhi 18:6a4db94011d3 189
sahilmgandhi 18:6a4db94011d3 190 DMA_HandleTypeDef *hdmatx; /* SmartCard Tx DMA Handle parameters */
sahilmgandhi 18:6a4db94011d3 191
sahilmgandhi 18:6a4db94011d3 192 DMA_HandleTypeDef *hdmarx; /* SmartCard Rx DMA Handle parameters */
sahilmgandhi 18:6a4db94011d3 193
sahilmgandhi 18:6a4db94011d3 194 HAL_LockTypeDef Lock; /* Locking object */
sahilmgandhi 18:6a4db94011d3 195
sahilmgandhi 18:6a4db94011d3 196 __IO HAL_SMARTCARD_StateTypeDef gState; /* SmartCard state information related to global Handle management
sahilmgandhi 18:6a4db94011d3 197 and also related to Tx operations.
sahilmgandhi 18:6a4db94011d3 198 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
sahilmgandhi 18:6a4db94011d3 199
sahilmgandhi 18:6a4db94011d3 200 __IO HAL_SMARTCARD_StateTypeDef RxState; /* SmartCard state information related to Rx operations.
sahilmgandhi 18:6a4db94011d3 201 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
sahilmgandhi 18:6a4db94011d3 202
sahilmgandhi 18:6a4db94011d3 203 __IO uint32_t ErrorCode; /* SmartCard Error code */
sahilmgandhi 18:6a4db94011d3 204
sahilmgandhi 18:6a4db94011d3 205 }SMARTCARD_HandleTypeDef;
sahilmgandhi 18:6a4db94011d3 206
sahilmgandhi 18:6a4db94011d3 207 /**
sahilmgandhi 18:6a4db94011d3 208 * @}
sahilmgandhi 18:6a4db94011d3 209 */
sahilmgandhi 18:6a4db94011d3 210
sahilmgandhi 18:6a4db94011d3 211 /* Exported constants --------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 212 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants
sahilmgandhi 18:6a4db94011d3 213 * @{
sahilmgandhi 18:6a4db94011d3 214 */
sahilmgandhi 18:6a4db94011d3 215 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
sahilmgandhi 18:6a4db94011d3 216 * @brief SMARTCARD Error Code
sahilmgandhi 18:6a4db94011d3 217 * @{
sahilmgandhi 18:6a4db94011d3 218 */
sahilmgandhi 18:6a4db94011d3 219 #define HAL_SMARTCARD_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
sahilmgandhi 18:6a4db94011d3 220 #define HAL_SMARTCARD_ERROR_PE ((uint32_t)0x00000001U) /*!< Parity error */
sahilmgandhi 18:6a4db94011d3 221 #define HAL_SMARTCARD_ERROR_NE ((uint32_t)0x00000002U) /*!< Noise error */
sahilmgandhi 18:6a4db94011d3 222 #define HAL_SMARTCARD_ERROR_FE ((uint32_t)0x00000004U) /*!< Frame error */
sahilmgandhi 18:6a4db94011d3 223 #define HAL_SMARTCARD_ERROR_ORE ((uint32_t)0x00000008U) /*!< Overrun error */
sahilmgandhi 18:6a4db94011d3 224 #define HAL_SMARTCARD_ERROR_DMA ((uint32_t)0x00000010U) /*!< DMA transfer error */
sahilmgandhi 18:6a4db94011d3 225 /**
sahilmgandhi 18:6a4db94011d3 226 * @}
sahilmgandhi 18:6a4db94011d3 227 */
sahilmgandhi 18:6a4db94011d3 228
sahilmgandhi 18:6a4db94011d3 229 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
sahilmgandhi 18:6a4db94011d3 230 * @{
sahilmgandhi 18:6a4db94011d3 231 */
sahilmgandhi 18:6a4db94011d3 232 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
sahilmgandhi 18:6a4db94011d3 233 /**
sahilmgandhi 18:6a4db94011d3 234 * @}
sahilmgandhi 18:6a4db94011d3 235 */
sahilmgandhi 18:6a4db94011d3 236
sahilmgandhi 18:6a4db94011d3 237 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
sahilmgandhi 18:6a4db94011d3 238 * @{
sahilmgandhi 18:6a4db94011d3 239 */
sahilmgandhi 18:6a4db94011d3 240 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
sahilmgandhi 18:6a4db94011d3 241 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
sahilmgandhi 18:6a4db94011d3 242 /**
sahilmgandhi 18:6a4db94011d3 243 * @}
sahilmgandhi 18:6a4db94011d3 244 */
sahilmgandhi 18:6a4db94011d3 245
sahilmgandhi 18:6a4db94011d3 246 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
sahilmgandhi 18:6a4db94011d3 247 * @{
sahilmgandhi 18:6a4db94011d3 248 */
sahilmgandhi 18:6a4db94011d3 249 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
sahilmgandhi 18:6a4db94011d3 250 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
sahilmgandhi 18:6a4db94011d3 251 /**
sahilmgandhi 18:6a4db94011d3 252 * @}
sahilmgandhi 18:6a4db94011d3 253 */
sahilmgandhi 18:6a4db94011d3 254
sahilmgandhi 18:6a4db94011d3 255 /** @defgroup SMARTCARD_Mode SMARTCARD Mode
sahilmgandhi 18:6a4db94011d3 256 * @{
sahilmgandhi 18:6a4db94011d3 257 */
sahilmgandhi 18:6a4db94011d3 258 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
sahilmgandhi 18:6a4db94011d3 259 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
sahilmgandhi 18:6a4db94011d3 260 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
sahilmgandhi 18:6a4db94011d3 261 /**
sahilmgandhi 18:6a4db94011d3 262 * @}
sahilmgandhi 18:6a4db94011d3 263 */
sahilmgandhi 18:6a4db94011d3 264
sahilmgandhi 18:6a4db94011d3 265 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
sahilmgandhi 18:6a4db94011d3 266 * @{
sahilmgandhi 18:6a4db94011d3 267 */
sahilmgandhi 18:6a4db94011d3 268 #define SMARTCARD_POLARITY_LOW ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 269 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
sahilmgandhi 18:6a4db94011d3 270 /**
sahilmgandhi 18:6a4db94011d3 271 * @}
sahilmgandhi 18:6a4db94011d3 272 */
sahilmgandhi 18:6a4db94011d3 273
sahilmgandhi 18:6a4db94011d3 274 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
sahilmgandhi 18:6a4db94011d3 275 * @{
sahilmgandhi 18:6a4db94011d3 276 */
sahilmgandhi 18:6a4db94011d3 277 #define SMARTCARD_PHASE_1EDGE ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 278 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
sahilmgandhi 18:6a4db94011d3 279 /**
sahilmgandhi 18:6a4db94011d3 280 * @}
sahilmgandhi 18:6a4db94011d3 281 */
sahilmgandhi 18:6a4db94011d3 282
sahilmgandhi 18:6a4db94011d3 283 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
sahilmgandhi 18:6a4db94011d3 284 * @{
sahilmgandhi 18:6a4db94011d3 285 */
sahilmgandhi 18:6a4db94011d3 286 #define SMARTCARD_LASTBIT_DISABLE ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 287 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
sahilmgandhi 18:6a4db94011d3 288 /**
sahilmgandhi 18:6a4db94011d3 289 * @}
sahilmgandhi 18:6a4db94011d3 290 */
sahilmgandhi 18:6a4db94011d3 291
sahilmgandhi 18:6a4db94011d3 292 /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State
sahilmgandhi 18:6a4db94011d3 293 * @{
sahilmgandhi 18:6a4db94011d3 294 */
sahilmgandhi 18:6a4db94011d3 295 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
sahilmgandhi 18:6a4db94011d3 296 #define SMARTCARD_NACK_DISABLE ((uint32_t)0x00000000U)
sahilmgandhi 18:6a4db94011d3 297 /**
sahilmgandhi 18:6a4db94011d3 298 * @}
sahilmgandhi 18:6a4db94011d3 299 */
sahilmgandhi 18:6a4db94011d3 300
sahilmgandhi 18:6a4db94011d3 301 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests
sahilmgandhi 18:6a4db94011d3 302 * @{
sahilmgandhi 18:6a4db94011d3 303 */
sahilmgandhi 18:6a4db94011d3 304 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
sahilmgandhi 18:6a4db94011d3 305 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
sahilmgandhi 18:6a4db94011d3 306 /**
sahilmgandhi 18:6a4db94011d3 307 * @}
sahilmgandhi 18:6a4db94011d3 308 */
sahilmgandhi 18:6a4db94011d3 309
sahilmgandhi 18:6a4db94011d3 310 /** @defgroup SMARTCARD_Prescaler SMARTCARD Prescaler
sahilmgandhi 18:6a4db94011d3 311 * @{
sahilmgandhi 18:6a4db94011d3 312 */
sahilmgandhi 18:6a4db94011d3 313 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 ((uint32_t)0x00000001U) /*!< SYSCLK divided by 2 */
sahilmgandhi 18:6a4db94011d3 314 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 ((uint32_t)0x00000002U) /*!< SYSCLK divided by 4 */
sahilmgandhi 18:6a4db94011d3 315 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 ((uint32_t)0x00000003U) /*!< SYSCLK divided by 6 */
sahilmgandhi 18:6a4db94011d3 316 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 ((uint32_t)0x00000004U) /*!< SYSCLK divided by 8 */
sahilmgandhi 18:6a4db94011d3 317 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 ((uint32_t)0x00000005U) /*!< SYSCLK divided by 10 */
sahilmgandhi 18:6a4db94011d3 318 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 ((uint32_t)0x00000006U) /*!< SYSCLK divided by 12 */
sahilmgandhi 18:6a4db94011d3 319 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 ((uint32_t)0x00000007U) /*!< SYSCLK divided by 14 */
sahilmgandhi 18:6a4db94011d3 320 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 ((uint32_t)0x00000008U) /*!< SYSCLK divided by 16 */
sahilmgandhi 18:6a4db94011d3 321 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 ((uint32_t)0x00000009U) /*!< SYSCLK divided by 18 */
sahilmgandhi 18:6a4db94011d3 322 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 ((uint32_t)0x0000000AU) /*!< SYSCLK divided by 20 */
sahilmgandhi 18:6a4db94011d3 323 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 ((uint32_t)0x0000000BU) /*!< SYSCLK divided by 22 */
sahilmgandhi 18:6a4db94011d3 324 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 ((uint32_t)0x0000000CU) /*!< SYSCLK divided by 24 */
sahilmgandhi 18:6a4db94011d3 325 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 ((uint32_t)0x0000000DU) /*!< SYSCLK divided by 26 */
sahilmgandhi 18:6a4db94011d3 326 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 ((uint32_t)0x0000000EU) /*!< SYSCLK divided by 28 */
sahilmgandhi 18:6a4db94011d3 327 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 ((uint32_t)0x0000000FU) /*!< SYSCLK divided by 30 */
sahilmgandhi 18:6a4db94011d3 328 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 ((uint32_t)0x00000010U) /*!< SYSCLK divided by 32 */
sahilmgandhi 18:6a4db94011d3 329 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 ((uint32_t)0x00000011U) /*!< SYSCLK divided by 34 */
sahilmgandhi 18:6a4db94011d3 330 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 ((uint32_t)0x00000012U) /*!< SYSCLK divided by 36 */
sahilmgandhi 18:6a4db94011d3 331 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 ((uint32_t)0x00000013U) /*!< SYSCLK divided by 38 */
sahilmgandhi 18:6a4db94011d3 332 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 ((uint32_t)0x00000014U) /*!< SYSCLK divided by 40 */
sahilmgandhi 18:6a4db94011d3 333 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 ((uint32_t)0x00000015U) /*!< SYSCLK divided by 42 */
sahilmgandhi 18:6a4db94011d3 334 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 ((uint32_t)0x00000016U) /*!< SYSCLK divided by 44 */
sahilmgandhi 18:6a4db94011d3 335 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 ((uint32_t)0x00000017U) /*!< SYSCLK divided by 46 */
sahilmgandhi 18:6a4db94011d3 336 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 ((uint32_t)0x00000018U) /*!< SYSCLK divided by 48 */
sahilmgandhi 18:6a4db94011d3 337 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 ((uint32_t)0x00000019U) /*!< SYSCLK divided by 50 */
sahilmgandhi 18:6a4db94011d3 338 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 ((uint32_t)0x0000001AU) /*!< SYSCLK divided by 52 */
sahilmgandhi 18:6a4db94011d3 339 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 ((uint32_t)0x0000001BU) /*!< SYSCLK divided by 54 */
sahilmgandhi 18:6a4db94011d3 340 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 ((uint32_t)0x0000001CU) /*!< SYSCLK divided by 56 */
sahilmgandhi 18:6a4db94011d3 341 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 ((uint32_t)0x0000001DU) /*!< SYSCLK divided by 58 */
sahilmgandhi 18:6a4db94011d3 342 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 ((uint32_t)0x0000001EU) /*!< SYSCLK divided by 60 */
sahilmgandhi 18:6a4db94011d3 343 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 ((uint32_t)0x0000001FU) /*!< SYSCLK divided by 62 */
sahilmgandhi 18:6a4db94011d3 344 /**
sahilmgandhi 18:6a4db94011d3 345 * @}
sahilmgandhi 18:6a4db94011d3 346 */
sahilmgandhi 18:6a4db94011d3 347
sahilmgandhi 18:6a4db94011d3 348 /** @defgroup SmartCard_Flags SMARTCARD Flags
sahilmgandhi 18:6a4db94011d3 349 * Elements values convention: 0xXXXX
sahilmgandhi 18:6a4db94011d3 350 * - 0xXXXX : Flag mask in the SR register
sahilmgandhi 18:6a4db94011d3 351 * @{
sahilmgandhi 18:6a4db94011d3 352 */
sahilmgandhi 18:6a4db94011d3 353 #define SMARTCARD_FLAG_TXE ((uint32_t)0x00000080U)
sahilmgandhi 18:6a4db94011d3 354 #define SMARTCARD_FLAG_TC ((uint32_t)0x00000040U)
sahilmgandhi 18:6a4db94011d3 355 #define SMARTCARD_FLAG_RXNE ((uint32_t)0x00000020U)
sahilmgandhi 18:6a4db94011d3 356 #define SMARTCARD_FLAG_IDLE ((uint32_t)0x00000010U)
sahilmgandhi 18:6a4db94011d3 357 #define SMARTCARD_FLAG_ORE ((uint32_t)0x00000008U)
sahilmgandhi 18:6a4db94011d3 358 #define SMARTCARD_FLAG_NE ((uint32_t)0x00000004U)
sahilmgandhi 18:6a4db94011d3 359 #define SMARTCARD_FLAG_FE ((uint32_t)0x00000002U)
sahilmgandhi 18:6a4db94011d3 360 #define SMARTCARD_FLAG_PE ((uint32_t)0x00000001U)
sahilmgandhi 18:6a4db94011d3 361 /**
sahilmgandhi 18:6a4db94011d3 362 * @}
sahilmgandhi 18:6a4db94011d3 363 */
sahilmgandhi 18:6a4db94011d3 364
sahilmgandhi 18:6a4db94011d3 365 /** @defgroup SmartCard_Interrupt_definition SMARTCARD Interrupts Definition
sahilmgandhi 18:6a4db94011d3 366 * Elements values convention: 0xY000XXXX
sahilmgandhi 18:6a4db94011d3 367 * - XXXX : Interrupt mask in the XX register
sahilmgandhi 18:6a4db94011d3 368 * - Y : Interrupt source register (2bits)
sahilmgandhi 18:6a4db94011d3 369 * - 01: CR1 register
sahilmgandhi 18:6a4db94011d3 370 * - 10: CR3 register
sahilmgandhi 18:6a4db94011d3 371 * @{
sahilmgandhi 18:6a4db94011d3 372 */
sahilmgandhi 18:6a4db94011d3 373 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
sahilmgandhi 18:6a4db94011d3 374 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
sahilmgandhi 18:6a4db94011d3 375 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
sahilmgandhi 18:6a4db94011d3 376 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
sahilmgandhi 18:6a4db94011d3 377 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
sahilmgandhi 18:6a4db94011d3 378 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE))
sahilmgandhi 18:6a4db94011d3 379 /**
sahilmgandhi 18:6a4db94011d3 380 * @}
sahilmgandhi 18:6a4db94011d3 381 */
sahilmgandhi 18:6a4db94011d3 382
sahilmgandhi 18:6a4db94011d3 383 /**
sahilmgandhi 18:6a4db94011d3 384 * @}
sahilmgandhi 18:6a4db94011d3 385 */
sahilmgandhi 18:6a4db94011d3 386
sahilmgandhi 18:6a4db94011d3 387 /* Exported macro ------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 388 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
sahilmgandhi 18:6a4db94011d3 389 * @{
sahilmgandhi 18:6a4db94011d3 390 */
sahilmgandhi 18:6a4db94011d3 391
sahilmgandhi 18:6a4db94011d3 392 /** @brief Reset SMARTCARD handle gstate & RxState
sahilmgandhi 18:6a4db94011d3 393 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 394 * @retval None
sahilmgandhi 18:6a4db94011d3 395 */
sahilmgandhi 18:6a4db94011d3 396 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
sahilmgandhi 18:6a4db94011d3 397 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
sahilmgandhi 18:6a4db94011d3 398 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
sahilmgandhi 18:6a4db94011d3 399 } while(0)
sahilmgandhi 18:6a4db94011d3 400
sahilmgandhi 18:6a4db94011d3 401 /** @brief Flushs the Smartcard DR register
sahilmgandhi 18:6a4db94011d3 402 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 403 */
sahilmgandhi 18:6a4db94011d3 404 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
sahilmgandhi 18:6a4db94011d3 405
sahilmgandhi 18:6a4db94011d3 406 /** @brief Checks whether the specified Smartcard flag is set or not.
sahilmgandhi 18:6a4db94011d3 407 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 408 * @param __FLAG__: specifies the flag to check.
sahilmgandhi 18:6a4db94011d3 409 * This parameter can be one of the following values:
sahilmgandhi 18:6a4db94011d3 410 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
sahilmgandhi 18:6a4db94011d3 411 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
sahilmgandhi 18:6a4db94011d3 412 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
sahilmgandhi 18:6a4db94011d3 413 * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag
sahilmgandhi 18:6a4db94011d3 414 * @arg SMARTCARD_FLAG_ORE: Overrun Error flag
sahilmgandhi 18:6a4db94011d3 415 * @arg SMARTCARD_FLAG_NE: Noise Error flag
sahilmgandhi 18:6a4db94011d3 416 * @arg SMARTCARD_FLAG_FE: Framing Error flag
sahilmgandhi 18:6a4db94011d3 417 * @arg SMARTCARD_FLAG_PE: Parity Error flag
sahilmgandhi 18:6a4db94011d3 418 * @retval The new state of __FLAG__ (TRUE or FALSE).
sahilmgandhi 18:6a4db94011d3 419 */
sahilmgandhi 18:6a4db94011d3 420 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
sahilmgandhi 18:6a4db94011d3 421
sahilmgandhi 18:6a4db94011d3 422 /** @brief Clears the specified Smartcard pending flags.
sahilmgandhi 18:6a4db94011d3 423 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 424 * @param __FLAG__: specifies the flag to check.
sahilmgandhi 18:6a4db94011d3 425 * This parameter can be any combination of the following values:
sahilmgandhi 18:6a4db94011d3 426 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag.
sahilmgandhi 18:6a4db94011d3 427 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag.
sahilmgandhi 18:6a4db94011d3 428 *
sahilmgandhi 18:6a4db94011d3 429 * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (Overrun
sahilmgandhi 18:6a4db94011d3 430 * error) flags are cleared by software sequence: a read operation to
sahilmgandhi 18:6a4db94011d3 431 * USART_SR register followed by a read operation to USART_DR register.
sahilmgandhi 18:6a4db94011d3 432 * @note RXNE flag can be also cleared by a read to the USART_DR register.
sahilmgandhi 18:6a4db94011d3 433 * @note TC flag can be also cleared by software sequence: a read operation to
sahilmgandhi 18:6a4db94011d3 434 * USART_SR register followed by a write operation to USART_DR register.
sahilmgandhi 18:6a4db94011d3 435 * @note TXE flag is cleared only by a write to the USART_DR register.
sahilmgandhi 18:6a4db94011d3 436 */
sahilmgandhi 18:6a4db94011d3 437 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
sahilmgandhi 18:6a4db94011d3 438
sahilmgandhi 18:6a4db94011d3 439 /** @brief Clear the SMARTCARD PE pending flag.
sahilmgandhi 18:6a4db94011d3 440 * @param __HANDLE__: specifies the USART Handle.
sahilmgandhi 18:6a4db94011d3 441 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
sahilmgandhi 18:6a4db94011d3 442 * SMARTCARD peripheral.
sahilmgandhi 18:6a4db94011d3 443 * @retval None
sahilmgandhi 18:6a4db94011d3 444 */
sahilmgandhi 18:6a4db94011d3 445 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \
sahilmgandhi 18:6a4db94011d3 446 do{ \
sahilmgandhi 18:6a4db94011d3 447 __IO uint32_t tmpreg_pe = 0x00U; \
sahilmgandhi 18:6a4db94011d3 448 tmpreg_pe = (__HANDLE__)->Instance->SR; \
sahilmgandhi 18:6a4db94011d3 449 tmpreg_pe = (__HANDLE__)->Instance->DR; \
sahilmgandhi 18:6a4db94011d3 450 UNUSED(tmpreg_pe); \
sahilmgandhi 18:6a4db94011d3 451 } while(0)
sahilmgandhi 18:6a4db94011d3 452
sahilmgandhi 18:6a4db94011d3 453 /** @brief Clear the SMARTCARD FE pending flag.
sahilmgandhi 18:6a4db94011d3 454 * @param __HANDLE__: specifies the USART Handle.
sahilmgandhi 18:6a4db94011d3 455 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
sahilmgandhi 18:6a4db94011d3 456 * SMARTCARD peripheral.
sahilmgandhi 18:6a4db94011d3 457 * @retval None
sahilmgandhi 18:6a4db94011d3 458 */
sahilmgandhi 18:6a4db94011d3 459 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
sahilmgandhi 18:6a4db94011d3 460
sahilmgandhi 18:6a4db94011d3 461 /** @brief Clear the SMARTCARD NE pending flag.
sahilmgandhi 18:6a4db94011d3 462 * @param __HANDLE__: specifies the USART Handle.
sahilmgandhi 18:6a4db94011d3 463 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
sahilmgandhi 18:6a4db94011d3 464 * SMARTCARD peripheral.
sahilmgandhi 18:6a4db94011d3 465 * @retval None
sahilmgandhi 18:6a4db94011d3 466 */
sahilmgandhi 18:6a4db94011d3 467 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
sahilmgandhi 18:6a4db94011d3 468
sahilmgandhi 18:6a4db94011d3 469 /** @brief Clear the SMARTCARD ORE pending flag.
sahilmgandhi 18:6a4db94011d3 470 * @param __HANDLE__: specifies the USART Handle.
sahilmgandhi 18:6a4db94011d3 471 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
sahilmgandhi 18:6a4db94011d3 472 * SMARTCARD peripheral.
sahilmgandhi 18:6a4db94011d3 473 * @retval None
sahilmgandhi 18:6a4db94011d3 474 */
sahilmgandhi 18:6a4db94011d3 475 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
sahilmgandhi 18:6a4db94011d3 476
sahilmgandhi 18:6a4db94011d3 477 /** @brief Clear the SMARTCARD IDLE pending flag.
sahilmgandhi 18:6a4db94011d3 478 * @param __HANDLE__: specifies the USART Handle.
sahilmgandhi 18:6a4db94011d3 479 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
sahilmgandhi 18:6a4db94011d3 480 * SMARTCARD peripheral.
sahilmgandhi 18:6a4db94011d3 481 * @retval None
sahilmgandhi 18:6a4db94011d3 482 */
sahilmgandhi 18:6a4db94011d3 483 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
sahilmgandhi 18:6a4db94011d3 484
sahilmgandhi 18:6a4db94011d3 485 /** @brief Enables or disables the specified SmartCard interrupts.
sahilmgandhi 18:6a4db94011d3 486 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 487 * @param __INTERRUPT__: specifies the SMARTCARD interrupt source to check.
sahilmgandhi 18:6a4db94011d3 488 * This parameter can be one of the following values:
sahilmgandhi 18:6a4db94011d3 489 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
sahilmgandhi 18:6a4db94011d3 490 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
sahilmgandhi 18:6a4db94011d3 491 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
sahilmgandhi 18:6a4db94011d3 492 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
sahilmgandhi 18:6a4db94011d3 493 * @arg SMARTCARD_IT_PE: Parity Error interrupt
sahilmgandhi 18:6a4db94011d3 494 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
sahilmgandhi 18:6a4db94011d3 495 */
sahilmgandhi 18:6a4db94011d3 496 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
sahilmgandhi 18:6a4db94011d3 497 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
sahilmgandhi 18:6a4db94011d3 498 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
sahilmgandhi 18:6a4db94011d3 499 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
sahilmgandhi 18:6a4db94011d3 500
sahilmgandhi 18:6a4db94011d3 501 /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
sahilmgandhi 18:6a4db94011d3 502 * @param __HANDLE__: specifies the SmartCard Handle.
sahilmgandhi 18:6a4db94011d3 503 * @param __IT__: specifies the SMARTCARD interrupt source to check.
sahilmgandhi 18:6a4db94011d3 504 * This parameter can be one of the following values:
sahilmgandhi 18:6a4db94011d3 505 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
sahilmgandhi 18:6a4db94011d3 506 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
sahilmgandhi 18:6a4db94011d3 507 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
sahilmgandhi 18:6a4db94011d3 508 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
sahilmgandhi 18:6a4db94011d3 509 * @arg SMARTCARD_IT_ERR: Error interrupt
sahilmgandhi 18:6a4db94011d3 510 * @arg SMARTCARD_IT_PE: Parity Error interrupt
sahilmgandhi 18:6a4db94011d3 511 * @retval The new state of __IT__ (TRUE or FALSE).
sahilmgandhi 18:6a4db94011d3 512 */
sahilmgandhi 18:6a4db94011d3 513 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
sahilmgandhi 18:6a4db94011d3 514
sahilmgandhi 18:6a4db94011d3 515 /** @brief Macro to enable the SMARTCARD's one bit sample method
sahilmgandhi 18:6a4db94011d3 516 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 517 * @retval None
sahilmgandhi 18:6a4db94011d3 518 */
sahilmgandhi 18:6a4db94011d3 519 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
sahilmgandhi 18:6a4db94011d3 520
sahilmgandhi 18:6a4db94011d3 521 /** @brief Macro to disable the SMARTCARD's one bit sample method
sahilmgandhi 18:6a4db94011d3 522 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 523 * @retval None
sahilmgandhi 18:6a4db94011d3 524 */
sahilmgandhi 18:6a4db94011d3 525 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
sahilmgandhi 18:6a4db94011d3 526
sahilmgandhi 18:6a4db94011d3 527 /** @brief Enable the USART associated to the SMARTCARD Handle
sahilmgandhi 18:6a4db94011d3 528 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 529 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
sahilmgandhi 18:6a4db94011d3 530 * @retval None
sahilmgandhi 18:6a4db94011d3 531 */
sahilmgandhi 18:6a4db94011d3 532 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
sahilmgandhi 18:6a4db94011d3 533
sahilmgandhi 18:6a4db94011d3 534 /** @brief Disable the USART associated to the SMARTCARD Handle
sahilmgandhi 18:6a4db94011d3 535 * @param __HANDLE__: specifies the SMARTCARD Handle.
sahilmgandhi 18:6a4db94011d3 536 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
sahilmgandhi 18:6a4db94011d3 537 * @retval None
sahilmgandhi 18:6a4db94011d3 538 */
sahilmgandhi 18:6a4db94011d3 539 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
sahilmgandhi 18:6a4db94011d3 540
sahilmgandhi 18:6a4db94011d3 541 /** @brief Macros to enable or disable the SmartCard DMA request.
sahilmgandhi 18:6a4db94011d3 542 * @param __HANDLE__: specifies the SmartCard Handle.
sahilmgandhi 18:6a4db94011d3 543 * @param __REQUEST__: specifies the SmartCard DMA request.
sahilmgandhi 18:6a4db94011d3 544 * This parameter can be one of the following values:
sahilmgandhi 18:6a4db94011d3 545 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
sahilmgandhi 18:6a4db94011d3 546 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
sahilmgandhi 18:6a4db94011d3 547 */
sahilmgandhi 18:6a4db94011d3 548 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
sahilmgandhi 18:6a4db94011d3 549 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
sahilmgandhi 18:6a4db94011d3 550
sahilmgandhi 18:6a4db94011d3 551 /**
sahilmgandhi 18:6a4db94011d3 552 * @}
sahilmgandhi 18:6a4db94011d3 553 */
sahilmgandhi 18:6a4db94011d3 554
sahilmgandhi 18:6a4db94011d3 555 /* Exported functions --------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 556 /** @addtogroup SMARTCARD_Exported_Functions
sahilmgandhi 18:6a4db94011d3 557 * @{
sahilmgandhi 18:6a4db94011d3 558 */
sahilmgandhi 18:6a4db94011d3 559
sahilmgandhi 18:6a4db94011d3 560 /** @addtogroup SMARTCARD_Exported_Functions_Group1
sahilmgandhi 18:6a4db94011d3 561 * @{
sahilmgandhi 18:6a4db94011d3 562 */
sahilmgandhi 18:6a4db94011d3 563 /* Initialization/de-initialization functions **********************************/
sahilmgandhi 18:6a4db94011d3 564 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 565 HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 566 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 567 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 568 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 569 /**
sahilmgandhi 18:6a4db94011d3 570 * @}
sahilmgandhi 18:6a4db94011d3 571 */
sahilmgandhi 18:6a4db94011d3 572
sahilmgandhi 18:6a4db94011d3 573 /** @addtogroup SMARTCARD_Exported_Functions_Group2
sahilmgandhi 18:6a4db94011d3 574 * @{
sahilmgandhi 18:6a4db94011d3 575 */
sahilmgandhi 18:6a4db94011d3 576 /* IO operation functions *******************************************************/
sahilmgandhi 18:6a4db94011d3 577 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 578 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
sahilmgandhi 18:6a4db94011d3 579 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 580 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 581 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 582 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
sahilmgandhi 18:6a4db94011d3 583
sahilmgandhi 18:6a4db94011d3 584 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 585 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 586 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 587 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 588 /**
sahilmgandhi 18:6a4db94011d3 589 * @}
sahilmgandhi 18:6a4db94011d3 590 */
sahilmgandhi 18:6a4db94011d3 591
sahilmgandhi 18:6a4db94011d3 592 /** @addtogroup SMARTCARD_Exported_Functions_Group3
sahilmgandhi 18:6a4db94011d3 593 * @{
sahilmgandhi 18:6a4db94011d3 594 */
sahilmgandhi 18:6a4db94011d3 595 /* Peripheral State functions **************************************************/
sahilmgandhi 18:6a4db94011d3 596 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 597 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
sahilmgandhi 18:6a4db94011d3 598
sahilmgandhi 18:6a4db94011d3 599 /**
sahilmgandhi 18:6a4db94011d3 600 * @}
sahilmgandhi 18:6a4db94011d3 601 */
sahilmgandhi 18:6a4db94011d3 602
sahilmgandhi 18:6a4db94011d3 603 /**
sahilmgandhi 18:6a4db94011d3 604 * @}
sahilmgandhi 18:6a4db94011d3 605 */
sahilmgandhi 18:6a4db94011d3 606 /* Private types -------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 607 /* Private variables ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 608 /* Private constants ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 609 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
sahilmgandhi 18:6a4db94011d3 610 * @{
sahilmgandhi 18:6a4db94011d3 611 */
sahilmgandhi 18:6a4db94011d3 612
sahilmgandhi 18:6a4db94011d3 613 /** @brief SMARTCARD interruptions flag mask
sahilmgandhi 18:6a4db94011d3 614 *
sahilmgandhi 18:6a4db94011d3 615 */
sahilmgandhi 18:6a4db94011d3 616 #define SMARTCARD_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
sahilmgandhi 18:6a4db94011d3 617 USART_CR1_IDLEIE | USART_CR3_EIE )
sahilmgandhi 18:6a4db94011d3 618
sahilmgandhi 18:6a4db94011d3 619 #define SMARTCARD_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_)))
sahilmgandhi 18:6a4db94011d3 620 #define SMARTCARD_DIVMANT(_PCLK_, _BAUD_) (SMARTCARD_DIV((_PCLK_), (_BAUD_))/100U)
sahilmgandhi 18:6a4db94011d3 621 #define SMARTCARD_DIVFRAQ(_PCLK_, _BAUD_) (((SMARTCARD_DIV((_PCLK_), (_BAUD_)) - (SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
sahilmgandhi 18:6a4db94011d3 622 /* SMARTCARD BRR = mantissa + overflow + fraction
sahilmgandhi 18:6a4db94011d3 623 = (SMARTCARD DIVMANT << 4) + (SMARTCARD DIVFRAQ & 0xF0) + (SMARTCARD DIVFRAQ & 0x0FU) */
sahilmgandhi 18:6a4db94011d3 624 #define SMARTCARD_BRR(_PCLK_, _BAUD_) (((SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
sahilmgandhi 18:6a4db94011d3 625 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
sahilmgandhi 18:6a4db94011d3 626 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
sahilmgandhi 18:6a4db94011d3 627
sahilmgandhi 18:6a4db94011d3 628 #define SMARTCARD_CR1_REG_INDEX 1U
sahilmgandhi 18:6a4db94011d3 629 #define SMARTCARD_CR3_REG_INDEX 3U
sahilmgandhi 18:6a4db94011d3 630 /**
sahilmgandhi 18:6a4db94011d3 631 * @}
sahilmgandhi 18:6a4db94011d3 632 */
sahilmgandhi 18:6a4db94011d3 633
sahilmgandhi 18:6a4db94011d3 634 /* Private macros --------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 635 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
sahilmgandhi 18:6a4db94011d3 636 * @{
sahilmgandhi 18:6a4db94011d3 637 */
sahilmgandhi 18:6a4db94011d3 638 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B)
sahilmgandhi 18:6a4db94011d3 639 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
sahilmgandhi 18:6a4db94011d3 640 ((STOPBITS) == SMARTCARD_STOPBITS_1_5))
sahilmgandhi 18:6a4db94011d3 641 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \
sahilmgandhi 18:6a4db94011d3 642 ((PARITY) == SMARTCARD_PARITY_ODD))
sahilmgandhi 18:6a4db94011d3 643 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & (uint32_t)0x0000FFF3U) == 0x00U) && ((MODE) != (uint32_t)0x000000U))
sahilmgandhi 18:6a4db94011d3 644 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
sahilmgandhi 18:6a4db94011d3 645 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
sahilmgandhi 18:6a4db94011d3 646 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
sahilmgandhi 18:6a4db94011d3 647 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
sahilmgandhi 18:6a4db94011d3 648 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \
sahilmgandhi 18:6a4db94011d3 649 ((NACK) == SMARTCARD_NACK_DISABLE))
sahilmgandhi 18:6a4db94011d3 650 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
sahilmgandhi 18:6a4db94011d3 651 /**
sahilmgandhi 18:6a4db94011d3 652 * @}
sahilmgandhi 18:6a4db94011d3 653 */
sahilmgandhi 18:6a4db94011d3 654
sahilmgandhi 18:6a4db94011d3 655 /* Private functions ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 656 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
sahilmgandhi 18:6a4db94011d3 657 * @{
sahilmgandhi 18:6a4db94011d3 658 */
sahilmgandhi 18:6a4db94011d3 659
sahilmgandhi 18:6a4db94011d3 660 /**
sahilmgandhi 18:6a4db94011d3 661 * @}
sahilmgandhi 18:6a4db94011d3 662 */
sahilmgandhi 18:6a4db94011d3 663
sahilmgandhi 18:6a4db94011d3 664 /**
sahilmgandhi 18:6a4db94011d3 665 * @}
sahilmgandhi 18:6a4db94011d3 666 */
sahilmgandhi 18:6a4db94011d3 667
sahilmgandhi 18:6a4db94011d3 668 /**
sahilmgandhi 18:6a4db94011d3 669 * @}
sahilmgandhi 18:6a4db94011d3 670 */
sahilmgandhi 18:6a4db94011d3 671 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 672 }
sahilmgandhi 18:6a4db94011d3 673 #endif
sahilmgandhi 18:6a4db94011d3 674
sahilmgandhi 18:6a4db94011d3 675 #endif /* __STM32F2xx_HAL_SMARTCARD_H */
sahilmgandhi 18:6a4db94011d3 676
sahilmgandhi 18:6a4db94011d3 677 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/