meh

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Mon May 19 18:14:09 2014 +0100
Revision:
84:0b3ab51c8877
Child:
92:4fc01daae5a5
Release 84 of the mbed library

Main changes:

- added LPC11U68 to the official build
- Bug fixes and new features for ST Nucleo boards
- I2C fixes for Freescale targets
- Added nRF51822 exporters

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 84:0b3ab51c8877 5 * @version V1.0.0
bogdanm 84:0b3ab51c8877 6 * @date 22-April-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_EP_TYPE_CTRL 0
bogdanm 84:0b3ab51c8877 86 #define PCD_EP_TYPE_ISOC 1
bogdanm 84:0b3ab51c8877 87 #define PCD_EP_TYPE_BULK 2
bogdanm 84:0b3ab51c8877 88 #define PCD_EP_TYPE_INTR 3
bogdanm 84:0b3ab51c8877 89
bogdanm 84:0b3ab51c8877 90 #define PCD_ENDP0 ((uint8_t)0)
bogdanm 84:0b3ab51c8877 91 #define PCD_ENDP1 ((uint8_t)1)
bogdanm 84:0b3ab51c8877 92 #define PCD_ENDP2 ((uint8_t)2)
bogdanm 84:0b3ab51c8877 93 #define PCD_ENDP3 ((uint8_t)3)
bogdanm 84:0b3ab51c8877 94 #define PCD_ENDP4 ((uint8_t)4)
bogdanm 84:0b3ab51c8877 95 #define PCD_ENDP5 ((uint8_t)5)
bogdanm 84:0b3ab51c8877 96 #define PCD_ENDP6 ((uint8_t)6)
bogdanm 84:0b3ab51c8877 97 #define PCD_ENDP7 ((uint8_t)7)
bogdanm 84:0b3ab51c8877 98
bogdanm 84:0b3ab51c8877 99 /* Endpoint Kind */
bogdanm 84:0b3ab51c8877 100 #define PCD_SNG_BUF 0
bogdanm 84:0b3ab51c8877 101 #define PCD_DBL_BUF 1
bogdanm 84:0b3ab51c8877 102
bogdanm 84:0b3ab51c8877 103 #define IS_PCD_ALL_INSTANCE IS_USB_ALL_INSTANCE
bogdanm 84:0b3ab51c8877 104 /**
bogdanm 84:0b3ab51c8877 105 * @brief PCD Initialization Structure definition
bogdanm 84:0b3ab51c8877 106 */
bogdanm 84:0b3ab51c8877 107 typedef struct
bogdanm 84:0b3ab51c8877 108 {
bogdanm 84:0b3ab51c8877 109 uint32_t dev_endpoints; /*!< Device Endpoints number.
bogdanm 84:0b3ab51c8877 110 This parameter depends on the used USB core.
bogdanm 84:0b3ab51c8877 111 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
bogdanm 84:0b3ab51c8877 112
bogdanm 84:0b3ab51c8877 113 uint32_t speed; /*!< USB Core speed.
bogdanm 84:0b3ab51c8877 114 This parameter can be any value of @ref USB_Core_Speed_ */
bogdanm 84:0b3ab51c8877 115
bogdanm 84:0b3ab51c8877 116 uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size.
bogdanm 84:0b3ab51c8877 117 This parameter can be any value of @ref USB_EP0_MPS_ */
bogdanm 84:0b3ab51c8877 118
bogdanm 84:0b3ab51c8877 119 uint32_t phy_itface; /*!< Select the used PHY interface.
bogdanm 84:0b3ab51c8877 120 This parameter can be any value of @ref USB_Core_PHY_ */
bogdanm 84:0b3ab51c8877 121
bogdanm 84:0b3ab51c8877 122 uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal.
bogdanm 84:0b3ab51c8877 123 This parameter can be set to ENABLE or DISABLE */
bogdanm 84:0b3ab51c8877 124
bogdanm 84:0b3ab51c8877 125 uint32_t low_power_enable; /*!< Enable or disable Low Power mode
bogdanm 84:0b3ab51c8877 126 This parameter can be set to ENABLE or DISABLE */
bogdanm 84:0b3ab51c8877 127
bogdanm 84:0b3ab51c8877 128 uint32_t lpm_enable; /*!< Enable or disable Link Power Management.
bogdanm 84:0b3ab51c8877 129 This parameter can be set to ENABLE or DISABLE */
bogdanm 84:0b3ab51c8877 130
bogdanm 84:0b3ab51c8877 131 uint32_t battery_charging_enable; /*!< Enable or disable Battery charging.
bogdanm 84:0b3ab51c8877 132 This parameter can be set to ENABLE or DISABLE */
bogdanm 84:0b3ab51c8877 133
bogdanm 84:0b3ab51c8877 134 }PCD_InitTypeDef;
bogdanm 84:0b3ab51c8877 135
bogdanm 84:0b3ab51c8877 136 typedef struct
bogdanm 84:0b3ab51c8877 137 {
bogdanm 84:0b3ab51c8877 138 uint8_t num; /*!< Endpoint number
bogdanm 84:0b3ab51c8877 139 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
bogdanm 84:0b3ab51c8877 140
bogdanm 84:0b3ab51c8877 141 uint8_t is_in; /*!< Endpoint direction
bogdanm 84:0b3ab51c8877 142 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
bogdanm 84:0b3ab51c8877 143
bogdanm 84:0b3ab51c8877 144 uint8_t is_stall; /*!< Endpoint stall condition
bogdanm 84:0b3ab51c8877 145 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
bogdanm 84:0b3ab51c8877 146
bogdanm 84:0b3ab51c8877 147 uint8_t type; /*!< Endpoint type
bogdanm 84:0b3ab51c8877 148 This parameter can be any value of @ref USB_EP_Type_ */
bogdanm 84:0b3ab51c8877 149
bogdanm 84:0b3ab51c8877 150 uint16_t pmaadress; /*!< PMA Address
bogdanm 84:0b3ab51c8877 151 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
bogdanm 84:0b3ab51c8877 152
bogdanm 84:0b3ab51c8877 153
bogdanm 84:0b3ab51c8877 154 uint16_t pmaaddr0; /*!< PMA Address0
bogdanm 84:0b3ab51c8877 155 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
bogdanm 84:0b3ab51c8877 156
bogdanm 84:0b3ab51c8877 157
bogdanm 84:0b3ab51c8877 158 uint16_t pmaaddr1; /*!< PMA Address1
bogdanm 84:0b3ab51c8877 159 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
bogdanm 84:0b3ab51c8877 160
bogdanm 84:0b3ab51c8877 161
bogdanm 84:0b3ab51c8877 162 uint8_t doublebuffer; /*!< Double buffer enable
bogdanm 84:0b3ab51c8877 163 This parameter can be 0 or 1 */
bogdanm 84:0b3ab51c8877 164
bogdanm 84:0b3ab51c8877 165 uint32_t maxpacket; /*!< Endpoint Max packet size
bogdanm 84:0b3ab51c8877 166 This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
bogdanm 84:0b3ab51c8877 167
bogdanm 84:0b3ab51c8877 168 uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
bogdanm 84:0b3ab51c8877 169
bogdanm 84:0b3ab51c8877 170
bogdanm 84:0b3ab51c8877 171 uint32_t xfer_len; /*!< Current transfer length */
bogdanm 84:0b3ab51c8877 172
bogdanm 84:0b3ab51c8877 173 uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
bogdanm 84:0b3ab51c8877 174
bogdanm 84:0b3ab51c8877 175 }PCD_EPTypeDef;
bogdanm 84:0b3ab51c8877 176
bogdanm 84:0b3ab51c8877 177 typedef USB_TypeDef PCD_TypeDef;
bogdanm 84:0b3ab51c8877 178
bogdanm 84:0b3ab51c8877 179 /**
bogdanm 84:0b3ab51c8877 180 * @brief PCD Handle Structure definition
bogdanm 84:0b3ab51c8877 181 */
bogdanm 84:0b3ab51c8877 182 typedef struct
bogdanm 84:0b3ab51c8877 183 {
bogdanm 84:0b3ab51c8877 184 PCD_TypeDef *Instance; /*!< Register base address */
bogdanm 84:0b3ab51c8877 185 PCD_InitTypeDef Init; /*!< PCD required parameters */
bogdanm 84:0b3ab51c8877 186 __IO uint8_t USB_Address; /*!< USB Address */
bogdanm 84:0b3ab51c8877 187 PCD_EPTypeDef IN_ep[5]; /*!< IN endpoint parameters */
bogdanm 84:0b3ab51c8877 188 PCD_EPTypeDef OUT_ep[5]; /*!< OUT endpoint parameters */
bogdanm 84:0b3ab51c8877 189 HAL_LockTypeDef Lock; /*!< PCD peripheral status */
bogdanm 84:0b3ab51c8877 190 __IO PCD_StateTypeDef State; /*!< PCD communication state */
bogdanm 84:0b3ab51c8877 191 uint32_t Setup[12]; /*!< Setup packet buffer */
bogdanm 84:0b3ab51c8877 192 void *pData; /*!< Pointer to upper stack Handler */
bogdanm 84:0b3ab51c8877 193
bogdanm 84:0b3ab51c8877 194 } PCD_HandleTypeDef;
bogdanm 84:0b3ab51c8877 195
bogdanm 84:0b3ab51c8877 196 #include "stm32l0xx_hal_pcd_ex.h"
bogdanm 84:0b3ab51c8877 197 /* Exported constants --------------------------------------------------------*/
bogdanm 84:0b3ab51c8877 198 /** @defgroup PCD_Exported_Constants
bogdanm 84:0b3ab51c8877 199 * @{
bogdanm 84:0b3ab51c8877 200 */
bogdanm 84:0b3ab51c8877 201
bogdanm 84:0b3ab51c8877 202 /** @defgroup PCD_Speed
bogdanm 84:0b3ab51c8877 203 * @{
bogdanm 84:0b3ab51c8877 204 */
bogdanm 84:0b3ab51c8877 205 #define PCD_SPEED_HIGH 0 /* Not Supported */
bogdanm 84:0b3ab51c8877 206 #define PCD_SPEED_FULL 2
bogdanm 84:0b3ab51c8877 207 /**
bogdanm 84:0b3ab51c8877 208 * @}
bogdanm 84:0b3ab51c8877 209 */
bogdanm 84:0b3ab51c8877 210
bogdanm 84:0b3ab51c8877 211 /** @defgroup USB_Core_PHY
bogdanm 84:0b3ab51c8877 212 * @{
bogdanm 84:0b3ab51c8877 213 */
bogdanm 84:0b3ab51c8877 214 #define PCD_PHY_EMBEDDED 2
bogdanm 84:0b3ab51c8877 215 /**
bogdanm 84:0b3ab51c8877 216 * @}
bogdanm 84:0b3ab51c8877 217 */
bogdanm 84:0b3ab51c8877 218
bogdanm 84:0b3ab51c8877 219 /** @defgroup USB_EP0_MPS
bogdanm 84:0b3ab51c8877 220 * @{
bogdanm 84:0b3ab51c8877 221 */
bogdanm 84:0b3ab51c8877 222 #define DEP0CTL_MPS_64 0
bogdanm 84:0b3ab51c8877 223 #define DEP0CTL_MPS_32 1
bogdanm 84:0b3ab51c8877 224 #define DEP0CTL_MPS_16 2
bogdanm 84:0b3ab51c8877 225 #define DEP0CTL_MPS_8 3
bogdanm 84:0b3ab51c8877 226
bogdanm 84:0b3ab51c8877 227 #define PCD_EP0MPS_64 DEP0CTL_MPS_64
bogdanm 84:0b3ab51c8877 228 #define PCD_EP0MPS_32 DEP0CTL_MPS_32
bogdanm 84:0b3ab51c8877 229 #define PCD_EP0MPS_16 DEP0CTL_MPS_16
bogdanm 84:0b3ab51c8877 230 #define PCD_EP0MPS_08 DEP0CTL_MPS_8
bogdanm 84:0b3ab51c8877 231 /**
bogdanm 84:0b3ab51c8877 232 * @}
bogdanm 84:0b3ab51c8877 233 */
bogdanm 84:0b3ab51c8877 234 /**
bogdanm 84:0b3ab51c8877 235 * @}
bogdanm 84:0b3ab51c8877 236 */
bogdanm 84:0b3ab51c8877 237
bogdanm 84:0b3ab51c8877 238 /* Exported macros -----------------------------------------------------------*/
bogdanm 84:0b3ab51c8877 239
bogdanm 84:0b3ab51c8877 240 /** @defgroup PCD_Interrupt_Clock
bogdanm 84:0b3ab51c8877 241 * @brief macros to handle interrupts and specific clock configurations
bogdanm 84:0b3ab51c8877 242 * @{
bogdanm 84:0b3ab51c8877 243 */
bogdanm 84:0b3ab51c8877 244 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISTR) & (__INTERRUPT__)) == (__INTERRUPT__))
bogdanm 84:0b3ab51c8877 245 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->ISTR) &= ~(__INTERRUPT__))
bogdanm 84:0b3ab51c8877 246
bogdanm 84:0b3ab51c8877 247 #define USB_EXTI_LINE_WAKEUP ((uint32_t)0x00040000) /*!< External interrupt line 18 Connected to the USB FS EXTI Line */
bogdanm 84:0b3ab51c8877 248
bogdanm 84:0b3ab51c8877 249 #define __HAL_USB_EXTI_ENABLE_IT() EXTI->IMR |= USB_EXTI_LINE_WAKEUP
bogdanm 84:0b3ab51c8877 250 #define __HAL_USB_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_EXTI_LINE_WAKEUP)
bogdanm 84:0b3ab51c8877 251
bogdanm 84:0b3ab51c8877 252 /* Internal macros -----------------------------------------------------------*/
bogdanm 84:0b3ab51c8877 253
bogdanm 84:0b3ab51c8877 254 /* SetENDPOINT */
bogdanm 84:0b3ab51c8877 255 #define PCD_SET_ENDPOINT(USBx, bEpNum,wRegValue) (*(&USBx->EP0R + bEpNum * 2)= (uint16_t)wRegValue)
bogdanm 84:0b3ab51c8877 256
bogdanm 84:0b3ab51c8877 257 /* GetENDPOINT */
bogdanm 84:0b3ab51c8877 258 #define PCD_GET_ENDPOINT(USBx, bEpNum) (*(&USBx->EP0R + bEpNum * 2))
bogdanm 84:0b3ab51c8877 259
bogdanm 84:0b3ab51c8877 260
bogdanm 84:0b3ab51c8877 261
bogdanm 84:0b3ab51c8877 262 /**
bogdanm 84:0b3ab51c8877 263 * @brief sets the type in the endpoint register(bits EP_TYPE[1:0])
bogdanm 84:0b3ab51c8877 264 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 265 * @param wType: Endpoint Type.
bogdanm 84:0b3ab51c8877 266 * @retval None
bogdanm 84:0b3ab51c8877 267 */
bogdanm 84:0b3ab51c8877 268 #define PCD_SET_EPTYPE(USBx, bEpNum,wType) (PCD_SET_ENDPOINT(USBx, bEpNum,\
bogdanm 84:0b3ab51c8877 269 ((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_T_MASK) | wType )))
bogdanm 84:0b3ab51c8877 270
bogdanm 84:0b3ab51c8877 271 /**
bogdanm 84:0b3ab51c8877 272 * @brief gets the type in the endpoint register(bits EP_TYPE[1:0])
bogdanm 84:0b3ab51c8877 273 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 274 * @retval Endpoint Type
bogdanm 84:0b3ab51c8877 275 */
bogdanm 84:0b3ab51c8877 276 #define PCD_GET_EPTYPE(USBx, bEpNum) (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_T_FIELD)
bogdanm 84:0b3ab51c8877 277
bogdanm 84:0b3ab51c8877 278
bogdanm 84:0b3ab51c8877 279 /**
bogdanm 84:0b3ab51c8877 280 * @brief free buffer used from the application realizing it to the line
bogdanm 84:0b3ab51c8877 281 toggles bit SW_BUF in the double buffered endpoint register
bogdanm 84:0b3ab51c8877 282 * @param bEpNum, bDir
bogdanm 84:0b3ab51c8877 283 * @retval None
bogdanm 84:0b3ab51c8877 284 */
bogdanm 84:0b3ab51c8877 285 #define PCD_FreeUserBuffer(USBx, bEpNum, bDir)\
bogdanm 84:0b3ab51c8877 286 {\
bogdanm 84:0b3ab51c8877 287 if (bDir == PCD_EP_DBUF_OUT)\
bogdanm 84:0b3ab51c8877 288 { /* OUT double buffered endpoint */\
bogdanm 84:0b3ab51c8877 289 PCD_TX_DTOG(USBx, bEpNum);\
bogdanm 84:0b3ab51c8877 290 }\
bogdanm 84:0b3ab51c8877 291 else if (bDir == PCD_EP_DBUF_IN)\
bogdanm 84:0b3ab51c8877 292 { /* IN double buffered endpoint */\
bogdanm 84:0b3ab51c8877 293 PCD_RX_DTOG(USBx, bEpNum);\
bogdanm 84:0b3ab51c8877 294 }\
bogdanm 84:0b3ab51c8877 295 }
bogdanm 84:0b3ab51c8877 296
bogdanm 84:0b3ab51c8877 297 /**
bogdanm 84:0b3ab51c8877 298 * @brief gets direction of the double buffered endpoint
bogdanm 84:0b3ab51c8877 299 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 300 * @retval EP_DBUF_OUT, EP_DBUF_IN,
bogdanm 84:0b3ab51c8877 301 * EP_DBUF_ERR if the endpoint counter not yet programmed.
bogdanm 84:0b3ab51c8877 302 */
bogdanm 84:0b3ab51c8877 303 #define PCD_GET_DB_DIR(USBx, bEpNum)\
bogdanm 84:0b3ab51c8877 304 {\
bogdanm 84:0b3ab51c8877 305 if ((uint16_t)(*PCD_EP_RX_CNT(USBx, bEpNum) & 0xFC00) != 0)\
bogdanm 84:0b3ab51c8877 306 return(PCD_EP_DBUF_OUT);\
bogdanm 84:0b3ab51c8877 307 else if (((uint16_t)(*PCD_EP_TX_CNT(USBx, bEpNum)) & 0x03FF) != 0)\
bogdanm 84:0b3ab51c8877 308 return(PCD_EP_DBUF_IN);\
bogdanm 84:0b3ab51c8877 309 else\
bogdanm 84:0b3ab51c8877 310 return(PCD_EP_DBUF_ERR);\
bogdanm 84:0b3ab51c8877 311 }
bogdanm 84:0b3ab51c8877 312
bogdanm 84:0b3ab51c8877 313 /**
bogdanm 84:0b3ab51c8877 314 * @brief sets the status for tx transfer (bits STAT_TX[1:0]).
bogdanm 84:0b3ab51c8877 315 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 316 * @param wState: new state
bogdanm 84:0b3ab51c8877 317 * @retval None
bogdanm 84:0b3ab51c8877 318 */
bogdanm 84:0b3ab51c8877 319 #define PCD_SET_EP_TX_STATUS(USBx, bEpNum, wState) {\
bogdanm 84:0b3ab51c8877 320 register uint16_t _wRegVal; \
bogdanm 84:0b3ab51c8877 321 \
bogdanm 84:0b3ab51c8877 322 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPTX_DTOGMASK;\
bogdanm 84:0b3ab51c8877 323 /* toggle first bit ? */ \
bogdanm 84:0b3ab51c8877 324 if((USB_EPTX_DTOG1 & wState)!= 0) \
bogdanm 84:0b3ab51c8877 325 _wRegVal ^= USB_EPTX_DTOG1; \
bogdanm 84:0b3ab51c8877 326 /* toggle second bit ? */ \
bogdanm 84:0b3ab51c8877 327 if((USB_EPTX_DTOG2 & wState)!= 0) \
bogdanm 84:0b3ab51c8877 328 _wRegVal ^= USB_EPTX_DTOG2; \
bogdanm 84:0b3ab51c8877 329 PCD_SET_ENDPOINT(USBx, bEpNum, (_wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX)); \
bogdanm 84:0b3ab51c8877 330 } /* PCD_SET_EP_TX_STATUS */
bogdanm 84:0b3ab51c8877 331
bogdanm 84:0b3ab51c8877 332 /**
bogdanm 84:0b3ab51c8877 333 * @brief sets the status for rx transfer (bits STAT_TX[1:0])
bogdanm 84:0b3ab51c8877 334 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 335 * @param wState: new state
bogdanm 84:0b3ab51c8877 336 * @retval None
bogdanm 84:0b3ab51c8877 337 */
bogdanm 84:0b3ab51c8877 338 #define PCD_SET_EP_RX_STATUS(USBx, bEpNum,wState) {\
bogdanm 84:0b3ab51c8877 339 register uint16_t _wRegVal; \
bogdanm 84:0b3ab51c8877 340 \
bogdanm 84:0b3ab51c8877 341 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPRX_DTOGMASK;\
bogdanm 84:0b3ab51c8877 342 /* toggle first bit ? */ \
bogdanm 84:0b3ab51c8877 343 if((USB_EPRX_DTOG1 & wState)!= 0) \
bogdanm 84:0b3ab51c8877 344 _wRegVal ^= USB_EPRX_DTOG1; \
bogdanm 84:0b3ab51c8877 345 /* toggle second bit ? */ \
bogdanm 84:0b3ab51c8877 346 if((USB_EPRX_DTOG2 & wState)!= 0) \
bogdanm 84:0b3ab51c8877 347 _wRegVal ^= USB_EPRX_DTOG2; \
bogdanm 84:0b3ab51c8877 348 PCD_SET_ENDPOINT(USBx, bEpNum, (_wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX)); \
bogdanm 84:0b3ab51c8877 349 } /* PCD_SET_EP_RX_STATUS */
bogdanm 84:0b3ab51c8877 350
bogdanm 84:0b3ab51c8877 351 /**
bogdanm 84:0b3ab51c8877 352 * @brief sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0])
bogdanm 84:0b3ab51c8877 353 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 354 * @param wStaterx: new state.
bogdanm 84:0b3ab51c8877 355 * @param wStatetx: new state.
bogdanm 84:0b3ab51c8877 356 * @retval None
bogdanm 84:0b3ab51c8877 357 */
bogdanm 84:0b3ab51c8877 358 #define PCD_SET_EP_TXRX_STATUS(USBx,bEpNum,wStaterx,wStatetx) {\
bogdanm 84:0b3ab51c8877 359 register uint32_t _wRegVal; \
bogdanm 84:0b3ab51c8877 360 \
bogdanm 84:0b3ab51c8877 361 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & (USB_EPRX_DTOGMASK |USB_EPTX_STAT) ;\
bogdanm 84:0b3ab51c8877 362 /* toggle first bit ? */ \
bogdanm 84:0b3ab51c8877 363 if((USB_EPRX_DTOG1 & wStaterx)!= 0) \
bogdanm 84:0b3ab51c8877 364 _wRegVal ^= USB_EPRX_DTOG1; \
bogdanm 84:0b3ab51c8877 365 /* toggle second bit ? */ \
bogdanm 84:0b3ab51c8877 366 if((USB_EPRX_DTOG2 & wStaterx)!= 0) \
bogdanm 84:0b3ab51c8877 367 _wRegVal ^= USB_EPRX_DTOG2; \
bogdanm 84:0b3ab51c8877 368 /* toggle first bit ? */ \
bogdanm 84:0b3ab51c8877 369 if((USB_EPTX_DTOG1 & wStatetx)!= 0) \
bogdanm 84:0b3ab51c8877 370 _wRegVal ^= USB_EPTX_DTOG1; \
bogdanm 84:0b3ab51c8877 371 /* toggle second bit ? */ \
bogdanm 84:0b3ab51c8877 372 if((USB_EPTX_DTOG2 & wStatetx)!= 0) \
bogdanm 84:0b3ab51c8877 373 _wRegVal ^= USB_EPTX_DTOG2; \
bogdanm 84:0b3ab51c8877 374 PCD_SET_ENDPOINT(USBx, bEpNum, _wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX); \
bogdanm 84:0b3ab51c8877 375 } /* PCD_SET_EP_TXRX_STATUS */
bogdanm 84:0b3ab51c8877 376
bogdanm 84:0b3ab51c8877 377 /**
bogdanm 84:0b3ab51c8877 378 * @brief gets the status for tx/rx transfer (bits STAT_TX[1:0]
bogdanm 84:0b3ab51c8877 379 * /STAT_RX[1:0])
bogdanm 84:0b3ab51c8877 380 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 381 * @retval status
bogdanm 84:0b3ab51c8877 382 */
bogdanm 84:0b3ab51c8877 383 #define PCD_GET_EP_TX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPTX_STAT)
bogdanm 84:0b3ab51c8877 384
bogdanm 84:0b3ab51c8877 385 #define PCD_GET_EP_RX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPRX_STAT)
bogdanm 84:0b3ab51c8877 386
bogdanm 84:0b3ab51c8877 387 /**
bogdanm 84:0b3ab51c8877 388 * @brief sets directly the VALID tx/rx-status into the endpoint register
bogdanm 84:0b3ab51c8877 389 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 390 * @retval None
bogdanm 84:0b3ab51c8877 391 */
bogdanm 84:0b3ab51c8877 392 #define PCD_SET_EP_TX_VALID(USBx, bEpNum) (PCD_SET_EP_TX_STATUS(USBx, bEpNum, USB_EP_TX_VALID))
bogdanm 84:0b3ab51c8877 393
bogdanm 84:0b3ab51c8877 394 #define PCD_SET_EP_RX_VALID(USBx, bEpNum) (PCD_SET_EP_RX_STATUS(USBx, bEpNum, USB_EP_RX_VALID))
bogdanm 84:0b3ab51c8877 395
bogdanm 84:0b3ab51c8877 396 /**
bogdanm 84:0b3ab51c8877 397 * @brief checks stall condition in an endpoint.
bogdanm 84:0b3ab51c8877 398 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 399 * @retval TRUE = endpoint in stall condition.
bogdanm 84:0b3ab51c8877 400 */
bogdanm 84:0b3ab51c8877 401 #define PCD_GET_EP_TX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_TX_STATUS(USBx, bEpNum) \
bogdanm 84:0b3ab51c8877 402 == USB_EP_TX_STALL)
bogdanm 84:0b3ab51c8877 403 #define PCD_GET_EP_RX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_RX_STATUS(USBx, bEpNum) \
bogdanm 84:0b3ab51c8877 404 == USB_EP_RX_STALL)
bogdanm 84:0b3ab51c8877 405
bogdanm 84:0b3ab51c8877 406 /**
bogdanm 84:0b3ab51c8877 407 * @brief set & clear EP_KIND bit.
bogdanm 84:0b3ab51c8877 408 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 409 * @retval None
bogdanm 84:0b3ab51c8877 410 */
bogdanm 84:0b3ab51c8877 411 #define PCD_SET_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
bogdanm 84:0b3ab51c8877 412 (USB_EP_CTR_RX|USB_EP_CTR_TX|((PCD_GET_ENDPOINT(USBx, bEpNum) | USB_EP_KIND) & USB_EPREG_MASK))))
bogdanm 84:0b3ab51c8877 413 #define PCD_CLEAR_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
bogdanm 84:0b3ab51c8877 414 (USB_EP_CTR_RX|USB_EP_CTR_TX|(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPKIND_MASK))))
bogdanm 84:0b3ab51c8877 415
bogdanm 84:0b3ab51c8877 416 /**
bogdanm 84:0b3ab51c8877 417 * @brief Sets/clears directly STATUS_OUT bit in the endpoint register.
bogdanm 84:0b3ab51c8877 418 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 419 * @retval None
bogdanm 84:0b3ab51c8877 420 */
bogdanm 84:0b3ab51c8877 421 #define PCD_SET_OUT_STATUS(USBx, bEpNum) PCD_SET_EP_KIND(USBx, bEpNum)
bogdanm 84:0b3ab51c8877 422 #define PCD_CLEAR_OUT_STATUS(USBx, bEpNum) PCD_CLEAR_EP_KIND(USBx, bEpNum)
bogdanm 84:0b3ab51c8877 423
bogdanm 84:0b3ab51c8877 424 /**
bogdanm 84:0b3ab51c8877 425 * @brief Sets/clears directly EP_KIND 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_EP_DBUF(USBx, bEpNum) PCD_SET_EP_KIND(USBx, bEpNum)
bogdanm 84:0b3ab51c8877 430 #define PCD_CLEAR_EP_DBUF(USBx, bEpNum) PCD_CLEAR_EP_KIND(USBx, bEpNum)
bogdanm 84:0b3ab51c8877 431
bogdanm 84:0b3ab51c8877 432 /**
bogdanm 84:0b3ab51c8877 433 * @brief Clears bit CTR_RX / CTR_TX 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_CLEAR_RX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum,\
bogdanm 84:0b3ab51c8877 438 PCD_GET_ENDPOINT(USBx, bEpNum) & 0x7FFF & USB_EPREG_MASK))
bogdanm 84:0b3ab51c8877 439 #define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum,\
bogdanm 84:0b3ab51c8877 440 PCD_GET_ENDPOINT(USBx, bEpNum) & 0xFF7F & USB_EPREG_MASK))
bogdanm 84:0b3ab51c8877 441
bogdanm 84:0b3ab51c8877 442 /**
bogdanm 84:0b3ab51c8877 443 * @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
bogdanm 84:0b3ab51c8877 444 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 445 * @retval None
bogdanm 84:0b3ab51c8877 446 */
bogdanm 84:0b3ab51c8877 447 #define PCD_RX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
bogdanm 84:0b3ab51c8877 448 USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_RX | (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK)))
bogdanm 84:0b3ab51c8877 449 #define PCD_TX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
bogdanm 84:0b3ab51c8877 450 USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_TX | (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK)))
bogdanm 84:0b3ab51c8877 451
bogdanm 84:0b3ab51c8877 452 /**
bogdanm 84:0b3ab51c8877 453 * @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register.
bogdanm 84:0b3ab51c8877 454 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 455 * @retval None
bogdanm 84:0b3ab51c8877 456 */
bogdanm 84:0b3ab51c8877 457 #define PCD_CLEAR_RX_DTOG(USBx, bEpNum) if((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_DTOG_RX) != 0)\
bogdanm 84:0b3ab51c8877 458 PCD_RX_DTOG(USBx, bEpNum)
bogdanm 84:0b3ab51c8877 459 #define PCD_CLEAR_TX_DTOG(USBx, bEpNum) if((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_DTOG_TX) != 0)\
bogdanm 84:0b3ab51c8877 460 PCD_TX_DTOG(USBx, bEpNum)
bogdanm 84:0b3ab51c8877 461
bogdanm 84:0b3ab51c8877 462 /**
bogdanm 84:0b3ab51c8877 463 * @brief Sets address in an endpoint register.
bogdanm 84:0b3ab51c8877 464 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 465 * @param bAddr: Address.
bogdanm 84:0b3ab51c8877 466 * @retval None
bogdanm 84:0b3ab51c8877 467 */
bogdanm 84:0b3ab51c8877 468 #define PCD_SET_EP_ADDRESS(USBx, bEpNum,bAddr) PCD_SET_ENDPOINT(USBx, bEpNum,\
bogdanm 84:0b3ab51c8877 469 USB_EP_CTR_RX|USB_EP_CTR_TX|(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK) | bAddr)
bogdanm 84:0b3ab51c8877 470
bogdanm 84:0b3ab51c8877 471 /**
bogdanm 84:0b3ab51c8877 472 * @brief Gets address in an endpoint register.
bogdanm 84:0b3ab51c8877 473 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 474 * @retval None
bogdanm 84:0b3ab51c8877 475 */
bogdanm 84:0b3ab51c8877 476 #define PCD_GET_EP_ADDRESS(USBx, bEpNum) ((uint8_t)(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPADDR_FIELD))
bogdanm 84:0b3ab51c8877 477 #define PCD_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t *)((USBx->BTABLE+bEpNum*8)+ ((uint32_t)USBx + 0x400)))
bogdanm 84:0b3ab51c8877 478 #define PCD_EP_TX_CNT(USBx, bEpNum) ((uint16_t *)((USBx->BTABLE+bEpNum*8+2)+ ((uint32_t)USBx + 0x400)))
bogdanm 84:0b3ab51c8877 479 #define PCD_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t *)((USBx->BTABLE+bEpNum*8+4)+ ((uint32_t)USBx + 0x400)))
bogdanm 84:0b3ab51c8877 480 #define PCD_EP_RX_CNT(USBx, bEpNum) ((uint16_t *)((USBx->BTABLE+bEpNum*8+6)+ ((uint32_t)USBx + 0x400)))
bogdanm 84:0b3ab51c8877 481
bogdanm 84:0b3ab51c8877 482 /**
bogdanm 84:0b3ab51c8877 483 * @brief sets address of the tx/rx buffer.
bogdanm 84:0b3ab51c8877 484 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 485 * @param wAddr: address to be set (must be word aligned).
bogdanm 84:0b3ab51c8877 486 * @retval None
bogdanm 84:0b3ab51c8877 487 */
bogdanm 84:0b3ab51c8877 488 #define PCD_SET_EP_TX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_TX_ADDRESS(USBx, bEpNum) = ((wAddr >> 1) << 1))
bogdanm 84:0b3ab51c8877 489 #define PCD_SET_EP_RX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_RX_ADDRESS(USBx, bEpNum) = ((wAddr >> 1) << 1))
bogdanm 84:0b3ab51c8877 490
bogdanm 84:0b3ab51c8877 491 /**
bogdanm 84:0b3ab51c8877 492 * @brief Gets address of the tx/rx buffer.
bogdanm 84:0b3ab51c8877 493 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 494 * @retval address of the buffer.
bogdanm 84:0b3ab51c8877 495 */
bogdanm 84:0b3ab51c8877 496 #define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS(USBx, bEpNum))
bogdanm 84:0b3ab51c8877 497 #define PCD_GET_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_RX_ADDRESS(USBx, bEpNum))
bogdanm 84:0b3ab51c8877 498
bogdanm 84:0b3ab51c8877 499 /**
bogdanm 84:0b3ab51c8877 500 * @brief Sets counter of rx buffer with no. of blocks.
bogdanm 84:0b3ab51c8877 501 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 502 * @param wCount: Counter.
bogdanm 84:0b3ab51c8877 503 * @retval None
bogdanm 84:0b3ab51c8877 504 */
bogdanm 84:0b3ab51c8877 505 #define PCD_CALC_BLK32(dwReg,wCount,wNBlocks) {\
bogdanm 84:0b3ab51c8877 506 wNBlocks = wCount >> 5;\
bogdanm 84:0b3ab51c8877 507 if((wCount & 0x1f) == 0)\
bogdanm 84:0b3ab51c8877 508 wNBlocks--;\
bogdanm 84:0b3ab51c8877 509 *pdwReg = (uint16_t)((wNBlocks << 10) | 0x8000);\
bogdanm 84:0b3ab51c8877 510 }/* PCD_CALC_BLK32 */
bogdanm 84:0b3ab51c8877 511
bogdanm 84:0b3ab51c8877 512 #define PCD_CALC_BLK2(dwReg,wCount,wNBlocks) {\
bogdanm 84:0b3ab51c8877 513 wNBlocks = wCount >> 1;\
bogdanm 84:0b3ab51c8877 514 if((wCount & 0x1) != 0)\
bogdanm 84:0b3ab51c8877 515 wNBlocks++;\
bogdanm 84:0b3ab51c8877 516 *pdwReg = (uint16_t)(wNBlocks << 10);\
bogdanm 84:0b3ab51c8877 517 }/* PCD_CALC_BLK2 */
bogdanm 84:0b3ab51c8877 518
bogdanm 84:0b3ab51c8877 519 #define PCD_SET_EP_CNT_RX_REG(dwReg,wCount) {\
bogdanm 84:0b3ab51c8877 520 uint16_t wNBlocks;\
bogdanm 84:0b3ab51c8877 521 if(wCount > 62){PCD_CALC_BLK32(dwReg,wCount,wNBlocks);}\
bogdanm 84:0b3ab51c8877 522 else {PCD_CALC_BLK2(dwReg,wCount,wNBlocks);}\
bogdanm 84:0b3ab51c8877 523 }/* PCD_SET_EP_CNT_RX_REG */
bogdanm 84:0b3ab51c8877 524
bogdanm 84:0b3ab51c8877 525 #define PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum,wCount) {\
bogdanm 84:0b3ab51c8877 526 uint16_t *pdwReg = PCD_EP_TX_CNT(USBx, bEpNum); \
bogdanm 84:0b3ab51c8877 527 PCD_SET_EP_CNT_RX_REG(pdwReg, wCount);\
bogdanm 84:0b3ab51c8877 528 }
bogdanm 84:0b3ab51c8877 529 /**
bogdanm 84:0b3ab51c8877 530 * @brief sets counter for the tx/rx buffer.
bogdanm 84:0b3ab51c8877 531 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 532 * @param wCount: Counter value.
bogdanm 84:0b3ab51c8877 533 * @retval None
bogdanm 84:0b3ab51c8877 534 */
bogdanm 84:0b3ab51c8877 535 #define PCD_SET_EP_TX_CNT(USBx, bEpNum,wCount) (*PCD_EP_TX_CNT(USBx, bEpNum) = wCount)
bogdanm 84:0b3ab51c8877 536 #define PCD_SET_EP_RX_CNT(USBx, bEpNum,wCount) {\
bogdanm 84:0b3ab51c8877 537 uint16_t *pdwReg = PCD_EP_RX_CNT(USBx, bEpNum); \
bogdanm 84:0b3ab51c8877 538 PCD_SET_EP_CNT_RX_REG(pdwReg, wCount);\
bogdanm 84:0b3ab51c8877 539 }
bogdanm 84:0b3ab51c8877 540
bogdanm 84:0b3ab51c8877 541 /**
bogdanm 84:0b3ab51c8877 542 * @brief gets counter of the tx buffer.
bogdanm 84:0b3ab51c8877 543 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 544 * @retval Counter value
bogdanm 84:0b3ab51c8877 545 */
bogdanm 84:0b3ab51c8877 546 #define PCD_GET_EP_TX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_TX_CNT(USBx, bEpNum)) & 0x3ff)
bogdanm 84:0b3ab51c8877 547 #define PCD_GET_EP_RX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_RX_CNT(USBx, bEpNum)) & 0x3ff)
bogdanm 84:0b3ab51c8877 548
bogdanm 84:0b3ab51c8877 549 /**
bogdanm 84:0b3ab51c8877 550 * @brief Sets buffer 0/1 address in a double buffer endpoint.
bogdanm 84:0b3ab51c8877 551 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 552 * @param wBuf0Addr: buffer 0 address.
bogdanm 84:0b3ab51c8877 553 * @retval Counter value
bogdanm 84:0b3ab51c8877 554 */
bogdanm 84:0b3ab51c8877 555 #define PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum,wBuf0Addr) {PCD_SET_EP_TX_ADDRESS(USBx, bEpNum, wBuf0Addr);}
bogdanm 84:0b3ab51c8877 556 #define PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum,wBuf1Addr) {PCD_SET_EP_RX_ADDRESS(USBx, bEpNum, wBuf1Addr);}
bogdanm 84:0b3ab51c8877 557
bogdanm 84:0b3ab51c8877 558 /**
bogdanm 84:0b3ab51c8877 559 * @brief Sets addresses in a double buffer endpoint.
bogdanm 84:0b3ab51c8877 560 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 561 * @param wBuf0Addr: buffer 0 address.
bogdanm 84:0b3ab51c8877 562 * @param wBuf1Addr = buffer 1 address.
bogdanm 84:0b3ab51c8877 563 * @retval None
bogdanm 84:0b3ab51c8877 564 */
bogdanm 84:0b3ab51c8877 565 #define PCD_SET_EP_DBUF_ADDR(USBx, bEpNum,wBuf0Addr,wBuf1Addr) { \
bogdanm 84:0b3ab51c8877 566 PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum, wBuf0Addr);\
bogdanm 84:0b3ab51c8877 567 PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum, wBuf1Addr);\
bogdanm 84:0b3ab51c8877 568 } /* PCD_SET_EP_DBUF_ADDR */
bogdanm 84:0b3ab51c8877 569
bogdanm 84:0b3ab51c8877 570 /**
bogdanm 84:0b3ab51c8877 571 * @brief Gets buffer 0/1 address of a double buffer endpoint.
bogdanm 84:0b3ab51c8877 572 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 573 * @retval None
bogdanm 84:0b3ab51c8877 574 */
bogdanm 84:0b3ab51c8877 575 #define PCD_GET_EP_DBUF0_ADDR(USBx, bEpNum) (PCD_GET_EP_TX_ADDRESS(USBx, bEpNum))
bogdanm 84:0b3ab51c8877 576 #define PCD_GET_EP_DBUF1_ADDR(USBx, bEpNum) (PCD_GET_EP_RX_ADDRESS(USBx, bEpNum))
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 * bDir: endpoint dir EP_DBUF_OUT = OUT
bogdanm 84:0b3ab51c8877 582 * EP_DBUF_IN = IN
bogdanm 84:0b3ab51c8877 583 * @param wCount: Counter value
bogdanm 84:0b3ab51c8877 584 * @retval None
bogdanm 84:0b3ab51c8877 585 */
bogdanm 84:0b3ab51c8877 586 #define PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount) { \
bogdanm 84:0b3ab51c8877 587 if(bDir == PCD_EP_DBUF_OUT)\
bogdanm 84:0b3ab51c8877 588 /* OUT endpoint */ \
bogdanm 84:0b3ab51c8877 589 {PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum,wCount);} \
bogdanm 84:0b3ab51c8877 590 else if(bDir == PCD_EP_DBUF_IN)\
bogdanm 84:0b3ab51c8877 591 /* IN endpoint */ \
bogdanm 84:0b3ab51c8877 592 *PCD_EP_TX_CNT(USBx, bEpNum) = (uint32_t)wCount; \
bogdanm 84:0b3ab51c8877 593 } /* SetEPDblBuf0Count*/
bogdanm 84:0b3ab51c8877 594
bogdanm 84:0b3ab51c8877 595 #define PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount) { \
bogdanm 84:0b3ab51c8877 596 if(bDir == PCD_EP_DBUF_OUT)\
bogdanm 84:0b3ab51c8877 597 /* OUT endpoint */ \
bogdanm 84:0b3ab51c8877 598 {PCD_SET_EP_RX_CNT(USBx, bEpNum,wCount);}\
bogdanm 84:0b3ab51c8877 599 else if(bDir == PCD_EP_DBUF_IN)\
bogdanm 84:0b3ab51c8877 600 /* IN endpoint */\
bogdanm 84:0b3ab51c8877 601 *PCD_EP_RX_CNT(USBx, bEpNum) = (uint32_t)wCount; \
bogdanm 84:0b3ab51c8877 602 } /* SetEPDblBuf1Count */
bogdanm 84:0b3ab51c8877 603
bogdanm 84:0b3ab51c8877 604 #define PCD_SET_EP_DBUF_CNT(USBx, bEpNum, bDir, wCount) {\
bogdanm 84:0b3ab51c8877 605 PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount); \
bogdanm 84:0b3ab51c8877 606 PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount); \
bogdanm 84:0b3ab51c8877 607 } /* PCD_SET_EP_DBUF_CNT */
bogdanm 84:0b3ab51c8877 608
bogdanm 84:0b3ab51c8877 609 /**
bogdanm 84:0b3ab51c8877 610 * @brief Gets buffer 0/1 rx/tx counter for double buffering.
bogdanm 84:0b3ab51c8877 611 * @param bEpNum: Endpoint Number.
bogdanm 84:0b3ab51c8877 612 * @retval None
bogdanm 84:0b3ab51c8877 613 */
bogdanm 84:0b3ab51c8877 614 #define PCD_GET_EP_DBUF0_CNT(USBx, bEpNum) (PCD_GET_EP_TX_CNT(USBx, bEpNum))
bogdanm 84:0b3ab51c8877 615 #define PCD_GET_EP_DBUF1_CNT(USBx, bEpNum) (PCD_GET_EP_RX_CNT(USBx, bEpNum))
bogdanm 84:0b3ab51c8877 616
bogdanm 84:0b3ab51c8877 617
bogdanm 84:0b3ab51c8877 618 /**
bogdanm 84:0b3ab51c8877 619 * @}
bogdanm 84:0b3ab51c8877 620 */
bogdanm 84:0b3ab51c8877 621
bogdanm 84:0b3ab51c8877 622 /* Exported functions --------------------------------------------------------*/
bogdanm 84:0b3ab51c8877 623
bogdanm 84:0b3ab51c8877 624 /* Initialization/de-initialization functions **********************************/
bogdanm 84:0b3ab51c8877 625 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 626 HAL_StatusTypeDef HAL_PCD_DeInit (PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 627 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 628 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 629
bogdanm 84:0b3ab51c8877 630 /* I/O operation functions *****************************************************/
bogdanm 84:0b3ab51c8877 631 /* Non-Blocking mode: Interrupt */
bogdanm 84:0b3ab51c8877 632 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 633 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 634 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 635
bogdanm 84:0b3ab51c8877 636 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
bogdanm 84:0b3ab51c8877 637 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
bogdanm 84:0b3ab51c8877 638 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 639 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 640 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 641 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 642 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 643 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
bogdanm 84:0b3ab51c8877 644 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
bogdanm 84:0b3ab51c8877 645 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 646 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 647
bogdanm 84:0b3ab51c8877 648
bogdanm 84:0b3ab51c8877 649
bogdanm 84:0b3ab51c8877 650 /* Peripheral Control functions ************************************************/
bogdanm 84:0b3ab51c8877 651 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 652 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 653 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
bogdanm 84:0b3ab51c8877 654 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
bogdanm 84:0b3ab51c8877 655 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
bogdanm 84:0b3ab51c8877 656 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
bogdanm 84:0b3ab51c8877 657 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
bogdanm 84:0b3ab51c8877 658 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
bogdanm 84:0b3ab51c8877 659 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
bogdanm 84:0b3ab51c8877 660 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
bogdanm 84:0b3ab51c8877 661 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
bogdanm 84:0b3ab51c8877 662 HAL_StatusTypeDef HAL_PCD_ActiveRemoteWakeup(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 663 HAL_StatusTypeDef HAL_PCD_DeActiveRemoteWakeup(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 664 /* Peripheral State functions **************************************************/
bogdanm 84:0b3ab51c8877 665 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
bogdanm 84:0b3ab51c8877 666
bogdanm 84:0b3ab51c8877 667 /**
bogdanm 84:0b3ab51c8877 668 * @}
bogdanm 84:0b3ab51c8877 669 */
bogdanm 84:0b3ab51c8877 670
bogdanm 84:0b3ab51c8877 671 /**
bogdanm 84:0b3ab51c8877 672 * @}
bogdanm 84:0b3ab51c8877 673 */
bogdanm 84:0b3ab51c8877 674
bogdanm 84:0b3ab51c8877 675 #ifdef __cplusplus
bogdanm 84:0b3ab51c8877 676 }
bogdanm 84:0b3ab51c8877 677 #endif
bogdanm 84:0b3ab51c8877 678
bogdanm 84:0b3ab51c8877 679
bogdanm 84:0b3ab51c8877 680 #endif /* __STM32L0xx_HAL_PCD_H */
bogdanm 84:0b3ab51c8877 681
bogdanm 84:0b3ab51c8877 682 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/