USBD ROM Stack  1.0
ROM based USB device stack
USB Core Layer

Detailed Description

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.

Data Structures

struct  WB_T
union  WORD_BYTE
struct  BM_T
union  REQUEST_TYPE
struct  USB_SETUP_PACKET
struct  USB_DEVICE_DESCRIPTOR
struct  USB_DEVICE_QUALIFIER_DESCRIPTOR
struct  USB_CONFIGURATION_DESCRIPTOR
struct  USB_INTERFACE_DESCRIPTOR
struct  USB_ENDPOINT_DESCRIPTOR
struct  USB_STRING_DESCRIPTOR
struct  USB_COMMON_DESCRIPTOR
struct  USB_OTHER_SPEED_CONFIGURATION
struct  USB_CORE_DESCS_T
 USB descriptors data structure. More...
struct  USBD_API_INIT_PARAM_T
 USB device stack initialization parameter data structure. More...
struct  USBD_CORE_API_T
 USBD stack Core API functions structure. More...

Typedefs

typedef void * USBD_HANDLE_T
typedef ErrorCode_t(* USB_CB_T )(USBD_HANDLE_T hUsb)
 USB device stack's event callback function type.
typedef ErrorCode_t(* USB_PARAM_CB_T )(USBD_HANDLE_T hUsb, uint32_t param1)
 USB device stack's event callback function type.
typedef ErrorCode_t(* USB_EP_HANDLER_T )(USBD_HANDLE_T hUsb, void *data, uint32_t event)
 USBD setup request and endpoint event handler type.

Defines

#define USB_CONFIG_POWER_MA(mA)   ((mA)/2)
#define USB_ENDPOINT_0_HS_MAXP   64
#define USB_ENDPOINT_0_LS_MAXP   8
#define USB_ENDPOINT_BULK_HS_MAXP   512

Typedef Documentation

typedef void* USBD_HANDLE_T

USB device stack/module handle.

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]hUsbHandle to the USB device stack.
Returns:
The call back should returns ErrorCode_t type to indicate success or error condition.
Return values:
LPC_OKOn success
ERR_USBD_UNHANDLEDEvent is not handled hence pass the event to next in line.
ERR_USBD_xxxOther error conditions.

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]hUsbHandle to the USB device stack.
[in]param1Extra information related to the event.
Returns:
The call back should returns ErrorCode_t type to indicate success or error condition.
Return values:
LPC_OKOn success
ERR_USBD_UNHANDLEDEvent is not handled hence pass the event to next in line.
ERR_USBD_xxxFor other error conditions.

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]hUsbHandle to the USB device stack.
[in]dataPointer to the data which will be passed when callback function is called by the stack.
[in]eventType 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_OKOn success.
ERR_USBD_UNHANDLEDEvent is not handled hence pass the event to next in line.
ERR_USBD_xxxFor other error conditions.

Define Documentation

#define REQUEST_HOST_TO_DEVICE   0

bmRequestType.Dir defines Request from host to device

#define REQUEST_DEVICE_TO_HOST   1

Request from device to host

#define REQUEST_STANDARD   0

bmRequestType.Type defines Standard Request

#define REQUEST_CLASS   1

Class Request

#define REQUEST_VENDOR   2

Vendor Request

#define REQUEST_RESERVED   3

Reserved Request

#define REQUEST_TO_DEVICE   0

bmRequestType.Recipient defines Request to device

#define REQUEST_TO_INTERFACE   1

Request to interface

#define REQUEST_TO_ENDPOINT   2

Request to endpoint

#define REQUEST_TO_OTHER   3

Request to other

#define USB_REQUEST_GET_STATUS   0

USB Standard Request Codes GET_STATUS request

#define USB_REQUEST_CLEAR_FEATURE   1

CLEAR_FEATURE request

#define USB_REQUEST_SET_FEATURE   3

SET_FEATURE request

#define USB_REQUEST_SET_ADDRESS   5

SET_ADDRESS request

#define USB_REQUEST_GET_DESCRIPTOR   6

GET_DESCRIPTOR request

#define USB_REQUEST_SET_DESCRIPTOR   7

SET_DESCRIPTOR request

#define USB_REQUEST_GET_CONFIGURATION   8

GET_CONFIGURATION request

#define USB_REQUEST_SET_CONFIGURATION   9

SET_CONFIGURATION request

#define USB_REQUEST_GET_INTERFACE   10

GET_INTERFACE request

#define USB_REQUEST_SET_INTERFACE   11

SET_INTERFACE request

#define USB_REQUEST_SYNC_FRAME   12

SYNC_FRAME request

#define USB_GETSTATUS_SELF_POWERED   0x01

USB GET_STATUS Bit Values SELF_POWERED status

#define USB_GETSTATUS_REMOTE_WAKEUP   0x02

REMOTE_WAKEUP capable status

#define USB_GETSTATUS_ENDPOINT_STALL   0x01

ENDPOINT_STALL status

#define USB_FEATURE_ENDPOINT_STALL   0

