usbstm32pyusb

Controlling audio streaming with pyusb


I am currently working on a project involving composite USB Device, I am using STM32Fxx for the process. One of the classes is USB Audio Class, which works perfectly(tested with audacity).

Due to my requirements I need to control the audio streaming with pyusb. I have already detached the drivers attached to the device using the following

dev = usb.core.find(idVendor=1155, idProduct=22362)

c = 1
for config in dev:
    for i in range(config.bNumInterfaces):
        if dev.is_kernel_driver_active(i):
            dev.detach_kernel_driver(i)
        print (i)
    c+=1

Is it possible to control the audio streaming using pyusb after detaching the drivers and use audacity to verify it?


Solution

  • The individual interfaces corresponding to a class can be detached by slightly modifying the above code

    if dev.is_kernel_driver_active(i):
        dev.detach_kernel_driver(i)
    

    where i is the corresponding interface number.

    This will detach only the only the interfaces you need to test while leaving other interfaces functional. Individual interfaces and their corresponding number can be found using the lsusb command