Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UsbHostMAX3421E_Hello
usb_ch9.h
00001 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 00017 Contact information 00018 ------------------- 00019 00020 Circuits At Home, LTD 00021 Web : http://www.circuitsathome.com 00022 e-mail : support@circuitsathome.com 00023 */ 00024 00025 #if !defined(_usb_h_) || defined(_ch9_h_) 00026 #error "Never include usb_ch9.h directly; include Usb.h instead" 00027 #else 00028 00029 /* USB chapter 9 structures */ 00030 #define _ch9_h_ 00031 00032 /* Misc.USB constants */ 00033 #define DEV_DESCR_LEN 18 //device descriptor length 00034 #define CONF_DESCR_LEN 9 //configuration descriptor length 00035 #define INTR_DESCR_LEN 9 //interface descriptor length 00036 #define EP_DESCR_LEN 7 //endpoint descriptor length 00037 00038 /* Standard Device Requests */ 00039 00040 #define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS 00041 #define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE 00042 #define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE 00043 #define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS 00044 #define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR 00045 #define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR 00046 #define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION 00047 #define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION 00048 #define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE 00049 #define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE 00050 #define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME 00051 00052 #define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt 00053 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up 00054 #define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode 00055 00056 /* Setup Data Constants */ 00057 00058 #define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer 00059 #define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer 00060 #define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard 00061 #define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class 00062 #define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor 00063 #define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device 00064 #define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface 00065 #define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint 00066 #define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other 00067 00068 /* USB descriptors */ 00069 00070 #define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor. 00071 #define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor. 00072 #define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor. 00073 #define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor. 00074 #define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor. 00075 #define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier. 00076 #define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration. 00077 #define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power. 00078 #define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor. 00079 00080 #define HID_DESCRIPTOR_HID 0x21 00081 00082 00083 00084 /* OTG SET FEATURE Constants */ 00085 #define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP 00086 #define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP 00087 #define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP 00088 00089 /* USB Endpoint Transfer Types */ 00090 #define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint. 00091 #define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint. 00092 #define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint. 00093 #define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint. 00094 #define bmUSB_TRANSFER_TYPE 0x03 // bit mask to separate transfer type from ISO attributes 00095 00096 00097 /* Standard Feature Selectors for CLEAR_FEATURE Requests */ 00098 #define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient 00099 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient 00100 #define USB_FEATURE_TEST_MODE 2 // Device recipient 00101 00102 /* descriptor data structures */ 00103 00104 /* Device descriptor structure */ 00105 typedef struct { 00106 uint8_t bLength; // Length of this descriptor. 00107 uint8_t bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE). 00108 uint16_t bcdUSB; // USB Spec Release Number (BCD). 00109 uint8_t bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. 00110 uint8_t bDeviceSubClass; // Subclass code (assigned by the USB-IF). 00111 uint8_t bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. 00112 uint8_t bMaxPacketSize0; // Maximum packet size for endpoint 0. 00113 uint16_t idVendor; // Vendor ID (assigned by the USB-IF). 00114 uint16_t idProduct; // Product ID (assigned by the manufacturer). 00115 uint16_t bcdDevice; // Device release number (BCD). 00116 uint8_t iManufacturer; // Index of String Descriptor describing the manufacturer. 00117 uint8_t iProduct; // Index of String Descriptor describing the product. 00118 uint8_t iSerialNumber; // Index of String Descriptor with the device's serial number. 00119 uint8_t bNumConfigurations; // Number of possible configurations. 00120 } __attribute__((packed)) USB_DEVICE_DESCRIPTOR; 00121 00122 /* Configuration descriptor structure */ 00123 typedef struct { 00124 uint8_t bLength; // Length of this descriptor. 00125 uint8_t bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION). 00126 uint16_t wTotalLength; // Total length of all descriptors for this configuration. 00127 uint8_t bNumInterfaces; // Number of interfaces in this configuration. 00128 uint8_t bConfigurationValue; // Value of this configuration (1 based). 00129 uint8_t iConfiguration; // Index of String Descriptor describing the configuration. 00130 uint8_t bmAttributes; // Configuration characteristics. 00131 uint8_t bMaxPower; // Maximum power consumed by this configuration. 00132 } __attribute__((packed)) USB_CONFIGURATION_DESCRIPTOR; 00133 00134 /* Interface descriptor structure */ 00135 typedef struct { 00136 uint8_t bLength; // Length of this descriptor. 00137 uint8_t bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE). 00138 uint8_t bInterfaceNumber; // Number of this interface (0 based). 00139 uint8_t bAlternateSetting; // Value of this alternate interface setting. 00140 uint8_t bNumEndpoints; // Number of endpoints in this interface. 00141 uint8_t bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. 00142 uint8_t bInterfaceSubClass; // Subclass code (assigned by the USB-IF). 00143 uint8_t bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. 00144 uint8_t iInterface; // Index of String Descriptor describing the interface. 00145 } __attribute__((packed)) USB_INTERFACE_DESCRIPTOR; 00146 00147 /* Endpoint descriptor structure */ 00148 typedef struct { 00149 uint8_t bLength; // Length of this descriptor. 00150 uint8_t bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT). 00151 uint8_t bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN). 00152 uint8_t bmAttributes; // Endpoint transfer type. 00153 uint16_t wMaxPacketSize; // Maximum packet size. 00154 uint8_t bInterval; // Polling interval in frames. 00155 } __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR; 00156 00157 /* HID descriptor */ 00158 typedef struct { 00159 uint8_t bLength; 00160 uint8_t bDescriptorType; 00161 uint16_t bcdHID; // HID class specification release 00162 uint8_t bCountryCode; 00163 uint8_t bNumDescriptors; // Number of additional class specific descriptors 00164 uint8_t bDescrType; // Type of class descriptor 00165 uint16_t wDescriptorLength; // Total size of the Report descriptor 00166 } __attribute__((packed)) USB_HID_DESCRIPTOR; 00167 00168 typedef struct { 00169 uint8_t bDescrType; // Type of class descriptor 00170 uint16_t wDescriptorLength; // Total size of the Report descriptor 00171 } __attribute__((packed)) HID_CLASS_DESCRIPTOR_LEN_AND_TYPE; 00172 00173 #endif // _ch9_h_
Generated on Tue Jul 12 2022 18:12:05 by
1.7.2