Module Description
The USB Core Layer implements the device abstraction defined in the Universal Serial Bus Specification, for applications to interact with the USB device interface on the device. The software in this layer responds to standard requests and returns standard descriptors. In current stack the Init() routine part of USBD_HW_API_T structure initializes both hardware layer and core layer.
◆ USBD_HANDLE_T
USB device stack/module handle.
◆ USB_CB_T
USB device stack's event callback function type.
The USB device stack exposes several event triggers through callback to application layer. The application layer can register methods to be called when such USB event happens.
- Parameters
-
[in] | hUsb | Handle to the USB device stack. |
- Returns
- The call back should returns ErrorCode_t type to indicate success or error condition.
- Return values
-
LPC_OK | On success |
ERR_USBD_UNHANDLED | Event is not handled hence pass the event to next in line. |
ERR_USBD_xxx | Other error conditions. |
◆ USB_PARAM_CB_T
USB device stack's event callback function type.
The USB device stack exposes several event triggers through callback to application layer. The application layer can register methods to be called when such USB event happens.
- Parameters
-
[in] | hUsb | Handle to the USB device stack. |
[in] | param1 | Extra information related to the event. |
- Returns
- The call back should returns ErrorCode_t type to indicate success or error condition.
- Return values
-
LPC_OK | On success |
ERR_USBD_UNHANDLED | Event is not handled hence pass the event to next in line. |
ERR_USBD_xxx | For other error conditions. |
◆ USB_EP_HANDLER_T
USBD setup request and endpoint event handler type.
The application layer should define the custom class's EP0 handler with function signature. The stack calls all the registered class handlers on any EP0 event before going through default handling of the event. This gives the class handlers to implement class specific request handlers and also to override the default stack handling for a particular event targeted to the interface. If an event is not handled by the callback the function should return ERR_USBD_UNHANDLED. For all other return codes the stack assumes that callback has taken care of the event and hence will not process the event any further and issues a STALL condition on EP0 indicating error to the host.
For endpoint interrupt handler the return value is ignored by the stack.
- Parameters
-
[in] | hUsb | Handle to the USB device stack. |
[in] | data | Pointer to the data which will be passed when callback function is called by the stack. |
[in] | event | Type of endpoint event. See USBD_EVENT_T for more details. |
- Returns
- The call back should returns ErrorCode_t type to indicate success or error condition.
- Return values
-
LPC_OK | On success. |
ERR_USBD_UNHANDLED | Event is not handled hence pass the event to next in line. |
ERR_USBD_xxx | For other error conditions. |
◆ REQUEST_HOST_TO_DEVICE
#define REQUEST_HOST_TO_DEVICE 0 |
bmRequestType.Dir definesRequest from host to device
◆ REQUEST_DEVICE_TO_HOST
#define REQUEST_DEVICE_TO_HOST 1 |
Request from device to host
◆ REQUEST_STANDARD
#define REQUEST_STANDARD 0 |
bmRequestType.Type definesStandard Request
◆ REQUEST_CLASS
◆ REQUEST_VENDOR
◆ REQUEST_RESERVED
#define REQUEST_RESERVED 3 |
◆ REQUEST_TO_DEVICE
#define REQUEST_TO_DEVICE 0 |
bmRequestType.Recipient definesRequest to device
◆ REQUEST_TO_INTERFACE
#define REQUEST_TO_INTERFACE 1 |
◆ REQUEST_TO_ENDPOINT
#define REQUEST_TO_ENDPOINT 2 |
◆ REQUEST_TO_OTHER
#define REQUEST_TO_OTHER 3 |
◆ USB_REQUEST_GET_STATUS
#define USB_REQUEST_GET_STATUS 0 |
USB Standard Request CodesGET_STATUS request
◆ USB_REQUEST_CLEAR_FEATURE
#define USB_REQUEST_CLEAR_FEATURE 1 |
◆ USB_REQUEST_SET_FEATURE
#define USB_REQUEST_SET_FEATURE 3 |
◆ USB_REQUEST_SET_ADDRESS
#define USB_REQUEST_SET_ADDRESS 5 |
◆ USB_REQUEST_GET_DESCRIPTOR
#define USB_REQUEST_GET_DESCRIPTOR 6 |
◆ USB_REQUEST_SET_DESCRIPTOR
#define USB_REQUEST_SET_DESCRIPTOR 7 |
◆ USB_REQUEST_GET_CONFIGURATION
#define USB_REQUEST_GET_CONFIGURATION 8 |
GET_CONFIGURATION request
◆ USB_REQUEST_SET_CONFIGURATION
#define USB_REQUEST_SET_CONFIGURATION 9 |
SET_CONFIGURATION request
◆ USB_REQUEST_GET_INTERFACE
#define USB_REQUEST_GET_INTERFACE 10 |
◆ USB_REQUEST_SET_INTERFACE
#define USB_REQUEST_SET_INTERFACE 11 |
◆ USB_REQUEST_SYNC_FRAME
#define USB_REQUEST_SYNC_FRAME 12 |
◆ USB_GETSTATUS_SELF_POWERED
#define USB_GETSTATUS_SELF_POWERED 0x01 |
USB GET_STATUS Bit ValuesSELF_POWERED status
◆ USB_GETSTATUS_REMOTE_WAKEUP
#define USB_GETSTATUS_REMOTE_WAKEUP 0x02 |
REMOTE_WAKEUP capable status
◆ USB_GETSTATUS_ENDPOINT_STALL
#define USB_GETSTATUS_ENDPOINT_STALL 0x01 |
◆ USB_FEATURE_ENDPOINT_STALL
#define USB_FEATURE_ENDPOINT_STALL 0 |
USB Standard Feature selectorsENDPOINT_STALL feature
◆ USB_FEATURE_REMOTE_WAKEUP
#define USB_FEATURE_REMOTE_WAKEUP 1 |
◆ USB_FEATURE_TEST_MODE
#define USB_FEATURE_TEST_MODE 2 |
◆ USB_DEVICE_DESCRIPTOR_TYPE
#define USB_DEVICE_DESCRIPTOR_TYPE 1 |
USB Descriptor TypesDevice descriptor type
◆ USB_CONFIGURATION_DESCRIPTOR_TYPE
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 |
Configuration descriptor type
◆ USB_STRING_DESCRIPTOR_TYPE
#define USB_STRING_DESCRIPTOR_TYPE 3 |
◆ USB_INTERFACE_DESCRIPTOR_TYPE
#define USB_INTERFACE_DESCRIPTOR_TYPE 4 |
Interface descriptor type
◆ USB_ENDPOINT_DESCRIPTOR_TYPE
#define USB_ENDPOINT_DESCRIPTOR_TYPE 5 |
◆ USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE
#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6 |
Device qualifier descriptor type
◆ USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE
#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7 |
Other speed configuration descriptor type
◆ USB_INTERFACE_POWER_DESCRIPTOR_TYPE
#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8 |
Interface power descriptor type
◆ USB_OTG_DESCRIPTOR_TYPE
#define USB_OTG_DESCRIPTOR_TYPE 9 |
◆ USB_DEBUG_DESCRIPTOR_TYPE
#define USB_DEBUG_DESCRIPTOR_TYPE 10 |
◆ USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE
#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11 |
Interface association descriptor type
◆ USB_DEVICE_CLASS_RESERVED
#define USB_DEVICE_CLASS_RESERVED 0x00 |
USB Device ClassesReserved device class
◆ USB_DEVICE_CLASS_AUDIO
#define USB_DEVICE_CLASS_AUDIO 0x01 |
◆ USB_DEVICE_CLASS_COMMUNICATIONS
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 |
Communications device class
◆ USB_DEVICE_CLASS_HUMAN_INTERFACE
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 |
Human interface device class
◆ USB_DEVICE_CLASS_MONITOR
#define USB_DEVICE_CLASS_MONITOR 0x04 |
◆ USB_DEVICE_CLASS_PHYSICAL_INTERFACE
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 |
physical interface device class
◆ USB_DEVICE_CLASS_POWER
#define USB_DEVICE_CLASS_POWER 0x06 |
◆ USB_DEVICE_CLASS_PRINTER
#define USB_DEVICE_CLASS_PRINTER 0x07 |
◆ USB_DEVICE_CLASS_STORAGE
#define USB_DEVICE_CLASS_STORAGE 0x08 |
◆ USB_DEVICE_CLASS_HUB
#define USB_DEVICE_CLASS_HUB 0x09 |
◆ USB_DEVICE_CLASS_MISCELLANEOUS
#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF |
miscellaneous device class
◆ USB_DEVICE_CLASS_APP
#define USB_DEVICE_CLASS_APP 0xFE |
◆ USB_DEVICE_CLASS_VENDOR_SPECIFIC
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF |
Vendor specific device class
◆ USB_CONFIG_POWERED_MASK
#define USB_CONFIG_POWERED_MASK 0x40 |
bmAttributes in Configuration DescriptorPower field mask
◆ USB_CONFIG_BUS_POWERED
#define USB_CONFIG_BUS_POWERED 0x80 |
◆ USB_CONFIG_SELF_POWERED
#define USB_CONFIG_SELF_POWERED 0xC0 |
◆ USB_CONFIG_REMOTE_WAKEUP
#define USB_CONFIG_REMOTE_WAKEUP 0x20 |
◆ USB_CONFIG_POWER_MA
#define USB_CONFIG_POWER_MA |
( |
|
mA | ) |
((mA) / 2) |
bMaxPower in Configuration Descriptor
◆ USB_ENDPOINT_DIRECTION_MASK
#define USB_ENDPOINT_DIRECTION_MASK 0x80 |
bEndpointAddress in Endpoint DescriptorEndopint address mask
◆ USB_ENDPOINT_OUT
#define USB_ENDPOINT_OUT |
( |
|
addr | ) |
((addr) | 0x00) |
Macro to convert OUT endopint number to endpoint address value.
◆ USB_ENDPOINT_IN
#define USB_ENDPOINT_IN |
( |
|
addr | ) |
((addr) | 0x80) |
Macro to convert IN endopint number to endpoint address value.
◆ USB_ENDPOINT_TYPE_MASK
#define USB_ENDPOINT_TYPE_MASK 0x03 |
bmAttributes in Endpoint DescriptorEndopint type mask
◆ USB_ENDPOINT_TYPE_CONTROL
#define USB_ENDPOINT_TYPE_CONTROL 0x00 |
◆ USB_ENDPOINT_TYPE_ISOCHRONOUS
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 |
isochronous Endopint type
◆ USB_ENDPOINT_TYPE_BULK
#define USB_ENDPOINT_TYPE_BULK 0x02 |
◆ USB_ENDPOINT_TYPE_INTERRUPT
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03 |
◆ USB_ENDPOINT_SYNC_MASK
#define USB_ENDPOINT_SYNC_MASK 0x0C |
◆ USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION
#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 |
no synchronization Endopint
◆ USB_ENDPOINT_SYNC_ASYNCHRONOUS
#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 |
Asynchronous sync Endopint
◆ USB_ENDPOINT_SYNC_ADAPTIVE
#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 |
◆ USB_ENDPOINT_SYNC_SYNCHRONOUS
#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C |
Synchronous sync Endopint
◆ USB_ENDPOINT_USAGE_MASK
#define USB_ENDPOINT_USAGE_MASK 0x30 |
◆ USB_ENDPOINT_USAGE_DATA
#define USB_ENDPOINT_USAGE_DATA 0x00 |
◆ USB_ENDPOINT_USAGE_FEEDBACK
#define USB_ENDPOINT_USAGE_FEEDBACK 0x10 |
Endopint feedback usage type
◆ USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK
#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 |
Endopint implicit feedback usage type
◆ USB_ENDPOINT_USAGE_RESERVED
#define USB_ENDPOINT_USAGE_RESERVED 0x30 |
Endopint reserved usage type
◆ USB_ENDPOINT_0_HS_MAXP
#define USB_ENDPOINT_0_HS_MAXP 64 |
Control endopint EP0's maximum packet size in high-speed mode.
◆ USB_ENDPOINT_0_LS_MAXP
#define USB_ENDPOINT_0_LS_MAXP 8 |
Control endopint EP0's maximum packet size in low-speed mode.
◆ USB_ENDPOINT_BULK_HS_MAXP
#define USB_ENDPOINT_BULK_HS_MAXP 512 |
Bulk endopint's maximum packet size in high-speed mode.