This is a for debugging \\\\\\\"BLUE USB\\\\\\\". You can connect with HCI mode. How to connect White Wizard Board TANK *White Wizard Board - Motor Driver Board * p 21 - IN_R1 * p 22 - IN_R2 * p 23 - IN_L2 * p 24 - IN_L1

Dependencies:   mbed

Committer:
halfpitch
Date:
Wed Aug 31 11:10:18 2011 +0000
Revision:
1:c56059923036
Parent:
0:a6476c138e84
Rev.B

Who changed what in which revision?

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