DHT11

Committer:
jhon309
Date:
Thu Aug 13 00:21:57 2015 +0000
Revision:
0:c52df770855b
DHT11

Who changed what in which revision?

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