![](/media/cache/profiles/ddcbe25988981920c872c1787382f04d.50x50_q85.jpg)
XOOMの動作状況を聞き処理を変えてみました。 USBケーブルを抜いた際に処理を終了するようにしました。
USBHost.h@3:432e5675d240, 2011-05-27 (annotated)
- Committer:
- abe00makoto
- Date:
- Fri May 27 18:51:15 2011 +0000
- Revision:
- 3:432e5675d240
- Parent:
- 0:9fb6c423e32c
nexus one support
maybe support add XOOM ,nexus S
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
abe00makoto | 0:9fb6c423e32c | 1 | |
abe00makoto | 0:9fb6c423e32c | 2 | /* |
abe00makoto | 0:9fb6c423e32c | 3 | Copyright (c) 2010 Peter Barrett |
abe00makoto | 0:9fb6c423e32c | 4 | |
abe00makoto | 0:9fb6c423e32c | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
abe00makoto | 0:9fb6c423e32c | 6 | of this software and associated documentation files (the "Software"), to deal |
abe00makoto | 0:9fb6c423e32c | 7 | in the Software without restriction, including without limitation the rights |
abe00makoto | 0:9fb6c423e32c | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
abe00makoto | 0:9fb6c423e32c | 9 | copies of the Software, and to permit persons to whom the Software is |
abe00makoto | 0:9fb6c423e32c | 10 | furnished to do so, subject to the following conditions: |
abe00makoto | 0:9fb6c423e32c | 11 | |
abe00makoto | 0:9fb6c423e32c | 12 | The above copyright notice and this permission notice shall be included in |
abe00makoto | 0:9fb6c423e32c | 13 | all copies or substantial portions of the Software. |
abe00makoto | 0:9fb6c423e32c | 14 | |
abe00makoto | 0:9fb6c423e32c | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
abe00makoto | 0:9fb6c423e32c | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
abe00makoto | 0:9fb6c423e32c | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
abe00makoto | 0:9fb6c423e32c | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
abe00makoto | 0:9fb6c423e32c | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
abe00makoto | 0:9fb6c423e32c | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
abe00makoto | 0:9fb6c423e32c | 21 | THE SOFTWARE. |
abe00makoto | 0:9fb6c423e32c | 22 | */ |
abe00makoto | 0:9fb6c423e32c | 23 | |
abe00makoto | 0:9fb6c423e32c | 24 | #ifndef USBHOST_H |
abe00makoto | 0:9fb6c423e32c | 25 | #define USBHOST_H |
abe00makoto | 0:9fb6c423e32c | 26 | |
abe00makoto | 0:9fb6c423e32c | 27 | #ifndef u8 |
abe00makoto | 0:9fb6c423e32c | 28 | typedef unsigned char u8; |
abe00makoto | 0:9fb6c423e32c | 29 | typedef unsigned short u16; |
abe00makoto | 0:9fb6c423e32c | 30 | typedef unsigned long u32; |
abe00makoto | 0:9fb6c423e32c | 31 | |
abe00makoto | 0:9fb6c423e32c | 32 | typedef char s8; |
abe00makoto | 0:9fb6c423e32c | 33 | typedef short s16; |
abe00makoto | 0:9fb6c423e32c | 34 | typedef char s32; |
abe00makoto | 0:9fb6c423e32c | 35 | #endif |
abe00makoto | 0:9fb6c423e32c | 36 | |
abe00makoto | 0:9fb6c423e32c | 37 | #define ENDPOINT_CONTROL 0 |
abe00makoto | 0:9fb6c423e32c | 38 | #define ENDPOINT_ISOCRONOUS 1 |
abe00makoto | 0:9fb6c423e32c | 39 | #define ENDPOINT_BULK 2 |
abe00makoto | 0:9fb6c423e32c | 40 | #define ENDPOINT_INTERRUPT 3 |
abe00makoto | 0:9fb6c423e32c | 41 | |
abe00makoto | 0:9fb6c423e32c | 42 | #define DESCRIPTOR_TYPE_DEVICE 1 |
abe00makoto | 0:9fb6c423e32c | 43 | #define DESCRIPTOR_TYPE_CONFIGURATION 2 |
abe00makoto | 0:9fb6c423e32c | 44 | #define DESCRIPTOR_TYPE_STRING 3 |
abe00makoto | 0:9fb6c423e32c | 45 | #define DESCRIPTOR_TYPE_INTERFACE 4 |
abe00makoto | 0:9fb6c423e32c | 46 | #define DESCRIPTOR_TYPE_ENDPOINT 5 |
abe00makoto | 0:9fb6c423e32c | 47 | |
abe00makoto | 0:9fb6c423e32c | 48 | #define DESCRIPTOR_TYPE_HID 0x21 |
abe00makoto | 0:9fb6c423e32c | 49 | #define DESCRIPTOR_TYPE_REPORT 0x22 |
abe00makoto | 0:9fb6c423e32c | 50 | #define DESCRIPTOR_TYPE_PHYSICAL 0x23 |
abe00makoto | 0:9fb6c423e32c | 51 | #define DESCRIPTOR_TYPE_HUB 0x29 |
abe00makoto | 0:9fb6c423e32c | 52 | |
abe00makoto | 0:9fb6c423e32c | 53 | enum USB_CLASS_CODE |
abe00makoto | 0:9fb6c423e32c | 54 | { |
abe00makoto | 0:9fb6c423e32c | 55 | CLASS_DEVICE, |
abe00makoto | 0:9fb6c423e32c | 56 | CLASS_AUDIO, |
abe00makoto | 0:9fb6c423e32c | 57 | CLASS_COMM_AND_CDC_CONTROL, |
abe00makoto | 0:9fb6c423e32c | 58 | CLASS_HID, |
abe00makoto | 0:9fb6c423e32c | 59 | CLASS_PHYSICAL = 0x05, |
abe00makoto | 0:9fb6c423e32c | 60 | CLASS_STILL_IMAGING, |
abe00makoto | 0:9fb6c423e32c | 61 | CLASS_PRINTER, |
abe00makoto | 0:9fb6c423e32c | 62 | CLASS_MASS_STORAGE, |
abe00makoto | 0:9fb6c423e32c | 63 | CLASS_HUB, |
abe00makoto | 0:9fb6c423e32c | 64 | CLASS_CDC_DATA, |
abe00makoto | 0:9fb6c423e32c | 65 | CLASS_SMART_CARD, |
abe00makoto | 0:9fb6c423e32c | 66 | CLASS_CONTENT_SECURITY = 0x0D, |
abe00makoto | 0:9fb6c423e32c | 67 | CLASS_VIDEO = 0x0E, |
abe00makoto | 0:9fb6c423e32c | 68 | CLASS_DIAGNOSTIC_DEVICE = 0xDC, |
abe00makoto | 0:9fb6c423e32c | 69 | CLASS_WIRELESS_CONTROLLER = 0xE0, |
abe00makoto | 0:9fb6c423e32c | 70 | CLASS_MISCELLANEOUS = 0xEF, |
abe00makoto | 0:9fb6c423e32c | 71 | CLASS_APP_SPECIFIC = 0xFE, |
abe00makoto | 0:9fb6c423e32c | 72 | CLASS_VENDOR_SPECIFIC = 0xFF |
abe00makoto | 0:9fb6c423e32c | 73 | }; |
abe00makoto | 0:9fb6c423e32c | 74 | |
abe00makoto | 0:9fb6c423e32c | 75 | #define DEVICE_TO_HOST 0x80 |
abe00makoto | 0:9fb6c423e32c | 76 | #define HOST_TO_DEVICE 0x00 |
abe00makoto | 0:9fb6c423e32c | 77 | #define REQUEST_TYPE_STANDARD 0x00 |
abe00makoto | 0:9fb6c423e32c | 78 | #define REQUEST_TYPE_CLASS 0x20 |
abe00makoto | 0:9fb6c423e32c | 79 | #define REQUEST_TYPE_VENDOR 0x40 |
abe00makoto | 0:9fb6c423e32c | 80 | #define RECIPIENT_DEVICE 0x00 |
abe00makoto | 0:9fb6c423e32c | 81 | #define RECIPIENT_INTERFACE 0x01 |
abe00makoto | 0:9fb6c423e32c | 82 | #define RECIPIENT_ENDPOINT 0x02 |
abe00makoto | 0:9fb6c423e32c | 83 | #define RECIPIENT_OTHER 0x03 |
abe00makoto | 0:9fb6c423e32c | 84 | |
abe00makoto | 0:9fb6c423e32c | 85 | #define GET_STATUS 0 |
abe00makoto | 0:9fb6c423e32c | 86 | #define CLEAR_FEATURE 1 |
abe00makoto | 0:9fb6c423e32c | 87 | #define SET_FEATURE 3 |
abe00makoto | 0:9fb6c423e32c | 88 | #define SET_ADDRESS 5 |
abe00makoto | 0:9fb6c423e32c | 89 | #define GET_DESCRIPTOR 6 |
abe00makoto | 0:9fb6c423e32c | 90 | #define SET_DESCRIPTOR 7 |
abe00makoto | 0:9fb6c423e32c | 91 | #define GET_CONFIGURATION 8 |
abe00makoto | 0:9fb6c423e32c | 92 | #define SET_CONFIGURATION 9 |
abe00makoto | 0:9fb6c423e32c | 93 | #define GET_INTERFACE 10 |
abe00makoto | 0:9fb6c423e32c | 94 | #define SET_INTERFACE 11 |
abe00makoto | 0:9fb6c423e32c | 95 | #define SYNCH_FRAME 11 |
abe00makoto | 0:9fb6c423e32c | 96 | |
abe00makoto | 0:9fb6c423e32c | 97 | /* HID Request Codes */ |
abe00makoto | 0:9fb6c423e32c | 98 | #define HID_REQUEST_GET_REPORT 0x01 |
abe00makoto | 0:9fb6c423e32c | 99 | #define HID_REQUEST_GET_IDLE 0x02 |
abe00makoto | 0:9fb6c423e32c | 100 | #define HID_REQUEST_GET_PROTOCOL 0x03 |
abe00makoto | 0:9fb6c423e32c | 101 | #define HID_REQUEST_SET_REPORT 0x09 |
abe00makoto | 0:9fb6c423e32c | 102 | #define HID_REQUEST_SET_IDLE 0x0A |
abe00makoto | 0:9fb6c423e32c | 103 | #define HID_REQUEST_SET_PROTOCOL 0x0B |
abe00makoto | 0:9fb6c423e32c | 104 | |
abe00makoto | 0:9fb6c423e32c | 105 | /* HID Report Types */ |
abe00makoto | 0:9fb6c423e32c | 106 | #define HID_REPORT_INPUT 0x01 |
abe00makoto | 0:9fb6c423e32c | 107 | #define HID_REPORT_OUTPUT 0x02 |
abe00makoto | 0:9fb6c423e32c | 108 | #define HID_REPORT_FEATURE 0x03 |
abe00makoto | 0:9fb6c423e32c | 109 | |
abe00makoto | 0:9fb6c423e32c | 110 | |
abe00makoto | 0:9fb6c423e32c | 111 | // -5 is nak |
abe00makoto | 0:9fb6c423e32c | 112 | /* |
abe00makoto | 0:9fb6c423e32c | 113 | 0010 ACK Handshake |
abe00makoto | 0:9fb6c423e32c | 114 | 1010 NAK Handshake |
abe00makoto | 0:9fb6c423e32c | 115 | 1110 STALL Handshake |
abe00makoto | 0:9fb6c423e32c | 116 | 0110 NYET (No Response Yet) |
abe00makoto | 0:9fb6c423e32c | 117 | */ |
abe00makoto | 0:9fb6c423e32c | 118 | |
abe00makoto | 0:9fb6c423e32c | 119 | #define IO_PENDING -100 |
abe00makoto | 0:9fb6c423e32c | 120 | #define ERR_ENDPOINT_NONE_LEFT -101 |
abe00makoto | 0:9fb6c423e32c | 121 | #define ERR_ENDPOINT_NOT_FOUND -102 |
abe00makoto | 0:9fb6c423e32c | 122 | #define ERR_DEVICE_NOT_FOUND -103 |
abe00makoto | 0:9fb6c423e32c | 123 | #define ERR_DEVICE_NONE_LEFT -104 |
abe00makoto | 0:9fb6c423e32c | 124 | #define ERR_HUB_INIT_FAILED -105 |
abe00makoto | 0:9fb6c423e32c | 125 | #define ERR_INTERFACE_NOT_FOUND -106 |
abe00makoto | 0:9fb6c423e32c | 126 | |
abe00makoto | 0:9fb6c423e32c | 127 | typedef struct |
abe00makoto | 0:9fb6c423e32c | 128 | { |
abe00makoto | 0:9fb6c423e32c | 129 | u8 bLength; |
abe00makoto | 0:9fb6c423e32c | 130 | u8 bDescriptorType; |
abe00makoto | 0:9fb6c423e32c | 131 | u16 bcdUSB; |
abe00makoto | 0:9fb6c423e32c | 132 | u8 bDeviceClass; |
abe00makoto | 0:9fb6c423e32c | 133 | u8 bDeviceSubClass; |
abe00makoto | 0:9fb6c423e32c | 134 | u8 bDeviceProtocol; |
abe00makoto | 0:9fb6c423e32c | 135 | u8 bMaxPacketSize; |
abe00makoto | 0:9fb6c423e32c | 136 | u16 idVendor; |
abe00makoto | 0:9fb6c423e32c | 137 | u16 idProduct; |
abe00makoto | 0:9fb6c423e32c | 138 | u16 bcdDevice; // version |
abe00makoto | 0:9fb6c423e32c | 139 | u8 iManufacturer; |
abe00makoto | 0:9fb6c423e32c | 140 | u8 iProduct; |
abe00makoto | 0:9fb6c423e32c | 141 | u8 iSerialNumber; |
abe00makoto | 0:9fb6c423e32c | 142 | u8 bNumConfigurations; |
abe00makoto | 0:9fb6c423e32c | 143 | } DeviceDescriptor; // 16 bytes |
abe00makoto | 0:9fb6c423e32c | 144 | |
abe00makoto | 0:9fb6c423e32c | 145 | typedef struct |
abe00makoto | 0:9fb6c423e32c | 146 | { |
abe00makoto | 0:9fb6c423e32c | 147 | u8 bLength; |
abe00makoto | 0:9fb6c423e32c | 148 | u8 bDescriptorType; |
abe00makoto | 0:9fb6c423e32c | 149 | u16 wTotalLength; |
abe00makoto | 0:9fb6c423e32c | 150 | u8 bNumInterfaces; |
abe00makoto | 0:9fb6c423e32c | 151 | u8 bConfigurationValue; // Value to use as an argument to select this configuration |
abe00makoto | 0:9fb6c423e32c | 152 | u8 iConfiguration; // Index of String Descriptor describing this configuration |
abe00makoto | 0:9fb6c423e32c | 153 | u8 bmAttributes; // Bitmap D7 Reserved, set to 1. (USB 1.0 Bus Powered),D6 Self Powered,D5 Remote Wakeup,D4..0 = 0 |
abe00makoto | 0:9fb6c423e32c | 154 | u8 bMaxPower; // Maximum Power Consumption in 2mA units |
abe00makoto | 0:9fb6c423e32c | 155 | } ConfigurationDescriptor; |
abe00makoto | 0:9fb6c423e32c | 156 | |
abe00makoto | 0:9fb6c423e32c | 157 | typedef struct |
abe00makoto | 0:9fb6c423e32c | 158 | { |
abe00makoto | 0:9fb6c423e32c | 159 | u8 bLength; |
abe00makoto | 0:9fb6c423e32c | 160 | u8 bDescriptorType; |
abe00makoto | 0:9fb6c423e32c | 161 | u8 bInterfaceNumber; |
abe00makoto | 0:9fb6c423e32c | 162 | u8 bAlternateSetting; |
abe00makoto | 0:9fb6c423e32c | 163 | u8 bNumEndpoints; |
abe00makoto | 0:9fb6c423e32c | 164 | u8 bInterfaceClass; |
abe00makoto | 0:9fb6c423e32c | 165 | u8 bInterfaceSubClass; |
abe00makoto | 0:9fb6c423e32c | 166 | u8 bInterfaceProtocol; |
abe00makoto | 0:9fb6c423e32c | 167 | u8 iInterface; // Index of String Descriptor Describing this interface |
abe00makoto | 0:9fb6c423e32c | 168 | } InterfaceDescriptor; |
abe00makoto | 0:9fb6c423e32c | 169 | |
abe00makoto | 0:9fb6c423e32c | 170 | typedef struct |
abe00makoto | 0:9fb6c423e32c | 171 | { |
abe00makoto | 0:9fb6c423e32c | 172 | u8 bLength; |
abe00makoto | 0:9fb6c423e32c | 173 | u8 bDescriptorType; |
abe00makoto | 0:9fb6c423e32c | 174 | u8 bEndpointAddress; // Bits 0:3 endpoint, Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints) |
abe00makoto | 0:9fb6c423e32c | 175 | u8 bmAttributes; // Bits 0:1 00 = Control, 01 = Isochronous, 10 = Bulk, 11 = Interrupt |
abe00makoto | 0:9fb6c423e32c | 176 | u16 wMaxPacketSize; |
abe00makoto | 0:9fb6c423e32c | 177 | u8 bInterval; // Interval for polling endpoint data transfers. |
abe00makoto | 0:9fb6c423e32c | 178 | } EndpointDescriptor; |
abe00makoto | 0:9fb6c423e32c | 179 | |
abe00makoto | 0:9fb6c423e32c | 180 | typedef struct { |
abe00makoto | 0:9fb6c423e32c | 181 | u8 bLength; |
abe00makoto | 0:9fb6c423e32c | 182 | u8 bDescriptorType; |
abe00makoto | 0:9fb6c423e32c | 183 | u16 bcdHID; |
abe00makoto | 0:9fb6c423e32c | 184 | u8 bCountryCode; |
abe00makoto | 0:9fb6c423e32c | 185 | u8 bNumDescriptors; |
abe00makoto | 0:9fb6c423e32c | 186 | u8 bDescriptorType2; |
abe00makoto | 0:9fb6c423e32c | 187 | u16 wDescriptorLength; |
abe00makoto | 0:9fb6c423e32c | 188 | } HIDDescriptor; |
abe00makoto | 0:9fb6c423e32c | 189 | |
abe00makoto | 0:9fb6c423e32c | 190 | //============================================================================ |
abe00makoto | 0:9fb6c423e32c | 191 | //============================================================================ |
abe00makoto | 0:9fb6c423e32c | 192 | |
abe00makoto | 0:9fb6c423e32c | 193 | |
abe00makoto | 0:9fb6c423e32c | 194 | void USBInit(); |
abe00makoto | 0:9fb6c423e32c | 195 | void USBLoop(); |
abe00makoto | 0:9fb6c423e32c | 196 | u8* USBGetBuffer(u32* len); |
abe00makoto | 0:9fb6c423e32c | 197 | |
abe00makoto | 0:9fb6c423e32c | 198 | // Optional callback for transfers, called at interrupt time |
abe00makoto | 0:9fb6c423e32c | 199 | typedef void (*USBCallback)(int device, int endpoint, int status, u8* data, int len, void* userData); |
abe00makoto | 0:9fb6c423e32c | 200 | |
abe00makoto | 0:9fb6c423e32c | 201 | // Transfers |
abe00makoto | 0:9fb6c423e32c | 202 | int USBControlTransfer(int device, int request_type, int request, int value, int index, u8* data, int length, USBCallback callback = 0, void* userData = 0); |
abe00makoto | 0:9fb6c423e32c | 203 | int USBInterruptTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0); |
abe00makoto | 0:9fb6c423e32c | 204 | int USBBulkTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0); |
abe00makoto | 0:9fb6c423e32c | 205 | |
abe00makoto | 0:9fb6c423e32c | 206 | // Standard Device methods |
abe00makoto | 0:9fb6c423e32c | 207 | int GetDescriptor(int device, int descType, int descIndex, u8* data, int length); |
abe00makoto | 0:9fb6c423e32c | 208 | int GetString(int device, int index, char* dst, int length); |
abe00makoto | 0:9fb6c423e32c | 209 | int SetAddress(int device, int new_addr); |
abe00makoto | 0:9fb6c423e32c | 210 | int SetConfiguration(int device, int configNum); |
abe00makoto | 0:9fb6c423e32c | 211 | int SetInterface(int device, int ifNum, int altNum); |
abe00makoto | 0:9fb6c423e32c | 212 | |
abe00makoto | 0:9fb6c423e32c | 213 | // Implemented to notify app of the arrival of a device |
abe00makoto | 0:9fb6c423e32c | 214 | void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc); |
abe00makoto | 0:9fb6c423e32c | 215 | |
abe00makoto | 0:9fb6c423e32c | 216 | #endif |