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