Android Open Accessory Library化してみました。 バルク転送の使い方が分かっていないため、相変わらず動作は不安定。 I do not understand the usage of the bulk transfer. Please teach someone.
AndroidAccessory.cpp@0:4fcfc05943ff, 2011-06-03 (annotated)
- Committer:
- abe00makoto
- Date:
- Fri Jun 03 17:43:15 2011 +0000
- Revision:
- 0:4fcfc05943ff
Android Open Accessory Library+ demokit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
abe00makoto | 0:4fcfc05943ff | 1 | #include <stdio.h> |
abe00makoto | 0:4fcfc05943ff | 2 | #include <stdlib.h> |
abe00makoto | 0:4fcfc05943ff | 3 | #include <string.h> |
abe00makoto | 0:4fcfc05943ff | 4 | |
abe00makoto | 0:4fcfc05943ff | 5 | #include "USBHost.h" |
abe00makoto | 0:4fcfc05943ff | 6 | #include "AndroidAccessory.h" |
abe00makoto | 0:4fcfc05943ff | 7 | #include "mbed.h" |
abe00makoto | 0:4fcfc05943ff | 8 | |
abe00makoto | 0:4fcfc05943ff | 9 | AndroidAccessory* _adk; |
abe00makoto | 0:4fcfc05943ff | 10 | |
abe00makoto | 0:4fcfc05943ff | 11 | void AdkreadCallback(int device, int endpoint, int status, u8* buf, int len, void* userData); |
abe00makoto | 0:4fcfc05943ff | 12 | void AdkwriteCallback(int device, int endpoint, int status, u8* buf, int len, void* userData); |
abe00makoto | 0:4fcfc05943ff | 13 | |
abe00makoto | 0:4fcfc05943ff | 14 | |
abe00makoto | 0:4fcfc05943ff | 15 | |
abe00makoto | 0:4fcfc05943ff | 16 | AndroidAccessory::AndroidAccessory(int rbuffsize,int wbuffsize, |
abe00makoto | 0:4fcfc05943ff | 17 | const char* manufacturer, |
abe00makoto | 0:4fcfc05943ff | 18 | const char *model, |
abe00makoto | 0:4fcfc05943ff | 19 | const char *description, |
abe00makoto | 0:4fcfc05943ff | 20 | const char *version, |
abe00makoto | 0:4fcfc05943ff | 21 | const char *uri, |
abe00makoto | 0:4fcfc05943ff | 22 | const char *serial |
abe00makoto | 0:4fcfc05943ff | 23 | ) { |
abe00makoto | 0:4fcfc05943ff | 24 | |
abe00makoto | 0:4fcfc05943ff | 25 | _adk=this; |
abe00makoto | 0:4fcfc05943ff | 26 | |
abe00makoto | 0:4fcfc05943ff | 27 | this->manufacturer=manufacturer; |
abe00makoto | 0:4fcfc05943ff | 28 | this->model=model; |
abe00makoto | 0:4fcfc05943ff | 29 | this->description=description; |
abe00makoto | 0:4fcfc05943ff | 30 | this->version=version; |
abe00makoto | 0:4fcfc05943ff | 31 | this->uri=uri; |
abe00makoto | 0:4fcfc05943ff | 32 | this->serial=serial; |
abe00makoto | 0:4fcfc05943ff | 33 | |
abe00makoto | 0:4fcfc05943ff | 34 | u32 len; |
abe00makoto | 0:4fcfc05943ff | 35 | u8* p=USBGetBuffer(&len); |
abe00makoto | 0:4fcfc05943ff | 36 | if (len<(rbuffsize+wbuffsize+255)) { |
abe00makoto | 0:4fcfc05943ff | 37 | error("buff size too big.please resize max=%d. currentSize=%d\r\n",len,(rbuffsize+wbuffsize+255)); |
abe00makoto | 0:4fcfc05943ff | 38 | } |
abe00makoto | 0:4fcfc05943ff | 39 | |
abe00makoto | 0:4fcfc05943ff | 40 | _readbuff=p; |
abe00makoto | 0:4fcfc05943ff | 41 | _readbuffsize=rbuffsize; |
abe00makoto | 0:4fcfc05943ff | 42 | p+=rbuffsize; |
abe00makoto | 0:4fcfc05943ff | 43 | _writebuff=p; |
abe00makoto | 0:4fcfc05943ff | 44 | _writebuffsize=wbuffsize; |
abe00makoto | 0:4fcfc05943ff | 45 | p+=wbuffsize; |
abe00makoto | 0:4fcfc05943ff | 46 | _strbuff=p; |
abe00makoto | 0:4fcfc05943ff | 47 | p+=255; |
abe00makoto | 0:4fcfc05943ff | 48 | |
abe00makoto | 0:4fcfc05943ff | 49 | } |
abe00makoto | 0:4fcfc05943ff | 50 | |
abe00makoto | 0:4fcfc05943ff | 51 | |
abe00makoto | 0:4fcfc05943ff | 52 | |
abe00makoto | 0:4fcfc05943ff | 53 | int AndroidAccessory::write(u8 *buff, int len) { |
abe00makoto | 0:4fcfc05943ff | 54 | log("AndroidAccessory::write "); |
abe00makoto | 0:4fcfc05943ff | 55 | // __disable_irq(); |
abe00makoto | 0:4fcfc05943ff | 56 | int ret=USBBulkTransfer(_device,output_ep,buff,len/*,AdkwriteCallback,this*/); |
abe00makoto | 0:4fcfc05943ff | 57 | // __enable_irq(); |
abe00makoto | 0:4fcfc05943ff | 58 | log("--ret=%d \r\n",ret); |
abe00makoto | 0:4fcfc05943ff | 59 | return ret; |
abe00makoto | 0:4fcfc05943ff | 60 | } |
abe00makoto | 0:4fcfc05943ff | 61 | |
abe00makoto | 0:4fcfc05943ff | 62 | #if 0 |
abe00makoto | 0:4fcfc05943ff | 63 | int AndroidAccessory::read(u8 *buff, int len) { |
abe00makoto | 0:4fcfc05943ff | 64 | if(_initok==false)return 0; |
abe00makoto | 0:4fcfc05943ff | 65 | |
abe00makoto | 0:4fcfc05943ff | 66 | log("AndroidAccessory::read "); |
abe00makoto | 0:4fcfc05943ff | 67 | // __disable_irq(); |
abe00makoto | 0:4fcfc05943ff | 68 | int ret=USBBulkTransfer(_device,input_ep|0x80,buff,len); |
abe00makoto | 0:4fcfc05943ff | 69 | // __enable_irq(); |
abe00makoto | 0:4fcfc05943ff | 70 | log("--ret=%d \r\n",ret); |
abe00makoto | 0:4fcfc05943ff | 71 | return ret; |
abe00makoto | 0:4fcfc05943ff | 72 | } |
abe00makoto | 0:4fcfc05943ff | 73 | #endif |
abe00makoto | 0:4fcfc05943ff | 74 | |
abe00makoto | 0:4fcfc05943ff | 75 | void AndroidAccessory::init(int device, int configuration, int interfaceNumber) { |
abe00makoto | 0:4fcfc05943ff | 76 | |
abe00makoto | 0:4fcfc05943ff | 77 | log("AndroidAccessory::init \r\n"); |
abe00makoto | 0:4fcfc05943ff | 78 | |
abe00makoto | 0:4fcfc05943ff | 79 | // _initok=false; |
abe00makoto | 0:4fcfc05943ff | 80 | _device = device; |
abe00makoto | 0:4fcfc05943ff | 81 | _configuration = configuration; |
abe00makoto | 0:4fcfc05943ff | 82 | _interfaceNumber = interfaceNumber; |
abe00makoto | 0:4fcfc05943ff | 83 | printf("device = %d configuration = %d interfaceNumber = %d\r\n", device, configuration, interfaceNumber); |
abe00makoto | 0:4fcfc05943ff | 84 | int err; |
abe00makoto | 0:4fcfc05943ff | 85 | |
abe00makoto | 0:4fcfc05943ff | 86 | u8* buffer=_strbuff; |
abe00makoto | 0:4fcfc05943ff | 87 | err = GetDescriptor(_device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,4); |
abe00makoto | 0:4fcfc05943ff | 88 | |
abe00makoto | 0:4fcfc05943ff | 89 | if (err < 0) { |
abe00makoto | 0:4fcfc05943ff | 90 | log("Failed to get descriptor\r\n"); |
abe00makoto | 0:4fcfc05943ff | 91 | return; |
abe00makoto | 0:4fcfc05943ff | 92 | } |
abe00makoto | 0:4fcfc05943ff | 93 | |
abe00makoto | 0:4fcfc05943ff | 94 | |
abe00makoto | 0:4fcfc05943ff | 95 | int len = buffer[2] | (buffer[3] << 8); |
abe00makoto | 0:4fcfc05943ff | 96 | if (len > 255) { |
abe00makoto | 0:4fcfc05943ff | 97 | log("config descriptor too large\n"); |
abe00makoto | 0:4fcfc05943ff | 98 | /* might want to truncate here */ |
abe00makoto | 0:4fcfc05943ff | 99 | return; |
abe00makoto | 0:4fcfc05943ff | 100 | } |
abe00makoto | 0:4fcfc05943ff | 101 | err = GetDescriptor(_device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,len); |
abe00makoto | 0:4fcfc05943ff | 102 | u8* p = buffer; |
abe00makoto | 0:4fcfc05943ff | 103 | input_ep=0; |
abe00makoto | 0:4fcfc05943ff | 104 | output_ep=0; |
abe00makoto | 0:4fcfc05943ff | 105 | EndpointDescriptor *epDesc; |
abe00makoto | 0:4fcfc05943ff | 106 | while (p<(buffer+len)) { |
abe00makoto | 0:4fcfc05943ff | 107 | u8 descLen = p[0]; |
abe00makoto | 0:4fcfc05943ff | 108 | u8 descType = p[1]; |
abe00makoto | 0:4fcfc05943ff | 109 | log("descLen=%d,descType=%d\r\n",descLen,descType); |
abe00makoto | 0:4fcfc05943ff | 110 | switch (descType) { |
abe00makoto | 0:4fcfc05943ff | 111 | case DESCRIPTOR_TYPE_CONFIGURATION: |
abe00makoto | 0:4fcfc05943ff | 112 | log("config desc\r\n"); |
abe00makoto | 0:4fcfc05943ff | 113 | break; |
abe00makoto | 0:4fcfc05943ff | 114 | case DESCRIPTOR_TYPE_INTERFACE: |
abe00makoto | 0:4fcfc05943ff | 115 | log("interface desc\r\n"); |
abe00makoto | 0:4fcfc05943ff | 116 | break; |
abe00makoto | 0:4fcfc05943ff | 117 | case DESCRIPTOR_TYPE_ENDPOINT: |
abe00makoto | 0:4fcfc05943ff | 118 | epDesc=(EndpointDescriptor*)p; |
abe00makoto | 0:4fcfc05943ff | 119 | if (!input_ep && (epDesc->bEndpointAddress& 0x80)) { |
abe00makoto | 0:4fcfc05943ff | 120 | input_ep=epDesc->bEndpointAddress& 0x7f; |
abe00makoto | 0:4fcfc05943ff | 121 | //PacketSize drop |
abe00makoto | 0:4fcfc05943ff | 122 | log("input Endpoint address=%d,wMaxPacketSize=%d,bmAttributes=%d\r\n",input_ep,epDesc->wMaxPacketSize,epDesc->bmAttributes); |
abe00makoto | 0:4fcfc05943ff | 123 | |
abe00makoto | 0:4fcfc05943ff | 124 | } else if (!output_ep) { |
abe00makoto | 0:4fcfc05943ff | 125 | output_ep=epDesc->bEndpointAddress& 0x7f; |
abe00makoto | 0:4fcfc05943ff | 126 | //PacketSize drop |
abe00makoto | 0:4fcfc05943ff | 127 | log("output Endpoint address=%d,wMaxPacketSize=%d,bmAttributes=%d\r\n",input_ep,epDesc->wMaxPacketSize,epDesc->bmAttributes); |
abe00makoto | 0:4fcfc05943ff | 128 | } else { |
abe00makoto | 0:4fcfc05943ff | 129 | //other |
abe00makoto | 0:4fcfc05943ff | 130 | log("non input,output Endpoint address=%d,wMaxPacketSize=%d,bmAttributes=%d\r\n",input_ep,epDesc->wMaxPacketSize,epDesc->bmAttributes); |
abe00makoto | 0:4fcfc05943ff | 131 | } |
abe00makoto | 0:4fcfc05943ff | 132 | break; |
abe00makoto | 0:4fcfc05943ff | 133 | default: |
abe00makoto | 0:4fcfc05943ff | 134 | log("unkown desc type(%d) \r\n",descType); |
abe00makoto | 0:4fcfc05943ff | 135 | } |
abe00makoto | 0:4fcfc05943ff | 136 | p+=descLen; |
abe00makoto | 0:4fcfc05943ff | 137 | } |
abe00makoto | 0:4fcfc05943ff | 138 | |
abe00makoto | 0:4fcfc05943ff | 139 | if (!(input_ep && output_ep)) { |
abe00makoto | 0:4fcfc05943ff | 140 | log("can't find accessory endpoints\r\n"); |
abe00makoto | 0:4fcfc05943ff | 141 | return; |
abe00makoto | 0:4fcfc05943ff | 142 | } |
abe00makoto | 0:4fcfc05943ff | 143 | |
abe00makoto | 0:4fcfc05943ff | 144 | log("SetConfiguration\r\n"); |
abe00makoto | 0:4fcfc05943ff | 145 | err = SetConfiguration(device,configuration); |
abe00makoto | 0:4fcfc05943ff | 146 | if (err < 0) { |
abe00makoto | 0:4fcfc05943ff | 147 | log("SetConfiguration error\r\n"); |
abe00makoto | 0:4fcfc05943ff | 148 | return; |
abe00makoto | 0:4fcfc05943ff | 149 | } |
abe00makoto | 0:4fcfc05943ff | 150 | |
abe00makoto | 0:4fcfc05943ff | 151 | |
abe00makoto | 0:4fcfc05943ff | 152 | log("interrupt setup\r\n"); |
abe00makoto | 0:4fcfc05943ff | 153 | //interrupt setup |
abe00makoto | 0:4fcfc05943ff | 154 | if (_readbuff==NULL || _readbuffsize<=0) { |
abe00makoto | 0:4fcfc05943ff | 155 | error("_readbuffer error please setup buffer call setReadBuffer function\r\n"); |
abe00makoto | 0:4fcfc05943ff | 156 | } |
abe00makoto | 0:4fcfc05943ff | 157 | |
abe00makoto | 0:4fcfc05943ff | 158 | if (IO_PENDING!=USBBulkTransfer(_device,input_ep|0x80,_readbuff,_readbuffsize,AdkreadCallback,this)) |
abe00makoto | 0:4fcfc05943ff | 159 | return; |
abe00makoto | 0:4fcfc05943ff | 160 | |
abe00makoto | 0:4fcfc05943ff | 161 | |
abe00makoto | 0:4fcfc05943ff | 162 | log("setupDevice\r\n"); |
abe00makoto | 0:4fcfc05943ff | 163 | this->setupDevice(); |
abe00makoto | 0:4fcfc05943ff | 164 | // _initok=true; |
abe00makoto | 0:4fcfc05943ff | 165 | } |
abe00makoto | 0:4fcfc05943ff | 166 | |
abe00makoto | 0:4fcfc05943ff | 167 | |
abe00makoto | 0:4fcfc05943ff | 168 | |
abe00makoto | 0:4fcfc05943ff | 169 | bool AndroidAccessory::switchDevice(int device) { |
abe00makoto | 0:4fcfc05943ff | 170 | |
abe00makoto | 0:4fcfc05943ff | 171 | if (1==getProtocol(device)) { |
abe00makoto | 0:4fcfc05943ff | 172 | log("device supports protocol 1\r\n"); |
abe00makoto | 0:4fcfc05943ff | 173 | |
abe00makoto | 0:4fcfc05943ff | 174 | } else { |
abe00makoto | 0:4fcfc05943ff | 175 | log("could not read device protocol version\r\n"); |
abe00makoto | 0:4fcfc05943ff | 176 | return false; |
abe00makoto | 0:4fcfc05943ff | 177 | } |
abe00makoto | 0:4fcfc05943ff | 178 | |
abe00makoto | 0:4fcfc05943ff | 179 | |
abe00makoto | 0:4fcfc05943ff | 180 | sendString(device,ACCESSORY_STRING_MANUFACTURER,manufacturer); |
abe00makoto | 0:4fcfc05943ff | 181 | sendString(device,ACCESSORY_STRING_MODEL,model); |
abe00makoto | 0:4fcfc05943ff | 182 | sendString(device,ACCESSORY_STRING_DESCRIPTION,description); |
abe00makoto | 0:4fcfc05943ff | 183 | sendString(device,ACCESSORY_STRING_VERSION,version); |
abe00makoto | 0:4fcfc05943ff | 184 | sendString(device,ACCESSORY_STRING_URI,uri); |
abe00makoto | 0:4fcfc05943ff | 185 | sendString(device,ACCESSORY_STRING_SERIAL,serial); |
abe00makoto | 0:4fcfc05943ff | 186 | USBControlTransfer(device, |
abe00makoto | 0:4fcfc05943ff | 187 | HOST_TO_DEVICE |REQUEST_TYPE_VENDOR|RECIPIENT_DEVICE, |
abe00makoto | 0:4fcfc05943ff | 188 | ACCESSORY_START, |
abe00makoto | 0:4fcfc05943ff | 189 | 0,//value |
abe00makoto | 0:4fcfc05943ff | 190 | 0, //index |
abe00makoto | 0:4fcfc05943ff | 191 | 0, |
abe00makoto | 0:4fcfc05943ff | 192 | 0, |
abe00makoto | 0:4fcfc05943ff | 193 | 0, |
abe00makoto | 0:4fcfc05943ff | 194 | 0 ); |
abe00makoto | 0:4fcfc05943ff | 195 | |
abe00makoto | 0:4fcfc05943ff | 196 | wait_ms(4); |
abe00makoto | 0:4fcfc05943ff | 197 | //reset usb host |
abe00makoto | 0:4fcfc05943ff | 198 | USBInit(); |
abe00makoto | 0:4fcfc05943ff | 199 | |
abe00makoto | 0:4fcfc05943ff | 200 | return true; |
abe00makoto | 0:4fcfc05943ff | 201 | |
abe00makoto | 0:4fcfc05943ff | 202 | } |
abe00makoto | 0:4fcfc05943ff | 203 | |
abe00makoto | 0:4fcfc05943ff | 204 | |
abe00makoto | 0:4fcfc05943ff | 205 | int AndroidAccessory::getProtocol(int device) { |
abe00makoto | 0:4fcfc05943ff | 206 | s16 data=-1; |
abe00makoto | 0:4fcfc05943ff | 207 | USBControlTransfer(device, |
abe00makoto | 0:4fcfc05943ff | 208 | DEVICE_TO_HOST|REQUEST_TYPE_VENDOR|RECIPIENT_DEVICE, |
abe00makoto | 0:4fcfc05943ff | 209 | ACCESSORY_GET_PROTOCOL, |
abe00makoto | 0:4fcfc05943ff | 210 | 0,//value |
abe00makoto | 0:4fcfc05943ff | 211 | 0, //index |
abe00makoto | 0:4fcfc05943ff | 212 | (u8*)&data, |
abe00makoto | 0:4fcfc05943ff | 213 | 2, |
abe00makoto | 0:4fcfc05943ff | 214 | 0, |
abe00makoto | 0:4fcfc05943ff | 215 | 0 ); |
abe00makoto | 0:4fcfc05943ff | 216 | return data; |
abe00makoto | 0:4fcfc05943ff | 217 | |
abe00makoto | 0:4fcfc05943ff | 218 | } |
abe00makoto | 0:4fcfc05943ff | 219 | |
abe00makoto | 0:4fcfc05943ff | 220 | void AndroidAccessory::sendString(int device, int index, const char *str) { |
abe00makoto | 0:4fcfc05943ff | 221 | |
abe00makoto | 0:4fcfc05943ff | 222 | LOG("send_string start(%d,%d,%s) %d \r\n",device,index,str,strlen(str)+1); |
abe00makoto | 0:4fcfc05943ff | 223 | strcpy((char*)_strbuff,str); |
abe00makoto | 0:4fcfc05943ff | 224 | //thankyou curryman san |
abe00makoto | 0:4fcfc05943ff | 225 | USBControlTransfer(device, |
abe00makoto | 0:4fcfc05943ff | 226 | HOST_TO_DEVICE|REQUEST_TYPE_VENDOR|RECIPIENT_DEVICE, |
abe00makoto | 0:4fcfc05943ff | 227 | ACCESSORY_SEND_STRING, |
abe00makoto | 0:4fcfc05943ff | 228 | 0,//value |
abe00makoto | 0:4fcfc05943ff | 229 | index, |
abe00makoto | 0:4fcfc05943ff | 230 | _strbuff, |
abe00makoto | 0:4fcfc05943ff | 231 | strlen(str)+1 |
abe00makoto | 0:4fcfc05943ff | 232 | ); |
abe00makoto | 0:4fcfc05943ff | 233 | |
abe00makoto | 0:4fcfc05943ff | 234 | LOG("send_string end(%d,%d,%s)\r\n",device,index,str); |
abe00makoto | 0:4fcfc05943ff | 235 | |
abe00makoto | 0:4fcfc05943ff | 236 | } |
abe00makoto | 0:4fcfc05943ff | 237 | |
abe00makoto | 0:4fcfc05943ff | 238 | |
abe00makoto | 0:4fcfc05943ff | 239 | /** from USBHost load function. initialize Android device**/ |
abe00makoto | 0:4fcfc05943ff | 240 | void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc) { |
abe00makoto | 0:4fcfc05943ff | 241 | printf("LoadDevice %d %02X:%02X:%02X\r\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol); |
abe00makoto | 0:4fcfc05943ff | 242 | char s[128]; |
abe00makoto | 0:4fcfc05943ff | 243 | |
abe00makoto | 0:4fcfc05943ff | 244 | for (int i = 1; i < 3; i++) { |
abe00makoto | 0:4fcfc05943ff | 245 | if (GetString(device,i,s,sizeof(s)) < 0) |
abe00makoto | 0:4fcfc05943ff | 246 | break; |
abe00makoto | 0:4fcfc05943ff | 247 | printf("%d: %s\r\n",i,s); |
abe00makoto | 0:4fcfc05943ff | 248 | } |
abe00makoto | 0:4fcfc05943ff | 249 | |
abe00makoto | 0:4fcfc05943ff | 250 | //for android ADK |
abe00makoto | 0:4fcfc05943ff | 251 | if ( ( deviceDesc->idVendor != 0x18D1 || |
abe00makoto | 0:4fcfc05943ff | 252 | ( deviceDesc->idProduct != 0x2D00 && deviceDesc->idProduct != 0x2D01)) |
abe00makoto | 0:4fcfc05943ff | 253 | &&_adk->switchDevice(device)) { |
abe00makoto | 0:4fcfc05943ff | 254 | |
abe00makoto | 0:4fcfc05943ff | 255 | printf(" try to change accmode.interfaceDesc->bInterfaceClass=%d\r\n",interfaceDesc->bInterfaceClass); |
abe00makoto | 0:4fcfc05943ff | 256 | //1th root |
abe00makoto | 0:4fcfc05943ff | 257 | //accmode_support=true; |
abe00makoto | 0:4fcfc05943ff | 258 | printf("accessory mode ok.\r\n"); |
abe00makoto | 0:4fcfc05943ff | 259 | return; |
abe00makoto | 0:4fcfc05943ff | 260 | } |
abe00makoto | 0:4fcfc05943ff | 261 | |
abe00makoto | 0:4fcfc05943ff | 262 | if (deviceDesc->idVendor == 0x18D1 && |
abe00makoto | 0:4fcfc05943ff | 263 | (deviceDesc->idProduct == 0x2D00 || deviceDesc->idProduct == 0x2D01)) { |
abe00makoto | 0:4fcfc05943ff | 264 | //2th root |
abe00makoto | 0:4fcfc05943ff | 265 | printf("connecting Android.\r\n"); |
abe00makoto | 0:4fcfc05943ff | 266 | printf("idVender=%x idProduct=%x interfaceDesc->bInterfaceClass=%d\r\n",deviceDesc->idVendor,deviceDesc->idProduct,interfaceDesc->bInterfaceClass); |
abe00makoto | 0:4fcfc05943ff | 267 | _adk->init(device,1,0); |
abe00makoto | 0:4fcfc05943ff | 268 | //_AdkUSB.loop(); |
abe00makoto | 0:4fcfc05943ff | 269 | return; |
abe00makoto | 0:4fcfc05943ff | 270 | } |
abe00makoto | 0:4fcfc05943ff | 271 | } |
abe00makoto | 0:4fcfc05943ff | 272 | |
abe00makoto | 0:4fcfc05943ff | 273 | void AdkreadCallback(int device, int endpoint, int status, u8* buf, int len, void* userData) { |
abe00makoto | 0:4fcfc05943ff | 274 | log("AdkreadCallback(int device=%d, int endpoint=%x, int status=%d, u8* buf=%p, int len=%d, void* userData=%p)\r\n", |
abe00makoto | 0:4fcfc05943ff | 275 | device,endpoint,status,buf,len,userData); |
abe00makoto | 0:4fcfc05943ff | 276 | // __disable_irq(); |
abe00makoto | 0:4fcfc05943ff | 277 | AndroidAccessory* t = (AndroidAccessory*)userData; |
abe00makoto | 0:4fcfc05943ff | 278 | if (status!=0) { |
abe00makoto | 0:4fcfc05943ff | 279 | log("adk end.\r\n"); |
abe00makoto | 0:4fcfc05943ff | 280 | t->adkEnd(); |
abe00makoto | 0:4fcfc05943ff | 281 | // __enable_irq(); |
abe00makoto | 0:4fcfc05943ff | 282 | USBInit(); |
abe00makoto | 0:4fcfc05943ff | 283 | return; |
abe00makoto | 0:4fcfc05943ff | 284 | } |
abe00makoto | 0:4fcfc05943ff | 285 | |
abe00makoto | 0:4fcfc05943ff | 286 | |
abe00makoto | 0:4fcfc05943ff | 287 | //virtual method run |
abe00makoto | 0:4fcfc05943ff | 288 | t->callbackRead(buf,len); |
abe00makoto | 0:4fcfc05943ff | 289 | |
abe00makoto | 0:4fcfc05943ff | 290 | USBBulkTransfer(device, endpoint , buf, len, AdkreadCallback, userData); |
abe00makoto | 0:4fcfc05943ff | 291 | |
abe00makoto | 0:4fcfc05943ff | 292 | // wait_ms(4); |
abe00makoto | 0:4fcfc05943ff | 293 | // __enable_irq(); |
abe00makoto | 0:4fcfc05943ff | 294 | } |
abe00makoto | 0:4fcfc05943ff | 295 | |
abe00makoto | 0:4fcfc05943ff | 296 | |
abe00makoto | 0:4fcfc05943ff | 297 | |
abe00makoto | 0:4fcfc05943ff | 298 | #if 0 |
abe00makoto | 0:4fcfc05943ff | 299 | void AdkwriteCallback(int device, int endpoint, int status, u8* buf, int len, void* userData) { |
abe00makoto | 0:4fcfc05943ff | 300 | |
abe00makoto | 0:4fcfc05943ff | 301 | log("AdkwriteCallback(int device=%d, int endpoint=%x, int status=%d, u8* buf=%p, int len=%d, void* userData=%p)\r\n", |
abe00makoto | 0:4fcfc05943ff | 302 | device,endpoint,status,buf,len,userData); |
abe00makoto | 0:4fcfc05943ff | 303 | |
abe00makoto | 0:4fcfc05943ff | 304 | //AndroidAccessory* t = (AndroidAccessory*)userData; |
abe00makoto | 0:4fcfc05943ff | 305 | //wait_ms(4); |
abe00makoto | 0:4fcfc05943ff | 306 | |
abe00makoto | 0:4fcfc05943ff | 307 | } |
abe00makoto | 0:4fcfc05943ff | 308 | #endif |