ch9.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009-2011 Oleg Mazurov, Circuits At Home, http://www.circuitsathome.com
00003  * MAX3421E USB host controller support
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the authors nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 /* USB chapter 9 structures */
00031 #ifndef _ch9_h_
00032 #define _ch9_h_
00033 
00034 /* Misc.USB constants */
00035 #define DEV_DESCR_LEN   18      //device descriptor length
00036 #define CONF_DESCR_LEN  9       //configuration descriptor length
00037 #define INTR_DESCR_LEN  9       //interface descriptor length
00038 #define EP_DESCR_LEN    7       //endpoint descriptor length
00039 
00040 /* Standard Device Requests */
00041 
00042 #define USB_REQUEST_GET_STATUS                  0       // Standard Device Request - GET STATUS
00043 #define USB_REQUEST_CLEAR_FEATURE               1       // Standard Device Request - CLEAR FEATURE
00044 #define USB_REQUEST_SET_FEATURE                 3       // Standard Device Request - SET FEATURE
00045 #define USB_REQUEST_SET_ADDRESS                 5       // Standard Device Request - SET ADDRESS
00046 #define USB_REQUEST_GET_DESCRIPTOR              6       // Standard Device Request - GET DESCRIPTOR
00047 #define USB_REQUEST_SET_DESCRIPTOR              7       // Standard Device Request - SET DESCRIPTOR
00048 #define USB_REQUEST_GET_CONFIGURATION           8       // Standard Device Request - GET CONFIGURATION
00049 #define USB_REQUEST_SET_CONFIGURATION           9       // Standard Device Request - SET CONFIGURATION
00050 #define USB_REQUEST_GET_INTERFACE               10      // Standard Device Request - GET INTERFACE
00051 #define USB_REQUEST_SET_INTERFACE               11      // Standard Device Request - SET INTERFACE
00052 #define USB_REQUEST_SYNCH_FRAME                 12      // Standard Device Request - SYNCH FRAME
00053 
00054 #define USB_FEATURE_ENDPOINT_HALT               0       // CLEAR/SET FEATURE - Endpoint Halt
00055 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP        1       // CLEAR/SET FEATURE - Device remote wake-up
00056 #define USB_FEATURE_TEST_MODE                   2       // CLEAR/SET FEATURE - Test mode
00057 
00058 /* Setup Data Constants */
00059 
00060 #define USB_SETUP_HOST_TO_DEVICE                0x00    // Device Request bmRequestType transfer direction - host to device transfer
00061 #define USB_SETUP_DEVICE_TO_HOST                0x80    // Device Request bmRequestType transfer direction - device to host transfer
00062 #define USB_SETUP_TYPE_STANDARD                 0x00    // Device Request bmRequestType type - standard
00063 #define USB_SETUP_TYPE_CLASS                    0x20    // Device Request bmRequestType type - class
00064 #define USB_SETUP_TYPE_VENDOR                   0x40    // Device Request bmRequestType type - vendor
00065 #define USB_SETUP_RECIPIENT_DEVICE              0x00    // Device Request bmRequestType recipient - device
00066 #define USB_SETUP_RECIPIENT_INTERFACE           0x01    // Device Request bmRequestType recipient - interface
00067 #define USB_SETUP_RECIPIENT_ENDPOINT            0x02    // Device Request bmRequestType recipient - endpoint
00068 #define USB_SETUP_RECIPIENT_OTHER               0x03    // Device Request bmRequestType recipient - other
00069 
00070 /* USB descriptors  */
00071 
00072 #define USB_DESCRIPTOR_DEVICE           0x01    // bDescriptorType for a Device Descriptor.
00073 #define USB_DESCRIPTOR_CONFIGURATION    0x02    // bDescriptorType for a Configuration Descriptor.
00074 #define USB_DESCRIPTOR_STRING           0x03    // bDescriptorType for a String Descriptor.
00075 #define USB_DESCRIPTOR_INTERFACE        0x04    // bDescriptorType for an Interface Descriptor.
00076 #define USB_DESCRIPTOR_ENDPOINT         0x05    // bDescriptorType for an Endpoint Descriptor.
00077 #define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06    // bDescriptorType for a Device Qualifier.
00078 #define USB_DESCRIPTOR_OTHER_SPEED      0x07    // bDescriptorType for a Other Speed Configuration.
00079 #define USB_DESCRIPTOR_INTERFACE_POWER  0x08    // bDescriptorType for Interface Power.
00080 #define USB_DESCRIPTOR_OTG              0x09    // bDescriptorType for an OTG Descriptor.
00081 
00082 /* OTG SET FEATURE Constants    */
00083 #define OTG_FEATURE_B_HNP_ENABLE                3       // SET FEATURE OTG - Enable B device to perform HNP
00084 #define OTG_FEATURE_A_HNP_SUPPORT               4       // SET FEATURE OTG - A device supports HNP
00085 #define OTG_FEATURE_A_ALT_HNP_SUPPORT           5       // SET FEATURE OTG - Another port on the A device supports HNP
00086 
00087 /* USB Endpoint Transfer Types  */
00088 #define USB_TRANSFER_TYPE_CONTROL               0x00    // Endpoint is a control endpoint.
00089 #define USB_TRANSFER_TYPE_ISOCHRONOUS           0x01    // Endpoint is an isochronous endpoint.
00090 #define USB_TRANSFER_TYPE_BULK                  0x02    // Endpoint is a bulk endpoint.
00091 #define USB_TRANSFER_TYPE_INTERRUPT             0x03    // Endpoint is an interrupt endpoint.
00092 #define bmUSB_TRANSFER_TYPE                     0x03    // bit mask to separate transfer type from ISO attributes
00093 
00094 
00095 /* Standard Feature Selectors for CLEAR_FEATURE Requests    */
00096 #define USB_FEATURE_ENDPOINT_STALL              0       // Endpoint recipient
00097 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP        1       // Device recipient
00098 #define USB_FEATURE_TEST_MODE                   2       // Device recipient
00099 
00100 /* HID constants. Not part of chapter 9 */
00101 /* Class-Specific Requests */
00102 #define HID_REQUEST_GET_REPORT      0x01
00103 #define HID_REQUEST_GET_IDLE        0x02
00104 #define HID_REQUEST_GET_PROTOCOL    0x03
00105 #define HID_REQUEST_SET_REPORT      0x09
00106 #define HID_REQUEST_SET_IDLE        0x0A
00107 #define HID_REQUEST_SET_PROTOCOL    0x0B
00108 
00109 /* Class Descriptor Types */
00110 #define HID_DESCRIPTOR_HID      0x21
00111 #define HID_DESCRIPTOR_REPORT   0x22
00112 #define HID_DESRIPTOR_PHY       0x23
00113 
00114 /* Protocol Selection */
00115 #define BOOT_PROTOCOL   0x00
00116 #define RPT_PROTOCOL    0x01
00117 /* HID Interface Class Code */
00118 #define HID_INTF                    0x03
00119 /* HID Interface Class SubClass Codes */
00120 #define BOOT_INTF_SUBCLASS          0x01
00121 /* HID Interface Class Protocol Codes */
00122 #define HID_PROTOCOL_NONE           0x00
00123 #define HID_PROTOCOL_KEYBOARD       0x01
00124 #define HID_PROTOCOL_MOUSE          0x02
00125 
00126 
00127 /* descriptor data structures */
00128 
00129 /* Device descriptor structure */
00130 typedef struct {
00131     byte bLength;               // Length of this descriptor.
00132     byte bDescriptorType;       // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE).
00133     unsigned int bcdUSB;        // USB Spec Release Number (BCD).
00134     byte bDeviceClass;          // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
00135     byte bDeviceSubClass;       // Subclass code (assigned by the USB-IF).
00136     byte bDeviceProtocol;       // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
00137     byte bMaxPacketSize0;       // Maximum packet size for endpoint 0.
00138     unsigned int idVendor;      // Vendor ID (assigned by the USB-IF).
00139     unsigned int idProduct;     // Product ID (assigned by the manufacturer).
00140     unsigned int bcdDevice;      // Device release number (BCD).
00141     byte iManufacturer;         // Index of String Descriptor describing the manufacturer.
00142     byte iProduct;              // Index of String Descriptor describing the product.
00143     byte iSerialNumber;         // Index of String Descriptor with the device's serial number.
00144     byte bNumConfigurations;    // Number of possible configurations.
00145 } USB_DEVICE_DESCRIPTOR;
00146 
00147 /* Configuration descriptor structure */
00148 typedef struct
00149 {
00150     byte bLength;               // Length of this descriptor.
00151     byte bDescriptorType;       // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION).
00152     unsigned int wTotalLength;          // Total length of all descriptors for this configuration.
00153     byte bNumInterfaces;        // Number of interfaces in this configuration.
00154     byte bConfigurationValue;   // Value of this configuration (1 based).
00155     byte iConfiguration;        // Index of String Descriptor describing the configuration.
00156     byte bmAttributes;          // Configuration characteristics.
00157     byte bMaxPower;             // Maximum power consumed by this configuration.
00158 } USB_CONFIGURATION_DESCRIPTOR;
00159 
00160 /* Interface descriptor structure */
00161 typedef struct
00162 {
00163     byte bLength;               // Length of this descriptor.
00164     byte bDescriptorType;       // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE).
00165     byte bInterfaceNumber;      // Number of this interface (0 based).
00166     byte bAlternateSetting;     // Value of this alternate interface setting.
00167     byte bNumEndpoints;         // Number of endpoints in this interface.
00168     byte bInterfaceClass;       // Class code (assigned by the USB-IF).  0xFF-Vendor specific.
00169     byte bInterfaceSubClass;    // Subclass code (assigned by the USB-IF).
00170     byte bInterfaceProtocol;    // Protocol code (assigned by the USB-IF).  0xFF-Vendor specific.
00171     byte iInterface;            // Index of String Descriptor describing the interface.
00172 } USB_INTERFACE_DESCRIPTOR;
00173 
00174 /* Endpoint descriptor structure */
00175 typedef struct
00176 {
00177     byte bLength;               // Length of this descriptor.
00178     byte bDescriptorType;       // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT).
00179     byte bEndpointAddress;      // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN).
00180     byte bmAttributes;          // Endpoint transfer type.
00181     unsigned int wMaxPacketSize;        // Maximum packet size.
00182     byte bInterval;             // Polling interval in frames.
00183 } USB_ENDPOINT_DESCRIPTOR;
00184 
00185 /* HID descriptor */
00186 typedef struct {
00187     byte bLength;                       
00188         byte bDescriptorType;   
00189         unsigned int bcdHID;                    
00190     byte bCountryCode;          
00191         byte bNumDescriptors;
00192         byte bDescrType;                        
00193     unsigned int wDescriptorLength;
00194 } USB_HID_DESCRIPTOR;
00195 
00196 #endif // _ch9_h_


rosserial_adk_demo
Author(s): Adam Stambler
autogenerated on Mon Dec 2 2013 12:02:02