meh

Fork of mbed by mbed official

Committer:
ricardobtez
Date:
Tue Apr 05 23:51:21 2016 +0000
Revision:
118:16969dd821af
Parent:
92:4fc01daae5a5
Child:
96:487b796308b0
dgdgr

Who changed what in which revision?

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