BYTE USBHostBlukWrite( BYTE deviceAddress, void *buffer, DWORD length ) { BYTE RetVal; DWORD i; // Validate the call if ((g_usbbt.initialized != 1) || (g_usbbt.deviceAddress != deviceAddress)) return USB_INVALID_STATE; if (g_usbbt.endpointBulkOUT_Busy) return USB_BUSY; UART2PrintString( "USBHostBlukWrite\r\n" ); for(i = 0; i < length; i++) { UART2PutHex(*((char*)buffer+i)); } UART2PrintString( "\r\n" ); // Set the busy flag and start a new OUT transfer. g_usbbt.endpointBulkOUT_Busy = 1; RetVal = USBHostWrite( deviceAddress, g_usbbt.endpointBulkOUT, (BYTE *)buffer, length ); if (RetVal != USB_SUCCESS) { g_usbbt.endpointBulkOUT_Busy = 0; // Clear flag to allow re-try } return RetVal; }
static BYTE USBHostBluetoothWrite(BLUETOOTH_ENDPOINT *ep, const void *buffer, DWORD length) { BYTE RetVal; // Validate the call assert(gc_BluetoothDevData.initialized); if (ep->busy) return USB_BUSY; // log_printf("Sending message with %u bytes to endpoint 0x%x: ", // (unsigned) length, // ep->address); // log_print_buf(buffer, length); // Set the busy flag and start a new OUT transfer. ep->busy = 1; if (ep->address == 0) { RetVal = USBHostIssueDeviceRequest(gc_BluetoothDevData.ID.deviceAddress, 0x20, 0, 0, 0,//gc_BluetoothDevData.interface, length, (BYTE *) buffer, USB_DEVICE_REQUEST_SET, gc_BluetoothDevData.driverID); } else { RetVal = USBHostWrite(gc_BluetoothDevData.ID.deviceAddress, ep->address, (BYTE *)buffer, length); } if (RetVal != USB_SUCCESS) { log_printf("Write failed"); ep->busy = 0; // Clear flag to allow re-try } return RetVal; }
BYTE USBHostMIDIWrite(void* handle, BYTE endpointIndex, void *buffer, WORD length) { MIDI_DEVICE *device = (MIDI_DEVICE*)handle; BYTE RetVal; RetVal = USBHostWrite( device->deviceAddress, device->endpoints[endpointIndex].endpointAddress, (BYTE *)buffer, length ); if (RetVal == USB_SUCCESS) { // Set the busy flag device->endpoints[endpointIndex].busy = TRUE; } return RetVal; } // USBHostMIDIWrite
BYTE USBHostBluetoothWrite_EP2( BYTE deviceAddress, void *buffer, DWORD length ) { BYTE RetVal; // Validate the call if (!API_VALID(deviceAddress)) return USB_INVALID_STATE; if (gc_DevData.flags.txAclBusy) return USB_BUSY; // Set the busy flag and start a new OUT transfer. gc_DevData.flags.txAclBusy = 1; RetVal = USBHostWrite( deviceAddress, USB_OUT_EP|USB_EP2, (BYTE *)buffer, length ); if (RetVal != USB_SUCCESS) { gc_DevData.flags.txAclBusy = 0; // Clear flag to allow re-try DelayMs(1); } return RetVal; } // USBHostBluetoothWrite
/**************************************************************************** Function: BYTE AndroidAppWrite_Pv1(void* handle, BYTE* data, DWORD size) Summary: Writes data out to the Android device Description: Writes data out to the Android device Precondition: Protocol version 1 sub-driver initialized through AndroidAppStart_Pv1() Parameters: void* handle - handle to the device that should receive the data BYTE* data - the data to send DWORD size - the amount of data to send Return Values: USB_SUCCESS - Write started successfully. USB_UNKNOWN_DEVICE - Device with the specified address not found. USB_INVALID_STATE - We are not in a normal running state. USB_ENDPOINT_ILLEGAL_TYPE - Must use USBHostControlWrite to write to a control endpoint. USB_ENDPOINT_ILLEGAL_DIRECTION - Must write to an OUT endpoint. USB_ENDPOINT_STALLED - Endpoint is stalled. Must be cleared by the application. USB_ENDPOINT_ERROR - Endpoint has too many errors. Must be cleared by the application. USB_ENDPOINT_BUSY - A Write is already in progress. USB_ENDPOINT_NOT_FOUND - Invalid endpoint. Remarks: None ***************************************************************************/ BYTE AndroidAppWrite_Pv1(void* handle, BYTE* data, DWORD size) { BYTE errorCode; 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(device->status.TXBusy == 1) { return USB_ENDPOINT_BUSY; } errorCode = USBHostWrite( device->address, ANDROID_GetOUTEndpointNum(device), data, size ); switch(errorCode) { case USB_ENDPOINT_BUSY: case USB_SUCCESS: device->status.TXBusy = 1; break; default: device->status.TXBusy = 0; break; } return errorCode; }
BYTE USBHostAndroidWrite(const void *buffer, DWORD length, ANDROID_INTERFACE_ID iid) { BYTE RetVal; ANDROID_INTERFACE *pInterface = &gc_DevData.interfaces[iid]; // Validate the call assert(pInterface->flags.initialized); if (pInterface->flags.txBusy) return USB_BUSY; log_printf("Sending message with %u bytes to endpoint 0x%x: ", (unsigned) length, pInterface->outEndpoint); log_print_buf(buffer, length); // Set the busy flag and start a new OUT transfer. pInterface->flags.txBusy = 1; RetVal = USBHostWrite(gc_DevData.ID.deviceAddress, pInterface->outEndpoint, (BYTE *)buffer, length); if (RetVal != USB_SUCCESS) { pInterface->flags.txBusy = 0; // Clear flag to allow re-try } return RetVal; } // USBHostAndroidWrite
uint8_t ChipKITUSBHost::Write(uint8_t deviceAddress, uint8_t endpoint, uint8_t * data, DWORD size) { return(USBHostWrite(deviceAddress, endpoint, data, size)); }