Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to know which USB interface to use?

Tags:

android

usb

The goal is to connect a guitar to USB host capable Android device, do some processing on the signal and play it through the device.

Problem is I'm not finding much documentation on it. The device shows up can contains 6 interfaces.

However, in all the examples I see, the first interface is always used..

UsbInterface intf = device.getInterface(0);

My device contains 6 interfaces BUT the first interface, i.e. getInterface(0) has no endpoints. 3/6 have no endpoints but the other 3 all have 1 end point.

I read that you need to find the correct interface and endpoint. In my case, I only want an IN endpoint to receive data.

Any advice on how to that would be very appreciated.

Cheers

like image 639
mgibson Avatar asked Apr 09 '14 13:04

mgibson


People also ask

What is Android device interface?

The Android Interface Definition Language (AIDL) is similar to other IDLs you might have worked with. It allows you to define the programming interface that both the client and service agree upon in order to communicate with each other using interprocess communication (IPC).

What is Android accessory mode?

USB accessory mode allows users to connect USB host hardware specifically designed for Android-powered devices. The accessories must adhere to the Android accessory protocol outlined in the Android Accessory Development Kit documentation.


1 Answers

This is how I got down to the bottom of it.

The last interface, I believe is the one I am looking for.

  • It has a direction value of USB_DIR_IN (3)
  • It has a endpoint type value USB_ENDPOINT_XFER_ISOC (1) signifying the regular isochronous connection I was looking for

    // Cycle through interfaces and print out endpoint info
    StringBuilder builder = new StringBuilder();
    
    for (int i=0; i<device.getInterfaceCount(); i++)
    {
        String epDirString = "No endpoints";
        String epTypeString = "No endpoints";
    
        if (device.getInterface(i).getEndpointCount() > 0)
        {
            epDirString = String.valueOf(device.getInterface(i).getEndpoint(0).getDirection());
            epTypeString = String.valueOf(device.getInterface(i).getEndpoint(0).getType());
        }
    
        builder.append("Int. " + i + " EP count: " + device.getInterface(i).getEndpointCount() + 
                       " || EP direction: " + epDirString + " || EP type: " + epTypeString + "\n");
    }
    
    // Show results in a dialog
    Builder dBuilder = new AlertDialog.Builder(USBActivity.this);       
    dBuilder.setMessage(builder.toString()).show();
    
like image 97
mgibson Avatar answered Sep 19 '22 23:09

mgibson