mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /******************************************************************************
<> 149:156823d33999 2 * @file usbd.h
<> 149:156823d33999 3 * @brief M451 series USB driver header file
<> 149:156823d33999 4 * @version 2.0.0
<> 149:156823d33999 5 * @date 10, January, 2014
<> 149:156823d33999 6 *
<> 149:156823d33999 7 * @note
<> 149:156823d33999 8 * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved.
<> 149:156823d33999 9 ******************************************************************************/
<> 149:156823d33999 10 #ifndef __USBD_H__
<> 149:156823d33999 11 #define __USBD_H__
<> 149:156823d33999 12
<> 149:156823d33999 13 #ifdef __cplusplus
<> 149:156823d33999 14 extern "C"
<> 149:156823d33999 15 {
<> 149:156823d33999 16 #endif
<> 149:156823d33999 17
<> 149:156823d33999 18 /** @addtogroup Standard_Driver Standard Driver
<> 149:156823d33999 19 @{
<> 149:156823d33999 20 */
<> 149:156823d33999 21
<> 149:156823d33999 22 /** @addtogroup USBD_Driver USBD Driver
<> 149:156823d33999 23 @{
<> 149:156823d33999 24 */
<> 149:156823d33999 25
<> 149:156823d33999 26 /** @addtogroup USBD_EXPORTED_STRUCTS USBD Exported Structs
<> 149:156823d33999 27 @{
<> 149:156823d33999 28 */
<> 149:156823d33999 29 typedef struct s_usbd_info
<> 149:156823d33999 30 {
<> 149:156823d33999 31 const uint8_t *gu8DevDesc; /*!< Pointer for USB Device Descriptor */
<> 149:156823d33999 32 const uint8_t *gu8ConfigDesc; /*!< Pointer for USB Configuration Descriptor */
<> 149:156823d33999 33 const uint8_t **gu8StringDesc; /*!< Pointer for USB String Descriptor pointers */
<> 149:156823d33999 34 const uint8_t **gu8HidReportDesc; /*!< Pointer for USB HID Report Descriptor */
<> 149:156823d33999 35 const uint32_t *gu32HidReportSize; /*!< Pointer for HID Report descriptor Size */
<> 149:156823d33999 36 const uint32_t *gu32ConfigHidDescIdx; /*!< Pointer for HID Descriptor start index */
<> 149:156823d33999 37
<> 149:156823d33999 38 } S_USBD_INFO_T;
<> 149:156823d33999 39
<> 149:156823d33999 40 extern const S_USBD_INFO_T gsInfo;
<> 149:156823d33999 41
<> 149:156823d33999 42 /*@}*/ /* end of group USBD_EXPORTED_STRUCTS */
<> 149:156823d33999 43
<> 149:156823d33999 44
<> 149:156823d33999 45
<> 149:156823d33999 46
<> 149:156823d33999 47 /** @addtogroup USBD_EXPORTED_CONSTANTS USBD Exported Constants
<> 149:156823d33999 48 @{
<> 149:156823d33999 49 */
<> 149:156823d33999 50 #define USBD_BUF_BASE (USBD_BASE+0x100)
<> 149:156823d33999 51 #define USBD_MAX_EP 8
<> 149:156823d33999 52
<> 149:156823d33999 53 #define EP0 0 /*!< Endpoint 0 */
<> 149:156823d33999 54 #define EP1 1 /*!< Endpoint 1 */
<> 149:156823d33999 55 #define EP2 2 /*!< Endpoint 2 */
<> 149:156823d33999 56 #define EP3 3 /*!< Endpoint 3 */
<> 149:156823d33999 57 #define EP4 4 /*!< Endpoint 4 */
<> 149:156823d33999 58 #define EP5 5 /*!< Endpoint 5 */
<> 149:156823d33999 59 #define EP6 6 /*!< Endpoint 6 */
<> 149:156823d33999 60 #define EP7 7 /*!< Endpoint 7 */
<> 149:156823d33999 61
<> 149:156823d33999 62
<> 149:156823d33999 63 /*!<USB Request Type */
<> 149:156823d33999 64 #define REQ_STANDARD 0x00
<> 149:156823d33999 65 #define REQ_CLASS 0x20
<> 149:156823d33999 66 #define REQ_VENDOR 0x40
<> 149:156823d33999 67
<> 149:156823d33999 68 /*!<USB Standard Request */
<> 149:156823d33999 69 #define GET_STATUS 0x00
<> 149:156823d33999 70 #define CLEAR_FEATURE 0x01
<> 149:156823d33999 71 #define SET_FEATURE 0x03
<> 149:156823d33999 72 #define SET_ADDRESS 0x05
<> 149:156823d33999 73 #define GET_DESCRIPTOR 0x06
<> 149:156823d33999 74 #define SET_DESCRIPTOR 0x07
<> 149:156823d33999 75 #define GET_CONFIGURATION 0x08
<> 149:156823d33999 76 #define SET_CONFIGURATION 0x09
<> 149:156823d33999 77 #define GET_INTERFACE 0x0A
<> 149:156823d33999 78 #define SET_INTERFACE 0x0B
<> 149:156823d33999 79 #define SYNC_FRAME 0x0C
<> 149:156823d33999 80
<> 149:156823d33999 81 /*!<USB Descriptor Type */
<> 149:156823d33999 82 #define DESC_DEVICE 0x01
<> 149:156823d33999 83 #define DESC_CONFIG 0x02
<> 149:156823d33999 84 #define DESC_STRING 0x03
<> 149:156823d33999 85 #define DESC_INTERFACE 0x04
<> 149:156823d33999 86 #define DESC_ENDPOINT 0x05
<> 149:156823d33999 87 #define DESC_QUALIFIER 0x06
<> 149:156823d33999 88 #define DESC_OTHERSPEED 0x07
<> 149:156823d33999 89
<> 149:156823d33999 90 /*!<USB HID Descriptor Type */
<> 149:156823d33999 91 #define DESC_HID 0x21
<> 149:156823d33999 92 #define DESC_HID_RPT 0x22
<> 149:156823d33999 93
<> 149:156823d33999 94 /*!<USB Descriptor Length */
<> 149:156823d33999 95 #define LEN_DEVICE 18
<> 149:156823d33999 96 #define LEN_CONFIG 9
<> 149:156823d33999 97 #define LEN_INTERFACE 9
<> 149:156823d33999 98 #define LEN_ENDPOINT 7
<> 149:156823d33999 99 #define LEN_HID 9
<> 149:156823d33999 100 #define LEN_CCID 0x36
<> 149:156823d33999 101
<> 149:156823d33999 102 /*!<USB Endpoint Type */
<> 149:156823d33999 103 #define EP_ISO 0x01
<> 149:156823d33999 104 #define EP_BULK 0x02
<> 149:156823d33999 105 #define EP_INT 0x03
<> 149:156823d33999 106
<> 149:156823d33999 107 #define EP_INPUT 0x80
<> 149:156823d33999 108 #define EP_OUTPUT 0x00
<> 149:156823d33999 109
<> 149:156823d33999 110 /*!<USB Feature Selector */
<> 149:156823d33999 111 #define FEATURE_DEVICE_REMOTE_WAKEUP 0x01
<> 149:156823d33999 112 #define FEATURE_ENDPOINT_HALT 0x00
<> 149:156823d33999 113
<> 149:156823d33999 114 /******************************************************************************/
<> 149:156823d33999 115 /* USB Specific Macros */
<> 149:156823d33999 116 /******************************************************************************/
<> 149:156823d33999 117
<> 149:156823d33999 118 #define USBD_WAKEUP_EN USBD_INTEN_WKEN_Msk /*!< USB Wake-up Enable */
<> 149:156823d33999 119 #define USBD_DRVSE0 USBD_SE0_SE0_Msk /*!< Drive SE0 */
<> 149:156823d33999 120
<> 149:156823d33999 121 #define USBD_DPPU_EN USBD_ATTR_DPPUEN_Msk /*!< USB D+ Pull-up Enable */
<> 149:156823d33999 122 #define USBD_PWRDN USBD_ATTR_PWRDN_Msk /*!< PHY Turn-On */
<> 149:156823d33999 123 #define USBD_PHY_EN USBD_ATTR_PHYEN_Msk /*!< PHY Enable */
<> 149:156823d33999 124 #define USBD_USB_EN USBD_ATTR_USBEN_Msk /*!< USB Enable */
<> 149:156823d33999 125
<> 149:156823d33999 126 #define USBD_INT_BUS USBD_INTEN_BUSIEN_Msk /*!< USB Bus Event Interrupt */
<> 149:156823d33999 127 #define USBD_INT_USB USBD_INTEN_USBIEN_Msk /*!< USB Event Interrupt */
<> 149:156823d33999 128 #define USBD_INT_FLDET USBD_INTEN_VBDETIEN_Msk /*!< USB VBUS Detection Interrupt */
<> 149:156823d33999 129 #define USBD_INT_WAKEUP (USBD_INTEN_NEVWKIEN_Msk | USBD_INTEN_WKEN_Msk) /*!< USB No-Event-Wake-Up Interrupt */
<> 149:156823d33999 130
<> 149:156823d33999 131 #define USBD_INTSTS_WAKEUP USBD_INTSTS_NEVWKIF_Msk /*!< USB No-Event-Wake-Up Interrupt Status */
<> 149:156823d33999 132 #define USBD_INTSTS_FLDET USBD_INTSTS_VBDETIF_Msk /*!< USB Float Detect Interrupt Status */
<> 149:156823d33999 133 #define USBD_INTSTS_BUS USBD_INTSTS_BUSIF_Msk /*!< USB Bus Event Interrupt Status */
<> 149:156823d33999 134 #define USBD_INTSTS_USB USBD_INTSTS_USBIF_Msk /*!< USB Event Interrupt Status */
<> 149:156823d33999 135 #define USBD_INTSTS_SETUP USBD_INTSTS_SETUP_Msk /*!< USB Setup Event */
<> 149:156823d33999 136 #define USBD_INTSTS_EP0 USBD_INTSTS_EPEVT0_Msk /*!< USB Endpoint 0 Event */
<> 149:156823d33999 137 #define USBD_INTSTS_EP1 USBD_INTSTS_EPEVT1_Msk /*!< USB Endpoint 1 Event */
<> 149:156823d33999 138 #define USBD_INTSTS_EP2 USBD_INTSTS_EPEVT2_Msk /*!< USB Endpoint 2 Event */
<> 149:156823d33999 139 #define USBD_INTSTS_EP3 USBD_INTSTS_EPEVT3_Msk /*!< USB Endpoint 3 Event */
<> 149:156823d33999 140 #define USBD_INTSTS_EP4 USBD_INTSTS_EPEVT4_Msk /*!< USB Endpoint 4 Event */
<> 149:156823d33999 141 #define USBD_INTSTS_EP5 USBD_INTSTS_EPEVT5_Msk /*!< USB Endpoint 5 Event */
<> 149:156823d33999 142 #define USBD_INTSTS_EP6 USBD_INTSTS_EPEVT6_Msk /*!< USB Endpoint 6 Event */
<> 149:156823d33999 143 #define USBD_INTSTS_EP7 USBD_INTSTS_EPEVT7_Msk /*!< USB Endpoint 7 Event */
<> 149:156823d33999 144
<> 149:156823d33999 145 #define USBD_STATE_USBRST USBD_ATTR_USBRST_Msk /*!< USB Bus Reset */
<> 149:156823d33999 146 #define USBD_STATE_SUSPEND USBD_ATTR_SUSPEND_Msk /*!< USB Bus Suspend */
<> 149:156823d33999 147 #define USBD_STATE_RESUME USBD_ATTR_RESUME_Msk /*!< USB Bus Resume */
<> 149:156823d33999 148 #define USBD_STATE_TIMEOUT USBD_ATTR_TOUT_Msk /*!< USB Bus Timeout */
<> 149:156823d33999 149
<> 149:156823d33999 150 #define USBD_CFGP_SSTALL USBD_CFGP_SSTALL_Msk /*!< Set Stall */
<> 149:156823d33999 151 #define USBD_CFG_CSTALL USBD_CFG_CSTALL_Msk /*!< Clear Stall */
<> 149:156823d33999 152
<> 149:156823d33999 153 #define USBD_CFG_EPMODE_DISABLE (0ul << USBD_CFG_STATE_Pos)/*!< Endpoint Disable */
<> 149:156823d33999 154 #define USBD_CFG_EPMODE_OUT (1ul << USBD_CFG_STATE_Pos)/*!< Out Endpoint */
<> 149:156823d33999 155 #define USBD_CFG_EPMODE_IN (2ul << USBD_CFG_STATE_Pos)/*!< In Endpoint */
<> 149:156823d33999 156 #define USBD_CFG_TYPE_ISO (1ul << USBD_CFG_ISOCH_Pos) /*!< Isochronous */
<> 149:156823d33999 157
<> 149:156823d33999 158
<> 149:156823d33999 159
<> 149:156823d33999 160 /*@}*/ /* end of group USBD_EXPORTED_CONSTANTS */
<> 149:156823d33999 161
<> 149:156823d33999 162
<> 149:156823d33999 163 /** @addtogroup USBD_EXPORTED_FUNCTIONS USBD Exported Functions
<> 149:156823d33999 164 @{
<> 149:156823d33999 165 */
<> 149:156823d33999 166
<> 149:156823d33999 167 /**
<> 149:156823d33999 168 * @brief Compare two input numbers and return maximum one.
<> 149:156823d33999 169 *
<> 149:156823d33999 170 * @param[in] a First number to be compared.
<> 149:156823d33999 171 * @param[in] b Second number to be compared.
<> 149:156823d33999 172 *
<> 149:156823d33999 173 * @return Maximum value between a and b.
<> 149:156823d33999 174 *
<> 149:156823d33999 175 * @details If a > b, then return a. Otherwise, return b.
<> 149:156823d33999 176 */
<> 149:156823d33999 177 #define Maximum(a,b) ((a)>(b) ? (a) : (b))
<> 149:156823d33999 178
<> 149:156823d33999 179
<> 149:156823d33999 180 /**
<> 149:156823d33999 181 * @brief Compare two input numbers and return minimum one
<> 149:156823d33999 182 *
<> 149:156823d33999 183 * @param[in] a First number to be compared
<> 149:156823d33999 184 * @param[in] b Second number to be compared
<> 149:156823d33999 185 *
<> 149:156823d33999 186 * @return Minimum value between a and b
<> 149:156823d33999 187 *
<> 149:156823d33999 188 * @details If a < b, then return a. Otherwise, return b.
<> 149:156823d33999 189 */
<> 149:156823d33999 190 #define Minimum(a,b) ((a)<(b) ? (a) : (b))
<> 149:156823d33999 191
<> 149:156823d33999 192
<> 149:156823d33999 193 /**
<> 149:156823d33999 194 * @brief Enable USB
<> 149:156823d33999 195 *
<> 149:156823d33999 196 * @param None
<> 149:156823d33999 197 *
<> 149:156823d33999 198 * @return None
<> 149:156823d33999 199 *
<> 149:156823d33999 200 * @details To set USB ATTR control register to enable USB and PHY.
<> 149:156823d33999 201 *
<> 149:156823d33999 202 */
<> 149:156823d33999 203 #define USBD_ENABLE_USB() ((uint32_t)(USBD->ATTR |= (USBD_USB_EN|USBD_PHY_EN)))
<> 149:156823d33999 204
<> 149:156823d33999 205 /**
<> 149:156823d33999 206 * @brief Disable USB
<> 149:156823d33999 207 *
<> 149:156823d33999 208 * @param None
<> 149:156823d33999 209 *
<> 149:156823d33999 210 * @return None
<> 149:156823d33999 211 *
<> 149:156823d33999 212 * @details To set USB ATTR control register to disable USB.
<> 149:156823d33999 213 *
<> 149:156823d33999 214 */
<> 149:156823d33999 215 #define USBD_DISABLE_USB() ((uint32_t)(USBD->ATTR &= ~USBD_USB_EN))
<> 149:156823d33999 216
<> 149:156823d33999 217 /**
<> 149:156823d33999 218 * @brief Enable USB PHY
<> 149:156823d33999 219 *
<> 149:156823d33999 220 * @param None
<> 149:156823d33999 221 *
<> 149:156823d33999 222 * @return None
<> 149:156823d33999 223 *
<> 149:156823d33999 224 * @details To set USB ATTR control register to enable USB PHY.
<> 149:156823d33999 225 *
<> 149:156823d33999 226 */
<> 149:156823d33999 227 #define USBD_ENABLE_PHY() ((uint32_t)(USBD->ATTR |= USBD_PHY_EN))
<> 149:156823d33999 228
<> 149:156823d33999 229 /**
<> 149:156823d33999 230 * @brief Disable USB PHY
<> 149:156823d33999 231 *
<> 149:156823d33999 232 * @param None
<> 149:156823d33999 233 *
<> 149:156823d33999 234 * @return None
<> 149:156823d33999 235 *
<> 149:156823d33999 236 * @details To set USB ATTR control register to disable USB PHY.
<> 149:156823d33999 237 *
<> 149:156823d33999 238 */
<> 149:156823d33999 239 #define USBD_DISABLE_PHY() ((uint32_t)(USBD->ATTR &= ~USBD_PHY_EN))
<> 149:156823d33999 240
<> 149:156823d33999 241 /**
<> 149:156823d33999 242 * @brief Enable SE0. Force USB PHY transceiver to drive SE0.
<> 149:156823d33999 243 *
<> 149:156823d33999 244 * @param None
<> 149:156823d33999 245 *
<> 149:156823d33999 246 * @return None
<> 149:156823d33999 247 *
<> 149:156823d33999 248 * @details Set DRVSE0 bit of USB_DRVSE0 register to enable software-disconnect function. Force USB PHY transceiver to drive SE0 to bus.
<> 149:156823d33999 249 *
<> 149:156823d33999 250 */
<> 149:156823d33999 251 #define USBD_SET_SE0() ((uint32_t)(USBD->SE0 |= USBD_DRVSE0))
<> 149:156823d33999 252
<> 149:156823d33999 253 /**
<> 149:156823d33999 254 * @brief Disable SE0
<> 149:156823d33999 255 *
<> 149:156823d33999 256 * @param None
<> 149:156823d33999 257 *
<> 149:156823d33999 258 * @return None
<> 149:156823d33999 259 *
<> 149:156823d33999 260 * @details Clear DRVSE0 bit of USB_DRVSE0 register to disable software-disconnect function.
<> 149:156823d33999 261 *
<> 149:156823d33999 262 */
<> 149:156823d33999 263 #define USBD_CLR_SE0() ((uint32_t)(USBD->SE0 &= ~USBD_DRVSE0))
<> 149:156823d33999 264
<> 149:156823d33999 265 /**
<> 149:156823d33999 266 * @brief Set USB device address
<> 149:156823d33999 267 *
<> 149:156823d33999 268 * @param[in] addr The USB device address.
<> 149:156823d33999 269 *
<> 149:156823d33999 270 * @return None
<> 149:156823d33999 271 *
<> 149:156823d33999 272 * @details Write USB device address to USB_FADDR register.
<> 149:156823d33999 273 *
<> 149:156823d33999 274 */
<> 149:156823d33999 275 #define USBD_SET_ADDR(addr) (USBD->FADDR = (addr))
<> 149:156823d33999 276
<> 149:156823d33999 277 /**
<> 149:156823d33999 278 * @brief Get USB device address
<> 149:156823d33999 279 *
<> 149:156823d33999 280 * @param None
<> 149:156823d33999 281 *
<> 149:156823d33999 282 * @return USB device address
<> 149:156823d33999 283 *
<> 149:156823d33999 284 * @details Read USB_FADDR register to get USB device address.
<> 149:156823d33999 285 *
<> 149:156823d33999 286 */
<> 149:156823d33999 287 #define USBD_GET_ADDR() ((uint32_t)(USBD->FADDR))
<> 149:156823d33999 288
<> 149:156823d33999 289 /**
<> 149:156823d33999 290 * @brief Enable USB interrupt function
<> 149:156823d33999 291 *
<> 149:156823d33999 292 * @param[in] intr The combination of the specified interrupt enable bits.
<> 149:156823d33999 293 * Each bit corresponds to a interrupt enable bit.
<> 149:156823d33999 294 * This parameter decides which interrupts will be enabled.
<> 149:156823d33999 295 * (USBD_INT_WAKEUP, USBD_INT_FLDET, USBD_INT_USB, USBD_INT_BUS)
<> 149:156823d33999 296 *
<> 149:156823d33999 297 * @return None
<> 149:156823d33999 298 *
<> 149:156823d33999 299 * @details Enable USB related interrupt functions specified by intr parameter.
<> 149:156823d33999 300 *
<> 149:156823d33999 301 */
<> 149:156823d33999 302 #define USBD_ENABLE_INT(intr) (USBD->INTEN |= (intr))
<> 149:156823d33999 303
<> 149:156823d33999 304 /**
<> 149:156823d33999 305 * @brief Get interrupt status
<> 149:156823d33999 306 *
<> 149:156823d33999 307 * @param None
<> 149:156823d33999 308 *
<> 149:156823d33999 309 * @return The value of USB_INTSTS register
<> 149:156823d33999 310 *
<> 149:156823d33999 311 * @details Return all interrupt flags of USB_INTSTS register.
<> 149:156823d33999 312 *
<> 149:156823d33999 313 */
<> 149:156823d33999 314 #define USBD_GET_INT_FLAG() ((uint32_t)(USBD->INTSTS))
<> 149:156823d33999 315
<> 149:156823d33999 316 /**
<> 149:156823d33999 317 * @brief Clear USB interrupt flag
<> 149:156823d33999 318 *
<> 149:156823d33999 319 * @param[in] flag The combination of the specified interrupt flags.
<> 149:156823d33999 320 * Each bit corresponds to a interrupt source.
<> 149:156823d33999 321 * This parameter decides which interrupt flags will be cleared.
<> 149:156823d33999 322 * (USBD_INTSTS_WAKEUP, USBD_INTSTS_FLDET, USBD_INTSTS_BUS, USBD_INTSTS_USB)
<> 149:156823d33999 323 *
<> 149:156823d33999 324 * @return None
<> 149:156823d33999 325 *
<> 149:156823d33999 326 * @details Clear USB related interrupt flags specified by flag parameter.
<> 149:156823d33999 327 *
<> 149:156823d33999 328 */
<> 149:156823d33999 329 #define USBD_CLR_INT_FLAG(flag) (USBD->INTSTS = (flag))
<> 149:156823d33999 330
<> 149:156823d33999 331 /**
<> 149:156823d33999 332 * @brief Get endpoint status
<> 149:156823d33999 333 *
<> 149:156823d33999 334 * @param None
<> 149:156823d33999 335 *
<> 149:156823d33999 336 * @return The value of USB_EPSTS register.
<> 149:156823d33999 337 *
<> 149:156823d33999 338 * @details Return all endpoint status.
<> 149:156823d33999 339 *
<> 149:156823d33999 340 */
<> 149:156823d33999 341 #define USBD_GET_EP_FLAG() ((uint32_t)(USBD->EPSTS))
<> 149:156823d33999 342
<> 149:156823d33999 343 /**
<> 149:156823d33999 344 * @brief Get USB bus state
<> 149:156823d33999 345 *
<> 149:156823d33999 346 * @param None
<> 149:156823d33999 347 *
<> 149:156823d33999 348 * @return The value of USB_ATTR[3:0].
<> 149:156823d33999 349 * Bit 0 indicates USB bus reset status.
<> 149:156823d33999 350 * Bit 1 indicates USB bus suspend status.
<> 149:156823d33999 351 * Bit 2 indicates USB bus resume status.
<> 149:156823d33999 352 * Bit 3 indicates USB bus time-out status.
<> 149:156823d33999 353 *
<> 149:156823d33999 354 * @details Return USB_ATTR[3:0] for USB bus events.
<> 149:156823d33999 355 *
<> 149:156823d33999 356 */
<> 149:156823d33999 357 #define USBD_GET_BUS_STATE() ((uint32_t)(USBD->ATTR & 0xf))
<> 149:156823d33999 358
<> 149:156823d33999 359 /**
<> 149:156823d33999 360 * @brief Check cable connection state
<> 149:156823d33999 361 *
<> 149:156823d33999 362 * @param None
<> 149:156823d33999 363 *
<> 149:156823d33999 364 * @retval 0 USB cable is not attached.
<> 149:156823d33999 365 * @retval 1 USB cable is attached.
<> 149:156823d33999 366 *
<> 149:156823d33999 367 * @details Check the connection state by FLDET bit of USB_FLDET register.
<> 149:156823d33999 368 *
<> 149:156823d33999 369 */
<> 149:156823d33999 370 #define USBD_IS_ATTACHED() ((uint32_t)(USBD->VBUSDET & USBD_VBUSDET_VBUSDET_Msk))
<> 149:156823d33999 371
<> 149:156823d33999 372 /**
<> 149:156823d33999 373 * @brief Stop USB transaction of the specified endpoint ID
<> 149:156823d33999 374 *
<> 149:156823d33999 375 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 376 *
<> 149:156823d33999 377 * @return None
<> 149:156823d33999 378 *
<> 149:156823d33999 379 * @details Write 1 to CLRRDY bit of USB_CFGPx register to stop USB transaction of the specified endpoint ID.
<> 149:156823d33999 380 *
<> 149:156823d33999 381 */
<> 149:156823d33999 382 #define USBD_STOP_TRANSACTION(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_CLRRDY_Msk)
<> 149:156823d33999 383
<> 149:156823d33999 384 /**
<> 149:156823d33999 385 * @brief Set USB DATA1 PID for the specified endpoint ID
<> 149:156823d33999 386 *
<> 149:156823d33999 387 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 388 *
<> 149:156823d33999 389 * @return None
<> 149:156823d33999 390 *
<> 149:156823d33999 391 * @details Set DSQ_SYNC bit of USB_CFGx register to specify the DATA1 PID for the following IN token transaction.
<> 149:156823d33999 392 * Base on this setting, hardware will toggle PID between DATA0 and DATA1 automatically for IN token transactions.
<> 149:156823d33999 393 *
<> 149:156823d33999 394 */
<> 149:156823d33999 395 #define USBD_SET_DATA1(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_DSQSYNC_Msk)
<> 149:156823d33999 396
<> 149:156823d33999 397 /**
<> 149:156823d33999 398 * @brief Set USB DATA0 PID for the specified endpoint ID
<> 149:156823d33999 399 *
<> 149:156823d33999 400 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 401 *
<> 149:156823d33999 402 * @return None
<> 149:156823d33999 403 *
<> 149:156823d33999 404 * @details Clear DSQ_SYNC bit of USB_CFGx register to specify the DATA0 PID for the following IN token transaction.
<> 149:156823d33999 405 * Base on this setting, hardware will toggle PID between DATA0 and DATA1 automatically for IN token transactions.
<> 149:156823d33999 406 *
<> 149:156823d33999 407 */
<> 149:156823d33999 408 #define USBD_SET_DATA0(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= (~USBD_CFG_DSQSYNC_Msk))
<> 149:156823d33999 409
<> 149:156823d33999 410 /**
<> 149:156823d33999 411 * @brief Set USB payload size (IN data)
<> 149:156823d33999 412 *
<> 149:156823d33999 413 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 414 *
<> 149:156823d33999 415 * @param[in] size The transfer length.
<> 149:156823d33999 416 *
<> 149:156823d33999 417 * @return None
<> 149:156823d33999 418 *
<> 149:156823d33999 419 * @details This macro will write the transfer length to USB_MXPLDx register for IN data transaction.
<> 149:156823d33999 420 *
<> 149:156823d33999 421 */
<> 149:156823d33999 422 #define USBD_SET_PAYLOAD_LEN(ep, size) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))) = (size))
<> 149:156823d33999 423
<> 149:156823d33999 424 /**
<> 149:156823d33999 425 * @brief Get USB payload size (OUT data)
<> 149:156823d33999 426 *
<> 149:156823d33999 427 * @param[in] ep The USB endpoint ID. M451 Series supports 8 endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 428 *
<> 149:156823d33999 429 * @return The value of USB_MXPLDx register.
<> 149:156823d33999 430 *
<> 149:156823d33999 431 * @details Get the data length of OUT data transaction by reading USB_MXPLDx register.
<> 149:156823d33999 432 *
<> 149:156823d33999 433 */
<> 149:156823d33999 434 #define USBD_GET_PAYLOAD_LEN(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))))
<> 149:156823d33999 435
<> 149:156823d33999 436 /**
<> 149:156823d33999 437 * @brief Configure endpoint
<> 149:156823d33999 438 *
<> 149:156823d33999 439 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 440 *
<> 149:156823d33999 441 * @param[in] config The USB configuration.
<> 149:156823d33999 442 *
<> 149:156823d33999 443 * @return None
<> 149:156823d33999 444 *
<> 149:156823d33999 445 * @details This macro will write config parameter to USB_CFGx register of specified endpoint ID.
<> 149:156823d33999 446 *
<> 149:156823d33999 447 */
<> 149:156823d33999 448 #define USBD_CONFIG_EP(ep, config) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) = (config))
<> 149:156823d33999 449
<> 149:156823d33999 450 /**
<> 149:156823d33999 451 * @brief Set USB endpoint buffer
<> 149:156823d33999 452 *
<> 149:156823d33999 453 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 454 *
<> 149:156823d33999 455 * @param[in] offset The SRAM offset.
<> 149:156823d33999 456 *
<> 149:156823d33999 457 * @return None
<> 149:156823d33999 458 *
<> 149:156823d33999 459 * @details This macro will set the SRAM offset for the specified endpoint ID.
<> 149:156823d33999 460 *
<> 149:156823d33999 461 */
<> 149:156823d33999 462 #define USBD_SET_EP_BUF_ADDR(ep, offset) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))) = (offset))
<> 149:156823d33999 463
<> 149:156823d33999 464 /**
<> 149:156823d33999 465 * @brief Get the offset of the specified USB endpoint buffer
<> 149:156823d33999 466 *
<> 149:156823d33999 467 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 468 *
<> 149:156823d33999 469 * @return The offset of the specified endpoint buffer.
<> 149:156823d33999 470 *
<> 149:156823d33999 471 * @details This macro will return the SRAM offset of the specified endpoint ID.
<> 149:156823d33999 472 *
<> 149:156823d33999 473 */
<> 149:156823d33999 474 #define USBD_GET_EP_BUF_ADDR(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))))
<> 149:156823d33999 475
<> 149:156823d33999 476 /**
<> 149:156823d33999 477 * @brief Set USB endpoint stall state
<> 149:156823d33999 478 *
<> 149:156823d33999 479 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 480 *
<> 149:156823d33999 481 * @return None
<> 149:156823d33999 482 *
<> 149:156823d33999 483 * @details Set USB endpoint stall state for the specified endpoint ID. Endpoint will respond STALL token automatically.
<> 149:156823d33999 484 *
<> 149:156823d33999 485 */
<> 149:156823d33999 486 #define USBD_SET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_SSTALL_Msk)
<> 149:156823d33999 487
<> 149:156823d33999 488 /**
<> 149:156823d33999 489 * @brief Clear USB endpoint stall state
<> 149:156823d33999 490 *
<> 149:156823d33999 491 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 492 *
<> 149:156823d33999 493 * @return None
<> 149:156823d33999 494 *
<> 149:156823d33999 495 * @details Clear USB endpoint stall state for the specified endpoint ID. Endpoint will respond ACK/NAK token.
<> 149:156823d33999 496 */
<> 149:156823d33999 497 #define USBD_CLR_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) &= ~USBD_CFGP_SSTALL_Msk)
<> 149:156823d33999 498
<> 149:156823d33999 499 /**
<> 149:156823d33999 500 * @brief Get USB endpoint stall state
<> 149:156823d33999 501 *
<> 149:156823d33999 502 * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7.
<> 149:156823d33999 503 *
<> 149:156823d33999 504 * @retval 0 USB endpoint is not stalled.
<> 149:156823d33999 505 * @retval Others USB endpoint is stalled.
<> 149:156823d33999 506 *
<> 149:156823d33999 507 * @details Get USB endpoint stall state of the specified endpoint ID.
<> 149:156823d33999 508 *
<> 149:156823d33999 509 */
<> 149:156823d33999 510 #define USBD_GET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) & USBD_CFGP_SSTALL_Msk)
<> 149:156823d33999 511
<> 149:156823d33999 512 /**
<> 149:156823d33999 513 * @brief To support byte access between USB SRAM and system SRAM
<> 149:156823d33999 514 *
<> 149:156823d33999 515 * @param[in] dest Destination pointer.
<> 149:156823d33999 516 *
<> 149:156823d33999 517 * @param[in] src Source pointer.
<> 149:156823d33999 518 *
<> 149:156823d33999 519 * @param[in] size Byte count.
<> 149:156823d33999 520 *
<> 149:156823d33999 521 * @return None
<> 149:156823d33999 522 *
<> 149:156823d33999 523 * @details This function will copy the number of data specified by size and src parameters to the address specified by dest parameter.
<> 149:156823d33999 524 *
<> 149:156823d33999 525 */
<> 149:156823d33999 526 static __INLINE void USBD_MemCopy(uint8_t *dest, uint8_t *src, int32_t size)
<> 149:156823d33999 527 {
<> 149:156823d33999 528 while(size--) *dest++ = *src++;
<> 149:156823d33999 529 }
<> 149:156823d33999 530
<> 149:156823d33999 531
<> 149:156823d33999 532 /**
<> 149:156823d33999 533 * @brief Set USB endpoint stall state
<> 149:156823d33999 534 *
<> 149:156823d33999 535 * @param[in] epnum USB endpoint number
<> 149:156823d33999 536 *
<> 149:156823d33999 537 * @return None
<> 149:156823d33999 538 *
<> 149:156823d33999 539 * @details Set USB endpoint stall state. Endpoint will respond STALL token automatically.
<> 149:156823d33999 540 *
<> 149:156823d33999 541 */
<> 149:156823d33999 542 static __INLINE void USBD_SetStall(uint8_t epnum)
<> 149:156823d33999 543 {
<> 149:156823d33999 544 uint32_t u32CfgAddr;
<> 149:156823d33999 545 uint32_t u32Cfg;
<> 149:156823d33999 546 int i;
<> 149:156823d33999 547
<> 149:156823d33999 548 for(i = 0; i < USBD_MAX_EP; i++)
<> 149:156823d33999 549 {
<> 149:156823d33999 550 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFG; /* USBD_CFG0 */
<> 149:156823d33999 551 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
<> 149:156823d33999 552
<> 149:156823d33999 553 if((u32Cfg & 0xf) == epnum)
<> 149:156823d33999 554 {
<> 149:156823d33999 555 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFGP; /* USBD_CFGP0 */
<> 149:156823d33999 556 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
<> 149:156823d33999 557
<> 149:156823d33999 558 *((__IO uint32_t *)(u32CfgAddr)) = (u32Cfg | USBD_CFGP_SSTALL);
<> 149:156823d33999 559 break;
<> 149:156823d33999 560 }
<> 149:156823d33999 561 }
<> 149:156823d33999 562 }
<> 149:156823d33999 563
<> 149:156823d33999 564 /**
<> 149:156823d33999 565 * @brief Clear USB endpoint stall state
<> 149:156823d33999 566 *
<> 149:156823d33999 567 * @param[in] epnum USB endpoint number
<> 149:156823d33999 568 *
<> 149:156823d33999 569 * @return None
<> 149:156823d33999 570 *
<> 149:156823d33999 571 * @details Clear USB endpoint stall state. Endpoint will respond ACK/NAK token.
<> 149:156823d33999 572 */
<> 149:156823d33999 573 static __INLINE void USBD_ClearStall(uint8_t epnum)
<> 149:156823d33999 574 {
<> 149:156823d33999 575 uint32_t u32CfgAddr;
<> 149:156823d33999 576 uint32_t u32Cfg;
<> 149:156823d33999 577 int i;
<> 149:156823d33999 578
<> 149:156823d33999 579 for(i = 0; i < USBD_MAX_EP; i++)
<> 149:156823d33999 580 {
<> 149:156823d33999 581 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFG; /* USBD_CFG0 */
<> 149:156823d33999 582 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
<> 149:156823d33999 583
<> 149:156823d33999 584 if((u32Cfg & 0xf) == epnum)
<> 149:156823d33999 585 {
<> 149:156823d33999 586 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFGP; /* USBD_CFGP0 */
<> 149:156823d33999 587 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
<> 149:156823d33999 588
<> 149:156823d33999 589 *((__IO uint32_t *)(u32CfgAddr)) = (u32Cfg & ~USBD_CFGP_SSTALL);
<> 149:156823d33999 590 break;
<> 149:156823d33999 591 }
<> 149:156823d33999 592 }
<> 149:156823d33999 593 }
<> 149:156823d33999 594
<> 149:156823d33999 595 /**
<> 149:156823d33999 596 * @brief Get USB endpoint stall state
<> 149:156823d33999 597 *
<> 149:156823d33999 598 * @param[in] epnum USB endpoint number
<> 149:156823d33999 599 *
<> 149:156823d33999 600 * @retval 0 USB endpoint is not stalled.
<> 149:156823d33999 601 * @retval Others USB endpoint is stalled.
<> 149:156823d33999 602 *
<> 149:156823d33999 603 * @details Get USB endpoint stall state.
<> 149:156823d33999 604 *
<> 149:156823d33999 605 */
<> 149:156823d33999 606 static __INLINE uint32_t USBD_GetStall(uint8_t epnum)
<> 149:156823d33999 607 {
<> 149:156823d33999 608 uint32_t u32CfgAddr;
<> 149:156823d33999 609 uint32_t u32Cfg;
<> 149:156823d33999 610 int i;
<> 149:156823d33999 611
<> 149:156823d33999 612 for(i = 0; i < USBD_MAX_EP; i++)
<> 149:156823d33999 613 {
<> 149:156823d33999 614 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFG; /* USBD_CFG0 */
<> 149:156823d33999 615 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
<> 149:156823d33999 616
<> 149:156823d33999 617 if((u32Cfg & 0xf) == epnum)
<> 149:156823d33999 618 {
<> 149:156823d33999 619 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFGP; /* USBD_CFGP0 */
<> 149:156823d33999 620 break;
<> 149:156823d33999 621 }
<> 149:156823d33999 622 }
<> 149:156823d33999 623
<> 149:156823d33999 624 return ((*((__IO uint32_t *)(u32CfgAddr))) & USBD_CFGP_SSTALL);
<> 149:156823d33999 625 }
<> 149:156823d33999 626
<> 149:156823d33999 627
<> 149:156823d33999 628 extern volatile uint8_t g_usbd_RemoteWakeupEn;
<> 149:156823d33999 629
<> 149:156823d33999 630
<> 149:156823d33999 631 typedef void (*VENDOR_REQ)(void); /*!< Functional pointer type definition for Vendor class */
<> 149:156823d33999 632 typedef void (*CLASS_REQ)(void); /*!< Functional pointer type declaration for USB class request callback handler */
<> 149:156823d33999 633 typedef void (*SET_INTERFACE_REQ)(void); /*!< Functional pointer type declaration for USB set interface request callback handler */
<> 149:156823d33999 634 typedef void (*SET_CONFIG_CB)(void); /*!< Functional pointer type declaration for USB set configuration request callback handler */
<> 149:156823d33999 635
<> 149:156823d33999 636
<> 149:156823d33999 637 /*--------------------------------------------------------------------*/
<> 149:156823d33999 638 void USBD_Open(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface);
<> 149:156823d33999 639 void USBD_Start(void);
<> 149:156823d33999 640 void USBD_GetSetupPacket(uint8_t *buf);
<> 149:156823d33999 641 void USBD_ProcessSetupPacket(void);
<> 149:156823d33999 642 void USBD_StandardRequest(void);
<> 149:156823d33999 643 void USBD_PrepareCtrlIn(uint8_t *pu8Buf, uint32_t u32Size);
<> 149:156823d33999 644 void USBD_CtrlIn(void);
<> 149:156823d33999 645 void USBD_PrepareCtrlOut(uint8_t *pu8Buf, uint32_t u32Size);
<> 149:156823d33999 646 void USBD_CtrlOut(void);
<> 149:156823d33999 647 void USBD_SwReset(void);
<> 149:156823d33999 648 void USBD_SetVendorRequest(VENDOR_REQ pfnVendorReq);
<> 149:156823d33999 649 void USBD_SetConfigCallback(SET_CONFIG_CB pfnSetConfigCallback);
<> 149:156823d33999 650 void USBD_LockEpStall(uint32_t u32EpBitmap);
<> 149:156823d33999 651
<> 149:156823d33999 652 /*@}*/ /* end of group USBD_EXPORTED_FUNCTIONS */
<> 149:156823d33999 653
<> 149:156823d33999 654 /*@}*/ /* end of group USBD_Driver */
<> 149:156823d33999 655
<> 149:156823d33999 656 /*@}*/ /* end of group Standard_Driver */
<> 149:156823d33999 657
<> 149:156823d33999 658 #ifdef __cplusplus
<> 149:156823d33999 659 }
<> 149:156823d33999 660 #endif
<> 149:156823d33999 661
<> 149:156823d33999 662 #endif //__USBD_H__
<> 149:156823d33999 663
<> 149:156823d33999 664 /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/