void USBHostAndroidTasks(void) { DWORD byteCount; BYTE errorCode; int iid; for (iid = 0; iid < ANDROID_INTERFACE_MAX; ++iid) { ANDROID_INTERFACE *pInterface = &gc_DevData.interfaces[iid]; if (gc_DevData.ID.deviceAddress && pInterface->flags.initialized) { if (pInterface->flags.rxBusy) { if (USBHostTransferIsComplete(gc_DevData.ID.deviceAddress, pInterface->inEndpoint, &errorCode, &byteCount)) { pInterface->flags.rxBusy = 0; pInterface->rxLength = byteCount; pInterface->rxErrorCode = errorCode; log_printf("Received message with %ld bytes on endpoint 0x%x", byteCount, pInterface->inEndpoint); } } if (pInterface->flags.txBusy) { if (USBHostTransferIsComplete(gc_DevData.ID.deviceAddress, pInterface->outEndpoint, &errorCode, &byteCount)) { pInterface->flags.txBusy = 0; pInterface->txErrorCode = errorCode; } } } } } // USBHostAndroidTasks
/**************************************************************************** Function: BOOL AndroidAppIsReadComplete_Pv1(void* handle, BYTE* errorCode, DWORD* size) Summary: Check to see if the last read to the Android device was completed Description: Check to see if the last read to the Android device was completed. If complete, returns the amount of data that was sent and the corresponding error code for the transmission. Precondition: Transfer has previously been requested from an Android device. Parameters: void* handle - the handle passed to the device in the EVENT_ANDROID_ATTACH event BYTE* errorCode - a pointer to the location where the resulting error code should be written DWORD* size - a pointer to the location where the resulting size information should be written Return Values: TRUE - Transfer is complete. FALSE - Transfer is not complete. Remarks: Possible values for errorCode are: * USB_SUCCESS - Transfer successful * USB_UNKNOWN_DEVICE - Device not attached * USB_ENDPOINT_STALLED - Endpoint STALL'd * USB_ENDPOINT_ERROR_ILLEGAL_PID - Illegal PID returned * USB_ENDPOINT_ERROR_BIT_STUFF * USB_ENDPOINT_ERROR_DMA * USB_ENDPOINT_ERROR_TIMEOUT * USB_ENDPOINT_ERROR_DATA_FIELD * USB_ENDPOINT_ERROR_CRC16 * USB_ENDPOINT_ERROR_END_OF_FRAME * USB_ENDPOINT_ERROR_PID_CHECK * USB_ENDPOINT_ERROR - Other error ***************************************************************************/ BOOL AndroidAppIsReadComplete_Pv1(void* handle, BYTE* errorCode, DWORD* size) { ANDROID_PROTOCOL_V1_DEVICE_DATA* device = (ANDROID_PROTOCOL_V1_DEVICE_DATA*)handle; if(device == NULL) { return USB_UNKNOWN_DEVICE; } if(device->address == 0) { return USB_UNKNOWN_DEVICE; } if(device->state != READY) { return USB_INVALID_STATE; } //If there was a transfer pending, then get the state of the transfer if(USBHostTransferIsComplete( device->address, ANDROID_GetINEndpointNum(device), errorCode, size ) == TRUE) { device->status.RXBusy = 0; return TRUE; } //Then the transfer was not complete. return FALSE; }
/**************************************************************************** Function: BOOL AndroidIsLastCommandComplete(BYTE address, BYTE *errorCode, DWORD *byteCount) Summary: Checks to see if the last command request is complete. Description: Checks to see if the last command request is complete. Precondition: AndroidAppStart() function has been called before the first calling of this function Parameters: BYTE address - the address of the device that issued the command BYTE* errorCode - pointer to the location where the error code should be stored DWORD* byteCount - pointer to the location where the size of the resulting transfer should be written. Return Values: TRUE - command is complete FALSE - command is still in progress Remarks: This function is implemented for polled transfer implementations but should be deprecated once polled transfer requests are removed. Internal API only. Should not be called by a user. ***************************************************************************/ BOOL AndroidIsLastCommandComplete(BYTE address, BYTE *errorCode, DWORD *byteCount) { return USBHostTransferIsComplete( address, //BYTE deviceAddress, 0, //BYTE endpoint, errorCode, //BYTE *errorCode, byteCount //DWORD *byteCount ); }
BOOL USBHostMIDITransferIsComplete(void* handle, BYTE endpointIndex, BYTE* errorCode, DWORD *byteCount ) { MIDI_DEVICE* device = (MIDI_DEVICE*)handle; if (USBHostTransferIsComplete(device->deviceAddress, endpointIndex, errorCode, byteCount) == TRUE) { device->endpoints[endpointIndex].busy = 0; return TRUE; } // Then this transfer is not complete return FALSE; }
BOOL ChipKITUSBHost::TransferIsComplete(uint8_t deviceAddress, uint8_t endpoint, uint8_t * errorCode, DWORD * byteCount) { return(USBHostTransferIsComplete(deviceAddress, endpoint, errorCode, byteCount)); }
void ManageDemoState ( void ) { int j; DWORD byteCount; BYTE errorCode; BYTE RetVal; //接続されていなかったら初期化 if (USBHostGenericDeviceDetached(deviceAddress) && deviceAddress != 0) { long i; for(i = 0;i < sizeof(jpeg);i++){ jpeg[i] = 0; } UART2PrintString( "Generic demo device detached - polled\r\n" ); DemoState = DEMO_INITIALIZE; deviceAddress = 0; } switch (DemoState) { case DEMO_INITIALIZE: DemoState = DEMO_STATE_IDLE; break; case DEMO_STATE_IDLE: //接続されたら、読み出し処理に移行 if (CheckForNewAttach()) { DemoState = DEMO_STATE_GET_INFO; UART2PrintString( "USB_Ver=" ); UART2PutDec(((USB_DEVICE_DESCRIPTOR *)pDeviceDescriptor)->bcdUSB >> 8); UART2PrintString( "-" ); UART2PutDec(((USB_DEVICE_DESCRIPTOR *)pDeviceDescriptor)->bcdUSB); UART2PrintString( "\r\n" ); } break; case DEMO_STATE_GET_INFO: if(control(GET_INFO, VS_PROBE_CONTROL, 1, param, 1) == USB_SUCCESS){ UART2PrintString( "GET_INFO, VS_PROBE_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_INFO; } break; case DEMO_STATE_WAIT_GET_INFO: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_INFO, VS_PROBE_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(param,byteCount); UART2PrintString( "\r\n" ); DemoState = DEMO_STATE_GET_DEF; } break; case DEMO_STATE_GET_DEF: if(control(GET_DEF, VS_PROBE_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "GET_DEF, VS_PROBE_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_DEF; } break; case DEMO_STATE_WAIT_GET_DEF: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_DEF, VS_PROBE_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState = DEMO_STATE_GET_MIN; } break; case DEMO_STATE_GET_MIN: if(control(GET_MIN, VS_PROBE_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "GET_MIN, VS_PROBE_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_MIN; } break; case DEMO_STATE_WAIT_GET_MIN: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_MIN, VS_PROBE_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState = DEMO_STATE_GET_MAX; } break; case DEMO_STATE_GET_MAX: if(control(GET_MAX, VS_PROBE_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "GET_MAX, VS_PROBE_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_MAX; } break; case DEMO_STATE_WAIT_GET_MAX: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_MAX, VS_PROBE_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState = DEMO_STATE_GET_CUR; } break; case DEMO_STATE_GET_CUR: if(control(GET_CUR, VS_PROBE_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "GET_CUR, VS_PROBE_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_CUR; } break; case DEMO_STATE_WAIT_GET_CUR: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_CUR, VS_PROBE_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState =DEMO_STATE_SET_CUR ; } break; case DEMO_STATE_SET_CUR: for(j = 0;j < param_len;j++){ temp[j] = 0; } temp[2] = 2;//フォーマットインデックス temp[3] = 1;//フレームインデックス /*temp[4] = 0x80; temp[5] = 0x84; temp[6] = 0x1E; temp[7] = 0x00;*/ temp[4] = 0x15;//30Hz temp[5] = 0x16; temp[6] = 0x05; temp[7] = 0x00; if(control(SET_CUR, VS_PROBE_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "SET_CUR, VS_PROBE_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_SET_CUR; } break; case DEMO_STATE_WAIT_SET_CUR: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=SET_CUR, VS_PROBE_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState =DEMO_STATE_GET_CUR2 ; } break; case DEMO_STATE_GET_CUR2: if(control(GET_CUR, VS_PROBE_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "GET_CUR2, VS_PROBE_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_CUR2; } break; case DEMO_STATE_WAIT_GET_CUR2: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_CUR2, VS_PROBE_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState =DEMO_STATE_GET_INFO2 ; } break; case DEMO_STATE_GET_INFO2: if(control(GET_INFO, VS_COMMIT_CONTROL, 1, param, 1) == USB_SUCCESS){ UART2PrintString( "GET_INFO, VS_COMMIT_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_INFO2; } break; case DEMO_STATE_WAIT_GET_INFO2: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_INFO, VS_COMMIT_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(param,byteCount); UART2PrintString( "\r\n" ); DemoState = DEMO_STATE_GET_CUR3; } break; case DEMO_STATE_GET_CUR3: if(control(GET_CUR, VS_COMMIT_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "GET_CUR2, VS_COMMIT_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_GET_CUR3; } break; case DEMO_STATE_WAIT_GET_CUR3: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=GET_CUR2, VS_COMMIT_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState =DEMO_STATE_SET_CUR2 ; } break; case DEMO_STATE_SET_CUR2: for(j = 0;j < param_len;j++){ temp[j] = 0; } temp[2] = 2; temp[3] = 0x01;//640x480 30Hz //temp[3] = 0x02;//160x120 30Hz //temp[3] = 0x0C;//800x600 temp[4] = 0x80;//5Hz temp[5] = 0x84; temp[6] = 0x1E; temp[7] = 0x00; /*temp[4] = 0x15;//30Hz temp[5] = 0x16; temp[6] = 0x05; temp[7] = 0x00;*/ if(control(SET_CUR, VS_COMMIT_CONTROL, 1, temp, param_len) == USB_SUCCESS){ UART2PrintString( "SET_CUR, VS_COMMIT_CONTROL\r\n" ); DemoState = DEMO_STATE_WAIT_SET_CUR2; } break; case DEMO_STATE_WAIT_SET_CUR2: if (USBHostTransferIsComplete( deviceAddress, 0, &errorCode, &byteCount )){ UART2PrintString( "OK=SET_CUR, VS_COMMIT_CONTROL\r\n" ); UART2PrintString( "Byte Count=" ); UART2PutDec(byteCount); UART2PrintString( "\r\n" ); packet_dump(temp,byteCount); UART2PrintString( "\r\n" ); DemoState =DEMO_STATE_SET_ISOCHRONOUS ; } break; case DEMO_STATE_SET_ISOCHRONOUS: if(USBHostIssueDeviceRequest( deviceAddress, 0x01, USB_REQUEST_SET_INTERFACE, 0x06/*Alternate Setting:0x1*/, 0x01/*interface:0x03*/, 0, NULL, USB_DEVICE_REQUEST_SET, 0x00 )== USB_SUCCESS){ UART2PrintString( "USB_REQUEST_SET_INTERFACE=OK!\r\n" ); DemoState =DEMO_STATE_WAIT_SET_ISOCHRONOUS ; } break; case DEMO_STATE_WAIT_SET_ISOCHRONOUS: if(USBHostReadIsochronous(deviceAddress,0x81,&isocData) == USB_SUCCESS){ //UART2PrintString( "USBHostReadIsochronous=OK!\r\n" ); DemoState = DEMO_STATE_ERROR; } break; case DEMO_STATE_ERROR: break; default: DemoState = DEMO_INITIALIZE; break; } //DelayMs(1); // 1ms delay } // ManageDemoState
void USBHostBluetoothTasks(void) { DWORD byteCount; BYTE errorCode; if (gc_BluetoothDevData.ID.deviceAddress && gc_BluetoothDevData.initialized) { if (gc_BluetoothDevData.intIn.busy) { if (USBHostTransferIsComplete(gc_BluetoothDevData.ID.deviceAddress, gc_BluetoothDevData.intIn.address, &errorCode, &byteCount)) { // if (byteCount) { // log_printf("Received interrupt with error code 0x%x, %ld bytes: ", // errorCode, byteCount); // log_print_buf(gc_BluetoothDevData.intIn.data, byteCount); // } gc_BluetoothDevData.intIn.busy = 0; USBHostBluetoothCallback(BLUETOOTH_EVENT_READ_INTERRUPT_DONE, errorCode, gc_BluetoothDevData.intIn.data, byteCount); } } if (gc_BluetoothDevData.bulkIn.busy) { if (USBHostTransferIsComplete(gc_BluetoothDevData.ID.deviceAddress, gc_BluetoothDevData.bulkIn.address, &errorCode, &byteCount)) { // if (byteCount) { // log_printf("Received bulk with error code 0x%x, %ld bytes: ", // errorCode, byteCount); // log_print_buf(gc_BluetoothDevData.bulkIn.data, byteCount); // } gc_BluetoothDevData.bulkIn.busy = 0; USBHostBluetoothCallback(BLUETOOTH_EVENT_READ_BULK_DONE, errorCode, gc_BluetoothDevData.bulkIn.data, byteCount); } } if (gc_BluetoothDevData.bulkOut.busy) { if (USBHostTransferIsComplete(gc_BluetoothDevData.ID.deviceAddress, gc_BluetoothDevData.bulkOut.address, &errorCode, &byteCount)) { gc_BluetoothDevData.bulkOut.busy = 0; USBHostBluetoothCallback(BLUETOOTH_EVENT_WRITE_BULK_DONE, errorCode, NULL, 0); } } if (gc_BluetoothDevData.ctrlOut.busy) { if (USBHostTransferIsComplete(gc_BluetoothDevData.ID.deviceAddress, gc_BluetoothDevData.ctrlOut.address, &errorCode, &byteCount)) { gc_BluetoothDevData.ctrlOut.busy = 0; USBHostBluetoothCallback(BLUETOOTH_EVENT_WRITE_CONTROL_DONE, errorCode, NULL, 0); } } } }