/***************************************************************************
                                 descript.h
                             -------------------
    project:  USB-device for Philips ISP1181

    begin                : Wed Sep 4 2002
    copyright            : (C) 2002 by HBM GmbH, Siegfried Wessler
    email                : siegfried.wessler@hbm.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef __DESCRIPT__
#define __DESCRIPT__


#include  "usbdev.h"


#define MAX_ENDPOINTS   14
#define NUM_INTERFACE   1



#define USB_DEFAULT                 0x00    /* No descriptor read*/
#define USB_DESCRIPTOR_READ         0x01    /* Descriptor read, Addr not assigned*/
#define USB_ADDRESS_ASSIGNED        0x02    /* Descriptor Read, Addr assigned*/
#define USB_CONFIGURED              0x03

/*GLOBAL STATUS VALUES*/
#define STD_COMMAND                 0x00
#define SETUP_COMMAND_PHASE         0x40
#define FUNCTION_ERROR              0x7F    /* Used when we are stalling the function EP0 */
#define HUB_ERROR                   0xFF    /* Used when we are stalling the HUB EP0 */

/*1.0 Request Values*/
#define GET_STATUS                  0x00
#define CLEAR_FEATURE               0x01
#define SET_FEATURE                 0x03
#define SET_ADDRESS                 0x05
#define GET_DESCRIPTOR              0x06
#define SET_DESCRIPTOR              0x07
#define GET_CONFIGURATION           0x08
#define SET_CONFIGURATION           0x09
#define GET_INTERFACE               0x0A
#define SET_INTERFACE               0x0B
#define SYNCH_FRAME                 0x0C

/*HID Request Values*/
#define GET_REPORT                  0x01
#define GET_IDLE                    0x02
#define GET_PROTOCOL                0x03
#define SET_REPORT                  0x09
#define SET_IDLE                    0x0A
#define SET_PROTOCOL                0x0B

/*Descriptor Types*/
#define DEVICE                      0x01
#define CONFIGURATION               0x02
#define XSTRING                     0x03
#define INTERFACE                   0x04
#define ENDPOINT                    0x05
#define HID                         0x21
#define HIDREPORT                   0x22
#define HIDPHYSICAL                 0x23

/*Class codes*/
#define HIDCLASS                    0x03
#define NOSUBCLASS                  0x00
#define BOOTSUBCLASS                0x01
#define VENDORSPEC                  0xFF

/*Recipient Selectors/Masks*/
#define RECIPIENT_MASK              0x1F
#define DEVICE_RECIPIENT            0x00
#define INTERFACE_RECIPIENT         0x01
#define ENDPOINT_RECIPIENT          0x02
#define OTHER_RECIPIENT             0x03


/*Feature Selectors*/
#define DEVICE_REMOTE_WAKEUP        0x00
#define ENDPOINT_STALL              0x00


#define USB_RECIPIENT            (UINT8)0x1F
#define USB_RECIPIENT_DEVICE     (UINT8)0x00
#define USB_RECIPIENT_INTERFACE  (UINT8)0x01
#define USB_RECIPIENT_ENDPOINT   (UINT8)0x02

#define USB_REQUEST_TYPE_MASK    (UINT8)0x60
#define USB_STANDARD_REQUEST     (UINT8)0x00
#define USB_CLASS_REQUEST        (UINT8)0x20
#define USB_VENDOR_REQUEST       (UINT8)0x40

#define USB_REQUEST_MASK         (UINT8)0x0F

#define DEVICE_ADDRESS_MASK      0x7F


#define USB_FEATURE_ENDPOINT_STALL          0x0000
#define USB_FEATURE_REMOTE_WAKEUP           0x0001
#define USB_FEATURE_POWER_D0                0x0002
#define USB_FEATURE_POWER_D1                0x0003
#define USB_FEATURE_POWER_D2                0x0004
#define USB_FEATURE_POWER_D3                0x0005

// ----------------------------------------------------

#define USB_DEVICE_DESCRIPTOR_TYPE          0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE   0x02
#define USB_STRING_DESCRIPTOR_TYPE          0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE       0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE        0x05
#define USB_POWER_DESCRIPTOR_TYPE           0x06

#define STR_INDEX_LANGUAGE                  0x00
#define STR_INDEX_MANUFACTURER              0x01
#define STR_INDEX_PRODUCT                   0x02
#define STR_INDEX_CONFIGURATION             0x04
#define STR_INDEX_INTERFACE                 0x05
#define STR_INDEX_SERIALNUMBER              0x03

#define USB_ATTR_CONTROL            0x00
#define USB_ATTR_ISOCHRON           0x01
#define USB_ATTR_BULK               0x02
#define USB_ATTR_INTERRUPT          0x03

#define USB_ATTR_SELF_POWERED         0x40

#define USB_LANGUAGE_ENGLISH          0x0009


// structure definitions:

typedef struct _device_request
{
  UINT8 bmRequestType;
  UINT8 bRequest;
  UINT16  wValue;
  UINT16  wIndex;
  UINT16  wLength;
} DEVICE_REQUEST;


#define MAX_CONTROLDATA_SIZE  8

typedef struct _control_xfer
{
  DEVICE_REQUEST DeviceRequest;
  UINT16  wLength;
  UINT16  wCount;
  UINT8 * pData;
  UINT8 dataBuffer[MAX_CONTROLDATA_SIZE];
} CONTROL_XFER;

