]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_pcd_ex.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3 / stm32f3xx_hal_pcd_ex.c
1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_hal_pcd_ex.c
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    12-Sept-2014
7   * @brief   Extended PCD HAL module driver.
8   *          This file provides firmware functions to manage the following 
9   *          functionalities of the USB Peripheral Controller:
10   *           + Configuration of the PMA for EP
11   *         
12   ******************************************************************************
13   * @attention
14   *
15   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
16   *
17   * Redistribution and use in source and binary forms, with or without modification,
18   * are permitted provided that the following conditions are met:
19   *   1. Redistributions of source code must retain the above copyright notice,
20   *      this list of conditions and the following disclaimer.
21   *   2. Redistributions in binary form must reproduce the above copyright notice,
22   *      this list of conditions and the following disclaimer in the documentation
23   *      and/or other materials provided with the distribution.
24   *   3. Neither the name of STMicroelectronics nor the names of its contributors
25   *      may be used to endorse or promote products derived from this software
26   *      without specific prior written permission.
27   *
28   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38   *
39   ******************************************************************************
40   */
41
42 /* Includes ------------------------------------------------------------------*/
43 #include "stm32f3xx_hal.h"
44
45 /** @addtogroup STM32F3xx_HAL_Driver
46   * @{
47   */
48
49 /** @defgroup PCDEx PCD Extended HAL module driver
50   * @brief PCDEx PCDEx Extended HAL module driver
51   * @{
52   */
53
54 #ifdef HAL_PCD_MODULE_ENABLED
55
56 #if defined(STM32F302xE) || defined(STM32F303xE) || \
57     defined(STM32F302xC) || defined(STM32F303xC) || \
58     defined(STM32F302x8)                         || \
59     defined(STM32F373xC)
60
61 /* Private typedef -----------------------------------------------------------*/
62 /* Private define ------------------------------------------------------------*/
63 /* Private macro -------------------------------------------------------------*/
64 /* Private variables ---------------------------------------------------------*/
65 /* Private function prototypes -----------------------------------------------*/
66 /* Exported functions ---------------------------------------------------------*/
67
68 /** @defgroup PCDEx_Exported_Functions PCD Extended Exported Functions
69   * @{
70   */
71
72 /** @defgroup PCDEx_Exported_Functions_Group1 Extended Initialization and de-initialization functions 
73  *  @brief    Initialization and Configuration functions 
74  *
75 @verbatim
76  ===============================================================================
77                  ##### Peripheral extended features methods #####
78  ===============================================================================
79 @endverbatim
80   * @{
81   */
82
83 /**
84   * @brief Configure PMA for EP
85   * @param  hpcd: PCD handle
86   * @param  ep_addr: endpoint address
87   * @param  ep_kind: endpoint Kind
88   *                @arg USB_SNG_BUF: Single Buffer used
89   *                @arg USB_DBL_BUF: Double Buffer used
90   * @param  pmaadress: EP address in The PMA: In case of single buffer endpoint
91   *                   this parameter is 16-bit value providing the address
92   *                   in PMA allocated to endpoint.
93   *                   In case of double buffer endpoint this parameter
94   *                   is a 32-bit value providing the endpoint buffer 0 address
95   *                   in the LSB part of 32-bit value and endpoint buffer 1 address
96   *                   in the MSB part of 32-bit value.
97   * @retval : status
98   */
99
100 HAL_StatusTypeDef  HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 
101                         uint16_t ep_addr,
102                         uint16_t ep_kind,
103                         uint32_t pmaadress)
104
105 {
106   PCD_EPTypeDef *ep;
107   
108   /* initialize ep structure*/
109   if ((0x80 & ep_addr) == 0x80)
110   {
111     ep = &hpcd->IN_ep[ep_addr & 0x7F];
112   }
113   else
114   {
115     ep = &hpcd->OUT_ep[ep_addr];
116   }
117   
118   /* Here we check if the endpoint is single or double Buffer*/
119   if (ep_kind == PCD_SNG_BUF)
120   {
121     /*Single Buffer*/
122     ep->doublebuffer = 0;
123     /*Configure te PMA*/
124     ep->pmaadress = (uint16_t)pmaadress;
125   }
126   else /*USB_DBL_BUF*/
127   {
128     /*Double Buffer Endpoint*/
129     ep->doublebuffer = 1;
130     /*Configure the PMA*/
131     ep->pmaaddr0 =  pmaadress & 0xFFFF;
132     ep->pmaaddr1 =  (pmaadress & 0xFFFF0000) >> 16;
133   }
134   
135   return HAL_OK; 
136 }
137 /**
138   * @}
139   */ 
140
141 /**
142   * @}
143   */ 
144
145 /** @defgroup PCDEx_Private_Functions PCD Extended Private Functions
146   * @{
147   */
148 #if defined(STM32F303xC)                         || \
149     defined(STM32F303x8) || defined(STM32F334x8) || \
150     defined(STM32F301x8)                         || \
151     defined(STM32F373xC) || defined(STM32F378xx)
152       
153      
154 /**
155   * @brief Copy a buffer from user memory area to packet memory area (PMA)
156   * @param   USBx: USB peripheral instance register address.
157   * @param   pbUsrBuf: pointer to user memory area.
158   * @param   wPMABufAddr: address into PMA.
159   * @param   wNBytes: no. of bytes to be copied.
160   * @retval None
161   */
162 void PCD_WritePMA(USB_TypeDef  *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
163 {
164   uint32_t n = (wNBytes + 1) >> 1;   /* n = (wNBytes + 1) / 2 */
165   uint32_t i, temp1, temp2;
166   uint16_t *pdwVal;
167   pdwVal = (uint16_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400);
168   for (i = n; i != 0; i--)
169   {
170     temp1 = (uint16_t) * pbUsrBuf;
171     pbUsrBuf++;
172     temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
173     *pdwVal++ = temp2;
174     pdwVal++;
175     pbUsrBuf++;
176   }
177 }
178
179 /**
180   * @brief Copy a buffer from user memory area to packet memory area (PMA)
181   * @param   USBx: USB peripheral instance register address.
182   * @param   pbUsrBuf: pointer to user memory area.
183   * @param   wPMABufAddr: address into PMA.
184   * @param   wNBytes: no. of bytes to be copied.
185   * @retval None
186   */
187 void PCD_ReadPMA(USB_TypeDef  *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
188 {
189   uint32_t n = (wNBytes + 1) >> 1;/* /2*/
190   uint32_t i;
191   uint32_t *pdwVal;
192   pdwVal = (uint32_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400);
193   for (i = n; i != 0; i--)
194   {
195     *(uint16_t*)pbUsrBuf++ = *pdwVal++;
196     pbUsrBuf++;
197   }
198 }
199 #endif /* STM32F303xC                || */
200        /* STM32F303x8 || STM32F334x8 || */
201        /* STM32F301x8                || */
202        /* STM32F373xC || STM32F378xx    */
203
204 #if defined(STM32F302xE) || defined(STM32F303xE) || \
205     defined(STM32F302xC)                         || \
206     defined(STM32F302x8) 
207 /**
208   * @brief Copy a buffer from user memory area to packet memory area (PMA)
209   * @param   USBx: USB peripheral instance register address.
210   * @param   pbUsrBuf: pointer to user memory area.
211   * @param   wPMABufAddr: address into PMA.
212   * @param   wNBytes: no. of bytes to be copied.
213   * @retval None
214   */
215 void PCD_WritePMA(USB_TypeDef  *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
216 {
217   uint32_t n = (wNBytes + 1) >> 1; 
218   uint32_t i;
219   uint16_t temp1, temp2;
220   uint16_t *pdwVal;
221   pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
222   
223   for (i = n; i != 0; i--)
224   {
225     temp1 = (uint16_t) * pbUsrBuf;
226     pbUsrBuf++;
227     temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
228     *pdwVal++ = temp2;
229     pbUsrBuf++;
230   }
231 }
232
233 /**
234   * @brief Copy a buffer from user memory area to packet memory area (PMA)
235   * @param   USBx: USB peripheral instance register address.
236   * @param   pbUsrBuf: pointer to user memory area.
237   * @param   wPMABufAddr: address into PMA.
238   * @param   wNBytes: no. of bytes to be copied.
239   * @retval None
240   */
241 void PCD_ReadPMA(USB_TypeDef  *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
242 {
243   uint32_t n = (wNBytes + 1) >> 1;
244   uint32_t i;
245   uint16_t *pdwVal;
246   pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
247   for (i = n; i != 0; i--)
248   {
249     *(uint16_t*)pbUsrBuf++ = *pdwVal++;
250     pbUsrBuf++;
251   }
252 }
253 #endif /* STM32F302xE || STM32F303xE || */
254        /* STM32F302xC                || */
255        /* STM32F302x8                   */
256
257 /**
258   * @}
259   */ 
260
261 /** @addtogroup PCDEx_Exported_Functions PCD Extended Exported Functions
262   * @{
263   */
264
265 /** @addtogroup PCDEx_Exported_Functions_Group1 Extended Initialization and de-initialization functions 
266   * @{
267   */
268 /**
269   * @brief  Software Device Connection
270   * @param  hpcd: PCD handle
271   * @param  state: Device state
272   * @retval None
273   */
274  __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
275 {
276   /* NOTE : This function Should not be modified, when the callback is needed,
277             the HAL_PCDEx_SetConnectionState could be implenetd in the user file
278    */ 
279 }
280 /**
281   * @}
282   */ 
283
284 /**
285   * @}
286   */
287 #endif /* STM32F302xE || STM32F303xE || */
288        /* STM32F302xC || STM32F303xC || */
289        /* STM32F302x8                || */
290        /* STM32F373xC                   */
291
292 #endif /* HAL_PCD_MODULE_ENABLED */
293 /**
294   * @}
295   */
296
297 /**
298   * @}
299   */
300
301 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/