make the device a composite device

This commit is contained in:
Samuel Sadok
2018-05-14 15:20:13 -07:00
parent 3fea671aac
commit d69f8312e0
11 changed files with 210 additions and 327 deletions
+19 -10
View File
@@ -46,20 +46,30 @@ class USBBulkTransport(odrive.protocol.PacketSource, odrive.protocol.PacketSink)
if platform.system() != 'Windows':
self.dev.reset()
interface_number = 1
#self.dev.set_configuration() # no args: set first configuration
# Find the best interface
self.cfg = self.dev.get_active_configuration()
custom_interfaces = [i for i in self.cfg.interfaces() if i.bInterfaceClass == 0x00 and i.bInterfaceSubClass == 0x01]
cdc_interfaces = [i for i in self.cfg.interfaces() if i.bInterfaceClass == 0x0a and i.bInterfaceSubClass == 0x00]
all_compatible_interfaces = custom_interfaces + cdc_interfaces
if len(all_compatible_interfaces) == 0:
raise Exception("the device has no compatible interfaces")
self.intf = all_compatible_interfaces[0]
# Try to detach kernel driver from interface
#interface_number = 1
try:
if self.dev.is_kernel_driver_active(interface_number):
self.dev.detach_kernel_driver(interface_number)
if self.dev.is_kernel_driver_active(self.intf.bInterfaceNumber):
self.dev.detach_kernel_driver(self.intf.bInterfaceNumber)
self._printer("Detached Kernel Driver")
else:
self._printer("Kernel Driver was not attached")
except NotImplementedError:
pass #is_kernel_driver_active not implemented on Windows
self.dev.set_configuration() # no args: set first configuration
self.cfg = self.dev.get_active_configuration()
self.intf = self.cfg[(1,0)] # this implicitly claims the interface
# write endpoint
# find write endpoint (first OUT endpoint)
self.epw = usb.util.find_descriptor(self.intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
@@ -67,9 +77,8 @@ class USBBulkTransport(odrive.protocol.PacketSource, odrive.protocol.PacketSink)
)
assert self.epw is not None
self._printer("EndpointAddress for writing {}".format(self.epw.bEndpointAddress))
# read endpoint
# find read endpoint (first IN endpoint)
self.epr = usb.util.find_descriptor(self.intf,
# match the first IN endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \