| USBD ROM Stack 2.0 ROM based USB device stack

Data Structures | Typedefs | Macros
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_BOS_DESCRIPTOR
struct | USB_SS_DEVICE_CAPABILITY_DESCRIPTOR
struct | USB_DEVICE_CAPABILITY_DESCRIPTOR
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. More...
typedef ErrorCode_t(* | USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t param1)
| USB device stack's event callback function type. More...
typedef ErrorCode_t(* | USB_EP_HANDLER_T) (USBD_HANDLE_T hUsb, void *data, uint32_t event)
| USBD setup request and endpoint event handler type. More...

## Macros
#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

## ◆ USBD_HANDLE_T

typedef void* USBD_HANDLE_T

USB device stack/module handle.

## ◆ USB_CB_T

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_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

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.

## Macro Definition Documentation

## ◆ 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

#define REQUEST_CLASS 1

Class Request

## ◆ REQUEST_VENDOR

#define REQUEST_VENDOR 2

Vendor Request

## ◆ REQUEST_RESERVED

#define REQUEST_RESERVED 3

Reserved Request

## ◆ REQUEST_TO_DEVICE

#define REQUEST_TO_DEVICE 0

bmRequestType.Recipient definesRequest to device

## ◆ REQUEST_TO_INTERFACE

#define REQUEST_TO_INTERFACE 1

Request to interface

## ◆ REQUEST_TO_ENDPOINT

#define REQUEST_TO_ENDPOINT 2

Request to endpoint

## ◆ REQUEST_TO_OTHER

#define REQUEST_TO_OTHER 3

Request to other

## ◆ 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

CLEAR_FEATURE request

## ◆ USB_REQUEST_SET_FEATURE

#define USB_REQUEST_SET_FEATURE 3

SET_FEATURE request

## ◆ USB_REQUEST_SET_ADDRESS

#define USB_REQUEST_SET_ADDRESS 5

SET_ADDRESS request

## ◆ USB_REQUEST_GET_DESCRIPTOR

#define USB_REQUEST_GET_DESCRIPTOR 6

GET_DESCRIPTOR request

## ◆ USB_REQUEST_SET_DESCRIPTOR

#define USB_REQUEST_SET_DESCRIPTOR 7

SET_DESCRIPTOR request

## ◆ 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

GET_INTERFACE request

## ◆ USB_REQUEST_SET_INTERFACE

#define USB_REQUEST_SET_INTERFACE 11

SET_INTERFACE request

## ◆ USB_REQUEST_SYNC_FRAME

#define USB_REQUEST_SYNC_FRAME 12

SYNC_FRAME request

## ◆ 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

ENDPOINT_STALL status

## ◆ 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

REMOTE_WAKEUP feature

## ◆ USB_FEATURE_TEST_MODE

#define USB_FEATURE_TEST_MODE 2

TEST_MODE feature

## ◆ 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

String descriptor type

## ◆ USB_INTERFACE_DESCRIPTOR_TYPE

#define USB_INTERFACE_DESCRIPTOR_TYPE 4

Interface descriptor type

## ◆ USB_ENDPOINT_DESCRIPTOR_TYPE

#define USB_ENDPOINT_DESCRIPTOR_TYPE 5

Endpoint descriptor type

## ◆ 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

OTG descriptor type

## ◆ USB_DEBUG_DESCRIPTOR_TYPE

#define USB_DEBUG_DESCRIPTOR_TYPE 10

Debug descriptor type

## ◆ 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

Audio device class

## ◆ 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

monitor device class

## ◆ 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

power device class

## ◆ USB_DEVICE_CLASS_PRINTER

#define USB_DEVICE_CLASS_PRINTER 0x07

Printer device class

## ◆ USB_DEVICE_CLASS_STORAGE

#define USB_DEVICE_CLASS_STORAGE 0x08

Storage device class

## ◆ USB_DEVICE_CLASS_HUB

#define USB_DEVICE_CLASS_HUB 0x09

Hub device class

## ◆ USB_DEVICE_CLASS_MISCELLANEOUS

#define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF

miscellaneous device class

## ◆ USB_DEVICE_CLASS_APP

#define USB_DEVICE_CLASS_APP 0xFE

Application device class

## ◆ 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

Bus powered

## ◆ USB_CONFIG_SELF_POWERED

#define USB_CONFIG_SELF_POWERED 0xC0

Self powered

## ◆ USB_CONFIG_REMOTE_WAKEUP

#define USB_CONFIG_REMOTE_WAKEUP 0x20

remote wakeup

## ◆ 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

Control Endopint type

## ◆ USB_ENDPOINT_TYPE_ISOCHRONOUS

#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01

isochronous Endopint type

## ◆ USB_ENDPOINT_TYPE_BULK

#define USB_ENDPOINT_TYPE_BULK 0x02

bulk Endopint type

## ◆ USB_ENDPOINT_TYPE_INTERRUPT

#define USB_ENDPOINT_TYPE_INTERRUPT 0x03

interrupt Endopint type

## ◆ USB_ENDPOINT_SYNC_MASK

#define USB_ENDPOINT_SYNC_MASK 0x0C

Endopint sync type mask

## ◆ 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

Adaptive sync Endopint

## ◆ USB_ENDPOINT_SYNC_SYNCHRONOUS

#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C

Synchronous sync Endopint

## ◆ USB_ENDPOINT_USAGE_MASK

#define USB_ENDPOINT_USAGE_MASK 0x30

Endopint usage type mask

## ◆ USB_ENDPOINT_USAGE_DATA

#define USB_ENDPOINT_USAGE_DATA 0x00

Endopint data usage type

## ◆ 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.