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