1/* 2 * Copyright 2009-2011 Oleg Mazurov, Circuits At Home, http://www.circuitsathome.com 3 * MAX3421E USB host controller support 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the authors nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30/* USB chapter 9 structures */ 31#ifndef _ch9_h_ 32#define _ch9_h_ 33 34/* Misc.USB constants */ 35#define DEV_DESCR_LEN 18 //device descriptor length 36#define CONF_DESCR_LEN 9 //configuration descriptor length 37#define INTR_DESCR_LEN 9 //interface descriptor length 38#define EP_DESCR_LEN 7 //endpoint descriptor length 39 40/* Standard Device Requests */ 41 42#define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS 43#define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE 44#define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE 45#define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS 46#define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR 47#define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR 48#define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION 49#define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION 50#define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE 51#define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE 52#define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME 53 54#define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt 55#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up 56#define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode 57 58/* Setup Data Constants */ 59 60#define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer 61#define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer 62#define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard 63#define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class 64#define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor 65#define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device 66#define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface 67#define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint 68#define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other 69 70/* USB descriptors */ 71 72#define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor. 73#define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor. 74#define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor. 75#define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor. 76#define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor. 77#define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier. 78#define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration. 79#define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power. 80#define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor. 81 82/* OTG SET FEATURE Constants */ 83#define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP 84#define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP 85#define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP 86 87/* USB Endpoint Transfer Types */ 88#define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint. 89#define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint. 90#define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint. 91#define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint. 92#define bmUSB_TRANSFER_TYPE 0x03 // bit mask to separate transfer type from ISO attributes 93 94 95/* Standard Feature Selectors for CLEAR_FEATURE Requests */ 96#define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient 97#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient 98#define USB_FEATURE_TEST_MODE 2 // Device recipient 99 100/* HID constants. Not part of chapter 9 */ 101/* Class-Specific Requests */ 102#define HID_REQUEST_GET_REPORT 0x01 103#define HID_REQUEST_GET_IDLE 0x02 104#define HID_REQUEST_GET_PROTOCOL 0x03 105#define HID_REQUEST_SET_REPORT 0x09 106#define HID_REQUEST_SET_IDLE 0x0A 107#define HID_REQUEST_SET_PROTOCOL 0x0B 108 109/* Class Descriptor Types */ 110#define HID_DESCRIPTOR_HID 0x21 111#define HID_DESCRIPTOR_REPORT 0x22 112#define HID_DESRIPTOR_PHY 0x23 113 114/* Protocol Selection */ 115#define BOOT_PROTOCOL 0x00 116#define RPT_PROTOCOL 0x01 117/* HID Interface Class Code */ 118#define HID_INTF 0x03 119/* HID Interface Class SubClass Codes */ 120#define BOOT_INTF_SUBCLASS 0x01 121/* HID Interface Class Protocol Codes */ 122#define HID_PROTOCOL_NONE 0x00 123#define HID_PROTOCOL_KEYBOARD 0x01 124#define HID_PROTOCOL_MOUSE 0x02 125 126 127/* descriptor data structures */ 128 129/* Device descriptor structure */ 130typedef struct { 131 byte bLength; // Length of this descriptor. 132 byte bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE). 133 unsigned int bcdUSB; // USB Spec Release Number (BCD). 134 byte bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. 135 byte bDeviceSubClass; // Subclass code (assigned by the USB-IF). 136 byte bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. 137 byte bMaxPacketSize0; // Maximum packet size for endpoint 0. 138 unsigned int idVendor; // Vendor ID (assigned by the USB-IF). 139 unsigned int idProduct; // Product ID (assigned by the manufacturer). 140 unsigned int bcdDevice; // Device release number (BCD). 141 byte iManufacturer; // Index of String Descriptor describing the manufacturer. 142 byte iProduct; // Index of String Descriptor describing the product. 143 byte iSerialNumber; // Index of String Descriptor with the device's serial number. 144 byte bNumConfigurations; // Number of possible configurations. 145} USB_DEVICE_DESCRIPTOR; 146 147/* Configuration descriptor structure */ 148typedef struct 149{ 150 byte bLength; // Length of this descriptor. 151 byte bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION). 152 unsigned int wTotalLength; // Total length of all descriptors for this configuration. 153 byte bNumInterfaces; // Number of interfaces in this configuration. 154 byte bConfigurationValue; // Value of this configuration (1 based). 155 byte iConfiguration; // Index of String Descriptor describing the configuration. 156 byte bmAttributes; // Configuration characteristics. 157 byte bMaxPower; // Maximum power consumed by this configuration. 158} USB_CONFIGURATION_DESCRIPTOR; 159 160/* Interface descriptor structure */ 161typedef struct 162{ 163 byte bLength; // Length of this descriptor. 164 byte bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE). 165 byte bInterfaceNumber; // Number of this interface (0 based). 166 byte bAlternateSetting; // Value of this alternate interface setting. 167 byte bNumEndpoints; // Number of endpoints in this interface. 168 byte bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. 169 byte bInterfaceSubClass; // Subclass code (assigned by the USB-IF). 170 byte bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. 171 byte iInterface; // Index of String Descriptor describing the interface. 172} USB_INTERFACE_DESCRIPTOR; 173 174/* Endpoint descriptor structure */ 175typedef struct 176{ 177 byte bLength; // Length of this descriptor. 178 byte bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT). 179 byte bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN). 180 byte bmAttributes; // Endpoint transfer type. 181 unsigned int wMaxPacketSize; // Maximum packet size. 182 byte bInterval; // Polling interval in frames. 183} USB_ENDPOINT_DESCRIPTOR; 184 185/* HID descriptor */ 186typedef struct { 187 byte bLength; 188 byte bDescriptorType; 189 unsigned int bcdHID; 190 byte bCountryCode; 191 byte bNumDescriptors; 192 byte bDescrType; 193 unsigned int wDescriptorLength; 194} USB_HID_DESCRIPTOR; 195 196#endif // _ch9_h_ 197