SILICON LABS USB Device Classes User Guide

SILICON-logo

SILICON LABS USB Device Classes

SILICON-LABS-USB-Device-Classes-PRODUCT

Overview

USB Device Classes

The USB classes available in Silicon Labs USB Device share some common characteristics. This section explains these characteristics and their interactions with the core layer.

For more information on a specific class, see the following:

  • CDC ACM Class
  • HID Class
  • MSC SCSI Class
  • Vendor Class

About Class Instances

The USB classes available in USB Device implement the concept of class instances. A class instance represents one function within a device. The function can be described by one interface or by a group of interfaces and belongs to a specific class.

Each USB class implementation has some configurations and functions in common, based on the concept of class instance. The common configurations and functions are presented in the table below. In the column title ‘Constants or Function’, the placeholder XXXX can be replaced by the name of the class: CDC, HID, MSC, CDC_ACM or VENDOR (Vendor for function names).

Constants and Functions Related to the Concept of Multiple Class Instances

Constant or Function Description
SL_USBD_XXXX_CLASS_INSTANCE_QUANTITY Configures the maximum number of class instances.
SL_USBD_XXXX_CONFIGURATION_QUANTITY Configures the maximum number of configurations. During the class initialization, a created class instance will be added to one or more configurations.
sl_usbd_XXXX_create_instance() Creates a new class instance.
sl_usbd_XXXX_add_to_configuration() Adds an existing class instance to the specified device configuration.
  • In terms of code implementation, the class will declare a local global variable that contains a class control structure. This class control structure is associated with one class instance and will contain specific information to manage the class instance.
  • The following figures show several case scenarios. Each figure includes a code example that corresponds to the case scenario.
  • The figure below represents a typical USB device. The device is Full-Speed (FS) and contains a single configuration. The function of the device is described by one interface composed of a pair of endpoints for data communication. One class instance is created and will allow you to manage the entire interface with its associated endpoint.

Figure – Multiple Class Instances – FS Device (1 Configuration with 1 Interface)SILICON-LABS-USB-Device-Classes (2)

The code corresponding to the FS Device (1 Configuration with 1 Interface) scenario is shown in the example below.

SILICON-LABS-USB-Device-Classes (3)
  1. Every class offers a set of callback functions for device connect/disconnect events and for class specific events. The callback structure object is passed as argument when creating the class instance with the sl_usbd_XXXX_create_instance() function. Also, initializes the class. All internal variables, structures, and class ports will be initialized. Note that the Init() function in some classes may take other arguments.
  2. Create the class instance, which is class_0. The function sl_usbd_XXXX_create_instance() allocates a class control structure associated with class_0. Depending on the class, sl_usbd_XXXX_create_instance() may have additional parameters aside from the class number that represent class-specific information stored in the class control structure.
  3. Add the class instance, class_0, to the specified configuration number, config_0. sl_usbd_XXXX_add_to_configuration()will create the interface 0 and its associated IN and OUT endpoints. As a result, the class instance encompasses the interface 0 and its endpoints. Any communication done on the interface 0 will use the class instance number, class_0.

The figure below represents a more complex example. A full-speed device is composed of two configurations. The device has two functions which belong to the same class, but each function is described by two interfaces and has a pair of bidirectional endpoints.

In this example, two class instances are created. Each class instance is associated with a group of interfaces as opposed to the single interface scenario.

Figure – Multiple Class Instances – FS Device (2 Configurations and Multiple Interfaces)SILICON-LABS-USB-Device-Classes (4)

The code corresponding to the FS Device (2 Configurations and Multiple Interfaces) scenario is shown in the example below. The error handling is omitted for clarity.

SILICON-LABS-USB-Device-Classes (1)
  1. Initialize the class. Any internal variables, structures, and class ports will be initialized.
  2. Create the class instance, class_0. The function sl_usbd_XXXX_create_instance() allocates a class control structure associated with class_0.
  3. Create the class instance, class_1. The function sl_usbd_XXXX_create_instance() allocates another class control structure associated with class_1.
  4. Add the class instance, class_0, to the configuration, cfg_0. sl_usbd_XXXX_add_to_configuration() will create the interface 0, interface 1, alternate interfaces, and the associated IN and OUT endpoints. The class instance number, class_0, will be used for any data communication on interface 0 or interface 1.
  5. Add the class instance, class_1, to the configuration, cfg_0. sl_usbd_XXXX_add_to_configuration() will create the interface 2, interface 3 and their associated IN and OUT endpoints. The class instance number, class_1, will be used for any data communication on interface 2 or interface 3.
  6. Add the same class instances, class_0 and class_1, to the other configuration, cfg_1.

Every class defines a structure of type sl_usbd_XXXX_callbacks_t. Its purpose is to give every class a set of callback functions to be called when an event occurs. Two callback functions are present in each class, detailed in the table below.

Common Class Callback Functions

Fields Description Function Signature
.enable Called when the USB class instance is enabled successfully. void app_usbd_XXXX_enable(uint8_t class_nbr);
.disable Called when the USB class instance is disabled. void app_usbd_XXXX_disable(uint8_t class_nbr);

Documents / Resources

PDF thumbnailUSB Device Classes
User Guide · USB Device Classes, Device Classes, Classes

Ask a Question

Use this section to ask about setup, compatibility, troubleshooting, or anything missing from this manual.

Ask a Question

Ask about setup, compatibility, troubleshooting, or anything missing from this manual. Name and email are optional.