extern  CONTROL_XFER  ControlData;


typedef struct _IO_REQUEST
{
  UINT16  uAddressL;
  UINT8 bAddressH;
  UINT16  uSize;

  UINT8 bCommand;
} IO_REQUEST, *PIO_REQUEST;


typedef struct _USB_STRING_DESCRIPTOR
{
  UINT8 bLength;
  UINT8 bDescriptorType;
  UINT8 bString[1];
} USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;


typedef struct _USB_DEVICE_DESCRIPTOR
{
  UINT8 bLength;
  UINT8 bDescriptorType;
  UINT16 bcdUSB;
  UINT8 bDeviceClass;
  UINT8 bDeviceSubClass;
  UINT8 bDeviceProtocol;
  UINT8 bMaxPacketSize0;
  UINT16 idVendor;
  UINT16 idProduct;
  UINT16 bcdDevice;
  UINT8 iManufacturer;
  UINT8 iProduct;
  UINT8 iSerialNumber;
  UINT8 bNumConfigurations;
} USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;

#define USB_DEVICE_DESCRIPTOR_LENGTH  18
extern  USB_DEVICE_DESCRIPTOR DeviceDescr;


typedef struct _USB_CONFIGURATION_DESCRIPTOR
{
    UINT8 bLength;
    UINT8 bDescriptorType;
    UINT16 wTotalLength;
    UINT8 bNumInterfaces;
    UINT8 bConfigurationValue;
    UINT8 iConfiguration;
    UINT8 bmAttributes;
    UINT8 MaxPower;
} USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;

#define USB_CONFIGURATION_DESCRIPTOR_LENGTH   9
extern USB_CONFIGURATION_DESCRIPTOR ConfigDescr;


typedef struct _USB_INTERFACE_DESCRIPTOR
{
  UINT8 bLength;
  UINT8 bDescriptorType;
  UINT8 bInterfaceNumber;
  UINT8 bAlternateSetting;
  UINT8 bNumEndpoints;
  UINT8 bInterfaceClass;
  UINT8 bInterfaceSubClass;
  UINT8 bInterfaceProtocol;
  UINT8 iInterface;
} USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;

#define USB_INTERFACE_DESCRIPTOR_LENGTH   9
extern  USB_INTERFACE_DESCRIPTOR InterfaceDescr;


typedef struct _USB_ENDPOINT_DESCRIPTOR {
    UINT8 bLength;
    UINT8 bDescriptorType;
    UINT8 bEndpointAddress;
    UINT8 bmAttributes;
    UINT16 wMaxPacketSize;
    UINT8 bInterval;
} USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;

#define USB_ENDPOINT_DESCRIPTOR_LENGTH    7
extern  USB_ENDPOINT_DESCRIPTOR EP_Descr[MAX_ENDPOINTS];


typedef struct _USB_STRING_LANGUAGE_DESCRIPTOR
{
  UINT8  bLength;
  UINT8  bDescriptorType;
  UINT16 ulanguageID;
} USB_STRING_LANGUAGE_DESCRIPTOR, *PUSB_STRING_LANGUAGE_DESCRIPTOR;

extern USB_STRING_LANGUAGE_DESCRIPTOR  strLanguage;


typedef struct _USB_STRING_INTERFACE_DESCRIPTOR
{
  UINT8  bLength;
  UINT8  bDescriptorType;
  UINT8  Interface[11*2];
} USB_STRING_INTERFACE_DESCRIPTOR, *PUSB_STRING_INTERFACE_DESCRIPTOR;

extern USB_STRING_INTERFACE_DESCRIPTOR  strInterface;


typedef struct _USB_STRING_CONFIGURATION_DESCRIPTOR
{
  UINT8  bLength;
  UINT8  bDescriptorType;
  UINT8  Configuration[8*2];
} USB_STRING_CONFIGURATION_DESCRIPTOR, *PUSB_STRING_CONFIGURATION_DESCRIPTOR;

extern  USB_STRING_CONFIGURATION_DESCRIPTOR  strConfiguration;


#define SERIALNUM_LENGTH    10

typedef struct _USB_STRING_SERIALNUMBER_DESCRIPTOR
{
  UINT8  bLength;
  UINT8  bDescriptorType;
  UINT8  SerialNum[SERIALNUM_LENGTH *2];
} USB_STRING_SERIALNUMBER_DESCRIPTOR, *PUSB_STRING_SERIALNUMBER_DESCRIPTOR;

extern USB_STRING_SERIALNUMBER_DESCRIPTOR  strSerialNum;


typedef struct _USB_STRING_PRODUCT_DESCRIPTOR
{
  UINT8  bLength;
  UINT8  bDescriptorType;
  UINT8  Product[8*2];
} USB_STRING_PRODUCT_DESCRIPTOR, *PUSB_STRING_PRODUCT_DESCRIPTOR;

extern USB_STRING_PRODUCT_DESCRIPTOR  strProduct;


typedef struct _USB_STRING_MANUFACTURER_DESCRIPTOR
{
  UINT8  bLength;
  UINT8  bDescriptorType;
  UINT8  Manufacturer[29*2];
} USB_STRING_MANUFACTURER_DESCRIPTOR, *PUSB_STRING_MANUFACTURER_DESCRIPTOR;

extern USB_STRING_MANUFACTURER_DESCRIPTOR  strManufacturer;


#endif
