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:
99:dbbf35b96557
.

Who changed what in which revision?

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