Talking Touch Tablet added to device
Dependencies: FATFileSystemv2 mbed
Fork of BlueUSB by
AutoEvents.cpp
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 #include "mbed.h" 00025 #include "USBHost.h" 00026 #include "Utils.h" 00027 00028 #define AUTOEVT(_class,_subclass,_protocol) (((_class) << 16) | ((_subclass) << 8) | _protocol) 00029 #define AUTO_KEYBOARD AUTOEVT(CLASS_HID,1,1) 00030 #define AUTO_MOUSE AUTOEVT(CLASS_HID,1,2) 00031 #define AUTO_TTT AUTOEVT(CLASS_HID,1,3) 00032 00033 u8 auto_mouse[4]; // buttons,dx,dy,scroll 00034 u8 auto_keyboard[8]; // modifiers,reserved,keycode1..keycode6 00035 u8 auto_joystick[4]; // x,y,buttons,throttle 00036 u8 auto_ttt[10]; // Talking touch tablet 00037 00038 void AutoEventCallback(int device, int endpoint, int status, u8* data, int len, void* userData) 00039 { 00040 int evt = (int)userData; 00041 switch (evt) 00042 { 00043 case AUTO_KEYBOARD: 00044 printf("AUTO_KEYBOARD "); 00045 break; 00046 case AUTO_MOUSE: 00047 printf("AUTO_MOUSE "); 00048 break; 00049 case 0x30000: 00050 printf("AUTO_TTT "); 00051 break; 00052 default: 00053 printf("HUH "); 00054 } 00055 printfBytes("data",data,len); 00056 USBInterruptTransfer(device,endpoint,data,len,AutoEventCallback,userData); 00057 } 00058 00059 // Establish transfers for interrupt events 00060 void AddAutoEvent(int device, InterfaceDescriptor* id, EndpointDescriptor* ed) 00061 { 00062 if ((ed->bmAttributes & 3) != ENDPOINT_INTERRUPT || !(ed->bEndpointAddress & 0x80)) 00063 return; 00064 00065 // Make automatic interrupt enpoints for known devices 00066 u32 evt = AUTOEVT(id->bInterfaceClass,id->bInterfaceSubClass,id->bInterfaceProtocol); 00067 u8* dst = 0; 00068 int len; 00069 switch (evt) 00070 { 00071 case AUTO_MOUSE: 00072 dst = auto_mouse; 00073 len = sizeof(auto_mouse); 00074 printf("AUTO_MOUSE, Interrupt endpoint %02X %08X\r\n\r",ed->bEndpointAddress,evt); 00075 break; 00076 case 0x30000: 00077 dst = auto_ttt; 00078 len = sizeof(auto_ttt); 00079 printf("AUTO_TTT, Interrupt endpoint %02X %08X\r\n\r",ed->bEndpointAddress,evt); 00080 break; 00081 case AUTO_KEYBOARD: 00082 dst = auto_keyboard; 00083 len = sizeof(auto_keyboard); 00084 break; 00085 default: 00086 printf("Interrupt endpoint %02X %08X\r\n",ed->bEndpointAddress,evt); 00087 break; 00088 } 00089 if (dst) 00090 { 00091 printf("Auto Event for %02X %08X\r\n",ed->bEndpointAddress,evt); 00092 USBInterruptTransfer(device,ed->bEndpointAddress,dst,len,AutoEventCallback,(void*)evt); 00093 } 00094 } 00095 00096 void PrintString(int device, int i) 00097 { 00098 u8 buffer[256]; 00099 int le = GetDescriptor(device,DESCRIPTOR_TYPE_STRING,i,buffer,255); 00100 if (le < 0) 00101 return; 00102 char* dst = (char*)buffer; 00103 for (int j = 2; j < le; j += 2) 00104 *dst++ = buffer[j]; 00105 *dst = 0; 00106 printf("%d:%s\r\n",i,(const char*)buffer); 00107 } 00108 00109 // Walk descriptors and create endpoints for a given device 00110 int StartAutoEvent(int device, int configuration, int interfaceNumber) 00111 { 00112 u8 buffer[255]; 00113 int err = GetDescriptor(device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,255); 00114 if (err < 0) 00115 return err; 00116 00117 int len = buffer[2] | (buffer[3] << 8); 00118 u8* d = buffer; 00119 u8* end = d + len; 00120 while (d < end) 00121 { 00122 if (d[1] == DESCRIPTOR_TYPE_INTERFACE) 00123 { 00124 InterfaceDescriptor* id = (InterfaceDescriptor*)d; 00125 if (id->bInterfaceNumber == interfaceNumber) 00126 { 00127 d += d[0]; 00128 while (d < end && d[1] != DESCRIPTOR_TYPE_INTERFACE) 00129 { 00130 if (d[1] == DESCRIPTOR_TYPE_ENDPOINT) 00131 AddAutoEvent(device,id,(EndpointDescriptor*)d); 00132 d += d[0]; 00133 } 00134 } 00135 } 00136 d += d[0]; 00137 } 00138 return 0; 00139 } 00140 00141 // Implemented in main.cpp 00142 int OnDiskInsert(int device); 00143 00144 // Implemented in TestShell.cpp 00145 int OnBluetoothInsert(int device); 00146 00147 void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc) 00148 { 00149 printf("LoadDevice %d %02X:%02X:%02X\r\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol); 00150 char s[128]; 00151 for (int i = 1; i < 3; i++) 00152 { 00153 if (GetString(device,i,s,sizeof(s)) < 0) 00154 break; 00155 printf("%d: %s\r\n",i,s); 00156 } 00157 00158 switch (interfaceDesc->bInterfaceClass) 00159 { 00160 case CLASS_MASS_STORAGE: 00161 if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50) 00162 OnDiskInsert(device); // it's SCSI! 00163 break; 00164 case CLASS_WIRELESS_CONTROLLER: 00165 if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01) 00166 OnBluetoothInsert(device); // it's bluetooth! 00167 break; 00168 default: 00169 StartAutoEvent(device,1,0); 00170 break; 00171 } 00172 }
Generated on Thu Jul 14 2022 17:55:04 by 1.7.2