my fork

Dependents:   Nucleo_blueNRG

Fork of mbed by mbed official

Committer:
Kojto
Date:
Tue Oct 28 16:40:41 2014 +0000
Revision:
90:cb3d968589d8
Child:
93:e188a91d3eaa
Release 90 of the mbed library

Changes:

- Freescale KSDK update (v1.0)
- K22 - new target addition
- KL43Z - new target addition
- Nucleo F091RC - new target addition
- Nucleo L152RE - STM32Cube driver
- Nordic - Softdevice v7.1.0
- Nvic files - BSD License
- LPC824 - various HAL fixes
- Nucleo F411RE - CMSIS - IAR files

Who changed what in which revision?

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