EFM32 Giant Gecko Software Documentation  efm32gg-doc-5.1.2
em_usbtypes.h
Go to the documentation of this file.
1 /***************************************************************************/
16 #ifndef __EM_USBTYPES_H
17 #define __EM_USBTYPES_H
18 
19 #include "em_device.h"
20 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
21 #include "em_usb.h"
22 #if defined( USB_DEVICE ) || defined( USB_HOST )
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
30 /* Limits imposed by the USB peripheral */
31 #define NP_RX_QUE_DEPTH 8
32 #define HP_RX_QUE_DEPTH 8
33 #define MAX_XFER_LEN 524287L /* 2^19 - 1 bytes */
34 #define MAX_PACKETS_PR_XFER 1023 /* 2^10 - 1 packets */
35 #if defined( _USB_DIEPTXF6_MASK )
36  #define MAX_NUM_TX_FIFOS 6 /* In addition to EP0 Tx FIFO */
37  #define MAX_NUM_IN_EPS 6 /* In addition to EP0 */
38  #define MAX_NUM_OUT_EPS 6 /* In addition to EP0 */
39  #define MAX_DEVICE_FIFO_SIZE_INWORDS 512U
40 #else
41  #define MAX_NUM_TX_FIFOS 3 /* In addition to EP0 Tx FIFO */
42  #define MAX_NUM_IN_EPS 3 /* In addition to EP0 */
43  #define MAX_NUM_OUT_EPS 3 /* In addition to EP0 */
44  #define MAX_DEVICE_FIFO_SIZE_INWORDS 384U
45 #endif
46 #define MIN_EP_FIFO_SIZE_INWORDS 16U /* Unit is words (32bit) */
47 #define MIN_EP_FIFO_SIZE_INBYTES 64U /* Unit is bytes (8bit) */
48 
49 /* For MCU's without USB host capability. */
50 #if !defined( USB_ROUTE_VBUSENPEN )
51 #define USB_VBUS_SWITCH_NOT_PRESENT
52 #endif
53 
54 /* Limit imposed by the USB standard */
55 #define MAX_USB_EP_NUM 15
56 
57 #if defined( USB_DEVICE )
58  /* Check power saving modes. */
59  #ifndef USB_PWRSAVE_MODE
60  /* Default powersave-mode is OFF. */
61  #define USB_PWRSAVE_MODE USB_PWRSAVE_MODE_OFF
62  #else
63  #if ( USB_PWRSAVE_MODE & \
64  ~( USB_PWRSAVE_MODE_ONSUSPEND | USB_PWRSAVE_MODE_ONVBUSOFF | \
65  USB_PWRSAVE_MODE_ENTEREM2 ) )
66  #error "Illegal USB powersave mode."
67  #endif
68  #endif /* ifndef USB_PWRSAVE_MODE */
69 
70  /* Check power saving low frequency clock selection. */
71  #ifndef USB_USBC_32kHz_CLK
72  /* Default clock source is LFXO. */
73  #define USB_USBC_32kHz_CLK USB_USBC_32kHz_CLK_LFXO
74  #else
75  #if ( ( USB_USBC_32kHz_CLK != USB_USBC_32kHz_CLK_LFXO ) && \
76  ( USB_USBC_32kHz_CLK != USB_USBC_32kHz_CLK_LFRCO ) )
77  #error "Illegal USB 32kHz powersave clock selection."
78  #endif
79  #endif /* ifndef USB_USBC_32kHz_CLK */
80 #endif /* defined( USB_DEVICE ) */
81 
82 #if defined( USB_HOST )
83  /* Check VBUS overcurrent definitions. */
84  #ifndef USB_VBUSOVRCUR_PORT
85  #define USB_VBUSOVRCUR_PORT gpioPortE
86  #define USB_VBUSOVRCUR_PIN 2
87  #define USB_VBUSOVRCUR_POLARITY USB_VBUSOVRCUR_POLARITY_LOW
88  #endif
89 #endif
90 
91 /* Developer mode debugging macro's */
92 #if defined( DEBUG_USB_INT_LO )
93  #define DEBUG_USB_INT_LO_PUTS( s ) USB_PUTS( s )
94  #define DEBUG_USB_INT_LO_PUTCHAR( c ) USB_PUTCHAR( c )
95 #else
96  #define DEBUG_USB_INT_LO_PUTS( s )
97  #define DEBUG_USB_INT_LO_PUTCHAR( c )
98 #endif /* defined( DEBUG_USB_INT_LO ) */
99 
100 #if defined( DEBUG_USB_INT_HI )
101  #define DEBUG_USB_INT_HI_PUTS( s ) USB_PUTS( s )
102  #define DEBUG_USB_INT_HI_PUTCHAR( c ) USB_PUTCHAR( c )
103 #else
104  #define DEBUG_USB_INT_HI_PUTS( s )
105  #define DEBUG_USB_INT_HI_PUTCHAR( c )
106 #endif /* defined( DEBUG_USB_INT_HI ) */
107 
108 #if defined( USB_HOST )
109  #if defined( NUM_APP_TIMERS )
110  #define HOSTPORT_TIMER_INDEX (NUM_APP_TIMERS)
111  #else
112  #define HOSTPORT_TIMER_INDEX (0)
113  #endif
114  #define HOSTCH_TIMER_INDEX (HOSTPORT_TIMER_INDEX + 1 )
115 #endif
116 
117 /* Macros for selecting a hardware timer. */
118 #define USB_TIMER0 0
119 #define USB_TIMER1 1
120 #define USB_TIMER2 2
121 #define USB_TIMER3 3
122 
123 #if defined( USB_HOST )
124 #define HCS_NAK 0x01
125 #define HCS_STALL 0x02
126 #define HCS_XACT 0x04
127 #define HCS_TGLERR 0x08
128 #define HCS_BABBLE 0x10
129 #define HCS_TIMEOUT 0x20
130 #define HCS_COMPLETED 0x40
131 #define HCS_RETRY 0x80
132 #endif
133 
134 #if defined( USB_DEVICE )
135 typedef enum
136 {
137  D_EP_IDLE = 0,
138  D_EP_TRANSMITTING = 1,
139  D_EP_RECEIVING = 2,
140  D_EP0_IN_STATUS = 3,
141  D_EP0_OUT_STATUS = 4
142 } USBD_EpState_TypeDef;
143 
144 typedef struct
145 {
146  bool in;
147  uint8_t zlp;
148  uint8_t num;
149  uint8_t addr;
150  uint8_t type;
151  uint8_t txFifoNum;
152  uint8_t *buf;
153  uint16_t packetSize;
154  uint16_t mask;
155  uint32_t remaining;
156  uint32_t xferred;
157  uint32_t hwXferSize;
158  uint32_t fifoSize;
159  USBD_EpState_TypeDef state;
160  USB_XferCompleteCb_TypeDef xferCompleteCb;
161 } USBD_Ep_TypeDef;
162 
163 typedef struct
164 {
165  USB_Setup_TypeDef *setup;
166  USB_Setup_TypeDef setupPkt[3];
167  uint8_t configurationValue; /* Must be DWORD aligned */
168  bool remoteWakeupEnabled;
169  uint8_t numberOfStrings;
170  uint8_t numberOfInterfaces;
171  USBD_State_TypeDef state;
172  USBD_State_TypeDef savedState;
173  USBD_State_TypeDef lastState;
174  const USB_DeviceDescriptor_TypeDef *deviceDescriptor;
175  const USB_ConfigurationDescriptor_TypeDef *configDescriptor;
176  const void * const *stringDescriptors;
177  const USBD_Callbacks_TypeDef *callbacks;
178  USBD_Ep_TypeDef ep[ NUM_EP_USED + 1 ];
179  uint8_t inEpAddr2EpIndex[ MAX_USB_EP_NUM + 1 ];
180  uint8_t outEpAddr2EpIndex[ MAX_USB_EP_NUM + 1 ];
181  uint32_t ep0MpsCode;
182 } USBD_Device_TypeDef;
183 #endif /* defined( USB_DEVICE ) */
184 
185 #if defined( USB_HOST )
186 typedef enum
187 {
188  H_PORT_DISCONNECTED = 0,
189  H_PORT_CONNECTED_DEBOUNCING = 1,
190  H_PORT_CONNECTED_RESETTING = 2,
191  H_PORT_CONNECTED = 3,
192  H_PORT_OVERCURRENT = 4
193 } USBH_PortState_TypeDef;
194 
195 typedef struct
196 {
197  int debounceTime;
198  int resetTime;
199 } USBH_AttachTiming_TypeDef;
200 
201 typedef struct
202 {
203  uint8_t *buf;
204  int errorCnt;
205  uint32_t remaining;
206  uint32_t xferred;
207  uint32_t hwXferSize;
208  uint8_t status;
209  bool idle;
210  USBH_Ep_TypeDef *ep;
211 } USBH_Hc_TypeDef;
212 #endif /* defined( USB_HOST ) */
213 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif /* defined( USB_DEVICE ) || defined( USB_HOST ) */
221 #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
222 #endif /* __EM_USBTYPES_H */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
USB Setup request package.
Definition: em_usb.h:377
USBD_State_TypeDef
USB device state enumerator.
Definition: em_usb.h:358
int(* USB_XferCompleteCb_TypeDef)(USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining)
USB transfer callback function.
Definition: em_usb.h:663
USB Device stack callback structure.
Definition: em_usb.h:799
USB protocol stack library API for EFM32/EZR32.
USB Configuration Descriptor.
Definition: em_usb.h:430
USB HOST endpoint status data.
Definition: em_usb.h:861
USB Device Descriptor.
Definition: em_usb.h:406