Exemplo n.º 1
0
void ChipKITUSBHost::TerminateTransfer(uint8_t deviceAddress, uint8_t endpoint)
{
    USBHostTerminateTransfer(deviceAddress, endpoint);
}
/****************************************************************************
  Function:
    BOOL AndroidAppEventHandler_Pv1( BYTE address, USB_EVENT event, void *data, DWORD size )

  Summary:
    Handles events from the host stack

  Description:
    Handles events from the host stack

  Precondition:
    None

  Parameters:
    BYTE address - the address of the device that caused the event
    USB_EVENT event - the event that occured
    void* data - the data for the event
    DWORD size - the size of the data in bytes

  Return Values:
    TRUE - the event was handled
    FALSE - the event was not handled

  Remarks:
    This is a internal API only.  This should not be called by anything other
    than the USB host stack via the client driver table
  ***************************************************************************/
BOOL AndroidAppEventHandler_Pv1( BYTE address, USB_EVENT event, void *data, DWORD size )
{
    HOST_TRANSFER_DATA* transfer_data = data ;
    ANDROID_PROTOCOL_V1_DEVICE_DATA *device = NULL;
    BYTE i;

    switch (event)
    {
        case EVENT_NONE:             // No event occured (NULL event)
            return TRUE;

        case EVENT_DETACH:           // USB cable has been detached (data: BYTE, address of device)
            for(i=0;i<NUM_ANDROID_DEVICES_SUPPORTED;i++)
            {
                if(devices_pv1[i].address == address)
                {
                    if(devices_pv1[i].state == ACCESSORY_STARTING) 
                    {
                        devices_pv1[i].state = WAITING_FOR_ACCESSORY_RETURN;
                    }

                    if(devices_pv1[i].state != WAITING_FOR_ACCESSORY_RETURN)
                    {
                        device = &devices_pv1[i];

                        USBHostTerminateTransfer( device->address, device->OUTEndpointNum );
                        USBHostTerminateTransfer( device->address, device->INEndpointNum );
                        USB_HOST_APP_EVENT_HANDLER(device->address,EVENT_ANDROID_DETACH,device,sizeof(ANDROID_PROTOCOL_V1_DEVICE_DATA*));
                        
                        //Device has timed out.  Destroy its info.
                        memset(&devices_pv1[i],0x00,sizeof(ANDROID_PROTOCOL_V1_DEVICE_DATA));
                    }
                    //If we are WAITING_FOR_ACCESSORY_RETURN, then we will timeout in data handler instead
                }
            }

            return TRUE;
        case EVENT_HUB_ATTACH:       // USB hub has been attached
            return TRUE;

        case EVENT_TRANSFER:         // A USB transfer has completed - NOT USED

            for(i=0;i<NUM_ANDROID_DEVICES_SUPPORTED;i++)
            {
                if(devices_pv1[i].address == address)
                {
                    device = &devices_pv1[i];
                }
            }

            //If this is for a device that we don't know about, get rid of it.
            if(device == NULL)
            {
                return FALSE;
            }

            //Otherwise, handle the data
            if(transfer_data->bEndpointAddress == 0x00)
            {
                //If the transfer was EP0, just clear the pending bit and 
                //  we will handle the rest in the tasks function so we don't
                //  duplicate state machine changes both here and there
                device->status.EP0TransferPending = 0;
            }
            
            return TRUE;
        case EVENT_RESUME:           // Device-mode resume received
            return TRUE;

        case EVENT_SUSPEND:          // Device-mode suspend/idle event received
            return TRUE;

        case EVENT_RESET:            // Device-mode bus reset received
            return TRUE;

        case EVENT_STALL:            // A stall has occured
            return TRUE;

        case EVENT_BUS_ERROR:            // BUS error has occurred
            return TRUE;

        default:
            break;
    }
    return FALSE;
}