Android - How to find out which USB interface to use?

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

The problem is that I do not find much documentation. The device can contain 6 interfaces.

However, in all the examples that 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 do not have endpoints, and the remaining 3 have 1 endpoint.

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

Any advice on how that would be greatly appreciated.

Greetings

+4
1

.

, , , .

  • USB_DIR_IN (3)
  • USB_ENDPOINT_XFER_ISOC (1), ,

    // 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();
    
+1

Source: https://habr.com/ru/post/1535744/


All Articles