USB device stack

Dependents:   mbed-mX-USB-TEST1 USBMSD_SD_HID_HelloWorld HidTest MIDI_usb_bridge ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Pull requests against this repository are no longer supported. Please raise against mbed OS 5 as documented above.

Committer:
Kojto
Date:
Thu Jul 27 12:14:04 2017 +0100
Revision:
71:53949e6131f6
Update libraries

Fixes the previous commmit, as some devices were not copied. USBDevice contains
now targets directory with all targets implementations

Who changed what in which revision?

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