#ifndef USBAudio2_h
#define USBAudio2_h

#include "usb.h"

typedef __packed struct
{
    USB_DescriptorSubBase;
    uint16_t            bcdADC;             // Revision of class specification
    uint8_t             bCategory;          // interface primary use 
    uint16_t            wTotalLength;       // Total size of class specific descriptors
    uint8_t             bmControls;
} USBAudio2_CI_Header;


typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bClockID;
    uint8_t             bmAttributes;
    uint8_t             bmControls;
    uint8_t             bAssocTerminal;
    uint8_t             iClockSource;
} USBAudio2_CI_ClockSource;

#define USBAUDIO2_CI_CLOCK_SOURCE   0xa

typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bClockID;
    uint8_t             bNrInPins;
    uint8_t             baCSourceID[];
} USBAudio2_CI_ClockSelector;

typedef __packed struct
{
    uint8_t             bmControls;
    uint8_t             iClockSelector;
} USBAudio2_CI_ClockSelectorPart2;

#define USBAudio2_CI_ClockSelector2(su) (USBAudio2_CI_ClockSelectorPart2*)(((char*)su)+(su)->bLength -\
                                                                sizeof(USBAudio2_CI_ClockSelectorPart2))
#define USBAUDIO2_CI_CLOCK_SELECTOR   0xb


typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bClockID;
    uint8_t             baCSourceID;
    uint8_t             bmControls;
    uint8_t             iClockMultiplier;
} USBAudio2_CI_ClockMultiplier;
#define USBAUDIO2_CI_CLOCK_MULTIPLIER   0xc

typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bTerminalID;        // ID of this input terminal
    uint16_t            wTerminalType;      
    uint8_t             bAssocTerminal;
    uint8_t             bCSourceID;
    uint8_t             bNrChannels;
    uint32_t            bmChannelConfig;
    uint8_t             iChannelNames;
    uint16_t            bmControls;
    uint8_t             iTerminal;
} USBAudio2_CI_InputTerminal;

typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bTerminalID;
    uint16_t            wTerminalType;
    uint8_t             bAssocTerminal;
    uint8_t             bSourceID;
    uint8_t             bCSourceID;
    uint16_t            bmControls;
    uint8_t             iTerminal;
} USBAudio2_CI_OutputTerminal;


typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bUnitID;
    uint8_t             bSourceID;
    uint32_t            bmaControls[];
} USBAudio2_CI_FeatureUnit;

typedef __packed struct
{
    uint8_t             iFeature;
} USBAudio2_CI_FeatureUnitPart1;

#define USBAudio2_CI_sizeof_fu_controls(fu) (((fu)->bLength -6)/4 )
#define USBAudio2_CI_FeatureUnit1(fu) (USBAudio2_CI_FeatureUnitPart1*)(((char*)(fu))+(fu)->bLength-\
                                         sizeof (USBAudio2_CI_FeatureUnitPart1) )


typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bTerminalLink;              // UnitID of the output terminal
    uint8_t             bmControls;                
    uint8_t             bFormatType;
    uint32_t            bmFormats;
    uint8_t             bNrChannels;
    uint32_t            bmChannelConfig;
    uint8_t             iChannelNames;
} USBAudio2_SI_General;

typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bFormatType;
    uint8_t             bSubSlotSize;              
    uint8_t             bBitResolution;             // bits per sample
} USBAudio2_SI_FormatType;

typedef USBAudio2_SI_FormatType USBAudio2_SI_FormatType_III;

typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bFormatType;
    uint16_t            wMaxBitRate;              
    uint8_t             wSlotsPerFrame;             // bits per sample
} USBAudio2_SI_FormatType_II;



typedef __packed struct
{
    USB_DescriptorSubBase;
    uint8_t             bmAttributes;
    uint8_t             bmControls;
    uint8_t             bLockDelayUnits;
    uint16_t            wLockDelay;
} USBAudio2_SE_General;


#endif
