EFM32 Happy Gecko Software Documentation  efm32hg-doc-5.1.2
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 
29 #if defined(USB_USE_PRINTF)
30 #include <stdio.h>
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #ifdef __CC_ARM
38 #pragma anon_unions
39 #endif
40 
41 #if defined(USB_HOST)
42 /***************************************************************************/
47 /***************************************************************************/
51 #else
52 /***************************************************************************/
57 /***************************************************************************/
61 #endif
62 
63 #define SILABS_USB_VID 0x10C4
65 /* SETUP request, direction of data stage */
66 #define USB_SETUP_DIR_OUT 0
67 #define USB_SETUP_DIR_IN 1
68 #define USB_SETUP_DIR_MASK 0x80
69 #define USB_SETUP_DIR_D2H 0x80
70 #define USB_SETUP_DIR_H2D 0x00
72 /* SETUP request type */
73 #define USB_SETUP_TYPE_STANDARD 0
74 #define USB_SETUP_TYPE_CLASS 1
75 #define USB_SETUP_TYPE_VENDOR 2
76 #define USB_SETUP_TYPE_STANDARD_MASK 0x00
77 #define USB_SETUP_TYPE_CLASS_MASK 0x20
78 #define USB_SETUP_TYPE_VENDOR_MASK 0x40
80 /* SETUP request recipient */
81 #define USB_SETUP_RECIPIENT_DEVICE 0
82 #define USB_SETUP_RECIPIENT_INTERFACE 1
83 #define USB_SETUP_RECIPIENT_ENDPOINT 2
84 #define USB_SETUP_RECIPIENT_OTHER 3
86 /* SETUP standard request codes for Full Speed devices */
87 #define GET_STATUS 0
88 #define CLEAR_FEATURE 1
89 #define SET_FEATURE 3
90 #define SET_ADDRESS 5
91 #define GET_DESCRIPTOR 6
92 #define SET_DESCRIPTOR 7
93 #define GET_CONFIGURATION 8
94 #define SET_CONFIGURATION 9
95 #define GET_INTERFACE 10
96 #define SET_INTERFACE 11
97 #define SYNCH_FRAME 12
99 /* SETUP class request codes */
100 #define USB_HID_GET_REPORT 0x01
101 #define USB_HID_GET_IDLE 0x02
102 #define USB_HID_SET_REPORT 0x09
103 #define USB_HID_SET_IDLE 0x0A
104 #define USB_HID_SET_PROTOCOL 0x0B
105 #define USB_CDC_SETLINECODING 0x20
106 #define USB_CDC_GETLINECODING 0x21
107 #define USB_CDC_SETCTRLLINESTATE 0x22
108 #define USB_MSD_BOTRESET 0xFF
109 #define USB_MSD_GETMAXLUN 0xFE
110 #define USB_AUDIO_GET_CUR 0x81
111 #define USB_AUDIO_SET_CUR 0x01
112 #define USB_AUDIO_GET_CUR 0x81
113 #define USB_AUDIO_SET_MIN 0x02
114 #define USB_AUDIO_GET_MIN 0x82
115 #define USB_AUDIO_SET_MAX 0x03
116 #define USB_AUDIO_GET_MAX 0x83
117 #define USB_AUDIO_SET_RES 0x04
118 #define USB_AUDIO_GET_RES 0x84
119 #define USB_AUDIO_SET_MEM 0x05
120 #define USB_AUDIO_GET_MEM 0x85
121 #define USB_AUDIO_GET_STAT 0xFF
123 /* SETUP command GET/SET_DESCRIPTOR decriptor types */
124 #define USB_DEVICE_DESCRIPTOR 1
125 #define USB_CONFIG_DESCRIPTOR 2
126 #define USB_STRING_DESCRIPTOR 3
127 #define USB_MAX_STRING_DESCRIPTOR_CHARS 126
128 #define USB_INTERFACE_DESCRIPTOR 4
129 #define USB_ENDPOINT_DESCRIPTOR 5
130 #define USB_DEVICE_QUALIFIER_DESCRIPTOR 6
131 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR 7
132 #define USB_INTERFACE_POWER_DESCRIPTOR 8
133 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR 11
134 #define USB_HID_DESCRIPTOR 0x21
135 #define USB_SMARTCARD_DESCRIPTOR 0x21
136 #define USB_HID_REPORT_DESCRIPTOR 0x22
137 #define USB_CS_INTERFACE_DESCRIPTOR 0x24
138 #define USB_CS_ENDPOINT_DESCRIPTOR 0x25
139 #define USB_HUB_DESCRIPTOR 0x29
140 #define USB_CA_HEADER_DESCRIPTOR 1
141 #define USB_CA_INPUT_TERMINAL_DESCRIPTOR 2
142 #define USB_CA_OUTPUT_TERMINAL_DESCRIPTOR 3
143 #define USB_CA_MIXER_UNIT_DESCRIPTOR 4
144 #define USB_CA_SELECTOR_UNIT_DESCRIPTOR 5
145 #define USB_CA_FEATURE_UNIT_DESCRIPTOR 6
146 #define USB_CA_PROCESSING_UNIT_DESCRIPTOR 7
147 #define USB_CA_EXTENSION_UNIT_DESCRIPTOR 8
148 #define USB_CA_EP_GENERAL_DESCRIPTOR 1
149 #define USB_CA_AS_GENERAL_DESCRIPTOR 1
150 #define USB_CA_FORMAT_TYPE_DESCRIPTOR 2
152 #define USB_DEVICE_DESCSIZE 18
153 #define USB_CONFIG_DESCSIZE 9
154 #define USB_INTERFACE_DESCSIZE 9
155 #define USB_ENDPOINT_DESCSIZE 7
156 #define USB_DEVICE_QUALIFIER_DESCSIZE 10
157 #define USB_OTHER_SPEED_CONFIG_DESCSIZE 9
158 #define USB_INTERFACE_ASSOCIATION_DESCSIZE 8
159 #define USB_HID_DESCSIZE 9
160 #define USB_SMARTCARD_DESCSIZE 54
161 #define USB_CDC_HEADER_FND_DESCSIZE 5
162 #define USB_CDC_CALLMNG_FND_DESCSIZE 5
163 #define USB_CDC_ACM_FND_DESCSIZE 4
164 #define USB_CA_INPUT_TERMINAL_DESCSIZE 12
165 #define USB_CA_OUTPUT_TERMINAL_DESCSIZE 9
166 #define USB_CA_EP_GENERAL_DESCSIZE 7
167 #define USB_CA_AS_GENERAL_DESCSIZE 7
168 #define USB_CA_STD_AS_ENDPOINT_DESCSZIE 9
170 /* Misc. USB definitions */
171 #define USB_LS_CTRL_EP_MAXSIZE 8
172 #define USB_LS_INTR_EP_MAXSIZE 8
173 #define USB_FS_CTRL_EP_MAXSIZE 64
174 #define USB_FS_INTR_EP_MAXSIZE 64
175 #define USB_FS_BULK_EP_MAXSIZE 64
176 #define USB_FS_ISOC_EP_MAXSIZE 1023
177 #define USB_EPTYPE_CTRL 0
178 #define USB_EPTYPE_ISOC 1
179 #define USB_EPTYPE_BULK 2
180 #define USB_EPTYPE_INTR 3
181 #define USB_EPSYNC_NO (0 << 2)
182 #define USB_EPSYNC_ASYNC (1 << 2)
183 #define USB_EPSYNC_ADAPTIVE (2 << 2)
184 #define USB_EPSYNC_SYNC (3 << 2)
185 #define USB_EP_DIR_IN 0x80
186 #define USB_SETUP_PKT_SIZE 8
187 #define USB_EPNUM_MASK 0x0F
188 #define USB_LANGID_ENUS 0x0409
189 #define USB_MAX_DEVICE_ADDRESS 127
191 #define CONFIG_DESC_BM_REMOTEWAKEUP 0x20
192 #define CONFIG_DESC_BM_SELFPOWERED 0x40
193 #define CONFIG_DESC_BM_RESERVED_D7 0x80
194 #define CONFIG_DESC_BM_TRANSFERTYPE 0x03
195 #define CONFIG_DESC_MAXPOWER_mA(x) (((x)+1)/2)
197 #define DEVICE_IS_SELFPOWERED 0x0001
198 #define REMOTE_WAKEUP_ENABLED 0x0002
199 #define USB_FEATURE_ENDPOINT_HALT 0
200 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1
202 #define HUB_FEATURE_PORT_RESET 4
203 #define HUB_FEATURE_PORT_POWER 8
204 #define HUB_FEATURE_C_PORT_CONNECTION 16
205 #define HUB_FEATURE_C_PORT_RESET 20
206 #define HUB_FEATURE_PORT_INDICATOR 22
208 #define USB_CLASS_CDC 2
209 #define USB_CLASS_CDC_DATA 0x0A
210 #define USB_CLASS_CDC_ACM 2
211 #define USB_CLASS_CDC_HFN 0
212 #define USB_CLASS_CDC_CMNGFN 1
213 #define USB_CLASS_CDC_ACMFN 2
214 #define USB_CLASS_CDC_UNIONFN 6
216 #define USB_CLASS_HID 3
217 #define USB_CLASS_HID_KEYBOARD 1
218 #define USB_CLASS_HID_MOUSE 2
220 #define USB_CLASS_HUB 9
222 #define USB_CLASS_MSD 8
223 #define USB_CLASS_MSD_BOT_TRANSPORT 0x50
224 #define USB_CLASS_MSD_SCSI_CMDSET 6
225 #define USB_CLASS_MSD_CSW_CMDPASSED 0
226 #define USB_CLASS_MSD_CSW_CMDFAILED 1
227 #define USB_CLASS_MSD_CSW_PHASEERROR 2
229 #define USB_CLASS_AUDIO 1
230 #define USB_CLASS_AUDIO_CONTROL 1
231 #define USB_CLASS_AUDIO_STREAMING 2
232 #define USB_CLASS_AUDIO_MIDISTREAMING 3
234 /*** Triplet for the device descriptor of a composite device using IAD descriptors. ***/
235 #define USB_CLASS_MISCELLANEOUS 0xEF
236 #define USB_CLASS_MISC_COMMON_SUBCLASS 2
237 #define USB_CLASS_MISC_IAD_PROTOCOL 1
239 #define PORT_FULL_SPEED 1
240 #define PORT_LOW_SPEED 2
242 #if defined(__GNUC__) /* GCC compilers */
243 #if defined(__CHAR16_TYPE__)
244 typedef __CHAR16_TYPE__ char16_t;
245 #else
246 typedef unsigned short char16_t;
247 #endif
248 
249 #elif defined(__ICCARM__) /* IAR compiler */
250 #include <uchar.h>
251 
252 #elif defined(__CC_ARM) /* MDK-ARM compiler */
253 typedef unsigned short char16_t;
254 #endif
255 
263 #define STATIC_CONST_STRING_DESC(_name, ...) \
264 SL_PACK_START(1) \
265 typedef struct \
266 { \
267  uint8_t len; \
268  uint8_t type; \
269  char16_t name[ 1 + sizeof((char16_t[]){__VA_ARGS__}) / 2]; \
270 } SL_ATTRIBUTE_PACKED _##_name; \
271 SL_PACK_END() \
272 SL_ALIGN(4) \
273 SL_PACK_START(1) \
274 static const _##_name _name SL_ATTRIBUTE_ALIGN(4)= \
275 { \
276  .len = sizeof(_##_name) - 2, \
277  .type = USB_STRING_DESCRIPTOR, \
278  .name = {__VA_ARGS__}, \
279  .name[((sizeof(_##_name) - 2) / 2) - 1] = '\0' \
280 } \
281 SL_PACK_END()
282 
286 #define STATIC_CONST_STRING_DESC_LANGID(_name, x, y) \
287 SL_PACK_START(1) \
288 typedef struct \
289 { \
290  uint8_t len; \
291  uint8_t type; \
292  uint8_t name[ 2 ]; \
293 } SL_ATTRIBUTE_PACKED _##_name; \
294 SL_PACK_END() \
295 SL_ALIGN(4) \
296 SL_PACK_START(1) \
297 static const _##_name _name SL_ATTRIBUTE_ALIGN(4)= \
298 { \
299  .len = 4, \
300  .type = USB_STRING_DESCRIPTOR, \
301  .name = { y, x } \
302 } \
303 SL_PACK_END()
304 
309 #define UBUF(x, y) SL_ALIGN(4) uint8_t x[((y)+3)&~3] SL_ATTRIBUTE_ALIGN(4)
310 
315 #define STATIC_UBUF(x, y) SL_ALIGN(4) static uint8_t x[((y)+3)&~3] SL_ATTRIBUTE_ALIGN(4)
316 
317 
319 typedef enum
320 {
321  /* NOTE: Please keep in sync with table errMsg[] in em_usbhal.c */
343 #if defined(USB_DEVICE)
344 /***************************************************************************/
349 #define USB_PWRSAVE_MODE_OFF 0
350 #define USB_PWRSAVE_MODE_ONSUSPEND 1
351 #define USB_PWRSAVE_MODE_ONVBUSOFF 2
352 #define USB_PWRSAVE_MODE_ENTEREM2 4
354 #define USB_USBC_32kHz_CLK_LFXO 0
355 #define USB_USBC_32kHz_CLK_LFRCO 1
358 typedef enum
359 {
370 #endif /* defined(USB_DEVICE) */
371 
376 SL_PACK_START(1)
377 typedef struct
378 {
379  union
380  {
381  struct
382  {
383  union
384  {
385  struct
386  {
387  uint8_t Recipient : 5;
388  uint8_t Type : 2;
389  uint8_t Direction : 1;
390  };
391  uint8_t bmRequestType;
392  };
393  uint8_t bRequest;
394  uint16_t wValue;
395  uint16_t wIndex;
396  uint16_t wLength;
397  };
398  uint32_t dw[2];
399  };
401 SL_PACK_END()
402 
403 
404 
405 SL_PACK_START(1)
406 typedef struct
407 {
408  uint8_t bLength;
409  uint8_t bDescriptorType;
410  uint16_t bcdUSB;
412  uint8_t bDeviceClass;
413  uint8_t bDeviceSubClass;
414  uint8_t bDeviceProtocol;
415  uint8_t bMaxPacketSize0;
416  uint16_t idVendor;
417  uint16_t idProduct;
418  uint16_t bcdDevice;
419  uint8_t iManufacturer;
420  uint8_t iProduct;
421  uint8_t iSerialNumber;
425 SL_PACK_END()
426 
427 
428 
429 SL_PACK_START(1)
430 typedef struct
431 {
432  uint8_t bLength;
433  uint8_t bDescriptorType;
434  uint16_t wTotalLength;
439  uint8_t bNumInterfaces;
444  uint8_t iConfiguration;
446  uint8_t bmAttributes;
451  uint8_t bMaxPower;
454 SL_PACK_END()
455 
456 
457 
458 SL_PACK_START(1)
459 typedef struct
460 {
461  uint8_t bLength;
462  uint8_t bDescriptorType;
468  uint8_t bNumEndpoints;
471  uint8_t bInterfaceClass;
492  uint8_t iInterface;
495 SL_PACK_END()
496 
497 
498 
499 SL_PACK_START(1)
500 typedef struct
501 {
502  uint8_t bLength;
503  uint8_t bDescriptorType;
505  uint8_t bmAttributes;
506  uint16_t wMaxPacketSize;
507  uint8_t bInterval;
509 SL_PACK_END()
510 
511 
512 
513 SL_PACK_START(1)
514 typedef struct
515 {
516  uint8_t len;
517  uint8_t type;
518  char16_t name[];
520 SL_PACK_END()
521 
522 
524 /*** -------------------- Serial port debug configuration ---------------- ***/
525 
526 #if defined(DOXY_DOC_ONLY)
527 
530 /***************************************************************************/
546 int USB_PUTCHAR(char c);
547 
548 /***************************************************************************/
561 void USB_PUTS(const char *p);
562 
563 /***************************************************************************/
579 int USB_PRINTF(const char *format, ...);
580 
582 #endif /* defined(DOXY_DOC_ONLY) */
583 
586 /* Hardware constraint, do not change. */
587 #define MAX_NUM_HOSTCHANNELS 14
588 
589 /* The DMA engine use one FIFO ram word for each host channel. */
590 #define MAX_HOST_FIFO_SIZE_INWORDS (512-MAX_NUM_HOSTCHANNELS)/*Unit is 4 bytes*/
591 
592 #if defined (USER_PUTCHAR)
593  void USB_Puts(const char *p);
594  #define USB_PUTS(s) USB_Puts(s)
595  #define USB_PUTCHAR(c) USER_PUTCHAR(c)
596 #else
597  #define USB_PUTS(s)
598  #define USB_PUTCHAR(c)
599 #endif
600 
601 #if defined(USB_USE_PRINTF)
602  #define USB_PRINTF printf
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 {
778  const USB_DeviceDescriptor_TypeDef *deviceDescriptor;
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 /***************************************************************************/
840 /*** -------------------- HOST mode API definitions ---------------------- ***/
841 
842 #define USB_VBUSOVRCUR_PORT_NONE -1
843 #define USB_VBUSOVRCUR_POLARITY_LOW 0
844 #define USB_VBUSOVRCUR_POLARITY_HIGH 1
847 typedef enum
848 {
849  H_EP_IDLE = 0,
850  H_EP_SETUP = 1,
851  H_EP_DATA_IN = 2,
852  H_EP_DATA_OUT = 3,
853  H_EP_STATUS_IN = 4,
854  H_EP_STATUS_OUT = 5,
855 } USBH_EpState_TypeDef;
856 
857 
861 typedef struct
862 {
863  USB_Setup_TypeDef setup;
864  uint8_t setupErrCnt;
865  USB_EndpointDescriptor_TypeDef epDesc;
866  struct USBH_Device_TypeDef *parentDevice;
867  uint8_t type;
868  uint16_t packetSize;
869  uint8_t hcOut;
870  uint8_t hcIn;
871  bool in;
872  uint8_t toggle;
873  USBH_EpState_TypeDef state;
874  uint8_t addr;
875  uint8_t *buf;
876  volatile bool xferCompleted;
877  USB_Status_TypeDef xferStatus;
878  USB_XferCompleteCb_TypeDef xferCompleteCb;
879  uint32_t xferred;
880  uint32_t remaining;
881  uint32_t timeout;
882 } USBH_Ep_TypeDef;
883 
884 
888 typedef struct USBH_Device_TypeDef
889 {
890  USB_DeviceDescriptor_TypeDef devDesc;
891  USB_ConfigurationDescriptor_TypeDef confDesc;
892  USB_InterfaceDescriptor_TypeDef itfDesc;
893  USBH_Ep_TypeDef ep0;
894  USBH_Ep_TypeDef *ep;
895  int numEp;
896  uint8_t addr;
897  uint8_t speed;
898 } USBH_Device_TypeDef;
899 
900 
904 typedef struct
905 {
906  uint32_t rxFifoSize;
907  uint32_t nptxFifoSize;
908  uint32_t ptxFifoSize;
909  uint32_t reserved;
910 } USBH_Init_TypeDef;
911 
912 
915 /* In DMA mode the total available FIFO space is smaller. */
916 /* The DMA controller use one FIFO word pr. channel for status. */
917 /* The unit in the table is byte. */
918 #define USBH_INIT_DEFAULT \
919 { \
920  MAX_HOST_FIFO_SIZE_INWORDS * 2,/* 1024 bytes Rx FIFO size. */ \
921  MAX_HOST_FIFO_SIZE_INWORDS, /* 512 bytes non-periodic Tx FIFO size. */ \
922  MAX_HOST_FIFO_SIZE_INWORDS, /* 512 bytes periodic Tx FIFO size. */ \
923  0 /* Reserved. */ \
924 }
925 
926 /*** -------------------- HOST mode API ---------------------------------- ***/
927 
928 int USBH_AssignHostChannel( USBH_Ep_TypeDef *ep, uint8_t hcnum);
929 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);
930 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);
931 bool USBH_DeviceConnected( void);
932 int USBH_GetConfigurationDescriptorB( USBH_Device_TypeDef *device, void *buf, int len, uint8_t configIndex);
933 int USBH_GetDeviceDescriptorB( USBH_Device_TypeDef *device, void *buf, int len);
934 uint8_t USBH_GetPortSpeed( void);
935 int USBH_GetStringB( USBH_Device_TypeDef *device, uint8_t *buf, int bufLen, uint8_t stringIndex, uint16_t langID);
936 int USBH_Init( const USBH_Init_TypeDef *p);
937 int USBH_InitDeviceData( USBH_Device_TypeDef *device, const uint8_t *buf, USBH_Ep_TypeDef *ep, int numEp, uint8_t deviceSpeed);
938 int USBH_PortReset( void);
939 int USBH_PortResume( void);
940 void USBH_PortSuspend( void);
941 void USBH_PrintString( const char *pre, const USB_StringDescriptor_TypeDef *s, const char *post);
942 
943 #if defined(USB_USE_PRINTF)
944 int USBH_PrintConfigurationDescriptor( const USB_ConfigurationDescriptor_TypeDef *config, int maxLen);
945 int USBH_PrintDeviceDescriptor( const USB_DeviceDescriptor_TypeDef *device);
946 int USBH_PrintEndpointDescriptor( const USB_EndpointDescriptor_TypeDef *endpoint);
947 int USBH_PrintInterfaceDescriptor( const USB_InterfaceDescriptor_TypeDef *interface);
948 #else
949 #define USBH_PrintConfigurationDescriptor( config, maxLen)
950 #define USBH_PrintDeviceDescriptor( device)
951 #define USBH_PrintEndpointDescriptor( endpoint)
952 #define USBH_PrintInterfaceDescriptor( interface)
953 #endif /* defined(USB_USE_PRINTF) */
954 
955 int USBH_QueryDeviceB( uint8_t *buf, size_t bufsize, uint8_t deviceSpeed);
956 USB_ConfigurationDescriptor_TypeDef* USBH_QGetConfigurationDescriptor( const uint8_t *buf, int configIndex);
957 USB_DeviceDescriptor_TypeDef* USBH_QGetDeviceDescriptor( const uint8_t *buf);
958 USB_EndpointDescriptor_TypeDef* USBH_QGetEndpointDescriptor( const uint8_t *buf, int configIndex, int interfaceIndex, int endpointIndex);
959 USB_InterfaceDescriptor_TypeDef* USBH_QGetInterfaceDescriptor( const uint8_t *buf, int configIndex, int interfaceIndex);
960 
961 int USBH_Read( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback);
962 int USBH_ReadB( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout);
963 int USBH_SetAddressB( USBH_Device_TypeDef *device, uint8_t deviceAddress);
964 int USBH_SetAltInterfaceB( USBH_Device_TypeDef *device, uint8_t interfaceIndex, uint8_t alternateSetting);
965 int USBH_SetConfigurationB( USBH_Device_TypeDef *device, uint8_t configValue);
966 int USBH_StallEpB( USBH_Ep_TypeDef *ep);
967 void USBH_Stop( void);
968 int USBH_UnStallEpB( USBH_Ep_TypeDef *ep);
969 int USBH_WaitForDeviceConnectionB( uint8_t *buf, int timeoutInSeconds);
970 int USBH_Write( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback);
971 int USBH_WriteB( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout);
972 
974 #endif /* defined(USB_HOST) */
975 
977 #ifdef __cplusplus
978 }
979 #endif
980 
981 #endif /* defined(USB_DEVICE) || defined(USB_HOST) */
982 #endif /* defined(USB_PRESENT) && (USB_COUNT == 1) */
983 #endif /* __EM_USB_H */
USB protocol stack library, application supplied configuration options.
void(* USBD_SofIntCb_TypeDef)(uint16_t sofNr)
USB Start Of Frame (SOF) interrupt callback function.
Definition: em_usb.h:716
const uint8_t * bufferingMultiplier
Definition: em_usb.h:782
const uint32_t reserved
Definition: em_usb.h:791
void USBTIMER_Stop(uint32_t id)
Stop a timer.
Definition: em_usbtimer.c:306
Emlib peripheral API "assert" implementation.
USB Device stack initialization structure.
Definition: em_usb.h:776
#define SL_PACK_END()
Macro for handling packed structs. Use this macro after the struct definition. With GCC...
Definition: em_common.h:157
uint8_t bmRequestType
Definition: em_usb.h:391
uint16_t wValue
Definition: em_usb.h:394
int USB_PRINTF(const char *format,...)
Transmit "printf" formated data on the debug serial port.
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:93
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
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:130
char * USB_GetErrorMsgString(int error)
Return an error message string for a given error code.
Definition: em_usbhal.c:72
General purpose utilities.
#define SL_PACK_START(x)
Macro for handling packed structs. Use this macro before the struct definition. X denotes the max...
Definition: em_common.h:150
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:138
USB Interface Descriptor.
Definition: em_usb.h:459
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:226
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
void USBD_AbortAllTransfers(void)
Abort all pending transfers.
Definition: em_usbd.c:55
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:319
void(* USBD_DeviceStateChangeCb_TypeDef)(USBD_State_TypeDef oldState, USBD_State_TypeDef newState)
USB State change callback function.
Definition: em_usb.h:731
uint16_t wIndex
Definition: em_usb.h:395
USB Device stack callback structure.
Definition: em_usb.h:799
const uint8_t * configDescriptor
Definition: em_usb.h:779
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 USBD_Callbacks_TypeDef USBD_Callbacks_TypeDef
USB Device stack callback structure.
const void *const * stringDescriptors
Definition: em_usb.h:780
int USBD_AbortTransfer(int epAddr)
Abort a pending transfer on a specific endpoint.
Definition: em_usbd.c:73
unsigned short char16_t
Definition: em_usb.h:246
USB Endpoint Descriptor.
Definition: em_usb.h:500
USBD_Callbacks_TypeDef_Pointer callbacks
Definition: em_usb.h:787
int USBD_RemoteWakeup(void)
Perform a remote wakeup signalling sequence.
Definition: em_usbd.c:661
int USBD_StallEp(int epAddr)
Set an endpoint in the stalled (halted) state.
Definition: em_usbd.c:737
uint16_t wLength
Definition: em_usb.h:396
USBD_State_TypeDef USBD_GetUsbState(void)
Get current USB device state.
Definition: em_usbd.c:186
bool(* USBD_IsSelfPoweredCb_TypeDef)(void)
USB power mode callback function.
Definition: em_usb.h:745
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:851
int USBD_UnStallEp(int epAddr)
Reset stall state on a stalled (halted) endpoint.
Definition: em_usbd.c:799
const uint8_t numberOfStrings
Definition: em_usb.h:781
const USBD_DeviceStateChangeCb_TypeDef usbStateChange
Definition: em_usb.h:803
void USBD_Stop(void)
Stop USB device stack operation.
Definition: em_usbd.c:776
#define SL_ATTRIBUTE_PACKED
GCC style macro for handling packed structs.
Definition: em_common.h:143
void USBD_Disconnect(void)
Stop USB device operation.
Definition: em_usbd.c:145
void USBTIMER_Init(void)
Activate the hardware timer used to pace the 1 millisecond timer system.
Definition: em_usbtimer.c:193
USB Configuration Descriptor.
Definition: em_usb.h:430
const char * USBD_GetUsbStateName(USBD_State_TypeDef state)
Get a string naming a device USB state.
Definition: em_usbd.c:201
const USBD_SetupCmdCb_TypeDef setupCmd
Definition: em_usb.h:804
const USBD_SofIntCb_TypeDef sofInt
Definition: em_usb.h:808
USB Device Descriptor.
Definition: em_usb.h:406
bool USBD_SafeToEnterEM2(void)
Check if it is ok to enter energy mode EM2.
Definition: em_usbd.c:693
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:237
uint8_t bRequest
Definition: em_usb.h:393
USB String Descriptor.
Definition: em_usb.h:514
void USBTIMER_DelayUs(uint32_t usec)
Active wait microsecond delay function. Can also be used inside interrupt handlers.
Definition: em_usbtimer.c:159
bool USBD_EpIsBusy(int epAddr)
Check if an endpoint is busy doing a transfer.
Definition: em_usbd.c:162
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:573