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 #include "mbed.h"
halfpitch 0:a6476c138e84 25 #include "USBHost.h"
halfpitch 0:a6476c138e84 26 #include "Utils.h"
halfpitch 0:a6476c138e84 27
halfpitch 0:a6476c138e84 28 #define AUTOEVT(_class,_subclass,_protocol) (((_class) << 16) | ((_subclass) << 8) | _protocol)
halfpitch 0:a6476c138e84 29 #define AUTO_KEYBOARD AUTOEVT(CLASS_HID,1,1)
halfpitch 0:a6476c138e84 30 #define AUTO_MOUSE AUTOEVT(CLASS_HID,1,2)
halfpitch 0:a6476c138e84 31
halfpitch 0:a6476c138e84 32 u8 auto_mouse[4]; // buttons,dx,dy,scroll
halfpitch 0:a6476c138e84 33 u8 auto_keyboard[8]; // modifiers,reserved,keycode1..keycode6
halfpitch 0:a6476c138e84 34 u8 auto_joystick[4]; // x,y,buttons,throttle
halfpitch 0:a6476c138e84 35
halfpitch 0:a6476c138e84 36 void AutoEventCallback(int device, int endpoint, int status, u8* data, int len, void* userData)
halfpitch 0:a6476c138e84 37 {
halfpitch 0:a6476c138e84 38 int evt = (int)userData;
halfpitch 0:a6476c138e84 39 switch (evt)
halfpitch 0:a6476c138e84 40 {
halfpitch 0:a6476c138e84 41 case AUTO_KEYBOARD:
halfpitch 0:a6476c138e84 42 printf("AUTO_KEYBOARD ");
halfpitch 0:a6476c138e84 43 break;
halfpitch 0:a6476c138e84 44 case AUTO_MOUSE:
halfpitch 0:a6476c138e84 45 printf("AUTO_MOUSE ");
halfpitch 0:a6476c138e84 46 break;
halfpitch 0:a6476c138e84 47 default:
halfpitch 0:a6476c138e84 48 printf("HUH ");
halfpitch 0:a6476c138e84 49 }
halfpitch 0:a6476c138e84 50 printfBytes("data",data,len);
halfpitch 0:a6476c138e84 51 USBInterruptTransfer(device,endpoint,data,len,AutoEventCallback,userData);
halfpitch 0:a6476c138e84 52 }
halfpitch 0:a6476c138e84 53
halfpitch 0:a6476c138e84 54 // Establish transfers for interrupt events
halfpitch 0:a6476c138e84 55 void AddAutoEvent(int device, InterfaceDescriptor* id, EndpointDescriptor* ed)
halfpitch 0:a6476c138e84 56 {
halfpitch 0:a6476c138e84 57 if ((ed->bmAttributes & 3) != ENDPOINT_INTERRUPT || !(ed->bEndpointAddress & 0x80))
halfpitch 0:a6476c138e84 58 return;
halfpitch 0:a6476c138e84 59
halfpitch 0:a6476c138e84 60 // Make automatic interrupt enpoints for known devices
halfpitch 0:a6476c138e84 61 u32 evt = AUTOEVT(id->bInterfaceClass,id->bInterfaceSubClass,id->bInterfaceProtocol);
halfpitch 0:a6476c138e84 62 u8* dst = 0;
halfpitch 0:a6476c138e84 63 int len;
halfpitch 0:a6476c138e84 64 switch (evt)
halfpitch 0:a6476c138e84 65 {
halfpitch 0:a6476c138e84 66 case AUTO_MOUSE:
halfpitch 0:a6476c138e84 67 dst = auto_mouse;
halfpitch 0:a6476c138e84 68 len = sizeof(auto_mouse);
halfpitch 0:a6476c138e84 69 break;
halfpitch 0:a6476c138e84 70 case AUTO_KEYBOARD:
halfpitch 0:a6476c138e84 71 dst = auto_keyboard;
halfpitch 0:a6476c138e84 72 len = sizeof(auto_keyboard);
halfpitch 0:a6476c138e84 73 break;
halfpitch 0:a6476c138e84 74 default:
halfpitch 0:a6476c138e84 75 printf("Interrupt endpoint %02X %08X\n",ed->bEndpointAddress,evt);
halfpitch 0:a6476c138e84 76 break;
halfpitch 0:a6476c138e84 77 }
halfpitch 0:a6476c138e84 78 if (dst)
halfpitch 0:a6476c138e84 79 {
halfpitch 0:a6476c138e84 80 printf("Auto Event for %02X %08X\n",ed->bEndpointAddress,evt);
halfpitch 0:a6476c138e84 81 USBInterruptTransfer(device,ed->bEndpointAddress,dst,len,AutoEventCallback,(void*)evt);
halfpitch 0:a6476c138e84 82 }
halfpitch 0:a6476c138e84 83 }
halfpitch 0:a6476c138e84 84
halfpitch 0:a6476c138e84 85 void PrintString(int device, int i)
halfpitch 0:a6476c138e84 86 {
halfpitch 0:a6476c138e84 87 u8 buffer[256];
halfpitch 0:a6476c138e84 88 int le = GetDescriptor(device,DESCRIPTOR_TYPE_STRING,i,buffer,255);
halfpitch 0:a6476c138e84 89 if (le < 0)
halfpitch 0:a6476c138e84 90 return;
halfpitch 0:a6476c138e84 91 char* dst = (char*)buffer;
halfpitch 0:a6476c138e84 92 for (int j = 2; j < le; j += 2)
halfpitch 0:a6476c138e84 93 *dst++ = buffer[j];
halfpitch 0:a6476c138e84 94 *dst = 0;
halfpitch 0:a6476c138e84 95 printf("%d:%s\n",i,(const char*)buffer);
halfpitch 0:a6476c138e84 96 }
halfpitch 0:a6476c138e84 97
halfpitch 0:a6476c138e84 98 // Walk descriptors and create endpoints for a given device
halfpitch 0:a6476c138e84 99 int StartAutoEvent(int device, int configuration, int interfaceNumber)
halfpitch 0:a6476c138e84 100 {
halfpitch 0:a6476c138e84 101 u8 buffer[255];
halfpitch 0:a6476c138e84 102 int err = GetDescriptor(device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,255);
halfpitch 0:a6476c138e84 103 if (err < 0)
halfpitch 0:a6476c138e84 104 return err;
halfpitch 0:a6476c138e84 105
halfpitch 0:a6476c138e84 106 int len = buffer[2] | (buffer[3] << 8);
halfpitch 0:a6476c138e84 107 u8* d = buffer;
halfpitch 0:a6476c138e84 108 u8* end = d + len;
halfpitch 0:a6476c138e84 109 while (d < end)
halfpitch 0:a6476c138e84 110 {
halfpitch 0:a6476c138e84 111 if (d[1] == DESCRIPTOR_TYPE_INTERFACE)
halfpitch 0:a6476c138e84 112 {
halfpitch 0:a6476c138e84 113 InterfaceDescriptor* id = (InterfaceDescriptor*)d;
halfpitch 0:a6476c138e84 114 if (id->bInterfaceNumber == interfaceNumber)
halfpitch 0:a6476c138e84 115 {
halfpitch 0:a6476c138e84 116 d += d[0];
halfpitch 0:a6476c138e84 117 while (d < end && d[1] != DESCRIPTOR_TYPE_INTERFACE)
halfpitch 0:a6476c138e84 118 {
halfpitch 0:a6476c138e84 119 if (d[1] == DESCRIPTOR_TYPE_ENDPOINT)
halfpitch 0:a6476c138e84 120 AddAutoEvent(device,id,(EndpointDescriptor*)d);
halfpitch 0:a6476c138e84 121 d += d[0];
halfpitch 0:a6476c138e84 122 }
halfpitch 0:a6476c138e84 123 }
halfpitch 0:a6476c138e84 124 }
halfpitch 0:a6476c138e84 125 d += d[0];
halfpitch 0:a6476c138e84 126 }
halfpitch 0:a6476c138e84 127 return 0;
halfpitch 0:a6476c138e84 128 }
halfpitch 0:a6476c138e84 129
halfpitch 0:a6476c138e84 130 // Implemented in main.cpp
halfpitch 0:a6476c138e84 131 int OnDiskInsert(int device);
halfpitch 0:a6476c138e84 132
halfpitch 0:a6476c138e84 133 // Implemented in TestShell.cpp
halfpitch 0:a6476c138e84 134 int OnBluetoothInsert(int device);
halfpitch 0:a6476c138e84 135
halfpitch 0:a6476c138e84 136 void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc)
halfpitch 0:a6476c138e84 137 {
halfpitch 0:a6476c138e84 138 printf("LoadDevice %d %02X:%02X:%02X\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol);
halfpitch 0:a6476c138e84 139 char s[128];
halfpitch 0:a6476c138e84 140 for (int i = 1; i < 3; i++)
halfpitch 0:a6476c138e84 141 {
halfpitch 0:a6476c138e84 142 if (GetString(device,i,s,sizeof(s)) < 0)
halfpitch 0:a6476c138e84 143 break;
halfpitch 0:a6476c138e84 144 printf("%d: %s\n",i,s);
halfpitch 0:a6476c138e84 145 }
halfpitch 0:a6476c138e84 146
halfpitch 0:a6476c138e84 147 switch (interfaceDesc->bInterfaceClass)
halfpitch 0:a6476c138e84 148 {
halfpitch 0:a6476c138e84 149 case CLASS_MASS_STORAGE:
halfpitch 0:a6476c138e84 150 if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50)
halfpitch 0:a6476c138e84 151 OnDiskInsert(device); // it's SCSI!
halfpitch 0:a6476c138e84 152 break;
halfpitch 0:a6476c138e84 153 case CLASS_WIRELESS_CONTROLLER:
halfpitch 0:a6476c138e84 154 if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01)
halfpitch 0:a6476c138e84 155 OnBluetoothInsert(device); // it's bluetooth!
halfpitch 0:a6476c138e84 156 break;
halfpitch 0:a6476c138e84 157 default:
halfpitch 0:a6476c138e84 158 StartAutoEvent(device,1,0);
halfpitch 0:a6476c138e84 159 break;
halfpitch 0:a6476c138e84 160 }
halfpitch 0:a6476c138e84 161 }