Jump to main content

##

# 2.1.2 USB Device Library Architecture

The USB Device Library features a modular and layered architecture, as illustrated in the following figure.

Figure 2-1.USB Device Library Architecture

As seen in the figure, the USB Device Library consists of the following three major components.

## USB Controller Driver (USBCD)

The USBCD manages the state of the USB peripheral and provides the Device Layer with structured data access methods to the USB. It also provides the Device Layer with USB events. The USBCD is a MPLAB Harmony driver and uses the MPLAB Harmony framework services for its operation. It supports only one client per instance of the USB Peripheral. This client is typically be the Device Layer. In the case of multiple USB peripherals, the USBCD can manage multiple USB peripherals, each being accessed by one client. The driver is accessed exclusively by the Device Layer in the USB Device Layer Architecture. The USBCD provides functions to:

- Enable, disable and stall Endpoints
- Schedule USB Transfers
- Attach or detach the device
- Control the Resume signaling

## Device Layer

The Device Layer responds to the enumeration requests issued by the USB Host. It has exclusive access to an instance of the USBCD and the control endpoint (Endpoint 0). When the Host issues a class specific control transfer request, the Device Layer will analyze the setup packet of the control transfer and will route the control transfer to the appropriate function driver. The Device Layer must be initialized with the following data:

- Master Descriptor Table - This is a table of all the configuration descriptors and string descriptors.
- Function Driver Registration Table - This table contains information about the function drivers in the application.
- USBCD initialization information - This specifies the USB peripheral interrupt, the USB Peripheral instance and Sleep mode operation options.

The Device Layer initializes all function drivers that are registered with it when it receives a Set Configuration (for a supported configuration) from the Host. It de-initializes the function drivers when a USB reset event occurs. It opens the USBCD and registers an event handler to receive USB events. The Device Layer can also be opened by the application (the application becomes a client to the Device Layer). The application can then receive bus and device events and respond to control transfer requests. The Device Layer provides events to the application such as device configured or device reset. Some of these events are notification-only events, while other events require the application to take action.

## Function Drivers

The Function Drivers implements various USB device classes as per the class specification. The USB Device Library architecture can support multiple instances of a function driver. An example would be a USB CDC device that emulates two serial ports. Function drivers provide an abstracted and an easy to use interface to the application. The application must register an event handler with the function driver to receive function driver events and must respond to some of these events with control transfer read/write functions. Function drivers access the bus through the Device Layer.