Fork of the official mbed C/C SDK provides the software platform and libraries to build your applications for RenBED.

Dependents:   1-RenBuggyTimed RenBED_RGB RenBED_RGB_PWM RenBED_RGB

Fork of mbed by mbed official

Committer:
elijahorr
Date:
Thu Apr 14 07:28:54 2016 +0000
Revision:
121:672067c3ada4
Parent:
93:e188a91d3eaa
.

Who changed what in which revision?

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