21 #if defined(USB_PRESENT) && (USB_COUNT == 1)
23 #if defined(USB_DEVICE) || defined(USB_HOST)
29 #if defined(USB_USE_PRINTF)
63 #define SILABS_USB_VID 0x10C4
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
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
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
88 #define CLEAR_FEATURE 1
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
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
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
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
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__)
243 #if defined(__CHAR16_TYPE__)
249 #elif defined(__ICCARM__)
252 #elif defined(__CC_ARM)
263 #define STATIC_CONST_STRING_DESC(_name, ...) \
269 char16_t name[ 1 + sizeof((char16_t[]){__VA_ARGS__}) / 2]; \
270 } SL_ATTRIBUTE_PACKED _##_name; \
274 static const _##_name _name SL_ATTRIBUTE_ALIGN(4)= \
276 .len = sizeof(_##_name) - 2, \
277 .type = USB_STRING_DESCRIPTOR, \
278 .name = {__VA_ARGS__}, \
279 .name[((sizeof(_##_name) - 2) / 2) - 1] = '\0' \
286 #define STATIC_CONST_STRING_DESC_LANGID(_name, x, y) \
293 } SL_ATTRIBUTE_PACKED _##_name; \
297 static const _##_name _name SL_ATTRIBUTE_ALIGN(4)= \
300 .type = USB_STRING_DESCRIPTOR, \
309 #define UBUF(x, y) SL_ALIGN(4) uint8_t x[((y)+3)&~3] SL_ATTRIBUTE_ALIGN(4)
315 #define STATIC_UBUF(x, y) SL_ALIGN(4) static uint8_t x[((y)+3)&~3] SL_ATTRIBUTE_ALIGN(4)
343 #if defined(USB_DEVICE)
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
387 uint8_t Recipient : 5;
389 uint8_t Direction : 1;
526 #if defined(DOXY_DOC_ONLY)
587 #define MAX_NUM_HOSTCHANNELS 14
590 #define MAX_HOST_FIFO_SIZE_INWORDS (512-MAX_NUM_HOSTCHANNELS)
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)
598 #define USB_PUTCHAR(c)
601 #if defined(USB_USE_PRINTF)
602 #define USB_PRINTF printf
604 #define USB_PRINTF(...)
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)
611 #define DEBUG_USB_API_PUTS(s)
612 #define DEBUG_USB_API_PUTCHAR(c)
621 #if defined(USB_HOST)
622 #if defined(NUM_APP_TIMERS)
623 #define NUM_QTIMERS (NUM_HC_USED + 2 + NUM_APP_TIMERS + 1)
625 #define NUM_QTIMERS (NUM_HC_USED + 2 + 1)
629 #if defined(NUM_APP_TIMERS)
630 #define NUM_QTIMERS (NUM_APP_TIMERS)
632 #define NUM_QTIMERS 0
677 #if defined(USB_USE_PRINTF)
680 #define USB_PrintErrorMsgString( pre, error)
687 #if (NUM_QTIMERS > 0)
693 #if defined(USB_DEVICE)
835 #if defined(USB_HOST)
842 #define USB_VBUSOVRCUR_PORT_NONE -1
843 #define USB_VBUSOVRCUR_POLARITY_LOW 0
844 #define USB_VBUSOVRCUR_POLARITY_HIGH 1
855 } USBH_EpState_TypeDef;
863 USB_Setup_TypeDef setup;
865 USB_EndpointDescriptor_TypeDef epDesc;
866 struct USBH_Device_TypeDef *parentDevice;
873 USBH_EpState_TypeDef state;
876 volatile bool xferCompleted;
888 typedef struct USBH_Device_TypeDef
890 USB_DeviceDescriptor_TypeDef devDesc;
891 USB_ConfigurationDescriptor_TypeDef confDesc;
892 USB_InterfaceDescriptor_TypeDef itfDesc;
898 } USBH_Device_TypeDef;
907 uint32_t nptxFifoSize;
908 uint32_t ptxFifoSize;
918 #define USBH_INIT_DEFAULT \
920 MAX_HOST_FIFO_SIZE_INWORDS * 2, \
921 MAX_HOST_FIFO_SIZE_INWORDS, \
922 MAX_HOST_FIFO_SIZE_INWORDS, \
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);
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);
949 #define USBH_PrintConfigurationDescriptor( config, maxLen)
950 #define USBH_PrintDeviceDescriptor( device)
951 #define USBH_PrintEndpointDescriptor( endpoint)
952 #define USBH_PrintInterfaceDescriptor( interface)
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);
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);
971 int USBH_WriteB( USBH_Ep_TypeDef *ep,
void *data,
int byteCount,
int timeout);
USB protocol stack library, application supplied configuration options.
void(* USBD_SofIntCb_TypeDef)(uint16_t sofNr)
USB Start Of Frame (SOF) interrupt callback function.
const uint8_t * bufferingMultiplier
uint8_t bInterfaceProtocol
void USBTIMER_Stop(uint32_t id)
Stop a timer.
Emlib peripheral API "assert" implementation.
uint8_t bInterfaceSubClass
USB Device stack initialization structure.
#define SL_PACK_END()
Macro for handling packed structs. Use this macro after the struct definition. With GCC...
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...
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
uint8_t bConfigurationValue
const USBD_UsbResetCb_TypeDef usbReset
void(* USBTIMER_Callback_TypeDef)(void)
USBTIMER callback function.
const USB_DeviceDescriptor_TypeDef * deviceDescriptor
void USBD_Connect(void)
Start USB device operation.
char * USB_GetErrorMsgString(int error)
Return an error message string for a given error code.
General purpose utilities.
#define SL_PACK_START(x)
Macro for handling packed structs. Use this macro before the struct definition. X denotes the max...
const USBD_IsSelfPoweredCb_TypeDef isSelfPowered
void USBTIMER_DelayMs(uint32_t msec)
Active wait millisecond delay function. Can also be used inside interrupt handlers.
USB Interface Descriptor.
int USBD_Init(const USBD_Init_TypeDef *p)
Initializes USB device hardware and internal protocol stack data structures, then connects the data-l...
USB Setup request package.
USBD_State_TypeDef
USB device state enumerator.
int(* USB_XferCompleteCb_TypeDef)(USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining)
USB transfer callback function.
void USBD_AbortAllTransfers(void)
Abort all pending transfers.
int(* USBD_SetupCmdCb_TypeDef)(const USB_Setup_TypeDef *setup)
USB setup request callback function.
USB_Status_TypeDef
USB transfer status enumerator.
void(* USBD_DeviceStateChangeCb_TypeDef)(USBD_State_TypeDef oldState, USBD_State_TypeDef newState)
USB State change callback function.
USB Device stack callback structure.
const uint8_t * configDescriptor
void(* USBD_UsbResetCb_TypeDef)(void)
USB Reset callback function.
void USB_PUTS(const char *p)
Transmit a zero terminated string on the debug serial port.
uint8_t bAlternateSetting
struct USBD_Callbacks_TypeDef USBD_Callbacks_TypeDef
USB Device stack callback structure.
const void *const * stringDescriptors
int USBD_AbortTransfer(int epAddr)
Abort a pending transfer on a specific endpoint.
USBD_Callbacks_TypeDef_Pointer callbacks
uint8_t bNumConfigurations
int USBD_RemoteWakeup(void)
Perform a remote wakeup signalling sequence.
int USBD_StallEp(int epAddr)
Set an endpoint in the stalled (halted) state.
USBD_State_TypeDef USBD_GetUsbState(void)
Get current USB device state.
bool(* USBD_IsSelfPoweredCb_TypeDef)(void)
USB power mode callback function.
int USBD_Write(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a write (IN) transfer on an endpoint.
int USBD_UnStallEp(int epAddr)
Reset stall state on a stalled (halted) endpoint.
const uint8_t numberOfStrings
const USBD_DeviceStateChangeCb_TypeDef usbStateChange
void USBD_Stop(void)
Stop USB device stack operation.
#define SL_ATTRIBUTE_PACKED
GCC style macro for handling packed structs.
void USBD_Disconnect(void)
Stop USB device operation.
void USBTIMER_Init(void)
Activate the hardware timer used to pace the 1 millisecond timer system.
USB Configuration Descriptor.
const char * USBD_GetUsbStateName(USBD_State_TypeDef state)
Get a string naming a device USB state.
const USBD_SetupCmdCb_TypeDef setupCmd
const USBD_SofIntCb_TypeDef sofInt
bool USBD_SafeToEnterEM2(void)
Check if it is ok to enter energy mode EM2.
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.
void USBTIMER_DelayUs(uint32_t usec)
Active wait microsecond delay function. Can also be used inside interrupt handlers.
bool USBD_EpIsBusy(int epAddr)
Check if an endpoint is busy doing a transfer.
int USBD_Read(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a read (OUT) transfer on an endpoint.