mbed w/ spi bug fig

Dependents:   display-puck

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu May 22 20:00:09 2014 +0100
Revision:
205:c41fc65bcfb4
Child:
218:44081b78fdc2
Synchronized with git revision ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb

Full URL: https://github.com/mbedmicro/mbed/commit/ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb/

[NUCLEO_F072RB] cmsis files

Who changed what in which revision?

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