USB Standard Feature selectors ENDPOINT_STALL feature

#define USB_FEATURE_REMOTE_WAKEUP   1

REMOTE_WAKEUP feature

#define USB_FEATURE_TEST_MODE   2

TEST_MODE feature

#define USB_DEVICE_DESCRIPTOR_TYPE   1

USB Descriptor Types Device descriptor type

#define USB_CONFIGURATION_DESCRIPTOR_TYPE   2

Configuration descriptor type

#define USB_STRING_DESCRIPTOR_TYPE   3

String descriptor type

#define USB_INTERFACE_DESCRIPTOR_TYPE   4

Interface descriptor type

#define USB_ENDPOINT_DESCRIPTOR_TYPE   5

Endpoint descriptor type

#define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE   6

Device qualifier descriptor type

#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE   7

Other speed configuration descriptor type

#define USB_INTERFACE_POWER_DESCRIPTOR_TYPE   8

Interface power descriptor type

#define USB_OTG_DESCRIPTOR_TYPE   9

OTG descriptor type

#define USB_DEBUG_DESCRIPTOR_TYPE   10

Debug descriptor type

#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE   11

Interface association descriptor type

#define USB_DEVICE_CLASS_RESERVED   0x00

USB Device Classes Reserved device class

#define USB_DEVICE_CLASS_AUDIO   0x01

Audio device class

#define USB_DEVICE_CLASS_COMMUNICATIONS   0x02

Communications device class

#define USB_DEVICE_CLASS_HUMAN_INTERFACE   0x03

Human interface device class

#define USB_DEVICE_CLASS_MONITOR   0x04

monitor device class

#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE   0x05

physical interface device class

#define USB_DEVICE_CLASS_POWER   0x06

power device class

#define USB_DEVICE_CLASS_PRINTER   0x07

Printer device class

#define USB_DEVICE_CLASS_STORAGE   0x08

Storage device class

#define USB_DEVICE_CLASS_HUB   0x09

Hub device class

#define USB_DEVICE_CLASS_MISCELLANEOUS   0xEF

miscellaneous device class

#define USB_DEVICE_CLASS_APP   0xFE

Application device class

#define USB_DEVICE_CLASS_VENDOR_SPECIFIC   0xFF

Vendor specific device class

#define USB_CONFIG_POWERED_MASK   0x40

bmAttributes in Configuration Descriptor Power field mask

#define USB_CONFIG_BUS_POWERED   0x80

Bus powered

#define USB_CONFIG_SELF_POWERED   0xC0

Self powered

#define USB_CONFIG_REMOTE_WAKEUP   0x20

remote wakeup

#define USB_CONFIG_POWER_MA (   mA)    ((mA)/2)

bMaxPower in Configuration Descriptor

#define USB_ENDPOINT_DIRECTION_MASK   0x80

bEndpointAddress in Endpoint Descriptor Endopint address mask

#define USB_ENDPOINT_OUT (   addr)    ((addr) | 0x00)

Macro to convert OUT endopint number to endpoint address value.

#define USB_ENDPOINT_IN (   addr)    ((addr) | 0x80)

Macro to convert IN endopint number to endpoint address value.

#define USB_ENDPOINT_TYPE_MASK   0x03

bmAttributes in Endpoint Descriptor Endopint type mask

#define USB_ENDPOINT_TYPE_CONTROL   0x00

Control Endopint type

#define USB_ENDPOINT_TYPE_ISOCHRONOUS   0x01

isochronous Endopint type

#define USB_ENDPOINT_TYPE_BULK   0x02

bulk Endopint type

#define USB_ENDPOINT_TYPE_INTERRUPT   0x03

interrupt Endopint type

#define USB_ENDPOINT_SYNC_MASK   0x0C

Endopint sync type mask

#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION   0x00

no synchronization Endopint

#define USB_ENDPOINT_SYNC_ASYNCHRONOUS   0x04

Asynchronous sync Endopint

#define USB_ENDPOINT_SYNC_ADAPTIVE   0x08

Adaptive sync Endopint

#define USB_ENDPOINT_SYNC_SYNCHRONOUS   0x0C

Synchronous sync Endopint

#define USB_ENDPOINT_USAGE_MASK   0x30

Endopint usage type mask

#define USB_ENDPOINT_USAGE_DATA   0x00

Endopint data usage type

#define USB_ENDPOINT_USAGE_FEEDBACK   0x10

Endopint feedback usage type

#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK   0x20

Endopint implicit feedback usage type

#define USB_ENDPOINT_USAGE_RESERVED   0x30

Endopint reserved usage type

#define USB_ENDPOINT_0_HS_MAXP   64

Control endopint EP0's maximum packet size in high-speed mode.

#define USB_ENDPOINT_0_LS_MAXP   8

Control endopint EP0's maximum packet size in low-speed mode.

#define USB_ENDPOINT_BULK_HS_MAXP   512

Bulk endopint's maximum packet size in high-speed mode.