BlueUSBをつかってみた
Dependencies: FatFileSystem mbed
Fork of PS3_BlueUSB by
USBHost.h
00001 00002 /* 00003 Copyright (c) 2010 Peter Barrett 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 00024 #ifndef USBHOST_H 00025 #define USBHOST_H 00026 00027 #ifndef u8 00028 typedef unsigned char u8; 00029 typedef unsigned short u16; 00030 typedef unsigned long u32; 00031 00032 typedef char s8; 00033 typedef short s16; 00034 typedef char s32; 00035 #endif 00036 00037 #define ENDPOINT_CONTROL 0 00038 #define ENDPOINT_ISOCRONOUS 1 00039 #define ENDPOINT_BULK 2 00040 #define ENDPOINT_INTERRUPT 3 00041 00042 #define DESCRIPTOR_TYPE_DEVICE 1 00043 #define DESCRIPTOR_TYPE_CONFIGURATION 2 00044 #define DESCRIPTOR_TYPE_STRING 3 00045 #define DESCRIPTOR_TYPE_INTERFACE 4 00046 #define DESCRIPTOR_TYPE_ENDPOINT 5 00047 00048 #define DESCRIPTOR_TYPE_HID 0x21 00049 #define DESCRIPTOR_TYPE_REPORT 0x22 00050 #define DESCRIPTOR_TYPE_PHYSICAL 0x23 00051 #define DESCRIPTOR_TYPE_HUB 0x29 00052 00053 enum USB_CLASS_CODE 00054 { 00055 CLASS_DEVICE, 00056 CLASS_AUDIO, 00057 CLASS_COMM_AND_CDC_CONTROL, 00058 CLASS_HID, 00059 CLASS_PHYSICAL = 0x05, 00060 CLASS_STILL_IMAGING, 00061 CLASS_PRINTER, 00062 CLASS_MASS_STORAGE, 00063 CLASS_HUB, 00064 CLASS_CDC_DATA, 00065 CLASS_SMART_CARD, 00066 CLASS_CONTENT_SECURITY = 0x0D, 00067 CLASS_VIDEO = 0x0E, 00068 CLASS_DIAGNOSTIC_DEVICE = 0xDC, 00069 CLASS_WIRELESS_CONTROLLER = 0xE0, 00070 CLASS_MISCELLANEOUS = 0xEF, 00071 CLASS_APP_SPECIFIC = 0xFE, 00072 CLASS_VENDOR_SPECIFIC = 0xFF 00073 }; 00074 00075 #define DEVICE_TO_HOST 0x80 00076 #define HOST_TO_DEVICE 0x00 00077 #define REQUEST_TYPE_STANDARD 0x00 00078 #define REQUEST_TYPE_CLASS 0x20 00079 #define REQUEST_TYPE_VENDOR 0x40 00080 #define RECIPIENT_DEVICE 0x00 00081 #define RECIPIENT_INTERFACE 0x01 00082 #define RECIPIENT_ENDPOINT 0x02 00083 #define RECIPIENT_OTHER 0x03 00084 00085 #define GET_STATUS 0 00086 #define CLEAR_FEATURE 1 00087 #define SET_FEATURE 3 00088 #define SET_ADDRESS 5 00089 #define GET_DESCRIPTOR 6 00090 #define SET_DESCRIPTOR 7 00091 #define GET_CONFIGURATION 8 00092 #define SET_CONFIGURATION 9 00093 #define GET_INTERFACE 10 00094 #define SET_INTERFACE 11 00095 #define SYNCH_FRAME 11 00096 00097 /* HID Request Codes */ 00098 #define HID_REQUEST_GET_REPORT 0x01 00099 #define HID_REQUEST_GET_IDLE 0x02 00100 #define HID_REQUEST_GET_PROTOCOL 0x03 00101 #define HID_REQUEST_SET_REPORT 0x09 00102 #define HID_REQUEST_SET_IDLE 0x0A 00103 #define HID_REQUEST_SET_PROTOCOL 0x0B 00104 00105 /* HID Report Types */ 00106 #define HID_REPORT_INPUT 0x01 00107 #define HID_REPORT_OUTPUT 0x02 00108 #define HID_REPORT_FEATURE 0x03 00109 00110 00111 // -5 is nak 00112 /* 00113 0010 ACK Handshake 00114 1010 NAK Handshake 00115 1110 STALL Handshake 00116 0110 NYET (No Response Yet) 00117 */ 00118 00119 #define IO_PENDING -100 00120 #define ERR_ENDPOINT_NONE_LEFT -101 00121 #define ERR_ENDPOINT_NOT_FOUND -102 00122 #define ERR_DEVICE_NOT_FOUND -103 00123 #define ERR_DEVICE_NONE_LEFT -104 00124 #define ERR_HUB_INIT_FAILED -105 00125 #define ERR_INTERFACE_NOT_FOUND -106 00126 00127 typedef struct 00128 { 00129 u8 bLength; 00130 u8 bDescriptorType; 00131 u16 bcdUSB; 00132 u8 bDeviceClass; 00133 u8 bDeviceSubClass; 00134 u8 bDeviceProtocol; 00135 u8 bMaxPacketSize; 00136 u16 idVendor; 00137 u16 idProduct; 00138 u16 bcdDevice; // version 00139 u8 iManufacturer; 00140 u8 iProduct; 00141 u8 iSerialNumber; 00142 u8 bNumConfigurations; 00143 } DeviceDescriptor; // 16 bytes 00144 00145 typedef struct 00146 { 00147 u8 bLength; 00148 u8 bDescriptorType; 00149 u16 wTotalLength; 00150 u8 bNumInterfaces; 00151 u8 bConfigurationValue; // Value to use as an argument to select this configuration 00152 u8 iConfiguration; // Index of String Descriptor describing this configuration 00153 u8 bmAttributes; // Bitmap D7 Reserved, set to 1. (USB 1.0 Bus Powered),D6 Self Powered,D5 Remote Wakeup,D4..0 = 0 00154 u8 bMaxPower; // Maximum Power Consumption in 2mA units 00155 } ConfigurationDescriptor; 00156 00157 typedef struct 00158 { 00159 u8 bLength; 00160 u8 bDescriptorType; 00161 u8 bInterfaceNumber; 00162 u8 bAlternateSetting; 00163 u8 bNumEndpoints; 00164 u8 bInterfaceClass; 00165 u8 bInterfaceSubClass; 00166 u8 bInterfaceProtocol; 00167 u8 iInterface; // Index of String Descriptor Describing this interface 00168 } InterfaceDescriptor; 00169 00170 typedef struct 00171 { 00172 u8 bLength; 00173 u8 bDescriptorType; 00174 u8 bEndpointAddress; // Bits 0:3 endpoint, Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints) 00175 u8 bmAttributes; // Bits 0:1 00 = Control, 01 = Isochronous, 10 = Bulk, 11 = Interrupt 00176 u16 wMaxPacketSize; 00177 u8 bInterval; // Interval for polling endpoint data transfers. 00178 } EndpointDescriptor; 00179 00180 typedef struct { 00181 u8 bLength; 00182 u8 bDescriptorType; 00183 u16 bcdHID; 00184 u8 bCountryCode; 00185 u8 bNumDescriptors; 00186 u8 bDescriptorType2; 00187 u16 wDescriptorLength; 00188 } HIDDescriptor; 00189 00190 //============================================================================ 00191 //============================================================================ 00192 00193 00194 void USBInit(); 00195 void USBLoop(); 00196 u8* USBGetBuffer(u32* len); 00197 00198 // Optional callback for transfers, called at interrupt time 00199 typedef void (*USBCallback)(int device, int endpoint, int status, u8* data, int len, void* userData); 00200 00201 // Transfers 00202 int USBControlTransfer(int device, int request_type, int request, int value, int index, u8* data, int length, USBCallback callback = 0, void* userData = 0); 00203 int USBInterruptTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0); 00204 int USBBulkTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0); 00205 00206 // Standard Device methods 00207 int GetDescriptor(int device, int descType, int descIndex, u8* data, int length); 00208 int GetString(int device, int index, char* dst, int length); 00209 int SetAddress(int device, int new_addr); 00210 int SetConfiguration(int device, int configNum); 00211 int SetInterface(int device, int ifNum, int altNum); 00212 00213 // Implemented to notify app of the arrival of a device 00214 void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc); 00215 00216 #endif
Generated on Wed Jul 13 2022 12:19:22 by 1.7.2