USB Libraries Help > USB Device Libraries > USB Device Layer Library > Using the Library > How the Library Works > Library Initialization > Function Driver Registration Table
MPLAB Harmony USB Stack
Function Driver Registration Table

The Function Driver Registration Table (defined by the USB_DEVICE_FUNCTION_REGISTRATION_TABLE data type) contains information about the function drivers that are present in the application. The Device Layer needs this information to establish the intended functionality of the USB Device and then manage the operation of the device. 

The Function Driver Registration Table contains an entry for every function driver instance contained in the application. Each entry is configuration specific. If a device that features multiple configurations, the Function Driver Registration Table will contains an entry for every function driver in each configuration. Entries are instance and configuration specific. Hence if a configuration contains two instances of the same function driver type, the Function Driver Registration Table will contain two entries to for the same function driver but with different instance indexes. A description of each member of the Function Driver Registration Table entry is as follows:

  • The configurationValue member of the entry specifies to which configuration this entry belongs. The Device Layer will process this entry when the configurationValue configuration is set.
  • The driver member of the entry should be set to Function Driver – Device Layer Interface Functions Object exported by the function driver. This object is provided by the function driver. In case of the CDC function driver, this is USB_DEVICE_CDC_FUNCTION_DRIVER. In case of HID function driver, this is USB_DEVICE_HID_FUNCTION_DRIVER. . Refer to the "Library Initialization" topic in Function Driver Specific help section for more details.
  • The funcDriverIndex member of the entry specifies the instance of the function driver that this entry relates to. The Device Layer will use this instance when communicating with the function driver. In a case where there are multiple instances of the same function driver in a configuration, the funcDriverIndex allows the Device Layer to uniquely identify the function driver.
  • The funcDriverInit member of the entry must point to the function driver instance specific initialization data structure. Function Drivers typically require an initialization data structure to be specified. The Device Layer passes the pointer to the initialization data structure when the function driver is initialized. Refer to the "Library Initialization" topic in Function Driver Specific help section for more details.
  • The interfaceNumber member of the entry must contain the interface number of the first interface that is owned by this function driver instance. The information is available from the Device Configuration Descriptor.
  • The numberOfInterfaces member of the entry must contain the number of interfaces following the interfaceNumber interface that is owned by this function driver instance. For example, a CDC Device requires two interfaces. The interfaceNumber member of Function Driver Registration Table entry for this function driver would be 0 and the numberOfInterfaces member would be 2. This indicates that Interface 0 and Interface 1 in the Device Configuration Descriptor are owned by this function driver.
  • The speed member of the entry specifies the device speeds for which this function driver should be initialized. This can be set to either USB_SPEED_FULL, USB_SPEED_HIGH or a logical OR combination of both. The Device Layer will initialize the function if the device attach speed matches the speed mention in the speed member of the entry.

The following code shows an example of Function Driver Registration Table for one function driver. The CDC Function Driver in this case has two interfaces.

/**************************************************
 * USB Device Layer Function Driver Registration
 * Table
 **************************************************/
const USB_DEVICE_FUNCTION_REGISTRATION_TABLE funcRegistrationTable[1] =
{
    {
         .configurationValue = 1 ,                  // Configuration descriptor index
         .driver = USB_DEVICE_CDC_FUNCTION_DRIVER,  // CDC APIs exposed to the device layer
         .funcDriverIndex = 0 ,                     // Instance index of CDC function driver
         .funcDriverInit = (void *)&cdcInit,        // CDC init data
         .interfaceNumber = 0 ,                     // Start interface number of this instance
         .numberOfInterfaces = 2 ,                  // Total number of interfaces contained in this instance
         .speed = USB_SPEED_FULL|USB_SPEED_HIGH     // USB Speed
    }
};

The following code shows an example of Function Driver Registration Table for two function drivers. This example demonstrates a Composite (CDC + MSD ) device. The CDC Function Driver uses two interfaces starting from interface 0. The MSD Function Driver has one interface starting from interface 2.

/***********************************************
 * Function Driver Registration Table
 **********************************************/
USB_DEVICE_FUNCTION_REGISTRATION_TABLE funcRegistrationTable[2] =
{
    {
        .speed = USB_SPEED_FULL|USB_SPEED_HIGH,     // Speed at which this device can operate
        .configurationValue = 1,                    // Configuration number to which this device belongs
        .interfaceNumber = 1,                       // Starting interface number for this function driver
        .numberOfInterfaces = 2,                    // Number of interfaces that this function driver owns.
        .funcDriverIndex = 0,                       // Function Driver index
        .funcDriverInit = &cdcInit,                 // Function Driver initialization data structure
        .driver = USB_DEVICE_CDC_FUNCTION_DRIVER    // CDC Function Driver.
    },
    {
        .speed = USB_SPEED_FULL|USB_SPEED_HIGH,     // Speed at which this device can operate
        .configurationValue = 1,                    // Configuration number to which this device belongs
        .interfaceNumber = 0,                       // Starting interface number for this function driver
        .numberOfInterfaces = 1,                    // Number of interfaces that this function driver owns.
        .funcDriverIndex = 0,                       // Function Driver index
        .funcDriverInit = &msdInit,                 // Function Driver initialization data structure
        .driver = USB_DEVICE_MSD_FUNCTION_DRIVER    // MSD Function Driver.
    },
};

The USB Device Layer Function Driver registration table can be placed in the data or program memory of the microcontroller. The contents of this table should not be modified while the application is running. Doing this will affect the operation of the device stack. A typical USB device application will not need to change the contents of this table while the application is running.