mbed(SerialHalfDuplex入り)

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Wed Jul 02 13:22:23 2014 +0100
Revision:
86:04dd9b1680ae
Child:
92:4fc01daae5a5
Release 86 of the mbed library

Main changes:


- bug fixes in various backends
- mbed "error" replaced by assert logic (mbed_assert)
- new ST Nucleo targets

Who changed what in which revision?

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