/*
 Descriptor structures and constants
 
 Copyright (c) 2008 Dimtel, Inc., All Rights Reserved

 $Id: usb_descriptors.h,v 1.2 2013/06/06 04:35:11 dim Exp $
 $Date: 2013/06/06 04:35:11 $
 $Author: dim $
 $Revision: 1.2 $
 $Log: usb_descriptors.h,v $
 Revision 1.2  2013/06/06 04:35:11  dim
 Added EP8 OUT to interface 0 for fast JTAG block loading

 Revision 1.1  2012/11/11 01:24:33  dim
 Moved from BxB, adapted to compile for both LLRF4 and IGP12

 Revision 1.1  2011/12/27 19:31:47  dim
 Updated to remove deprecated constructs (at, sfr, xdata, sbit)

 Revision 1.1.1.1  2009/06/02 20:25:58  dim
 Initial import

*/

#ifndef _USB_DESCRIPTORS_H_
#define _USB_DESCRIPTORS_H_

#include "../include/data_types.h"

typedef struct usb_device
{
  uchar  bLength;		/* Descriptor length, bytes */
  uchar  bDescriptorType;	/* Descriptor type */
  ushort bcdUSB;		/* USB specification version */
  uchar  bDeviceClass;		/* Device class (0xff - vendor specific) */
  uchar  bDeviceSubClass;	/* Device sub-class */
  uchar  bDeviceProtocol;	/* Device protocol */
  uchar  bMaxPacketSize0;	/* Max packet size for EP0 */
  ushort idVendor;		/* VID */
  ushort idProduct;		/* PID */
  ushort bcdDevice;		/* Device ID */
  uchar  iManufacturer;		/* Manufacturer string index */
  uchar  iProduct;		/* Product string index */
  uchar  iSerialNumber;		/* Serial number string index */
  uchar  bNumConfigurations;	/* Number of configurations */
} usb_device;

typedef struct usb_qualifier
{
  uchar  bLength;		/* Descriptor length, bytes */
  uchar  bDescriptorType;	/* Descriptor type */
  ushort bcdUSB;		/* USB specification version */
  uchar  bDeviceClass;		/* Device class (0xff - vendor specific) */
  uchar  bDeviceSubClass;	/* Device sub-class */
  uchar  bDeviceProtocol;	/* Device protocol */
  uchar  bMaxPacketSize0;	/* Max packet size for EP0 */
  uchar  bNumConfigurations;	/* Number of configurations */
  uchar  bReserved;		/* Must be set to 0 */
} usb_qualifier;

typedef struct usb_config
{
  uchar  bLength;		/* Descriptor length, bytes */
  uchar  bDescriptorType;	/* Descriptor type */
  ushort wTotalLength;		/* Total length with interface and EP descriptors */
  uchar  bNumInterfaces;	/* Number of interfaces in this configuration */
  uchar  bConfigurationValue;	/* Config to select */
  uchar  iConfiguration;	/* Configuration string index */
  uchar  bmAttributes;		/* Attributes */
  uchar  bMaxPower;		/* Max. power */
} usb_config;

typedef struct usb_interface
{
  uchar  bLength;		/* Descriptor length, bytes */
  uchar  bDescriptorType;	/* Descriptor type */
  uchar  bInterfaceNumber;	/* Zero-based index */
  uchar  bAlternateSetting;	/* Alternate setting */
  uchar  bNumEndpoints;		/* Endpoints */
  uchar  bDeviceClass;		/* Device class (0xff - vendor specific) */
  uchar  bDeviceSubClass;	/* Device sub-class */
  uchar  bDeviceProtocol;	/* Device protocol */
  uchar  iInterface;		/* Interface description string index */
} usb_interface;

typedef struct usb_endpoint
{
  uchar  bLength;		/* Descriptor length, bytes */
  uchar  bDescriptorType;	/* Descriptor type */
  uchar  bEndpointAddress;	/* Endpoint address, direction in MSB */
  uchar  bmAttributes;		/* Transfer type */
  ushort wMaxPacketSize;	/* Maximum packet size */
  uchar  bInterval;		/* Polling interval */
} usb_endpoint;

/* Create a fully allocated structure with config, interface, and
   endpoint descriptors all combined. This is not portable - the
   structure is linked to interface/endpoint architecture used by
   this project.
*/
typedef struct usb_config_full
{
  usb_config config;
  usb_interface iface_alt0;
  usb_endpoint  ep8;
  usb_interface iface_alt1;
  usb_endpoint  ep2;
  usb_endpoint  ep6;
} usb_config_full;

typedef struct usb_string
{
  uchar bLength;
  uchar bDescriptorType;
  uchar wData;
} usb_string;

#endif /* _USB_DESCRIPTORS_H_ */
