EFM32 Wonder Gecko Software Documentation  efm32wg-doc-4.2.1
em_usb.h
Go to the documentation of this file.
1 /***************************************************************************/
16 #ifndef __EM_USB_H
17 #define __EM_USB_H
18 
19 #include "em_device.h"
20 #include "em_assert.h"
21 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
22 #include "usbconfig.h"
23 #if defined( USB_DEVICE ) || defined( USB_HOST )
24 
25 #include <string.h>
26 #include <stddef.h>
27 #include "em_common.h"
28 #include "em_int.h"
29 
30 #if defined( USB_USE_PRINTF )
31 #include <stdio.h>
32 #endif
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #ifdef __CC_ARM
39 #pragma anon_unions
40 #endif
41 
42 /***************************************************************************/
48 /***************************************************************************/
55 #define SILABS_USB_VID 0x10C4
57 /* SETUP request, direction of data stage */
58 #define USB_SETUP_DIR_OUT 0
59 #define USB_SETUP_DIR_IN 1
60 #define USB_SETUP_DIR_MASK 0x80
61 #define USB_SETUP_DIR_D2H 0x80
62 #define USB_SETUP_DIR_H2D 0x00
64 /* SETUP request type */
65 #define USB_SETUP_TYPE_STANDARD 0
66 #define USB_SETUP_TYPE_CLASS 1
67 #define USB_SETUP_TYPE_VENDOR 2
68 #define USB_SETUP_TYPE_STANDARD_MASK 0x00
69 #define USB_SETUP_TYPE_CLASS_MASK 0x20
70 #define USB_SETUP_TYPE_VENDOR_MASK 0x40
72 /* SETUP request recipient */
73 #define USB_SETUP_RECIPIENT_DEVICE 0
74 #define USB_SETUP_RECIPIENT_INTERFACE 1
75 #define USB_SETUP_RECIPIENT_ENDPOINT 2
76 #define USB_SETUP_RECIPIENT_OTHER 3
78 /* SETUP standard request codes for Full Speed devices */
79 #define GET_STATUS 0
80 #define CLEAR_FEATURE 1
81 #define SET_FEATURE 3
82 #define SET_ADDRESS 5
83 #define GET_DESCRIPTOR 6
84 #define SET_DESCRIPTOR 7
85 #define GET_CONFIGURATION 8
86 #define SET_CONFIGURATION 9
87 #define GET_INTERFACE 10
88 #define SET_INTERFACE 11
89 #define SYNCH_FRAME 12
91 /* SETUP class request codes */
92 #define USB_HID_GET_REPORT 0x01
93 #define USB_HID_GET_IDLE 0x02
94 #define USB_HID_SET_REPORT 0x09
95 #define USB_HID_SET_IDLE 0x0A
96 #define USB_HID_SET_PROTOCOL 0x0B
97 #define USB_CDC_SETLINECODING 0x20
98 #define USB_CDC_GETLINECODING 0x21
99 #define USB_CDC_SETCTRLLINESTATE 0x22
100 #define USB_MSD_BOTRESET 0xFF
101 #define USB_MSD_GETMAXLUN 0xFE
102 #define USB_AUDIO_GET_CUR 0x81
103 #define USB_AUDIO_SET_CUR 0x01
104 #define USB_AUDIO_GET_CUR 0x81
105 #define USB_AUDIO_SET_MIN 0x02
106 #define USB_AUDIO_GET_MIN 0x82
107 #define USB_AUDIO_SET_MAX 0x03
108 #define USB_AUDIO_GET_MAX 0x83
109 #define USB_AUDIO_SET_RES 0x04
110 #define USB_AUDIO_GET_RES 0x84
111 #define USB_AUDIO_SET_MEM 0x05
112 #define USB_AUDIO_GET_MEM 0x85
113 #define USB_AUDIO_GET_STAT 0xFF
115 /* SETUP command GET/SET_DESCRIPTOR decriptor types */
116 #define USB_DEVICE_DESCRIPTOR 1
117 #define USB_CONFIG_DESCRIPTOR 2
118 #define USB_STRING_DESCRIPTOR 3
119 #define USB_MAX_STRING_DESCRIPTOR_CHARS 126
120 #define USB_INTERFACE_DESCRIPTOR 4
121 #define USB_ENDPOINT_DESCRIPTOR 5
122 #define USB_DEVICE_QUALIFIER_DESCRIPTOR 6
123 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR 7
124 #define USB_INTERFACE_POWER_DESCRIPTOR 8
125 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR 11
126 #define USB_HID_DESCRIPTOR 0x21
127 #define USB_SMARTCARD_DESCRIPTOR 0x21
128 #define USB_HID_REPORT_DESCRIPTOR 0x22
129 #define USB_CS_INTERFACE_DESCRIPTOR 0x24
130 #define USB_CS_ENDPOINT_DESCRIPTOR 0x25
131 #define USB_HUB_DESCRIPTOR 0x29
132 #define USB_CA_HEADER_DESCRIPTOR 1
133 #define USB_CA_INPUT_TERMINAL_DESCRIPTOR 2
134 #define USB_CA_OUTPUT_TERMINAL_DESCRIPTOR 3
135 #define USB_CA_MIXER_UNIT_DESCRIPTOR 4
136 #define USB_CA_SELECTOR_UNIT_DESCRIPTOR 5
137 #define USB_CA_FEATURE_UNIT_DESCRIPTOR 6
138 #define USB_CA_PROCESSING_UNIT_DESCRIPTOR 7
139 #define USB_CA_EXTENSION_UNIT_DESCRIPTOR 8
140 #define USB_CA_EP_GENERAL_DESCRIPTOR 1
141 #define USB_CA_AS_GENERAL_DESCRIPTOR 1
142 #define USB_CA_FORMAT_TYPE_DESCRIPTOR 2
144 #define USB_DEVICE_DESCSIZE 18
145 #define USB_CONFIG_DESCSIZE 9
146 #define USB_INTERFACE_DESCSIZE 9
147 #define USB_ENDPOINT_DESCSIZE 7
148 #define USB_DEVICE_QUALIFIER_DESCSIZE 10
149 #define USB_OTHER_SPEED_CONFIG_DESCSIZE 9
150 #define USB_INTERFACE_ASSOCIATION_DESCSIZE 8
151 #define USB_HID_DESCSIZE 9
152 #define USB_SMARTCARD_DESCSIZE 54
153 #define USB_CDC_HEADER_FND_DESCSIZE 5
154 #define USB_CDC_CALLMNG_FND_DESCSIZE 5
155 #define USB_CDC_ACM_FND_DESCSIZE 4
156 #define USB_CA_INPUT_TERMINAL_DESCSIZE 12
157 #define USB_CA_OUTPUT_TERMINAL_DESCSIZE 9
158 #define USB_CA_EP_GENERAL_DESCSIZE 7
159 #define USB_CA_AS_GENERAL_DESCSIZE 7
160 #define USB_CA_STD_AS_ENDPOINT_DESCSZIE 9
162 /* Misc. USB definitions */
163 #define USB_LS_CTRL_EP_MAXSIZE 8
164 #define USB_LS_INTR_EP_MAXSIZE 8
165 #define USB_FS_CTRL_EP_MAXSIZE 64
166 #define USB_FS_INTR_EP_MAXSIZE 64
167 #define USB_FS_BULK_EP_MAXSIZE 64
168 #define USB_FS_ISOC_EP_MAXSIZE 1023
169 #define USB_EPTYPE_CTRL 0
170 #define USB_EPTYPE_ISOC 1
171 #define USB_EPTYPE_BULK 2
172 #define USB_EPTYPE_INTR 3
173 #define USB_EPSYNC_NO (0 << 2)
174 #define USB_EPSYNC_ASYNC (1 << 2)
175 #define USB_EPSYNC_ADAPTIVE (2 << 2)
176 #define USB_EPSYNC_SYNC (3 << 2)
177 #define USB_EP_DIR_IN 0x80
178 #define USB_SETUP_PKT_SIZE 8
179 #define USB_EPNUM_MASK 0x0F
180 #define USB_LANGID_ENUS 0x0409
181 #define USB_MAX_DEVICE_ADDRESS 127
183 #define CONFIG_DESC_BM_REMOTEWAKEUP 0x20
184 #define CONFIG_DESC_BM_SELFPOWERED 0x40
185 #define CONFIG_DESC_BM_RESERVED_D7 0x80
186 #define CONFIG_DESC_BM_TRANSFERTYPE 0x03
187 #define CONFIG_DESC_MAXPOWER_mA(x) (((x)+1)/2)
189 #define DEVICE_IS_SELFPOWERED 0x0001
190 #define REMOTE_WAKEUP_ENABLED 0x0002
191 #define USB_FEATURE_ENDPOINT_HALT 0
192 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1
194 #define HUB_FEATURE_PORT_RESET 4
195 #define HUB_FEATURE_PORT_POWER 8
196 #define HUB_FEATURE_C_PORT_CONNECTION 16
197 #define HUB_FEATURE_C_PORT_RESET 20
198 #define HUB_FEATURE_PORT_INDICATOR 22
200 #define USB_CLASS_CDC 2
201 #define USB_CLASS_CDC_DATA 0x0A
202 #define USB_CLASS_CDC_ACM 2
203 #define USB_CLASS_CDC_HFN 0
204 #define USB_CLASS_CDC_CMNGFN 1
205 #define USB_CLASS_CDC_ACMFN 2
206 #define USB_CLASS_CDC_UNIONFN 6
208 #define USB_CLASS_HID 3
209 #define USB_CLASS_HID_KEYBOARD 1
210 #define USB_CLASS_HID_MOUSE 2
212 #define USB_CLASS_HUB 9
214 #define USB_CLASS_MSD 8
215 #define USB_CLASS_MSD_BOT_TRANSPORT 0x50
216 #define USB_CLASS_MSD_SCSI_CMDSET 6
217 #define USB_CLASS_MSD_CSW_CMDPASSED 0
218 #define USB_CLASS_MSD_CSW_CMDFAILED 1
219 #define USB_CLASS_MSD_CSW_PHASEERROR 2
221 #define USB_CLASS_AUDIO 1
222 #define USB_CLASS_AUDIO_CONTROL 1
223 #define USB_CLASS_AUDIO_STREAMING 2
224 #define USB_CLASS_AUDIO_MIDISTREAMING 3
226 /*** Triplet for the device descriptor of a composite device using IAD descriptors. ***/
227 #define USB_CLASS_MISCELLANEOUS 0xEF
228 #define USB_CLASS_MISC_COMMON_SUBCLASS 2
229 #define USB_CLASS_MISC_IAD_PROTOCOL 1
231 #define PORT_FULL_SPEED 1
232 #define PORT_LOW_SPEED 2
234 #if defined( __GNUC__ ) /* GCC compilers */
235 #if defined( __CHAR16_TYPE__ )
236 typedef __CHAR16_TYPE__ char16_t;
237 #else
238 typedef unsigned short char16_t;
239 #endif
240 
241 #elif defined( __ICCARM__ ) /* IAR compiler */
242 #include <uchar.h>
243 
244 #elif defined( __CC_ARM ) /* MDK-ARM compiler */
245 typedef unsigned short char16_t;
246 #endif
247 
255 #define STATIC_CONST_STRING_DESC( _name, ... ) \
256 EFM32_PACK_START( 1 ) \
257 typedef struct \
258 { \
259  uint8_t len; \
260  uint8_t type; \
261  char16_t name[ 1 + sizeof( (char16_t[]){__VA_ARGS__} ) / 2]; \
262 } __attribute__ ((packed)) _##_name; \
263 EFM32_PACK_END() \
264 EFM32_ALIGN( 4 ) \
265 EFM32_PACK_START( 1 ) \
266 static const _##_name _name __attribute__ ((aligned(4)))= \
267 { \
268  .len = sizeof( _##_name ) - 2, \
269  .type = USB_STRING_DESCRIPTOR, \
270  .name = {__VA_ARGS__}, \
271  .name[ ( ( sizeof( _##_name ) - 2 ) / 2 ) - 1 ] = '\0' \
272 } \
273 EFM32_PACK_END()
274 
278 #define STATIC_CONST_STRING_DESC_LANGID( _name, x, y ) \
279 EFM32_PACK_START( 1 ) \
280 typedef struct \
281 { \
282  uint8_t len; \
283  uint8_t type; \
284  uint8_t name[ 2 ]; \
285 } __attribute__ ((packed)) _##_name; \
286 EFM32_PACK_END() \
287 EFM32_ALIGN( 4 ) \
288 EFM32_PACK_START( 1 ) \
289 static const _##_name _name __attribute__ ((aligned(4)))= \
290 { \
291  .len = 4, \
292  .type = USB_STRING_DESCRIPTOR, \
293  .name = { y, x } \
294 } \
295 EFM32_PACK_END()
296 
301 #if !defined(__GNUC__)
302 #define UBUF( x, y ) EFM32_ALIGN( 4 ) uint8_t x[((y)+3)&~3]
303 #define STATIC_UBUF( x, y ) EFM32_ALIGN( 4 ) static uint8_t x[((y)+3)&~3]
304 #else
305 #define UBUF( x, y ) uint8_t x[((y)+3)&~3] __attribute__ ((aligned(4)))
306 
311 #define STATIC_UBUF( x, y ) static uint8_t x[((y)+3)&~3] __attribute__ ((aligned(4)))
312 #endif
313 
314 
316 typedef enum
317 {
318  /* NOTE: Please keep in sync with table errMsg[] in em_usbhal.c */
340 #if defined( USB_DEVICE )
341 /***************************************************************************/
347 #define USB_PWRSAVE_MODE_OFF 0
348 #define USB_PWRSAVE_MODE_ONSUSPEND 1
349 #define USB_PWRSAVE_MODE_ONVBUSOFF 2
350 #define USB_PWRSAVE_MODE_ENTEREM2 4
352 #define USB_USBC_32kHz_CLK_LFXO 0
353 #define USB_USBC_32kHz_CLK_LFRCO 1
356 typedef enum
357 {
368 #endif /* defined( USB_DEVICE ) */
369 
374 EFM32_PACK_START( 1 )
375 typedef struct
376 {
377  union
378  {
379  struct
380  {
381  union
382  {
383  struct
384  {
385  uint8_t Recipient : 5;
386  uint8_t Type : 2;
387  uint8_t Direction : 1;
388  };
389  uint8_t bmRequestType;
390  };
391  uint8_t bRequest;
392  uint16_t wValue;
393  uint16_t wIndex;
394  uint16_t wLength;
395  };
396  uint32_t dw[2];
397  };
398 } __attribute__ ((packed)) USB_Setup_TypeDef;
400 
401 
403 EFM32_PACK_START( 1 )
404 typedef struct
405 {
406  uint8_t bLength;
407  uint8_t bDescriptorType;
408  uint16_t bcdUSB;
410  uint8_t bDeviceClass;
411  uint8_t bDeviceSubClass;
412  uint8_t bDeviceProtocol;
413  uint8_t bMaxPacketSize0;
414  uint16_t idVendor;
415  uint16_t idProduct;
416  uint16_t bcdDevice;
417  uint8_t iManufacturer;
418  uint8_t iProduct;
419  uint8_t iSerialNumber;
422 } __attribute__ ((packed)) USB_DeviceDescriptor_TypeDef;
424 
425 
427 EFM32_PACK_START( 1 )
428 typedef struct
429 {
430  uint8_t bLength;
431  uint8_t bDescriptorType;
432  uint16_t wTotalLength;
437  uint8_t bNumInterfaces;
442  uint8_t iConfiguration;
444  uint8_t bmAttributes;
449  uint8_t bMaxPower;
451 } __attribute__ ((packed)) USB_ConfigurationDescriptor_TypeDef;
453 
454 
456 EFM32_PACK_START( 1 )
457 typedef struct
458 {
459  uint8_t bLength;
460  uint8_t bDescriptorType;
466  uint8_t bNumEndpoints;
469  uint8_t bInterfaceClass;
490  uint8_t iInterface;
492 } __attribute__ ((packed)) USB_InterfaceDescriptor_TypeDef;
494 
495 
497 EFM32_PACK_START( 1 )
498 typedef struct
499 {
500  uint8_t bLength;
501  uint8_t bDescriptorType;
503  uint8_t bmAttributes;
504  uint16_t wMaxPacketSize;
505  uint8_t bInterval;
506 } __attribute__ ((packed)) USB_EndpointDescriptor_TypeDef;
508 
509 
511 EFM32_PACK_START( 1 )
512 typedef struct
513 {
514  uint8_t len;
515  uint8_t type;
516  char16_t name[];
517 } __attribute__ ((packed)) USB_StringDescriptor_TypeDef;
519 
522 /*** -------------------- Serial port debug configuration ---------------- ***/
523 
524 #if defined( DOXY_DOC_ONLY )
525 
528 /***************************************************************************/
544 int USB_PUTCHAR( char c );
545 
546 /***************************************************************************/
559 void USB_PUTS( const char *p );
560 
561 /***************************************************************************/
574 int USB_PRINTF( const char *format, ... );
575 
577 #endif /* defined( DOXY_DOC_ONLY ) */
578 
581 /* Hardware constraint, do not change. */
582 #define MAX_NUM_HOSTCHANNELS 14
583 
584 /* The DMA engine use one FIFO ram word for each host channel. */
585 #define MAX_HOST_FIFO_SIZE_INWORDS (512-MAX_NUM_HOSTCHANNELS)/*Unit is 4 bytes*/
586 
587 #if defined ( USER_PUTCHAR )
588  void USB_Puts( const char *p );
589  #define USB_PUTS( s ) USB_Puts( s )
590  #define USB_PUTCHAR( c ) USER_PUTCHAR( c )
591 #else
592  #define USB_PUTS( s )
593  #define USB_PUTCHAR( c )
594 #endif
595 
596 #if defined( USB_USE_PRINTF )
597  /* Use a printf which don't support floating point formatting */
598  #if defined(__ICCARM__) || defined (__CC_ARM) || defined (__CROSSWORKS_ARM)
599  #define USB_PRINTF printf
600  #else
601  #define USB_PRINTF iprintf
602  #endif
603 #else
604  #define USB_PRINTF(...)
605 #endif /* defined( USB_USE_PRINTF ) */
606 
607 #if defined( DEBUG_USB_API )
608  #define DEBUG_USB_API_PUTS( s ) USB_PUTS( s )
609  #define DEBUG_USB_API_PUTCHAR( c ) USB_PUTCHAR( c )
610 #else
611  #define DEBUG_USB_API_PUTS( s )
612  #define DEBUG_USB_API_PUTCHAR( c )
613 #endif /* defined( DEBUG_USB_API ) */
614 
617 /*** -------------------- Common API definitions ------------------------- ***/
618 
621 #if defined( USB_HOST )
622  #if defined( NUM_APP_TIMERS )
623  #define NUM_QTIMERS ( NUM_HC_USED + 2 + NUM_APP_TIMERS + 1 )
624  #else
625  #define NUM_QTIMERS ( NUM_HC_USED + 2 + 1 )
626  #endif
627  /* + 2 for default ctrl. host ch. 0 & 1, + 1 for host port timer */
628 #else
629  #if defined( NUM_APP_TIMERS )
630  #define NUM_QTIMERS ( NUM_APP_TIMERS )
631  #else
632  #define NUM_QTIMERS 0
633  #endif
634 #endif /* defined( USB_HOST ) */
635 
640 /***************************************************************************/
663 typedef int (*USB_XferCompleteCb_TypeDef)( USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining );
664 
665 /***************************************************************************/
673 typedef void (*USBTIMER_Callback_TypeDef)( void );
674 
675 char *USB_GetErrorMsgString( int error );
676 
677 #if defined( USB_USE_PRINTF )
678  void USB_PrintErrorMsgString( char *pre, int error );
679 #else
680  #define USB_PrintErrorMsgString( pre, error )
681 #endif
682 
683 void USBTIMER_DelayMs( uint32_t msec );
684 void USBTIMER_DelayUs( uint32_t usec );
685 void USBTIMER_Init( void );
686 
687 #if ( NUM_QTIMERS > 0 )
688  void USBTIMER_Start( uint32_t id, uint32_t timeout, USBTIMER_Callback_TypeDef callback );
689  void USBTIMER_Stop( uint32_t id );
690 #endif /* ( NUM_QTIMERS > 0 ) */
691 
693 #if defined( USB_DEVICE )
694 
696 /*** -------------------- DEVICE mode API definitions -------------------- ***/
697 
698 /***************************************************************************/
704 typedef void (*USBD_UsbResetCb_TypeDef)( void );
705 
706 /***************************************************************************/
716 typedef void (*USBD_SofIntCb_TypeDef)( uint16_t sofNr );
717 
718 /***************************************************************************/
732 
733 /***************************************************************************/
745 typedef bool (*USBD_IsSelfPoweredCb_TypeDef)( void );
746 
747 /***************************************************************************/
765 typedef int (*USBD_SetupCmdCb_TypeDef)( const USB_Setup_TypeDef *setup );
766 
769 typedef struct USBD_Callbacks_TypeDef const *USBD_Callbacks_TypeDef_Pointer;
776 typedef struct
777 {
779  const uint8_t *configDescriptor;
780  const void * const *stringDescriptors;
781  const uint8_t numberOfStrings;
782  const uint8_t *bufferingMultiplier;
787  USBD_Callbacks_TypeDef_Pointer callbacks;
791  const uint32_t reserved;
793 
794 
800 {
811 
812 
813 /*** -------------------- DEVICE mode API -------------------------------- ***/
814 
815 void USBD_AbortAllTransfers( void );
816 int USBD_AbortTransfer( int epAddr );
817 void USBD_Connect( void );
818 void USBD_Disconnect( void );
819 bool USBD_EpIsBusy( int epAddr );
821 const char * USBD_GetUsbStateName( USBD_State_TypeDef state );
822 int USBD_Init( const USBD_Init_TypeDef *p );
823 int USBD_Read( int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback );
824 int USBD_RemoteWakeup( void );
825 bool USBD_SafeToEnterEM2( void );
826 int USBD_StallEp( int epAddr );
827 void USBD_Stop( void );
828 int USBD_UnStallEp( int epAddr );
829 int USBD_Write( int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback );
830 
832 #endif /* defined( USB_DEVICE ) */
833 
834 
835 #if defined( USB_HOST )
836 /***************************************************************************/
841 /*** -------------------- HOST mode API definitions ---------------------- ***/
842 
843 #define USB_VBUSOVRCUR_PORT_NONE -1
844 #define USB_VBUSOVRCUR_POLARITY_LOW 0
845 #define USB_VBUSOVRCUR_POLARITY_HIGH 1
848 typedef enum
849 {
850  H_EP_IDLE = 0,
857 
858 
862 typedef struct
863 {
865  uint8_t setupErrCnt;
868  uint8_t type;
869  uint16_t packetSize;
870  uint8_t hcOut;
871  uint8_t hcIn;
872  bool in;
873  uint8_t toggle;
875  uint8_t addr;
876  uint8_t *buf;
877  volatile bool xferCompleted;
880  uint32_t xferred;
881  uint32_t remaining;
882  uint32_t timeout;
884 
885 
889 typedef struct USBH_Device_TypeDef
890 {
896  int numEp;
897  uint8_t addr;
898  uint8_t speed;
900 
901 
905 typedef struct
906 {
907  uint32_t rxFifoSize;
908  uint32_t nptxFifoSize;
909  uint32_t ptxFifoSize;
910  uint32_t reserved;
912 
913 
916 /* In DMA mode the total available FIFO space is smaller. */
917 /* The DMA controller use one FIFO word pr. channel for status. */
918 /* The unit in the table is byte. */
919 #define USBH_INIT_DEFAULT \
920 { \
921  MAX_HOST_FIFO_SIZE_INWORDS * 2,/* 1024 bytes Rx FIFO size. */ \
922  MAX_HOST_FIFO_SIZE_INWORDS, /* 512 bytes non-periodic Tx FIFO size. */ \
923  MAX_HOST_FIFO_SIZE_INWORDS, /* 512 bytes periodic Tx FIFO size. */ \
924  0 /* Reserved. */ \
925 }
926 
927 /*** -------------------- HOST mode API ---------------------------------- ***/
928 
929 int USBH_AssignHostChannel( USBH_Ep_TypeDef *ep, uint8_t hcnum );
930 int USBH_ControlMsg( USBH_Ep_TypeDef *ep, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void *data, int timeout, USB_XferCompleteCb_TypeDef callback );
931 int USBH_ControlMsgB( USBH_Ep_TypeDef *ep, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void *data, int timeout );
932 bool USBH_DeviceConnected( void );
933 int USBH_GetConfigurationDescriptorB( USBH_Device_TypeDef *device, void *buf, int len, uint8_t configIndex );
934 int USBH_GetDeviceDescriptorB( USBH_Device_TypeDef *device, void *buf, int len );
935 uint8_t USBH_GetPortSpeed( void );
936 int USBH_GetStringB( USBH_Device_TypeDef *device, uint8_t *buf, int bufLen, uint8_t stringIndex, uint16_t langID );
937 int USBH_Init( const USBH_Init_TypeDef *p );
938 int USBH_InitDeviceData( USBH_Device_TypeDef *device, const uint8_t *buf, USBH_Ep_TypeDef *ep, int numEp, uint8_t deviceSpeed );
939 int USBH_PortReset( void );
940 int USBH_PortResume( void );
941 void USBH_PortSuspend( void );
942 void USBH_PrintString( const char *pre, const USB_StringDescriptor_TypeDef *s, const char *post );
943 
944 #if defined( USB_USE_PRINTF )
949 #else
950 #define USBH_PrintConfigurationDescriptor( config, maxLen )
951 #define USBH_PrintDeviceDescriptor( device )
952 #define USBH_PrintEndpointDescriptor( endpoint )
953 #define USBH_PrintInterfaceDescriptor( interface )
954 #endif /* defined( USB_USE_PRINTF ) */
955 
956 int USBH_QueryDeviceB( uint8_t *buf, size_t bufsize, uint8_t deviceSpeed );
957 USB_ConfigurationDescriptor_TypeDef* USBH_QGetConfigurationDescriptor( const uint8_t *buf, int configIndex );
959 USB_EndpointDescriptor_TypeDef* USBH_QGetEndpointDescriptor( const uint8_t *buf, int configIndex, int interfaceIndex, int endpointIndex );
960 USB_InterfaceDescriptor_TypeDef* USBH_QGetInterfaceDescriptor( const uint8_t *buf, int configIndex, int interfaceIndex );
961 
962 int USBH_Read( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback );
963 int USBH_ReadB( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout );
964 int USBH_SetAddressB( USBH_Device_TypeDef *device, uint8_t deviceAddress );
965 int USBH_SetAltInterfaceB( USBH_Device_TypeDef *device, uint8_t interfaceIndex, uint8_t alternateSetting );
966 int USBH_SetConfigurationB( USBH_Device_TypeDef *device, uint8_t configValue );
967 int USBH_StallEpB( USBH_Ep_TypeDef *ep );
968 void USBH_Stop( void );
970 int USBH_WaitForDeviceConnectionB( uint8_t *buf, int timeoutInSeconds );
971 int USBH_Write( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback );
972 int USBH_WriteB( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout );
973 
975 #endif /* defined( USB_HOST ) */
976 
978 #ifdef __cplusplus
979 }
980 #endif
981 
982 #endif /* defined( USB_DEVICE ) || defined( USB_HOST ) */
983 #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
984 #endif /* __EM_USB_H */
uint8_t hcIn
Definition: em_usb.h:871
void(* USBD_SofIntCb_TypeDef)(uint16_t sofNr)
USB Start Of Frame (SOF) interrupt callback function.
Definition: em_usb.h:716
int USBH_WriteB(USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout)
Write data to device endpoint, blocking version.
Definition: em_usbh.c:2417
const uint8_t * bufferingMultiplier
Definition: em_usb.h:782
const uint32_t reserved
Definition: em_usb.h:791
int USBH_UnStallEpB(USBH_Ep_TypeDef *ep)
Reset stall state on a stalled (halted) endpoint.
Definition: em_usbh.c:2068
void USBTIMER_Stop(uint32_t id)
Stop a timer.
Definition: em_usbtimer.c:302
Emlib peripheral API "assert" implementation.
USB Device stack initialization structure.
Definition: em_usb.h:776
void USBH_PortSuspend(void)
Set the USB port in suspend mode.
Definition: em_usbh.c:1036
uint8_t bmRequestType
Definition: em_usb.h:389
uint32_t xferred
Definition: em_usb.h:880
uint32_t ptxFifoSize
Definition: em_usb.h:909
uint16_t wValue
Definition: em_usb.h:392
USB HOST device definition.
Definition: em_usb.h:889
int USB_PRINTF(const char *format,...)
Transmit "printf" formated data on the debug serial port.
USB_DeviceDescriptor_TypeDef * USBH_QGetDeviceDescriptor(const uint8_t *buf)
Return a pointer to the device descriptor.
Definition: em_usbh.c:1387
void USB_PrintErrorMsgString(char *pre, int error)
Format and print a text string given an error code, prepends an optional user supplied leader string...
Definition: em_usbhal.c:92
#define EFM32_PACK_START(x)
Definition: em_common.h:88
int USBH_ReadB(USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout)
Read data from device endpoint, blocking version.
Definition: em_usbh.c:1794
USB Host stack initialization structure.
Definition: em_usb.h:905
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
USB_InterfaceDescriptor_TypeDef * USBH_QGetInterfaceDescriptor(const uint8_t *buf, int configIndex, int interfaceIndex)
Return a pointer to an interface descriptor.
Definition: em_usbh.c:1506
int USBH_GetDeviceDescriptorB(USBH_Device_TypeDef *device, void *buf, int len)
Read a device descriptor from a device.
Definition: em_usbh.c:704
int USBH_PrintConfigurationDescriptor(const USB_ConfigurationDescriptor_TypeDef *config, int maxLen)
Pretty print a configuration descriptor on the debug serial port.
Definition: em_usbh.c:1085
const USBD_UsbResetCb_TypeDef usbReset
Definition: em_usb.h:801
void(* USBTIMER_Callback_TypeDef)(void)
USBTIMER callback function.
Definition: em_usb.h:673
const USB_DeviceDescriptor_TypeDef * deviceDescriptor
Definition: em_usb.h:778
void USBD_Connect(void)
Start USB device operation.
Definition: em_usbd.c:123
USBH_Ep_TypeDef * ep
Definition: em_usb.h:895
int USBH_ControlMsgB(USBH_Ep_TypeDef *ep, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void *data, int timeout)
Send a SETUP command to a device, blocking version.
Definition: em_usbh.c:367
char * USB_GetErrorMsgString(int error)
Return an error message string for a given error code.
Definition: em_usbhal.c:71
Emlib general purpose utilities.
#define EFM32_PACK_END()
Definition: em_common.h:95
const USBD_IsSelfPoweredCb_TypeDef isSelfPowered
Definition: em_usb.h:805
void USBTIMER_DelayMs(uint32_t msec)
Active wait millisecond delay function. Can also be used inside interrupt handlers.
Definition: em_usbtimer.c:135
USB Interface Descriptor.
Definition: em_usb.h:457
int USBD_Init(const USBD_Init_TypeDef *p)
Initializes USB device hardware and internal protocol stack data structures, then connects the data-l...
Definition: em_usbd.c:218
USB Setup request package.
Definition: em_usb.h:375
uint8_t setupErrCnt
Definition: em_usb.h:865
USBD_State_TypeDef
USB device state enumerator.
Definition: em_usb.h:356
int(* USB_XferCompleteCb_TypeDef)(USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining)
USB transfer callback function.
Definition: em_usb.h:663
void USBD_AbortAllTransfers(void)
Abort all pending transfers.
Definition: em_usbd.c:53
uint16_t packetSize
Definition: em_usb.h:869
bool USBH_DeviceConnected(void)
Check if a device is connected.
Definition: em_usbh.c:612
int(* USBD_SetupCmdCb_TypeDef)(const USB_Setup_TypeDef *setup)
USB setup request callback function.
Definition: em_usb.h:765
USB_Status_TypeDef
USB transfer status enumerator.
Definition: em_usb.h:316
int USBH_GetConfigurationDescriptorB(USBH_Device_TypeDef *device, void *buf, int len, uint8_t configIndex)
Read a configuration descriptor from a device.
Definition: em_usbh.c:647
void(* USBD_DeviceStateChangeCb_TypeDef)(USBD_State_TypeDef oldState, USBD_State_TypeDef newState)
USB State change callback function.
Definition: em_usb.h:731
Interrupt enable/disable unit API.
uint16_t wIndex
Definition: em_usb.h:393
int USBH_SetAddressB(USBH_Device_TypeDef *device, uint8_t deviceAddress)
Give a device an USB address.
Definition: em_usbh.c:1841
USB Device stack callback structure.
Definition: em_usb.h:799
volatile bool xferCompleted
Definition: em_usb.h:877
uint32_t timeout
Definition: em_usb.h:882
USB_Status_TypeDef xferStatus
Definition: em_usb.h:878
int USBH_StallEpB(USBH_Ep_TypeDef *ep)
Set an endpoint in the stalled (halted) state.
Definition: em_usbh.c:2009
const uint8_t * configDescriptor
Definition: em_usb.h:779
int USBH_SetAltInterfaceB(USBH_Device_TypeDef *device, uint8_t interfaceIndex, uint8_t alternateSetting)
Activate a device interface within current device configuration.
Definition: em_usbh.c:1897
void USBH_PrintString(const char *pre, const USB_StringDescriptor_TypeDef *s, const char *post)
Print a USB string descriptor on the debug serial port.
Definition: em_usbh.c:1268
struct USBH_Device_TypeDef * parentDevice
Definition: em_usb.h:867
void(* USBD_UsbResetCb_TypeDef)(void)
USB Reset callback function.
Definition: em_usb.h:704
void USB_PUTS(const char *p)
Transmit a zero terminated string on the debug serial port.
struct USBH_Device_TypeDef USBH_Device_TypeDef
USB HOST device definition.
struct USBD_Callbacks_TypeDef USBD_Callbacks_TypeDef
USB Device stack callback structure.
int USBH_Init(const USBH_Init_TypeDef *p)
Initialize host protocol stack data structures.
Definition: em_usbh.c:837
const void *const * stringDescriptors
Definition: em_usb.h:780
int USBH_GetStringB(USBH_Device_TypeDef *device, uint8_t *buf, int bufLen, uint8_t stringIndex, uint16_t langID)
Read a string descriptor from a device.
Definition: em_usbh.c:779
int USBD_AbortTransfer(int epAddr)
Abort a pending transfer on a specific endpoint.
Definition: em_usbd.c:67
USB_ConfigurationDescriptor_TypeDef confDesc
Definition: em_usb.h:892
unsigned short char16_t
Definition: em_usb.h:238
USBH_Ep_TypeDef ep0
Definition: em_usb.h:894
USB Endpoint Descriptor.
Definition: em_usb.h:498
int USBH_PortReset(void)
Drive reset signalling on the USB port.
Definition: em_usbh.c:982
uint8_t addr
Definition: em_usb.h:875
int USBH_Read(USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback)
Read data from device endpoint, non-blocking version.
Definition: em_usbh.c:1672
USBD_Callbacks_TypeDef_Pointer callbacks
Definition: em_usb.h:787
USB_InterfaceDescriptor_TypeDef itfDesc
Definition: em_usb.h:893
int USBD_RemoteWakeup(void)
Perform a remote wakeup signalling sequence.
Definition: em_usbd.c:631
int USBD_StallEp(int epAddr)
Set an endpoint in the stalled (halted) state.
Definition: em_usbd.c:708
uint32_t remaining
Definition: em_usb.h:881
uint32_t reserved
Definition: em_usb.h:910
int USBH_WaitForDeviceConnectionB(uint8_t *buf, int timeoutInSeconds)
Wait for device connection.
Definition: em_usbh.c:2146
uint16_t wLength
Definition: em_usb.h:394
USBD_State_TypeDef USBD_GetUsbState(void)
Get current USB device state.
Definition: em_usbd.c:179
bool(* USBD_IsSelfPoweredCb_TypeDef)(void)
USB power mode callback function.
Definition: em_usb.h:745
uint32_t rxFifoSize
Definition: em_usb.h:907
int USBD_Write(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a write (IN) transfer on an endpoint.
Definition: em_usbd.c:820
int USBD_UnStallEp(int epAddr)
Reset stall state on a stalled (halted) endpoint.
Definition: em_usbd.c:769
const uint8_t numberOfStrings
Definition: em_usb.h:781
int USBH_PrintDeviceDescriptor(const USB_DeviceDescriptor_TypeDef *device)
Pretty print a device descriptor on the debug serial port.
Definition: em_usbh.c:1142
uint8_t type
Definition: em_usb.h:868
const USBD_DeviceStateChangeCb_TypeDef usbStateChange
Definition: em_usb.h:803
USB_EndpointDescriptor_TypeDef * USBH_QGetEndpointDescriptor(const uint8_t *buf, int configIndex, int interfaceIndex, int endpointIndex)
Return a pointer to an endpoint descriptor.
Definition: em_usbh.c:1434
USB_DeviceDescriptor_TypeDef devDesc
Definition: em_usb.h:891
void USBD_Stop(void)
Stop USB device stack operation.
Definition: em_usbd.c:747
uint8_t USBH_GetPortSpeed(void)
Get the bus speed of the device attached to the USB port.
Definition: em_usbh.c:741
USB_Setup_TypeDef setup
Definition: em_usb.h:864
int USBH_PrintEndpointDescriptor(const USB_EndpointDescriptor_TypeDef *endpoint)
Pretty print an endpoint descriptor on the debug serial port.
Definition: em_usbh.c:1184
USB_ConfigurationDescriptor_TypeDef * USBH_QGetConfigurationDescriptor(const uint8_t *buf, int configIndex)
Return a pointer to a configuration descriptor.
Definition: em_usbh.c:1331
USBH_EpState_TypeDef
Definition: em_usb.h:848
void USBD_Disconnect(void)
Stop USB device operation.
Definition: em_usbd.c:138
int USBH_SetConfigurationB(USBH_Device_TypeDef *device, uint8_t configValue)
Activate a device configuration.
Definition: em_usbh.c:1956
uint32_t nptxFifoSize
Definition: em_usb.h:908
void USBTIMER_Init(void)
Activate the hardware timer used to pace the 1 millisecond timer system.
Definition: em_usbtimer.c:190
USB Configuration Descriptor.
Definition: em_usb.h:428
const char * USBD_GetUsbStateName(USBD_State_TypeDef state)
Get a string naming a device USB state.
Definition: em_usbd.c:194
USB_EndpointDescriptor_TypeDef epDesc
Definition: em_usb.h:866
const USBD_SetupCmdCb_TypeDef setupCmd
Definition: em_usb.h:804
USB_XferCompleteCb_TypeDef xferCompleteCb
Definition: em_usb.h:879
int USBH_ControlMsg(USBH_Ep_TypeDef *ep, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void *data, int timeout, USB_XferCompleteCb_TypeDef callback)
Send a SETUP command to a device, non-blocking version.
Definition: em_usbh.c:246
USB HOST endpoint status data.
Definition: em_usb.h:862
const USBD_SofIntCb_TypeDef sofInt
Definition: em_usb.h:808
int USBH_QueryDeviceB(uint8_t *buf, size_t bufsize, uint8_t deviceSpeed)
Will request both the device descriptor and the entire configuration descriptor from the device at US...
Definition: em_usbh.c:1582
uint8_t toggle
Definition: em_usb.h:873
int USBH_PrintInterfaceDescriptor(const USB_InterfaceDescriptor_TypeDef *interface)
Pretty print an interface descriptor on the debug serial port.
Definition: em_usbh.c:1219
int USBH_PortResume(void)
Drive resume signalling on the USB port.
Definition: em_usbh.c:1012
USB Device Descriptor.
Definition: em_usb.h:404
bool USBD_SafeToEnterEM2(void)
Check if it is ok to enter energy mode EM2.
Definition: em_usbd.c:665
int USBH_InitDeviceData(USBH_Device_TypeDef *device, const uint8_t *buf, USBH_Ep_TypeDef *ep, int numEp, uint8_t deviceSpeed)
Populate device and endpoint data structures with data retrieved during device enumeration.
Definition: em_usbh.c:905
int USB_PUTCHAR(char c)
Transmit a single char on the debug serial port.
void USBTIMER_Start(uint32_t id, uint32_t timeout, USBTIMER_Callback_TypeDef callback)
Start a timer.
Definition: em_usbtimer.c:234
void USBH_Stop(void)
Stop USB host operation.
Definition: em_usbh.c:2036
uint8_t bRequest
Definition: em_usb.h:391
USB String Descriptor.
Definition: em_usb.h:512
void USBTIMER_DelayUs(uint32_t usec)
Active wait microsecond delay function. Can also be used inside interrupt handlers.
Definition: em_usbtimer.c:156
int USBH_Write(USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback)
Write data to device endpoint, non-blocking version.
Definition: em_usbh.c:2297
uint8_t hcOut
Definition: em_usb.h:870
bool USBD_EpIsBusy(int epAddr)
Check if an endpoint is busy doing a transfer.
Definition: em_usbd.c:155
uint8_t * buf
Definition: em_usb.h:876
int USBH_AssignHostChannel(USBH_Ep_TypeDef *ep, uint8_t hcnum)
Assign a host channel to a given endpoint.
Definition: em_usbh.c:160
USBH_EpState_TypeDef state
Definition: em_usb.h:874
int USBD_Read(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a read (OUT) transfer on an endpoint.
Definition: em_usbd.c:545