mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
237:f3da66175598
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 237:f3da66175598 1 /**
mbed_official 237:f3da66175598 2 ******************************************************************************
mbed_official 237:f3da66175598 3 * @file stm32f3xx_hal_pcd.h
mbed_official 237:f3da66175598 4 * @author MCD Application Team
mbed_official 237:f3da66175598 5 * @version V1.0.1
mbed_official 237:f3da66175598 6 * @date 18-June-2014
mbed_official 237:f3da66175598 7 * @brief Header file of PCD HAL module.
mbed_official 237:f3da66175598 8 ******************************************************************************
mbed_official 237:f3da66175598 9 * @attention
mbed_official 237:f3da66175598 10 *
mbed_official 237:f3da66175598 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 237:f3da66175598 12 *
mbed_official 237:f3da66175598 13 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 237:f3da66175598 14 * are permitted provided that the following conditions are met:
mbed_official 237:f3da66175598 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 237:f3da66175598 16 * this list of conditions and the following disclaimer.
mbed_official 237:f3da66175598 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 237:f3da66175598 18 * this list of conditions and the following disclaimer in the documentation
mbed_official 237:f3da66175598 19 * and/or other materials provided with the distribution.
mbed_official 237:f3da66175598 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 237:f3da66175598 21 * may be used to endorse or promote products derived from this software
mbed_official 237:f3da66175598 22 * without specific prior written permission.
mbed_official 237:f3da66175598 23 *
mbed_official 237:f3da66175598 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 237:f3da66175598 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 237:f3da66175598 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 237:f3da66175598 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 237:f3da66175598 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 237:f3da66175598 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 237:f3da66175598 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 237:f3da66175598 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 237:f3da66175598 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 237:f3da66175598 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 237:f3da66175598 34 *
mbed_official 237:f3da66175598 35 ******************************************************************************
mbed_official 237:f3da66175598 36 */
mbed_official 237:f3da66175598 37
mbed_official 237:f3da66175598 38 /* Define to prevent recursive inclusion -------------------------------------*/
mbed_official 237:f3da66175598 39 #ifndef __STM32F3xx_HAL_PCD_H
mbed_official 237:f3da66175598 40 #define __STM32F3xx_HAL_PCD_H
mbed_official 237:f3da66175598 41
mbed_official 237:f3da66175598 42 #ifdef __cplusplus
mbed_official 237:f3da66175598 43 extern "C" {
mbed_official 237:f3da66175598 44 #endif
mbed_official 237:f3da66175598 45
mbed_official 237:f3da66175598 46 #if defined(STM32F302x8) || defined(STM32F302xC) || \
mbed_official 237:f3da66175598 47 defined(STM32F303xC) || defined(STM32F373xC)
mbed_official 237:f3da66175598 48
mbed_official 237:f3da66175598 49 /* Includes ------------------------------------------------------------------*/
mbed_official 237:f3da66175598 50 #include "stm32f3xx_hal_def.h"
mbed_official 237:f3da66175598 51
mbed_official 237:f3da66175598 52 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 237:f3da66175598 53 * @{
mbed_official 237:f3da66175598 54 */
mbed_official 237:f3da66175598 55
mbed_official 237:f3da66175598 56 /** @addtogroup PCD
mbed_official 237:f3da66175598 57 * @{
mbed_official 237:f3da66175598 58 */
mbed_official 237:f3da66175598 59
mbed_official 237:f3da66175598 60 /* Exported types ------------------------------------------------------------*/
mbed_official 237:f3da66175598 61
mbed_official 237:f3da66175598 62 /**
mbed_official 237:f3da66175598 63 * @brief PCD State structures definition
mbed_official 237:f3da66175598 64 */
mbed_official 237:f3da66175598 65 typedef enum
mbed_official 237:f3da66175598 66 {
mbed_official 237:f3da66175598 67 PCD_READY = 0x00,
mbed_official 237:f3da66175598 68 PCD_ERROR = 0x01,
mbed_official 237:f3da66175598 69 PCD_BUSY = 0x02,
mbed_official 237:f3da66175598 70 PCD_TIMEOUT = 0x03
mbed_official 237:f3da66175598 71 } PCD_StateTypeDef;
mbed_official 237:f3da66175598 72
mbed_official 237:f3da66175598 73 typedef enum
mbed_official 237:f3da66175598 74 {
mbed_official 237:f3da66175598 75 /* double buffered endpoint direction */
mbed_official 237:f3da66175598 76 PCD_EP_DBUF_OUT,
mbed_official 237:f3da66175598 77 PCD_EP_DBUF_IN,
mbed_official 237:f3da66175598 78 PCD_EP_DBUF_ERR,
mbed_official 237:f3da66175598 79 }PCD_EP_DBUF_DIR;
mbed_official 237:f3da66175598 80
mbed_official 237:f3da66175598 81 /* endpoint buffer number */
mbed_official 237:f3da66175598 82 typedef enum
mbed_official 237:f3da66175598 83 {
mbed_official 237:f3da66175598 84 PCD_EP_NOBUF,
mbed_official 237:f3da66175598 85 PCD_EP_BUF0,
mbed_official 237:f3da66175598 86 PCD_EP_BUF1
mbed_official 237:f3da66175598 87 }PCD_EP_BUF_NUM;
mbed_official 237:f3da66175598 88
mbed_official 237:f3da66175598 89 /**
mbed_official 237:f3da66175598 90 * @brief PCD Initialization Structure definition
mbed_official 237:f3da66175598 91 */
mbed_official 237:f3da66175598 92 typedef struct
mbed_official 237:f3da66175598 93 {
mbed_official 237:f3da66175598 94 uint32_t dev_endpoints; /*!< Device Endpoints number.
mbed_official 237:f3da66175598 95 This parameter depends on the used USB core.
mbed_official 237:f3da66175598 96 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
mbed_official 237:f3da66175598 97
mbed_official 237:f3da66175598 98 uint32_t speed; /*!< USB Core speed.
mbed_official 237:f3da66175598 99 This parameter can be any value of @ref USB_Core_Speed */
mbed_official 237:f3da66175598 100
mbed_official 237:f3da66175598 101 uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size.
mbed_official 237:f3da66175598 102 This parameter can be any value of @ref USB_EP0_MPS */
mbed_official 237:f3da66175598 103
mbed_official 237:f3da66175598 104 uint32_t phy_itface; /*!< Select the used PHY interface.
mbed_official 237:f3da66175598 105 This parameter can be any value of @ref USB_Core_PHY */
mbed_official 237:f3da66175598 106
mbed_official 237:f3da66175598 107 uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */
mbed_official 237:f3da66175598 108
mbed_official 237:f3da66175598 109 uint32_t low_power_enable; /*!< Enable or disable Low Power mode */
mbed_official 237:f3da66175598 110
mbed_official 237:f3da66175598 111 uint32_t lpm_enable; /*!< Enable or disable Battery charging. */
mbed_official 237:f3da66175598 112
mbed_official 237:f3da66175598 113 uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */
mbed_official 237:f3da66175598 114
mbed_official 237:f3da66175598 115 }PCD_InitTypeDef;
mbed_official 237:f3da66175598 116
mbed_official 237:f3da66175598 117 typedef struct
mbed_official 237:f3da66175598 118 {
mbed_official 237:f3da66175598 119 uint8_t num; /*!< Endpoint number
mbed_official 237:f3da66175598 120 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
mbed_official 237:f3da66175598 121
mbed_official 237:f3da66175598 122 uint8_t is_in; /*!< Endpoint direction
mbed_official 237:f3da66175598 123 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
mbed_official 237:f3da66175598 124
mbed_official 237:f3da66175598 125 uint8_t is_stall; /*!< Endpoint stall condition
mbed_official 237:f3da66175598 126 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
mbed_official 237:f3da66175598 127
mbed_official 237:f3da66175598 128 uint8_t type; /*!< Endpoint type
mbed_official 237:f3da66175598 129 This parameter can be any value of @ref USB_EP_Type */
mbed_official 237:f3da66175598 130
mbed_official 237:f3da66175598 131 uint16_t pmaadress; /*!< PMA Address
mbed_official 237:f3da66175598 132 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
mbed_official 237:f3da66175598 133
mbed_official 237:f3da66175598 134
mbed_official 237:f3da66175598 135 uint16_t pmaaddr0; /*!< PMA Address0
mbed_official 237:f3da66175598 136 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
mbed_official 237:f3da66175598 137
mbed_official 237:f3da66175598 138
mbed_official 237:f3da66175598 139 uint16_t pmaaddr1; /*!< PMA Address1
mbed_official 237:f3da66175598 140 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
mbed_official 237:f3da66175598 141
mbed_official 237:f3da66175598 142
mbed_official 237:f3da66175598 143 uint8_t doublebuffer; /*!< Double buffer enable
mbed_official 237:f3da66175598 144 This parameter can be 0 or 1 */
mbed_official 237:f3da66175598 145
mbed_official 237:f3da66175598 146 uint32_t maxpacket; /*!< Endpoint Max packet size
mbed_official 237:f3da66175598 147 This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
mbed_official 237:f3da66175598 148
mbed_official 237:f3da66175598 149 uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
mbed_official 237:f3da66175598 150
mbed_official 237:f3da66175598 151
mbed_official 237:f3da66175598 152 uint32_t xfer_len; /*!< Current transfer length */
mbed_official 237:f3da66175598 153
mbed_official 237:f3da66175598 154 uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
mbed_official 237:f3da66175598 155
mbed_official 237:f3da66175598 156 }PCD_EPTypeDef;
mbed_official 237:f3da66175598 157
mbed_official 237:f3da66175598 158 typedef USB_TypeDef PCD_TypeDef;
mbed_official 237:f3da66175598 159
mbed_official 237:f3da66175598 160 /**
mbed_official 237:f3da66175598 161 * @brief PCD Handle Structure definition
mbed_official 237:f3da66175598 162 */
mbed_official 237:f3da66175598 163 typedef struct
mbed_official 237:f3da66175598 164 {
mbed_official 237:f3da66175598 165 PCD_TypeDef *Instance; /*!< Register base address */
mbed_official 237:f3da66175598 166 PCD_InitTypeDef Init; /*!< PCD required parameters */
mbed_official 237:f3da66175598 167 __IO uint8_t USB_Address; /*!< USB Address */
mbed_official 237:f3da66175598 168 PCD_EPTypeDef IN_ep[5]; /*!< IN endpoint parameters */
mbed_official 237:f3da66175598 169 PCD_EPTypeDef OUT_ep[5]; /*!< OUT endpoint parameters */
mbed_official 237:f3da66175598 170 HAL_LockTypeDef Lock; /*!< PCD peripheral status */
mbed_official 237:f3da66175598 171 __IO PCD_StateTypeDef State; /*!< PCD communication state */
mbed_official 237:f3da66175598 172 uint32_t Setup[12]; /*!< Setup packet buffer */
mbed_official 237:f3da66175598 173 void *pData; /*!< Pointer to upper stack Handler */
mbed_official 237:f3da66175598 174
mbed_official 237:f3da66175598 175 } PCD_HandleTypeDef;
mbed_official 237:f3da66175598 176
mbed_official 237:f3da66175598 177 #include "stm32f3xx_hal_pcd_ex.h"
mbed_official 237:f3da66175598 178 /* Exported constants --------------------------------------------------------*/
mbed_official 237:f3da66175598 179 /** @defgroup PCD_Exported_Constants
mbed_official 237:f3da66175598 180 * @{
mbed_official 237:f3da66175598 181 */
mbed_official 237:f3da66175598 182
mbed_official 237:f3da66175598 183 /** @defgroup USB_Core_Speed
mbed_official 237:f3da66175598 184 * @{
mbed_official 237:f3da66175598 185 */
mbed_official 237:f3da66175598 186 #define PCD_SPEED_HIGH 0 /* Not Supported */
mbed_official 237:f3da66175598 187 #define PCD_SPEED_FULL 2
mbed_official 237:f3da66175598 188 /**
mbed_official 237:f3da66175598 189 * @}
mbed_official 237:f3da66175598 190 */
mbed_official 237:f3da66175598 191
mbed_official 237:f3da66175598 192 /** @defgroup USB_Core_PHY
mbed_official 237:f3da66175598 193 * @{
mbed_official 237:f3da66175598 194 */
mbed_official 237:f3da66175598 195 #define PCD_PHY_EMBEDDED 2
mbed_official 237:f3da66175598 196 /**
mbed_official 237:f3da66175598 197 * @}
mbed_official 237:f3da66175598 198 */
mbed_official 237:f3da66175598 199
mbed_official 237:f3da66175598 200 /** @defgroup USB_EP0_MPS
mbed_official 237:f3da66175598 201 * @{
mbed_official 237:f3da66175598 202 */
mbed_official 237:f3da66175598 203 #define DEP0CTL_MPS_64 0
mbed_official 237:f3da66175598 204 #define DEP0CTL_MPS_32 1
mbed_official 237:f3da66175598 205 #define DEP0CTL_MPS_16 2
mbed_official 237:f3da66175598 206 #define DEP0CTL_MPS_8 3
mbed_official 237:f3da66175598 207
mbed_official 237:f3da66175598 208 #define PCD_EP0MPS_64 DEP0CTL_MPS_64
mbed_official 237:f3da66175598 209 #define PCD_EP0MPS_32 DEP0CTL_MPS_32
mbed_official 237:f3da66175598 210 #define PCD_EP0MPS_16 DEP0CTL_MPS_16
mbed_official 237:f3da66175598 211 #define PCD_EP0MPS_08 DEP0CTL_MPS_8
mbed_official 237:f3da66175598 212 /**
mbed_official 237:f3da66175598 213 * @}
mbed_official 237:f3da66175598 214 */
mbed_official 237:f3da66175598 215
mbed_official 237:f3da66175598 216 /** @defgroup USB_EP_Type
mbed_official 237:f3da66175598 217 * @{
mbed_official 237:f3da66175598 218 */
mbed_official 237:f3da66175598 219 #define PCD_EP_TYPE_CTRL 0
mbed_official 237:f3da66175598 220 #define PCD_EP_TYPE_ISOC 1
mbed_official 237:f3da66175598 221 #define PCD_EP_TYPE_BULK 2
mbed_official 237:f3da66175598 222 #define PCD_EP_TYPE_INTR 3
mbed_official 237:f3da66175598 223 /**
mbed_official 237:f3da66175598 224 * @}
mbed_official 237:f3da66175598 225 */
mbed_official 237:f3da66175598 226
mbed_official 237:f3da66175598 227 #define PCD_ENDP0 ((uint8_t)0)
mbed_official 237:f3da66175598 228 #define PCD_ENDP1 ((uint8_t)1)
mbed_official 237:f3da66175598 229 #define PCD_ENDP2 ((uint8_t)2)
mbed_official 237:f3da66175598 230 #define PCD_ENDP3 ((uint8_t)3)
mbed_official 237:f3da66175598 231 #define PCD_ENDP4 ((uint8_t)4)
mbed_official 237:f3da66175598 232 #define PCD_ENDP5 ((uint8_t)5)
mbed_official 237:f3da66175598 233 #define PCD_ENDP6 ((uint8_t)6)
mbed_official 237:f3da66175598 234 #define PCD_ENDP7 ((uint8_t)7)
mbed_official 237:f3da66175598 235
mbed_official 237:f3da66175598 236 /* Endpoint Kind */
mbed_official 237:f3da66175598 237 #define PCD_SNG_BUF 0
mbed_official 237:f3da66175598 238 #define PCD_DBL_BUF 1
mbed_official 237:f3da66175598 239
mbed_official 237:f3da66175598 240 #define IS_PCD_ALL_INSTANCE IS_USB_ALL_INSTANCE
mbed_official 237:f3da66175598 241
mbed_official 237:f3da66175598 242 /**
mbed_official 237:f3da66175598 243 * @}
mbed_official 237:f3da66175598 244 */
mbed_official 237:f3da66175598 245
mbed_official 237:f3da66175598 246 /* Exported macros -----------------------------------------------------------*/
mbed_official 237:f3da66175598 247
mbed_official 237:f3da66175598 248 /** @defgroup PCD_Interrupt_Clock
mbed_official 237:f3da66175598 249 * @brief macros to handle interrupts and specific clock configurations
mbed_official 237:f3da66175598 250 * @{
mbed_official 237:f3da66175598 251 */
mbed_official 237:f3da66175598 252 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISTR) & (__INTERRUPT__)) == (__INTERRUPT__))
mbed_official 237:f3da66175598 253 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->ISTR) = ~(__INTERRUPT__))
mbed_official 237:f3da66175598 254
mbed_official 237:f3da66175598 255 #define USB_EXTI_LINE_WAKEUP ((uint32_t)0x00040000) /*!< External interrupt line 18 Connected to the USB FS EXTI Line */
mbed_official 237:f3da66175598 256
mbed_official 237:f3da66175598 257 #define __HAL_USB_EXTI_ENABLE_IT() EXTI->IMR |= USB_EXTI_LINE_WAKEUP
mbed_official 237:f3da66175598 258 #define __HAL_USB_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_EXTI_LINE_WAKEUP)
mbed_official 237:f3da66175598 259 #define __HAL_USB_EXTI_GENERATE_SWIT(__EXTILINE__) (EXTI->SWIER |= (__EXTILINE__))
mbed_official 237:f3da66175598 260
mbed_official 237:f3da66175598 261 /* Internal macros -----------------------------------------------------------*/
mbed_official 237:f3da66175598 262
mbed_official 237:f3da66175598 263 /* SetENDPOINT */
mbed_official 237:f3da66175598 264 #define PCD_SET_ENDPOINT(USBx, bEpNum,wRegValue) (*(&USBx->EP0R + bEpNum * 2)= (uint16_t)wRegValue)
mbed_official 237:f3da66175598 265
mbed_official 237:f3da66175598 266 /* GetENDPOINT */
mbed_official 237:f3da66175598 267 #define PCD_GET_ENDPOINT(USBx, bEpNum) (*(&USBx->EP0R + bEpNum * 2))
mbed_official 237:f3da66175598 268
mbed_official 237:f3da66175598 269
mbed_official 237:f3da66175598 270
mbed_official 237:f3da66175598 271 /**
mbed_official 237:f3da66175598 272 * @brief sets the type in the endpoint register(bits EP_TYPE[1:0])
mbed_official 237:f3da66175598 273 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 274 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 275 * @param wType: Endpoint Type.
mbed_official 237:f3da66175598 276 * @retval None
mbed_official 237:f3da66175598 277 */
mbed_official 237:f3da66175598 278 #define PCD_SET_EPTYPE(USBx, bEpNum,wType) (PCD_SET_ENDPOINT(USBx, bEpNum,\
mbed_official 237:f3da66175598 279 ((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_T_MASK) | wType )))
mbed_official 237:f3da66175598 280
mbed_official 237:f3da66175598 281 /**
mbed_official 237:f3da66175598 282 * @brief gets the type in the endpoint register(bits EP_TYPE[1:0])
mbed_official 237:f3da66175598 283 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 284 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 285 * @retval Endpoint Type
mbed_official 237:f3da66175598 286 */
mbed_official 237:f3da66175598 287 #define PCD_GET_EPTYPE(USBx, bEpNum) (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_T_FIELD)
mbed_official 237:f3da66175598 288
mbed_official 237:f3da66175598 289
mbed_official 237:f3da66175598 290 /**
mbed_official 237:f3da66175598 291 * @brief free buffer used from the application realizing it to the line
mbed_official 237:f3da66175598 292 toggles bit SW_BUF in the double buffered endpoint register
mbed_official 237:f3da66175598 293 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 294 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 295 * @param bDir: Direction
mbed_official 237:f3da66175598 296 * @retval None
mbed_official 237:f3da66175598 297 */
mbed_official 237:f3da66175598 298 #define PCD_FreeUserBuffer(USBx, bEpNum, bDir)\
mbed_official 237:f3da66175598 299 {\
mbed_official 237:f3da66175598 300 if (bDir == PCD_EP_DBUF_OUT)\
mbed_official 237:f3da66175598 301 { /* OUT double buffered endpoint */\
mbed_official 237:f3da66175598 302 PCD_TX_DTOG(USBx, bEpNum);\
mbed_official 237:f3da66175598 303 }\
mbed_official 237:f3da66175598 304 else if (bDir == PCD_EP_DBUF_IN)\
mbed_official 237:f3da66175598 305 { /* IN double buffered endpoint */\
mbed_official 237:f3da66175598 306 PCD_RX_DTOG(USBx, bEpNum);\
mbed_official 237:f3da66175598 307 }\
mbed_official 237:f3da66175598 308 }
mbed_official 237:f3da66175598 309
mbed_official 237:f3da66175598 310 /**
mbed_official 237:f3da66175598 311 * @brief gets direction of the double buffered endpoint
mbed_official 237:f3da66175598 312 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 313 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 314 * @retval EP_DBUF_OUT, EP_DBUF_IN,
mbed_official 237:f3da66175598 315 * EP_DBUF_ERR if the endpoint counter not yet programmed.
mbed_official 237:f3da66175598 316 */
mbed_official 237:f3da66175598 317 #define PCD_GET_DB_DIR(USBx, bEpNum)\
mbed_official 237:f3da66175598 318 {\
mbed_official 237:f3da66175598 319 if ((uint16_t)(*PCD_EP_RX_CNT(USBx, bEpNum) & 0xFC00) != 0)\
mbed_official 237:f3da66175598 320 return(PCD_EP_DBUF_OUT);\
mbed_official 237:f3da66175598 321 else if (((uint16_t)(*PCD_EP_TX_CNT(USBx, bEpNum)) & 0x03FF) != 0)\
mbed_official 237:f3da66175598 322 return(PCD_EP_DBUF_IN);\
mbed_official 237:f3da66175598 323 else\
mbed_official 237:f3da66175598 324 return(PCD_EP_DBUF_ERR);\
mbed_official 237:f3da66175598 325 }
mbed_official 237:f3da66175598 326
mbed_official 237:f3da66175598 327 /**
mbed_official 237:f3da66175598 328 * @brief sets the status for tx transfer (bits STAT_TX[1:0]).
mbed_official 237:f3da66175598 329 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 330 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 331 * @param wState: new state
mbed_official 237:f3da66175598 332 * @retval None
mbed_official 237:f3da66175598 333 */
mbed_official 237:f3da66175598 334 #define PCD_SET_EP_TX_STATUS(USBx, bEpNum, wState) {\
mbed_official 237:f3da66175598 335 register uint16_t _wRegVal; \
mbed_official 237:f3da66175598 336 \
mbed_official 237:f3da66175598 337 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPTX_DTOGMASK;\
mbed_official 237:f3da66175598 338 /* toggle first bit ? */ \
mbed_official 237:f3da66175598 339 if((USB_EPTX_DTOG1 & wState)!= 0) \
mbed_official 237:f3da66175598 340 _wRegVal ^= USB_EPTX_DTOG1; \
mbed_official 237:f3da66175598 341 /* toggle second bit ? */ \
mbed_official 237:f3da66175598 342 if((USB_EPTX_DTOG2 & wState)!= 0) \
mbed_official 237:f3da66175598 343 _wRegVal ^= USB_EPTX_DTOG2; \
mbed_official 237:f3da66175598 344 PCD_SET_ENDPOINT(USBx, bEpNum, (_wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX)); \
mbed_official 237:f3da66175598 345 } /* PCD_SET_EP_TX_STATUS */
mbed_official 237:f3da66175598 346
mbed_official 237:f3da66175598 347 /**
mbed_official 237:f3da66175598 348 * @brief sets the status for rx transfer (bits STAT_TX[1:0])
mbed_official 237:f3da66175598 349 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 350 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 351 * @param wState: new state
mbed_official 237:f3da66175598 352 * @retval None
mbed_official 237:f3da66175598 353 */
mbed_official 237:f3da66175598 354 #define PCD_SET_EP_RX_STATUS(USBx, bEpNum,wState) {\
mbed_official 237:f3da66175598 355 register uint16_t _wRegVal; \
mbed_official 237:f3da66175598 356 \
mbed_official 237:f3da66175598 357 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPRX_DTOGMASK;\
mbed_official 237:f3da66175598 358 /* toggle first bit ? */ \
mbed_official 237:f3da66175598 359 if((USB_EPRX_DTOG1 & wState)!= 0) \
mbed_official 237:f3da66175598 360 _wRegVal ^= USB_EPRX_DTOG1; \
mbed_official 237:f3da66175598 361 /* toggle second bit ? */ \
mbed_official 237:f3da66175598 362 if((USB_EPRX_DTOG2 & wState)!= 0) \
mbed_official 237:f3da66175598 363 _wRegVal ^= USB_EPRX_DTOG2; \
mbed_official 237:f3da66175598 364 PCD_SET_ENDPOINT(USBx, bEpNum, (_wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX)); \
mbed_official 237:f3da66175598 365 } /* PCD_SET_EP_RX_STATUS */
mbed_official 237:f3da66175598 366
mbed_official 237:f3da66175598 367 /**
mbed_official 237:f3da66175598 368 * @brief sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0])
mbed_official 237:f3da66175598 369 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 370 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 371 * @param wStaterx: new state.
mbed_official 237:f3da66175598 372 * @param wStatetx: new state.
mbed_official 237:f3da66175598 373 * @retval None
mbed_official 237:f3da66175598 374 */
mbed_official 237:f3da66175598 375 #define PCD_SET_EP_TXRX_STATUS(USBx,bEpNum,wStaterx,wStatetx) {\
mbed_official 237:f3da66175598 376 register uint32_t _wRegVal; \
mbed_official 237:f3da66175598 377 \
mbed_official 237:f3da66175598 378 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & (USB_EPRX_DTOGMASK |USB_EPTX_STAT) ;\
mbed_official 237:f3da66175598 379 /* toggle first bit ? */ \
mbed_official 237:f3da66175598 380 if((USB_EPRX_DTOG1 & wStaterx)!= 0) \
mbed_official 237:f3da66175598 381 _wRegVal ^= USB_EPRX_DTOG1; \
mbed_official 237:f3da66175598 382 /* toggle second bit ? */ \
mbed_official 237:f3da66175598 383 if((USB_EPRX_DTOG2 & wStaterx)!= 0) \
mbed_official 237:f3da66175598 384 _wRegVal ^= USB_EPRX_DTOG2; \
mbed_official 237:f3da66175598 385 /* toggle first bit ? */ \
mbed_official 237:f3da66175598 386 if((USB_EPTX_DTOG1 & wStatetx)!= 0) \
mbed_official 237:f3da66175598 387 _wRegVal ^= USB_EPTX_DTOG1; \
mbed_official 237:f3da66175598 388 /* toggle second bit ? */ \
mbed_official 237:f3da66175598 389 if((USB_EPTX_DTOG2 & wStatetx)!= 0) \
mbed_official 237:f3da66175598 390 _wRegVal ^= USB_EPTX_DTOG2; \
mbed_official 237:f3da66175598 391 PCD_SET_ENDPOINT(USBx, bEpNum, _wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX); \
mbed_official 237:f3da66175598 392 } /* PCD_SET_EP_TXRX_STATUS */
mbed_official 237:f3da66175598 393
mbed_official 237:f3da66175598 394 /**
mbed_official 237:f3da66175598 395 * @brief gets the status for tx/rx transfer (bits STAT_TX[1:0]
mbed_official 237:f3da66175598 396 * /STAT_RX[1:0])
mbed_official 237:f3da66175598 397 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 398 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 399 * @retval status
mbed_official 237:f3da66175598 400 */
mbed_official 237:f3da66175598 401 #define PCD_GET_EP_TX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPTX_STAT)
mbed_official 237:f3da66175598 402
mbed_official 237:f3da66175598 403 #define PCD_GET_EP_RX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPRX_STAT)
mbed_official 237:f3da66175598 404
mbed_official 237:f3da66175598 405 /**
mbed_official 237:f3da66175598 406 * @brief sets directly the VALID tx/rx-status into the endpoint register
mbed_official 237:f3da66175598 407 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 408 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 409 * @retval None
mbed_official 237:f3da66175598 410 */
mbed_official 237:f3da66175598 411 #define PCD_SET_EP_TX_VALID(USBx, bEpNum) (PCD_SET_EP_TX_STATUS(USBx, bEpNum, USB_EP_TX_VALID))
mbed_official 237:f3da66175598 412
mbed_official 237:f3da66175598 413 #define PCD_SET_EP_RX_VALID(USBx, bEpNum) (PCD_SET_EP_RX_STATUS(USBx, bEpNum, USB_EP_RX_VALID))
mbed_official 237:f3da66175598 414
mbed_official 237:f3da66175598 415 /**
mbed_official 237:f3da66175598 416 * @brief checks stall condition in an endpoint.
mbed_official 237:f3da66175598 417 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 418 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 419 * @retval TRUE = endpoint in stall condition.
mbed_official 237:f3da66175598 420 */
mbed_official 237:f3da66175598 421 #define PCD_GET_EP_TX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_TX_STATUS(USBx, bEpNum) \
mbed_official 237:f3da66175598 422 == USB_EP_TX_STALL)
mbed_official 237:f3da66175598 423 #define PCD_GET_EP_RX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_RX_STATUS(USBx, bEpNum) \
mbed_official 237:f3da66175598 424 == USB_EP_RX_STALL)
mbed_official 237:f3da66175598 425
mbed_official 237:f3da66175598 426 /**
mbed_official 237:f3da66175598 427 * @brief set & clear EP_KIND bit.
mbed_official 237:f3da66175598 428 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 429 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 430 * @retval None
mbed_official 237:f3da66175598 431 */
mbed_official 237:f3da66175598 432 #define PCD_SET_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
mbed_official 237:f3da66175598 433 (USB_EP_CTR_RX|USB_EP_CTR_TX|((PCD_GET_ENDPOINT(USBx, bEpNum) | USB_EP_KIND) & USB_EPREG_MASK))))
mbed_official 237:f3da66175598 434 #define PCD_CLEAR_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
mbed_official 237:f3da66175598 435 (USB_EP_CTR_RX|USB_EP_CTR_TX|(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPKIND_MASK))))
mbed_official 237:f3da66175598 436
mbed_official 237:f3da66175598 437 /**
mbed_official 237:f3da66175598 438 * @brief Sets/clears directly STATUS_OUT bit in the endpoint register.
mbed_official 237:f3da66175598 439 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 440 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 441 * @retval None
mbed_official 237:f3da66175598 442 */
mbed_official 237:f3da66175598 443 #define PCD_SET_OUT_STATUS(USBx, bEpNum) PCD_SET_EP_KIND(USBx, bEpNum)
mbed_official 237:f3da66175598 444 #define PCD_CLEAR_OUT_STATUS(USBx, bEpNum) PCD_CLEAR_EP_KIND(USBx, bEpNum)
mbed_official 237:f3da66175598 445
mbed_official 237:f3da66175598 446 /**
mbed_official 237:f3da66175598 447 * @brief Sets/clears directly EP_KIND bit in the endpoint register.
mbed_official 237:f3da66175598 448 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 449 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 450 * @retval None
mbed_official 237:f3da66175598 451 */
mbed_official 237:f3da66175598 452 #define PCD_SET_EP_DBUF(USBx, bEpNum) PCD_SET_EP_KIND(USBx, bEpNum)
mbed_official 237:f3da66175598 453 #define PCD_CLEAR_EP_DBUF(USBx, bEpNum) PCD_CLEAR_EP_KIND(USBx, bEpNum)
mbed_official 237:f3da66175598 454
mbed_official 237:f3da66175598 455 /**
mbed_official 237:f3da66175598 456 * @brief Clears bit CTR_RX / CTR_TX in the endpoint register.
mbed_official 237:f3da66175598 457 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 458 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 459 * @retval None
mbed_official 237:f3da66175598 460 */
mbed_official 237:f3da66175598 461 #define PCD_CLEAR_RX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum,\
mbed_official 237:f3da66175598 462 PCD_GET_ENDPOINT(USBx, bEpNum) & 0x7FFF & USB_EPREG_MASK))
mbed_official 237:f3da66175598 463 #define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum,\
mbed_official 237:f3da66175598 464 PCD_GET_ENDPOINT(USBx, bEpNum) & 0xFF7F & USB_EPREG_MASK))
mbed_official 237:f3da66175598 465
mbed_official 237:f3da66175598 466 /**
mbed_official 237:f3da66175598 467 * @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
mbed_official 237:f3da66175598 468 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 469 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 470 * @retval None
mbed_official 237:f3da66175598 471 */
mbed_official 237:f3da66175598 472 #define PCD_RX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
mbed_official 237:f3da66175598 473 USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_RX | (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK)))
mbed_official 237:f3da66175598 474 #define PCD_TX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
mbed_official 237:f3da66175598 475 USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_TX | (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK)))
mbed_official 237:f3da66175598 476
mbed_official 237:f3da66175598 477 /**
mbed_official 237:f3da66175598 478 * @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register.
mbed_official 237:f3da66175598 479 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 480 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 481 * @retval None
mbed_official 237:f3da66175598 482 */
mbed_official 237:f3da66175598 483 #define PCD_CLEAR_RX_DTOG(USBx, bEpNum) if((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_DTOG_RX) != 0)\
mbed_official 237:f3da66175598 484 PCD_RX_DTOG(USBx, bEpNum)
mbed_official 237:f3da66175598 485 #define PCD_CLEAR_TX_DTOG(USBx, bEpNum) if((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_DTOG_TX) != 0)\
mbed_official 237:f3da66175598 486 PCD_TX_DTOG(USBx, bEpNum)
mbed_official 237:f3da66175598 487
mbed_official 237:f3da66175598 488 /**
mbed_official 237:f3da66175598 489 * @brief Sets address in an endpoint register.
mbed_official 237:f3da66175598 490 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 491 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 492 * @param bAddr: Address.
mbed_official 237:f3da66175598 493 * @retval None
mbed_official 237:f3da66175598 494 */
mbed_official 237:f3da66175598 495 #define PCD_SET_EP_ADDRESS(USBx, bEpNum,bAddr) PCD_SET_ENDPOINT(USBx, bEpNum,\
mbed_official 237:f3da66175598 496 USB_EP_CTR_RX|USB_EP_CTR_TX|(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK) | bAddr)
mbed_official 237:f3da66175598 497
mbed_official 237:f3da66175598 498 #define PCD_GET_EP_ADDRESS(USBx, bEpNum) ((uint8_t)(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPADDR_FIELD))
mbed_official 237:f3da66175598 499
mbed_official 237:f3da66175598 500 /**
mbed_official 237:f3da66175598 501 * @brief sets address of the tx/rx buffer.
mbed_official 237:f3da66175598 502 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 503 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 504 * @param wAddr: address to be set (must be word aligned).
mbed_official 237:f3da66175598 505 * @retval None
mbed_official 237:f3da66175598 506 */
mbed_official 237:f3da66175598 507 #define PCD_SET_EP_TX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_TX_ADDRESS(USBx, bEpNum) = ((wAddr >> 1) << 1))
mbed_official 237:f3da66175598 508 #define PCD_SET_EP_RX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_RX_ADDRESS(USBx, bEpNum) = ((wAddr >> 1) << 1))
mbed_official 237:f3da66175598 509
mbed_official 237:f3da66175598 510 /**
mbed_official 237:f3da66175598 511 * @brief Gets address of the tx/rx buffer.
mbed_official 237:f3da66175598 512 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 513 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 514 * @retval address of the buffer.
mbed_official 237:f3da66175598 515 */
mbed_official 237:f3da66175598 516 #define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS(USBx, bEpNum))
mbed_official 237:f3da66175598 517 #define PCD_GET_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_RX_ADDRESS(USBx, bEpNum))
mbed_official 237:f3da66175598 518
mbed_official 237:f3da66175598 519 /**
mbed_official 237:f3da66175598 520 * @brief Sets counter of rx buffer with no. of blocks.
mbed_official 237:f3da66175598 521 * @param dwReg: Register
mbed_official 237:f3da66175598 522 * @param wCount: Counter.
mbed_official 237:f3da66175598 523 * @param wNBlocks: no. of Blocks.
mbed_official 237:f3da66175598 524 * @retval None
mbed_official 237:f3da66175598 525 */
mbed_official 237:f3da66175598 526 #define PCD_CALC_BLK32(dwReg,wCount,wNBlocks) {\
mbed_official 237:f3da66175598 527 wNBlocks = wCount >> 5;\
mbed_official 237:f3da66175598 528 if((wCount & 0x1f) == 0)\
mbed_official 237:f3da66175598 529 wNBlocks--;\
mbed_official 237:f3da66175598 530 *pdwReg = (uint16_t)((wNBlocks << 10) | 0x8000);\
mbed_official 237:f3da66175598 531 }/* PCD_CALC_BLK32 */
mbed_official 237:f3da66175598 532
mbed_official 237:f3da66175598 533 #define PCD_CALC_BLK2(dwReg,wCount,wNBlocks) {\
mbed_official 237:f3da66175598 534 wNBlocks = wCount >> 1;\
mbed_official 237:f3da66175598 535 if((wCount & 0x1) != 0)\
mbed_official 237:f3da66175598 536 wNBlocks++;\
mbed_official 237:f3da66175598 537 *pdwReg = (uint16_t)(wNBlocks << 10);\
mbed_official 237:f3da66175598 538 }/* PCD_CALC_BLK2 */
mbed_official 237:f3da66175598 539
mbed_official 237:f3da66175598 540 #define PCD_SET_EP_CNT_RX_REG(dwReg,wCount) {\
mbed_official 237:f3da66175598 541 uint16_t wNBlocks;\
mbed_official 237:f3da66175598 542 if(wCount > 62){PCD_CALC_BLK32(dwReg,wCount,wNBlocks);}\
mbed_official 237:f3da66175598 543 else {PCD_CALC_BLK2(dwReg,wCount,wNBlocks);}\
mbed_official 237:f3da66175598 544 }/* PCD_SET_EP_CNT_RX_REG */
mbed_official 237:f3da66175598 545
mbed_official 237:f3da66175598 546 #define PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum,wCount) {\
mbed_official 237:f3da66175598 547 uint16_t *pdwReg = PCD_EP_TX_CNT(USBx, bEpNum); \
mbed_official 237:f3da66175598 548 PCD_SET_EP_CNT_RX_REG(pdwReg, wCount);\
mbed_official 237:f3da66175598 549 }
mbed_official 237:f3da66175598 550 /**
mbed_official 237:f3da66175598 551 * @brief sets counter for the tx/rx buffer.
mbed_official 237:f3da66175598 552 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 553 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 554 * @param wCount: Counter value.
mbed_official 237:f3da66175598 555 * @retval None
mbed_official 237:f3da66175598 556 */
mbed_official 237:f3da66175598 557 #define PCD_SET_EP_TX_CNT(USBx, bEpNum,wCount) (*PCD_EP_TX_CNT(USBx, bEpNum) = wCount)
mbed_official 237:f3da66175598 558
mbed_official 237:f3da66175598 559
mbed_official 237:f3da66175598 560 /**
mbed_official 237:f3da66175598 561 * @brief gets counter of the tx buffer.
mbed_official 237:f3da66175598 562 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 563 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 564 * @retval Counter value
mbed_official 237:f3da66175598 565 */
mbed_official 237:f3da66175598 566 #define PCD_GET_EP_TX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_TX_CNT(USBx, bEpNum)) & 0x3ff)
mbed_official 237:f3da66175598 567 #define PCD_GET_EP_RX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_RX_CNT(USBx, bEpNum)) & 0x3ff)
mbed_official 237:f3da66175598 568
mbed_official 237:f3da66175598 569 /**
mbed_official 237:f3da66175598 570 * @brief Sets buffer 0/1 address in a double buffer endpoint.
mbed_official 237:f3da66175598 571 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 572 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 573 * @param wBuf0Addr: buffer 0 address.
mbed_official 237:f3da66175598 574 * @retval Counter value
mbed_official 237:f3da66175598 575 */
mbed_official 237:f3da66175598 576 #define PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum,wBuf0Addr) {PCD_SET_EP_TX_ADDRESS(USBx, bEpNum, wBuf0Addr);}
mbed_official 237:f3da66175598 577 #define PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum,wBuf1Addr) {PCD_SET_EP_RX_ADDRESS(USBx, bEpNum, wBuf1Addr);}
mbed_official 237:f3da66175598 578
mbed_official 237:f3da66175598 579 /**
mbed_official 237:f3da66175598 580 * @brief Sets addresses in a double buffer endpoint.
mbed_official 237:f3da66175598 581 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 582 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 583 * @param wBuf0Addr: buffer 0 address.
mbed_official 237:f3da66175598 584 * @param wBuf1Addr = buffer 1 address.
mbed_official 237:f3da66175598 585 * @retval None
mbed_official 237:f3da66175598 586 */
mbed_official 237:f3da66175598 587 #define PCD_SET_EP_DBUF_ADDR(USBx, bEpNum,wBuf0Addr,wBuf1Addr) { \
mbed_official 237:f3da66175598 588 PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum, wBuf0Addr);\
mbed_official 237:f3da66175598 589 PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum, wBuf1Addr);\
mbed_official 237:f3da66175598 590 } /* PCD_SET_EP_DBUF_ADDR */
mbed_official 237:f3da66175598 591
mbed_official 237:f3da66175598 592 /**
mbed_official 237:f3da66175598 593 * @brief Gets buffer 0/1 address of a double buffer endpoint.
mbed_official 237:f3da66175598 594 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 595 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 596 * @retval None
mbed_official 237:f3da66175598 597 */
mbed_official 237:f3da66175598 598 #define PCD_GET_EP_DBUF0_ADDR(USBx, bEpNum) (PCD_GET_EP_TX_ADDRESS(USBx, bEpNum))
mbed_official 237:f3da66175598 599 #define PCD_GET_EP_DBUF1_ADDR(USBx, bEpNum) (PCD_GET_EP_RX_ADDRESS(USBx, bEpNum))
mbed_official 237:f3da66175598 600
mbed_official 237:f3da66175598 601 /**
mbed_official 237:f3da66175598 602 * @brief Gets buffer 0/1 address of a double buffer endpoint.
mbed_official 237:f3da66175598 603 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 604 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 605 * @param bDir: endpoint dir EP_DBUF_OUT = OUT
mbed_official 237:f3da66175598 606 * EP_DBUF_IN = IN
mbed_official 237:f3da66175598 607 * @param wCount: Counter value
mbed_official 237:f3da66175598 608 * @retval None
mbed_official 237:f3da66175598 609 */
mbed_official 237:f3da66175598 610 #define PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount) { \
mbed_official 237:f3da66175598 611 if(bDir == PCD_EP_DBUF_OUT)\
mbed_official 237:f3da66175598 612 /* OUT endpoint */ \
mbed_official 237:f3da66175598 613 {PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum,wCount);} \
mbed_official 237:f3da66175598 614 else if(bDir == PCD_EP_DBUF_IN)\
mbed_official 237:f3da66175598 615 /* IN endpoint */ \
mbed_official 237:f3da66175598 616 *PCD_EP_TX_CNT(USBx, bEpNum) = (uint32_t)wCount; \
mbed_official 237:f3da66175598 617 } /* SetEPDblBuf0Count*/
mbed_official 237:f3da66175598 618
mbed_official 237:f3da66175598 619 #define PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount) { \
mbed_official 237:f3da66175598 620 if(bDir == PCD_EP_DBUF_OUT)\
mbed_official 237:f3da66175598 621 /* OUT endpoint */ \
mbed_official 237:f3da66175598 622 {PCD_SET_EP_RX_CNT(USBx, bEpNum,wCount);}\
mbed_official 237:f3da66175598 623 else if(bDir == PCD_EP_DBUF_IN)\
mbed_official 237:f3da66175598 624 /* IN endpoint */\
mbed_official 237:f3da66175598 625 *PCD_EP_RX_CNT(USBx, bEpNum) = (uint32_t)wCount; \
mbed_official 237:f3da66175598 626 } /* SetEPDblBuf1Count */
mbed_official 237:f3da66175598 627
mbed_official 237:f3da66175598 628 #define PCD_SET_EP_DBUF_CNT(USBx, bEpNum, bDir, wCount) {\
mbed_official 237:f3da66175598 629 PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount); \
mbed_official 237:f3da66175598 630 PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount); \
mbed_official 237:f3da66175598 631 } /* PCD_SET_EP_DBUF_CNT */
mbed_official 237:f3da66175598 632
mbed_official 237:f3da66175598 633 /**
mbed_official 237:f3da66175598 634 * @brief Gets buffer 0/1 rx/tx counter for double buffering.
mbed_official 237:f3da66175598 635 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 636 * @param bEpNum: Endpoint Number.
mbed_official 237:f3da66175598 637 * @retval None
mbed_official 237:f3da66175598 638 */
mbed_official 237:f3da66175598 639 #define PCD_GET_EP_DBUF0_CNT(USBx, bEpNum) (PCD_GET_EP_TX_CNT(USBx, bEpNum))
mbed_official 237:f3da66175598 640 #define PCD_GET_EP_DBUF1_CNT(USBx, bEpNum) (PCD_GET_EP_RX_CNT(USBx, bEpNum))
mbed_official 237:f3da66175598 641
mbed_official 237:f3da66175598 642
mbed_official 237:f3da66175598 643 /**
mbed_official 237:f3da66175598 644 * @}
mbed_official 237:f3da66175598 645 */
mbed_official 237:f3da66175598 646
mbed_official 237:f3da66175598 647 /* Exported functions --------------------------------------------------------*/
mbed_official 237:f3da66175598 648
mbed_official 237:f3da66175598 649 /* Initialization/de-initialization functions **********************************/
mbed_official 237:f3da66175598 650 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 651 HAL_StatusTypeDef HAL_PCD_DeInit (PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 652 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 653 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 654
mbed_official 237:f3da66175598 655 /* I/O operation functions *****************************************************/
mbed_official 237:f3da66175598 656 /* Non-Blocking mode: Interrupt */
mbed_official 237:f3da66175598 657 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 658 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 659 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 660
mbed_official 237:f3da66175598 661 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
mbed_official 237:f3da66175598 662 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
mbed_official 237:f3da66175598 663 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 664 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 665 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 666 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 667 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 668 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
mbed_official 237:f3da66175598 669 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
mbed_official 237:f3da66175598 670 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 671 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 672
mbed_official 237:f3da66175598 673 /* Peripheral Control functions ************************************************/
mbed_official 237:f3da66175598 674 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 675 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 676 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
mbed_official 237:f3da66175598 677 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
mbed_official 237:f3da66175598 678 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
mbed_official 237:f3da66175598 679 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
mbed_official 237:f3da66175598 680 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
mbed_official 237:f3da66175598 681 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
mbed_official 237:f3da66175598 682 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
mbed_official 237:f3da66175598 683 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
mbed_official 237:f3da66175598 684 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
mbed_official 237:f3da66175598 685 HAL_StatusTypeDef HAL_PCD_ActiveRemoteWakeup(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 686 HAL_StatusTypeDef HAL_PCD_DeActiveRemoteWakeup(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 687 /* Peripheral State functions **************************************************/
mbed_official 237:f3da66175598 688 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
mbed_official 237:f3da66175598 689
mbed_official 237:f3da66175598 690 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
mbed_official 237:f3da66175598 691 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
mbed_official 237:f3da66175598 692 /**
mbed_official 237:f3da66175598 693 * @}
mbed_official 237:f3da66175598 694 */
mbed_official 237:f3da66175598 695
mbed_official 237:f3da66175598 696 /**
mbed_official 237:f3da66175598 697 * @}
mbed_official 237:f3da66175598 698 */
mbed_official 237:f3da66175598 699
mbed_official 237:f3da66175598 700 #endif /* defined(STM32F302x8) || defined(STM32F302xC) || */
mbed_official 237:f3da66175598 701 /* defined(STM32F303xC) || defined(STM32F373xC) */
mbed_official 237:f3da66175598 702
mbed_official 237:f3da66175598 703 #ifdef __cplusplus
mbed_official 237:f3da66175598 704 }
mbed_official 237:f3da66175598 705 #endif
mbed_official 237:f3da66175598 706
mbed_official 237:f3da66175598 707
mbed_official 237:f3da66175598 708 #endif /* __STM32F3xx_HAL_PCD_H */
mbed_official 237:f3da66175598 709
mbed_official 237:f3da66175598 710 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/