Jump to main content

##

# 2.3.2.3.1 Initializing the Library

The Audio 1.0 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 Audio 1.0 Function Driver should be registered with the Device_layer through the Device Layer Function Driver Registration Table. The Audio 1.0 Function Driver requires a initialization data structure to be specified. This is a USB_DEVICE_AUDIO_INIT data type that specifies the size of the read and write queues. The funcDriverInit member of the function driver registration table entry of the Audio 1.0 Function Driver instance should point to this initialization data structure. The USB_DEVICE_AUDIO_FUNCTION_DRIVER object is a global object provided by the Audio 1.0 Function Driver and provides the Device Layer with an entry point into the Audio 1.0 Function Driver. The following code shows an example of how the Audio 1.0 Function Driver can be registered with the Device Layer.

    /* This code shows an example of how an Audio 1.0 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
     * Audio 1.0 Function Driver instance. */
    /* The Audio 1.0 Function Driver requires an initialization data structure that
     * specifies the read and write buffer queue sizes. Note that these settings are
     * also affected by the USB_DEVICE_AUDIO_QUEUE_DEPTH_COMBINED configuration
     * macro. */
    const USB_DEVICE_AUDIO_INIT audioDeviceInit =
    {
        .queueSizeRead = 1,
        .queueSizeWrite = 1
    };

    const USB_DEVICE_FUNC_REGISTRATION_TABLE funcRegistrationTable[1] =
    {
        {
            .speed = USB_SPEED_FULL,                    // Supported speed
            .configurationValue = 1,                    // To be initialized for Configuration 1
            .interfaceNumber = 0,                       // Starting interface number.
            .numberOfInterfaces = 2,                    // Number of interfaces in this instance
            .funcDriverIndex = 0,                       // Function Driver instance index is 0
            .funcDriverInit = &audioDeviceInit,         // Function Driver does not need initialization data structure
            .driver = USB_DEVICE_AUDIO_FUNCTION_DRIVER  // Pointer to Function Driver - Device Layer interface functions
        },
    };

The following figure illustrates the typical sequence that is followed in the application when using the Audio 1.0 Function Driver.

Figure 2-6.Typical USB Audio 1.0 Device Sequence

1. Call set of APIs to initialize USB Device Layer (refer to the USB Device Layer Library section for details about these APIs).
2. The Device Layer provides a callback to the application for any USB Device events like attached, powered, configured, etc. The application should receive a callback with an event USB_DEVICE_EVENT_CONFIGURED to proceed.
3. Once the Device Layer is configured, the application needs to register a callback function with the Audio 1.0 Function Driver to receive Audio Control transfers, and also other Audio 1.0 Function Driver events. Now the application can use Audio 1.0 Function Driver APIs to communicate with the USB Host.