Fork of the official USBDevice library
Fork of USBDevice by
USBDevice/targets/TARGET_Silicon_Labs/inc/em_usbtypes.h@76:f0fd8d911b24, 2017-04-28 (annotated)
- Committer:
- screamer
- Date:
- Fri Apr 28 17:01:10 2017 +0000
- Branch:
- device-files
- Revision:
- 76:f0fd8d911b24
- Parent:
- USBDevice/TARGET_Silicon_Labs/inc/em_usbtypes.h@59:2af474687369
Changed the layout of USBDevice implementation for various targets to match mbed-os/targets. This also reduces the amount of files being compiled as USBDevice code for other targets is not compiled.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 59:2af474687369 | 1 | /***************************************************************************//** |
mbed_official | 59:2af474687369 | 2 | * @file em_usbtypes.h |
mbed_official | 59:2af474687369 | 3 | * @brief USB protocol stack library, internal type definitions. |
mbed_official | 59:2af474687369 | 4 | * @version 3.20.14 |
mbed_official | 59:2af474687369 | 5 | ******************************************************************************* |
mbed_official | 59:2af474687369 | 6 | * @section License |
mbed_official | 59:2af474687369 | 7 | * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b> |
mbed_official | 59:2af474687369 | 8 | ******************************************************************************* |
mbed_official | 59:2af474687369 | 9 | * |
mbed_official | 59:2af474687369 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 59:2af474687369 | 11 | * you may not use this file except in compliance with the License. |
mbed_official | 59:2af474687369 | 12 | * You may obtain a copy of the License at |
mbed_official | 59:2af474687369 | 13 | * |
mbed_official | 59:2af474687369 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 59:2af474687369 | 15 | * |
mbed_official | 59:2af474687369 | 16 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 59:2af474687369 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 59:2af474687369 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 59:2af474687369 | 19 | * See the License for the specific language governing permissions and |
mbed_official | 59:2af474687369 | 20 | * limitations under the License. |
mbed_official | 59:2af474687369 | 21 | * |
mbed_official | 59:2af474687369 | 22 | ******************************************************************************/ |
mbed_official | 59:2af474687369 | 23 | |
mbed_official | 59:2af474687369 | 24 | #ifndef __EM_USBTYPES_H |
mbed_official | 59:2af474687369 | 25 | #define __EM_USBTYPES_H |
mbed_official | 59:2af474687369 | 26 | |
mbed_official | 59:2af474687369 | 27 | #include "em_device.h" |
mbed_official | 59:2af474687369 | 28 | #if defined( USB_PRESENT ) && ( USB_COUNT == 1 ) |
mbed_official | 59:2af474687369 | 29 | #include "em_usb.h" |
mbed_official | 59:2af474687369 | 30 | #if defined( USB_DEVICE ) || defined( USB_HOST ) |
mbed_official | 59:2af474687369 | 31 | |
mbed_official | 59:2af474687369 | 32 | #ifdef __cplusplus |
mbed_official | 59:2af474687369 | 33 | extern "C" { |
mbed_official | 59:2af474687369 | 34 | #endif |
mbed_official | 59:2af474687369 | 35 | |
mbed_official | 59:2af474687369 | 36 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
mbed_official | 59:2af474687369 | 37 | |
mbed_official | 59:2af474687369 | 38 | /* Limits imposed by the USB peripheral */ |
mbed_official | 59:2af474687369 | 39 | #define NP_RX_QUE_DEPTH 8 |
mbed_official | 59:2af474687369 | 40 | #define HP_RX_QUE_DEPTH 8 |
mbed_official | 59:2af474687369 | 41 | #define MAX_XFER_LEN 524287L /* 2^19 - 1 bytes */ |
mbed_official | 59:2af474687369 | 42 | #define MAX_PACKETS_PR_XFER 1023 /* 2^10 - 1 packets */ |
mbed_official | 59:2af474687369 | 43 | #if defined( _USB_DIEPTXF6_MASK ) |
mbed_official | 59:2af474687369 | 44 | #define MAX_NUM_TX_FIFOS 6 /* In addition to EP0 Tx FIFO */ |
mbed_official | 59:2af474687369 | 45 | #define MAX_NUM_IN_EPS 6 /* In addition to EP0 */ |
mbed_official | 59:2af474687369 | 46 | #define MAX_NUM_OUT_EPS 6 /* In addition to EP0 */ |
mbed_official | 59:2af474687369 | 47 | #define MAX_DEVICE_FIFO_SIZE_INWORDS 512U |
mbed_official | 59:2af474687369 | 48 | #else |
mbed_official | 59:2af474687369 | 49 | #define MAX_NUM_TX_FIFOS 3 /* In addition to EP0 Tx FIFO */ |
mbed_official | 59:2af474687369 | 50 | #define MAX_NUM_IN_EPS 3 /* In addition to EP0 */ |
mbed_official | 59:2af474687369 | 51 | #define MAX_NUM_OUT_EPS 3 /* In addition to EP0 */ |
mbed_official | 59:2af474687369 | 52 | #define MAX_DEVICE_FIFO_SIZE_INWORDS 384U |
mbed_official | 59:2af474687369 | 53 | #endif |
mbed_official | 59:2af474687369 | 54 | #define MIN_EP_FIFO_SIZE_INWORDS 16U /* Unit is words (32bit) */ |
mbed_official | 59:2af474687369 | 55 | #define MIN_EP_FIFO_SIZE_INBYTES 64U /* Unit is bytes (8bit) */ |
mbed_official | 59:2af474687369 | 56 | |
mbed_official | 59:2af474687369 | 57 | /* For MCU's without USB host capability. */ |
mbed_official | 59:2af474687369 | 58 | #if !defined( USB_ROUTE_VBUSENPEN ) |
mbed_official | 59:2af474687369 | 59 | #define USB_VBUS_SWITCH_NOT_PRESENT |
mbed_official | 59:2af474687369 | 60 | #endif |
mbed_official | 59:2af474687369 | 61 | |
mbed_official | 59:2af474687369 | 62 | /* Limit imposed by the USB standard */ |
mbed_official | 59:2af474687369 | 63 | #define MAX_USB_EP_NUM 15 |
mbed_official | 59:2af474687369 | 64 | |
mbed_official | 59:2af474687369 | 65 | #if defined( USB_DEVICE ) |
mbed_official | 59:2af474687369 | 66 | /* Check power saving modes. */ |
mbed_official | 59:2af474687369 | 67 | #ifndef USB_PWRSAVE_MODE |
mbed_official | 59:2af474687369 | 68 | /* Default powersave-mode is OFF. */ |
mbed_official | 59:2af474687369 | 69 | #define USB_PWRSAVE_MODE USB_PWRSAVE_MODE_OFF |
mbed_official | 59:2af474687369 | 70 | #else |
mbed_official | 59:2af474687369 | 71 | #if ( USB_PWRSAVE_MODE & \ |
mbed_official | 59:2af474687369 | 72 | ~( USB_PWRSAVE_MODE_ONSUSPEND | USB_PWRSAVE_MODE_ONVBUSOFF | \ |
mbed_official | 59:2af474687369 | 73 | USB_PWRSAVE_MODE_ENTEREM2 ) ) |
mbed_official | 59:2af474687369 | 74 | #error "Illegal USB powersave mode." |
mbed_official | 59:2af474687369 | 75 | #endif |
mbed_official | 59:2af474687369 | 76 | #endif /* ifndef USB_PWRSAVE_MODE */ |
mbed_official | 59:2af474687369 | 77 | |
mbed_official | 59:2af474687369 | 78 | /* Check power saving low frequency clock selection. */ |
mbed_official | 59:2af474687369 | 79 | #ifndef USB_USBC_32kHz_CLK |
mbed_official | 59:2af474687369 | 80 | /* Default clock source is LFXO. */ |
mbed_official | 59:2af474687369 | 81 | #define USB_USBC_32kHz_CLK USB_USBC_32kHz_CLK_LFXO |
mbed_official | 59:2af474687369 | 82 | #else |
mbed_official | 59:2af474687369 | 83 | #if ( ( USB_USBC_32kHz_CLK != USB_USBC_32kHz_CLK_LFXO ) && \ |
mbed_official | 59:2af474687369 | 84 | ( USB_USBC_32kHz_CLK != USB_USBC_32kHz_CLK_LFRCO ) ) |
mbed_official | 59:2af474687369 | 85 | #error "Illegal USB 32kHz powersave clock selection." |
mbed_official | 59:2af474687369 | 86 | #endif |
mbed_official | 59:2af474687369 | 87 | #endif /* ifndef USB_USBC_32kHz_CLK */ |
mbed_official | 59:2af474687369 | 88 | #endif /* defined( USB_DEVICE ) */ |
mbed_official | 59:2af474687369 | 89 | |
mbed_official | 59:2af474687369 | 90 | #if defined( USB_HOST ) |
mbed_official | 59:2af474687369 | 91 | /* Check VBUS overcurrent definitions. */ |
mbed_official | 59:2af474687369 | 92 | #ifndef USB_VBUSOVRCUR_PORT |
mbed_official | 59:2af474687369 | 93 | #define USB_VBUSOVRCUR_PORT gpioPortE |
mbed_official | 59:2af474687369 | 94 | #define USB_VBUSOVRCUR_PIN 2 |
mbed_official | 59:2af474687369 | 95 | #define USB_VBUSOVRCUR_POLARITY USB_VBUSOVRCUR_POLARITY_LOW |
mbed_official | 59:2af474687369 | 96 | #endif |
mbed_official | 59:2af474687369 | 97 | #endif |
mbed_official | 59:2af474687369 | 98 | |
mbed_official | 59:2af474687369 | 99 | /* Developer mode debugging macro's */ |
mbed_official | 59:2af474687369 | 100 | #if defined( DEBUG_USB_INT_LO ) |
mbed_official | 59:2af474687369 | 101 | #define DEBUG_USB_INT_LO_PUTS( s ) USB_PUTS( s ) |
mbed_official | 59:2af474687369 | 102 | #define DEBUG_USB_INT_LO_PUTCHAR( c ) USB_PUTCHAR( c ) |
mbed_official | 59:2af474687369 | 103 | #else |
mbed_official | 59:2af474687369 | 104 | #define DEBUG_USB_INT_LO_PUTS( s ) |
mbed_official | 59:2af474687369 | 105 | #define DEBUG_USB_INT_LO_PUTCHAR( c ) |
mbed_official | 59:2af474687369 | 106 | #endif /* defined( DEBUG_USB_INT_LO ) */ |
mbed_official | 59:2af474687369 | 107 | |
mbed_official | 59:2af474687369 | 108 | #if defined( DEBUG_USB_INT_HI ) |
mbed_official | 59:2af474687369 | 109 | #define DEBUG_USB_INT_HI_PUTS( s ) USB_PUTS( s ) |
mbed_official | 59:2af474687369 | 110 | #define DEBUG_USB_INT_HI_PUTCHAR( c ) USB_PUTCHAR( c ) |
mbed_official | 59:2af474687369 | 111 | #else |
mbed_official | 59:2af474687369 | 112 | #define DEBUG_USB_INT_HI_PUTS( s ) |
mbed_official | 59:2af474687369 | 113 | #define DEBUG_USB_INT_HI_PUTCHAR( c ) |
mbed_official | 59:2af474687369 | 114 | #endif /* defined( DEBUG_USB_INT_HI ) */ |
mbed_official | 59:2af474687369 | 115 | |
mbed_official | 59:2af474687369 | 116 | #if defined( USB_HOST ) |
mbed_official | 59:2af474687369 | 117 | #if defined( NUM_APP_TIMERS ) |
mbed_official | 59:2af474687369 | 118 | #define HOSTPORT_TIMER_INDEX (NUM_APP_TIMERS) |
mbed_official | 59:2af474687369 | 119 | #else |
mbed_official | 59:2af474687369 | 120 | #define HOSTPORT_TIMER_INDEX (0) |
mbed_official | 59:2af474687369 | 121 | #endif |
mbed_official | 59:2af474687369 | 122 | #define HOSTCH_TIMER_INDEX (HOSTPORT_TIMER_INDEX + 1 ) |
mbed_official | 59:2af474687369 | 123 | #endif |
mbed_official | 59:2af474687369 | 124 | |
mbed_official | 59:2af474687369 | 125 | /* Macros for selecting a hardware timer. */ |
mbed_official | 59:2af474687369 | 126 | #define USB_TIMER0 0 |
mbed_official | 59:2af474687369 | 127 | #define USB_TIMER1 1 |
mbed_official | 59:2af474687369 | 128 | #define USB_TIMER2 2 |
mbed_official | 59:2af474687369 | 129 | #define USB_TIMER3 3 |
mbed_official | 59:2af474687369 | 130 | |
mbed_official | 59:2af474687369 | 131 | #if defined( USB_HOST ) |
mbed_official | 59:2af474687369 | 132 | #define HCS_NAK 0x01 |
mbed_official | 59:2af474687369 | 133 | #define HCS_STALL 0x02 |
mbed_official | 59:2af474687369 | 134 | #define HCS_XACT 0x04 |
mbed_official | 59:2af474687369 | 135 | #define HCS_TGLERR 0x08 |
mbed_official | 59:2af474687369 | 136 | #define HCS_BABBLE 0x10 |
mbed_official | 59:2af474687369 | 137 | #define HCS_TIMEOUT 0x20 |
mbed_official | 59:2af474687369 | 138 | #define HCS_COMPLETED 0x40 |
mbed_official | 59:2af474687369 | 139 | #define HCS_RETRY 0x80 |
mbed_official | 59:2af474687369 | 140 | #endif |
mbed_official | 59:2af474687369 | 141 | |
mbed_official | 59:2af474687369 | 142 | #if defined( USB_DEVICE ) |
mbed_official | 59:2af474687369 | 143 | typedef enum |
mbed_official | 59:2af474687369 | 144 | { |
mbed_official | 59:2af474687369 | 145 | D_EP_IDLE = 0, |
mbed_official | 59:2af474687369 | 146 | D_EP_TRANSMITTING = 1, |
mbed_official | 59:2af474687369 | 147 | D_EP_RECEIVING = 2, |
mbed_official | 59:2af474687369 | 148 | D_EP0_IN_STATUS = 3, |
mbed_official | 59:2af474687369 | 149 | D_EP0_OUT_STATUS = 4 |
mbed_official | 59:2af474687369 | 150 | } USBD_EpState_TypeDef; |
mbed_official | 59:2af474687369 | 151 | |
mbed_official | 59:2af474687369 | 152 | typedef struct |
mbed_official | 59:2af474687369 | 153 | { |
mbed_official | 59:2af474687369 | 154 | bool in; |
mbed_official | 59:2af474687369 | 155 | uint8_t zlp; |
mbed_official | 59:2af474687369 | 156 | uint8_t num; |
mbed_official | 59:2af474687369 | 157 | uint8_t addr; |
mbed_official | 59:2af474687369 | 158 | uint8_t type; |
mbed_official | 59:2af474687369 | 159 | uint8_t txFifoNum; |
mbed_official | 59:2af474687369 | 160 | uint8_t *buf; |
mbed_official | 59:2af474687369 | 161 | uint16_t packetSize; |
mbed_official | 59:2af474687369 | 162 | uint16_t mask; |
mbed_official | 59:2af474687369 | 163 | uint32_t remaining; |
mbed_official | 59:2af474687369 | 164 | uint32_t xferred; |
mbed_official | 59:2af474687369 | 165 | uint32_t hwXferSize; |
mbed_official | 59:2af474687369 | 166 | uint32_t fifoSize; |
mbed_official | 59:2af474687369 | 167 | USBD_EpState_TypeDef state; |
mbed_official | 59:2af474687369 | 168 | USB_XferCompleteCb_TypeDef xferCompleteCb; |
mbed_official | 59:2af474687369 | 169 | } USBD_Ep_TypeDef; |
mbed_official | 59:2af474687369 | 170 | |
mbed_official | 59:2af474687369 | 171 | typedef struct |
mbed_official | 59:2af474687369 | 172 | { |
mbed_official | 59:2af474687369 | 173 | USB_Setup_TypeDef *setup; |
mbed_official | 59:2af474687369 | 174 | USB_Setup_TypeDef setupPkt[3]; |
mbed_official | 59:2af474687369 | 175 | uint8_t configurationValue; /* Must be DWORD aligned */ |
mbed_official | 59:2af474687369 | 176 | bool remoteWakeupEnabled; |
mbed_official | 59:2af474687369 | 177 | uint8_t numberOfStrings; |
mbed_official | 59:2af474687369 | 178 | uint8_t numberOfInterfaces; |
mbed_official | 59:2af474687369 | 179 | USBD_State_TypeDef state; |
mbed_official | 59:2af474687369 | 180 | USBD_State_TypeDef savedState; |
mbed_official | 59:2af474687369 | 181 | USBD_State_TypeDef lastState; |
mbed_official | 59:2af474687369 | 182 | const USB_DeviceDescriptor_TypeDef *deviceDescriptor; |
mbed_official | 59:2af474687369 | 183 | const USB_ConfigurationDescriptor_TypeDef *configDescriptor; |
mbed_official | 59:2af474687369 | 184 | const void * const *stringDescriptors; |
mbed_official | 59:2af474687369 | 185 | const USBD_Callbacks_TypeDef *callbacks; |
mbed_official | 59:2af474687369 | 186 | USBD_Ep_TypeDef ep[ NUM_EP_USED + 1 ]; |
mbed_official | 59:2af474687369 | 187 | uint8_t inEpAddr2EpIndex[ MAX_USB_EP_NUM + 1 ]; |
mbed_official | 59:2af474687369 | 188 | uint8_t outEpAddr2EpIndex[ MAX_USB_EP_NUM + 1 ]; |
mbed_official | 59:2af474687369 | 189 | uint32_t ep0MpsCode; |
mbed_official | 59:2af474687369 | 190 | } USBD_Device_TypeDef; |
mbed_official | 59:2af474687369 | 191 | #endif /* defined( USB_DEVICE ) */ |
mbed_official | 59:2af474687369 | 192 | |
mbed_official | 59:2af474687369 | 193 | #if defined( USB_HOST ) |
mbed_official | 59:2af474687369 | 194 | typedef enum |
mbed_official | 59:2af474687369 | 195 | { |
mbed_official | 59:2af474687369 | 196 | H_PORT_DISCONNECTED = 0, |
mbed_official | 59:2af474687369 | 197 | H_PORT_CONNECTED_DEBOUNCING = 1, |
mbed_official | 59:2af474687369 | 198 | H_PORT_CONNECTED_RESETTING = 2, |
mbed_official | 59:2af474687369 | 199 | H_PORT_CONNECTED = 3, |
mbed_official | 59:2af474687369 | 200 | H_PORT_OVERCURRENT = 4 |
mbed_official | 59:2af474687369 | 201 | } USBH_PortState_TypeDef; |
mbed_official | 59:2af474687369 | 202 | |
mbed_official | 59:2af474687369 | 203 | typedef struct |
mbed_official | 59:2af474687369 | 204 | { |
mbed_official | 59:2af474687369 | 205 | int debounceTime; |
mbed_official | 59:2af474687369 | 206 | int resetTime; |
mbed_official | 59:2af474687369 | 207 | } USBH_AttachTiming_TypeDef; |
mbed_official | 59:2af474687369 | 208 | |
mbed_official | 59:2af474687369 | 209 | typedef struct |
mbed_official | 59:2af474687369 | 210 | { |
mbed_official | 59:2af474687369 | 211 | uint8_t *buf; |
mbed_official | 59:2af474687369 | 212 | int errorCnt; |
mbed_official | 59:2af474687369 | 213 | uint32_t remaining; |
mbed_official | 59:2af474687369 | 214 | uint32_t xferred; |
mbed_official | 59:2af474687369 | 215 | uint32_t hwXferSize; |
mbed_official | 59:2af474687369 | 216 | uint8_t status; |
mbed_official | 59:2af474687369 | 217 | bool idle; |
mbed_official | 59:2af474687369 | 218 | USBH_Ep_TypeDef *ep; |
mbed_official | 59:2af474687369 | 219 | } USBH_Hc_TypeDef; |
mbed_official | 59:2af474687369 | 220 | #endif /* defined( USB_HOST ) */ |
mbed_official | 59:2af474687369 | 221 | |
mbed_official | 59:2af474687369 | 222 | /** @endcond */ |
mbed_official | 59:2af474687369 | 223 | |
mbed_official | 59:2af474687369 | 224 | #ifdef __cplusplus |
mbed_official | 59:2af474687369 | 225 | } |
mbed_official | 59:2af474687369 | 226 | #endif |
mbed_official | 59:2af474687369 | 227 | |
mbed_official | 59:2af474687369 | 228 | #endif /* defined( USB_DEVICE ) || defined( USB_HOST ) */ |
mbed_official | 59:2af474687369 | 229 | #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */ |
mbed_official | 59:2af474687369 | 230 | #endif /* __EM_USBTYPES_H */ |