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

 $Id: usb_defs.h,v 1.1 2013/06/03 17:40:13 dim Exp $
 $Date: 2013/06/03 17:40:13 $
 $Author: dim $
 $Revision: 1.1 $
 $Log: usb_defs.h,v $
 Revision 1.1  2013/06/03 17:40:13  dim
 Initial import in src_common/

 Revision 1.2  2011/12/27 19:49:01  dim
 Removed extra comment closure

 Revision 1.1  2011/12/27 19:34:26  dim
 Initial import


*/

#ifndef _USB_DEFS_H_
#define _USB_DEFS_H_

/* Descriptor types */
#define USB_DT_DEVICE                   0x01
#define USB_DT_CONFIG                   0x02
#define USB_DT_STRING                   0x03
#define USB_DT_INTERFACE                0x04
#define USB_DT_ENDPOINT                 0x05
#define USB_DT_DEVICE_QUALIFIER         0x06
#define USB_DT_OTHER_SPEED_CONFIG       0x07

/* Device feature masks */
#define USB_DEVICE_SELF_POWERED         0       /* (read only) */
#define USB_DEVICE_REMOTE_WAKEUP        1       /* dev may initiate wakeup */

/* Direction flag: endpoint and bRequestType */
#define USB_DIR_OUT                     0               /* to device */
#define USB_DIR_IN                      0x80            /* to host */

/* bRequestType field: request type */
#define USB_TYPE_MASK                   (0x03 << 5)
#define USB_TYPE_STANDARD               (0x00 << 5)
#define USB_TYPE_CLASS                  (0x01 << 5)
#define USB_TYPE_VENDOR                 (0x02 << 5)
#define USB_TYPE_RESERVED               (0x03 << 5)

/* bRequestType field: recipient */
#define USB_RECIP_MASK                  0x1f
#define USB_RECIP_DEVICE                0x00
#define USB_RECIP_INTERFACE             0x01
#define USB_RECIP_ENDPOINT              0x02
#define USB_RECIP_OTHER                 0x03

/* Standard request types (bRequest field) */
#define USB_REQ_GET_STATUS              0x00
#define USB_REQ_CLEAR_FEATURE           0x01
#define USB_REQ_SET_FEATURE             0x03
#define USB_REQ_SET_ADDRESS             0x05
#define USB_REQ_GET_DESCRIPTOR          0x06
#define USB_REQ_SET_DESCRIPTOR          0x07
#define USB_REQ_GET_CONFIGURATION       0x08
#define USB_REQ_SET_CONFIGURATION       0x09
#define USB_REQ_GET_INTERFACE           0x0A
#define USB_REQ_SET_INTERFACE           0x0B
#define USB_REQ_SYNCH_FRAME             0x0C

/* bmAttributes field of config descriptor */
#define USB_CONFIG_ATT_ONE              (1 << 7)        /* must be set */
#define USB_CONFIG_ATT_SELFPOWER        (1 << 6)        /* self powered */
#define USB_CONFIG_ATT_WAKEUP           (1 << 5)        /* can wakeup */
#define USB_CONFIG_ATT_BATTERY          (1 << 4)        /* battery powered */

/* Endpoint masks */
#define USB_ENDPOINT_NUMBER_MASK        0x0f    /* in bEndpointAddress */
#define USB_ENDPOINT_DIR_MASK           0x80

/* Endpoint attributes */
#define USB_ENDPOINT_XFERTYPE_MASK      0x03    /* in bmAttributes */
#define USB_ENDPOINT_XFER_CONTROL       0
#define USB_ENDPOINT_XFER_ISOC          1
#define USB_ENDPOINT_XFER_BULK          2
#define USB_ENDPOINT_XFER_INT           3

#endif /* _USB_DEFS_H_ */
