2.9.2.3.1 Library Initialization

The Printer Function Driver instance for a USB device configuration is initialized by the Device Layer when the configuration is set by the host. This process does not require application intervention. Each instance of the Printer Function Driver should be registered with the Device layer through the Device Layer Function Driver Registration Table. The Printer Function Driver does require an initialization data structure to be defined for each instance of the function driver. This initialization data structure should be of the type USB_DEVICE_PRINTER_INIT. This data structure specifies the read/write queue sizes and IEEE 1284 device ID string. The funcDriverInit member of the function driver registration table entry for the Printer Function Driver instance should be set to point to the corresponding initialization data structure. The USB_DEVICE_PRINTER_FUNCTION_DRIVER object is a global object provided by the Printer Function Driver and points to the Printer Function Driver - Device Layer interface functions, which are required by the Device Layer.

The following code an example of how multiple instances of Printer Function Driver can registered with the Device Layer.

This below sample code shows an example of how a Printer function driver instances can be registered with the Device Layer via the Device Layer Function Driver Registration Table. In this case Device Configuration 1 consists of one instance of Printer function driver.

/* Define the Printer initialization data structure for a Printer instance.
* Set read queue size to 1 and write queue size to 1 */
const USB_DEVICE_PRINTER_INIT printerInit =
{
   .queueSizeRead = 1,
   .queueSizeWrite = 1,
   .length = DEVICE_ID_STRING_LENGTH,
   .deviceID_String = DEVICE_ID_STRING
};

const USB_DEVICE_FUNCTION_REGISTRATION_TABLE funcRegistrationTable[1] =
{
        /* Function 0 */
  {
   .configurationValue = 1,                               // Configuration value
   .interfaceNumber = 0,                                    // First interface number of this
                                                            function
   .speed = USB_SPEED_FULL,                                 // Function Speed
   .numberOfInterfaces = 1,                                 // Number of interfaces
   .funcDriverIndex = 0,                                    // Index of Printer Function Driver
   .driver = (void*)USB_DEVICE_PRINTER_FUNCTION_DRIVER,  // USB Printer function data exposed to
        device layer
   .funcDriverInit = (void*)&printerInit                 // Function driver initialization data
  },
};