]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_smartcard_ex.c
Merge pull request #24 from marknsikora/master
[max/tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F0 / stm32f0xx_hal_smartcard_ex.c
1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_hal_smartcard_ex.c
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    11-December-2014
7   * @brief   SMARTCARD HAL module driver.
8   *
9   *          This file provides extended firmware functions to manage the following 
10   *          functionalities of the SmartCard.
11   *           + Initialization and de-initialization function
12   *           + Peripheral Control function
13   *
14   *           
15   @verbatim       
16  ===============================================================================
17                         ##### How to use this driver #####
18  ===============================================================================
19     [..]
20     The Extended SMARTCARD HAL driver can be used as follows:
21
22
23     (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(), 
24         then if required, program SMARTCARD advanced features (TX/RX pins swap, TimeOut, 
25         auto-retry counter,...) in the hsmartcard AdvancedInit structure.
26
27
28
29   @endverbatim
30   ******************************************************************************
31   * @attention
32   *
33   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
34   *
35   * Redistribution and use in source and binary forms, with or without modification,
36   * are permitted provided that the following conditions are met:
37   *   1. Redistributions of source code must retain the above copyright notice,
38   *      this list of conditions and the following disclaimer.
39   *   2. Redistributions in binary form must reproduce the above copyright notice,
40   *      this list of conditions and the following disclaimer in the documentation
41   *      and/or other materials provided with the distribution.
42   *   3. Neither the name of STMicroelectronics nor the names of its contributors
43   *      may be used to endorse or promote products derived from this software
44   *      without specific prior written permission.
45   *
46   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
50   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56   *
57   ******************************************************************************  
58   */
59
60 /* Includes ------------------------------------------------------------------*/
61 #include "stm32f0xx_hal.h"
62
63 #ifdef HAL_SMARTCARD_MODULE_ENABLED
64
65 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)  
66
67 /** @addtogroup STM32F0xx_HAL_Driver
68   * @{
69   */
70
71 /** @defgroup SMARTCARDEx SMARTCARD Extended HAL module driver
72   * @brief SMARTCARD Extended HAL module driver
73   * @{
74   */
75
76 /* Private typedef -----------------------------------------------------------*/
77 /* Private define ------------------------------------------------------------*/
78 /* Private macro -------------------------------------------------------------*/
79 /* Private variables ---------------------------------------------------------*/
80 /* Private function prototypes -----------------------------------------------*/
81 /* Exported functions ---------------------------------------------------------*/
82
83 /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARDEx Exported Functions
84   * @{
85   */
86
87 /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
88   * @brief    Extended control functions
89   *
90 @verbatim   
91  ===============================================================================
92                       ##### Peripheral Control functions #####
93  ===============================================================================  
94     [..]
95     This subsection provides a set of functions allowing to initialize the SMARTCARD.
96      (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly 
97      (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly  
98      (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
99      (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature                      
100                
101 @endverbatim
102   * @{
103   */
104
105 /**
106   * @brief Update on the fly the SMARTCARD block length in RTOR register
107   * @param hsmartcard: SMARTCARD handle
108   * @param BlockLength: SMARTCARD block length (8-bit long at most)  
109   * @retval None
110   */
111 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
112 {
113   MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
114 }
115
116 /**
117   * @brief Update on the fly the receiver timeout value in RTOR register
118   * @param hsmartcard: SMARTCARD handle
119   * @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout
120   *                     value must be less or equal to 0x0FFFFFFFF. 
121   * @retval None
122   */
123 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
124 {
125   assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
126   MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue); 
127 }
128
129 /**
130   * @brief Enable the SMARTCARD receiver timeout feature
131   * @param hsmartcard: SMARTCARD handle
132   * @retval HAL status
133   */
134 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
135 {
136  
137   /* Process Locked */
138   __HAL_LOCK(hsmartcard);
139   
140   hsmartcard->State = HAL_SMARTCARD_STATE_BUSY;
141   
142   /* Set the USART RTOEN bit */
143   hsmartcard->Instance->CR2 |= USART_CR2_RTOEN;
144   
145   hsmartcard->State = HAL_SMARTCARD_STATE_READY;
146   
147   /* Process Unlocked */
148   __HAL_UNLOCK(hsmartcard);
149   
150   return HAL_OK;   
151 }
152
153 /**
154   * @brief Disable the SMARTCARD receiver timeout feature
155   * @param hsmartcard: SMARTCARD handle
156   * @retval HAL status
157   */
158 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
159 {
160  
161   /* Process Locked */
162   __HAL_LOCK(hsmartcard);
163   
164   hsmartcard->State = HAL_SMARTCARD_STATE_BUSY;
165   
166   /* Clear the USART RTOEN bit */
167   hsmartcard->Instance->CR2 &= ~(USART_CR2_RTOEN);
168   
169   hsmartcard->State = HAL_SMARTCARD_STATE_READY;
170   
171   /* Process Unlocked */
172   __HAL_UNLOCK(hsmartcard);
173   
174   return HAL_OK;   
175 }
176
177 /**
178   * @}
179   */
180
181 /**
182   * @}
183   */
184
185 /**
186   * @}
187   */
188
189 /**
190   * @}
191   */
192
193 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)  */  
194
195 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
196
197 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/