#ifndef __USBDEF_H
#define __USBDEF_H

#include "stdint.h"

//
// USB Standard Enum Commands
//
#define USB_CMD_GET_STATUS                      0x00
#define USB_CMD_CLEAR_FEATURE                   0x01
#define USB_CMD_SET_FEATURE                     0x03
#define USB_CMD_SET_ADDRESS                     0x05
#define USB_CMD_GET_DESCRIPTOR                  0x06
#define USB_CMD_SET_DESCRIPTOR                  0x07
#define USB_CMD_GET_CONFIG                      0x08
#define USB_CMD_SET_CONFIG                      0x09
#define USB_CMD_GET_INTERFACE                   0x0A
#define USB_CMD_SET_INTERFACE                   0x0B
#define USB_CMD_SYNC_FRAME                      0x0C
#define USB_CMD_SET_SEL                         0x30
#define USB_CMD_ISO_DELAY                       0x31

// USB Enum Commands
#define USB_CMD_GET_MAX_LUN                     0xFE    // Massage Storage
#define USB_CMD_MASS_STORAGE_RESET              0xFF    // Massage Storage

// Descriptor Type & Length & Structure
//
#define USB_DSCR_TYPE_DEVICE                    0x01    // Device
#define USB_DSCR_TYPE_CONFIG                    0x02    // Configuration
#define USB_DSCR_TYPE_STRING                    0x03    // String
#define USB_DSCR_TYPE_INTERFACE                 0x04    // Interface
#define USB_DSCR_TYPE_ENDPOINT                  0x05    // Endpoint
#define USB_DSCR_TYPE_DEVICE_QUAL               0x06    // Device Qualifier

#define USB_DSCR_TYPE_HID_DEVICE                0x21 // Descriptor type: HID Device 
#define USB_DSCR_TYPE_GET_HID_Report            0x22 // Descriptor type: HID Device 

#define USB_DSCR_LEN_DEVICE                     18
#define USB_DSCR_LEN_DEVICE_QUAL                10
#define USB_DSCR_LEN_CONFIG                     9
#define USB_DSCR_LEN_INTERFACE                  9
#define USB_DSCR_LEN_ENDPOINT                   7
#define USB_DSCR_LEN_STRING                     4


typedef struct 
{
    uint8_t cLength;
    uint8_t cDescriptorType;
    uint8_t cBcdUSBL;
    uint8_t cBcdUSBH;
    uint8_t cDeviceClass;
    uint8_t cDeviceSubclass;
    uint8_t cDeviceProtocol;
    uint8_t cMaxPacketSize0;
    uint8_t cIdVendorL;
    uint8_t cIdVendorH;
    uint8_t cIdProductL;
    uint8_t cIdProductH;
    uint8_t cBcdDeviceL;
    uint8_t cBcdDeviceH;
    uint8_t cIManufacturer;
    uint8_t cIProduct;
    uint8_t cISerialNumber;
    uint8_t cNumConfiguration;
}USB_DEVICE_DESCRIPTOR;

typedef struct
{
    uint8_t cLength;
    uint8_t cDescriptorType;
    uint8_t cBcdUSBL;
    uint8_t cBcdUSBH;
    uint8_t cDeviceClass;
    uint8_t cDeviceSubclass;
    uint8_t cDeviceProtocol;
    uint8_t cMaxPacketSize0;
    uint8_t cNumConfiguration;
    uint8_t cReserve;
}USB_DEVICE_QUAL_DESCRIPTOR;

typedef struct
{
    uint8_t cLength;
    uint8_t cDescriptorType;
    uint8_t cTotalLengthL;
    uint8_t cTotalLengthH;
    uint8_t cNumInterface;
    uint8_t cConfigurationValue;
    uint8_t cConfiguration;
    uint8_t cAttributes;
    uint8_t cMaxPower;
}USB_CONFIG_DESCRIPTOR;

typedef struct 
{
    uint8_t cLength;
    uint8_t cDescriptorType;
    uint8_t cInterfaceNumber;
    uint8_t cAlternateSetting;
    uint8_t cNumEndpoints;
    uint8_t cInterfaceClass;
    uint8_t cInterfaceSubclass;
    uint8_t cInterfaceProtocol;
    uint8_t cInterface;
}USB_INTERFACE_DESCRIPTOR;

typedef struct
{
    uint8_t cLength;
    uint8_t cDescriptorType;
    uint8_t cEndpointAddress;
    uint8_t cAttribute;
    uint8_t cMaxPacketSizeL;
    uint8_t cMaxPacketSizeH;
    uint8_t cInterval;
}USB_ENDPOINT_DESCRIPTOR;

//
//  USB Setup Packet
//
typedef struct 
{
    uint8_t cRequestType;
    uint8_t cRequest;
    uint8_t cValueL;
    uint8_t cValueH;
    uint8_t cIndexL;
    uint8_t cIndexH;
    uint8_t cLengthL;
    uint8_t cLengthH;
}USB_SETUP_PACKET;



typedef struct
{
    uint8_t cLength;
    uint8_t cDescriptorType;
    uint8_t cEndpointAddress;
    uint8_t cAttribute;
    uint8_t cMaxPacketSizeL;
    uint8_t cMaxPacketSizeH;
    uint8_t cInterval;
    uint8_t cReportSize;
    uint8_t cBB;

}USB_HID_DESCRIPTOR;

typedef struct
{
    uint8_t cLength;
    uint8_t cDescriptorType;
    uint8_t cBCDH;
    uint8_t cBCDL;
 	  uint8_t cCLASS;
    uint8_t cSubCLASS;
    uint8_t cSubSubCLASS;
    uint8_t cSize;
    uint8_t cNum;
    uint8_t cRev;

}USB_QUAL_DESCRIPTOR;

#endif
