@@ -56,28 +56,36 @@ def __init__(self):
56
56
self .winusb_interfaces = []
57
57
self .device_interface_guids = {}
58
58
59
- def interface (self , with_winusb = True , guid_discriminator = None ):
59
+ def interface (self , with_winusb = True , guid = None , guid_discriminator = None ):
60
60
n = self ._next_interface
61
61
self ._next_interface += 1
62
- if with_winusb :
63
- if guid_discriminator is None :
64
- raise RuntimeError ('Specify guid_discriminator for WinUSB-capable interfaces.' )
65
62
66
- self .winusb_interfaces .append (n )
63
+ if guid is not None and guid_discriminator is not None :
64
+ raise RuntimeError ('Specify either guid or guid_discriminator, not both.' )
67
65
68
66
if guid_discriminator is not None :
69
- if not with_winusb :
70
- raise RuntimeError ('guid_discriminator is Windows-specific. There is no reason to apply to non-WinUSB interfaces' )
71
-
72
67
assert guid_discriminator <= 0xFFFF
73
68
74
69
fields = list (DEVICE_INTERFACE_GUID_BASE .fields )
75
70
fields [1 ] = guid_discriminator
76
- new_uuid = uuid .UUID (fields = fields )
77
- if new_uuid in self .device_interface_guids .values ():
78
- raise RuntimeError (f'Duplicated GUID discriminator: 0x{ guid_discriminator :02X} ' )
71
+ guid = str (uuid .UUID (fields = fields ))
72
+
73
+ if guid is not None :
74
+ if not with_winusb :
75
+ raise RuntimeError ('guid and guid_discriminator is Windows-specific. There is no reason to apply to non-WinUSB interfaces' )
79
76
80
- self .device_interface_guids [n ] = new_uuid
77
+ guid = uuid .UUID (guid )
78
+
79
+ if guid in self .device_interface_guids .values ():
80
+ raise RuntimeError (f'Duplicated GUID: { guid } ' )
81
+
82
+ self .device_interface_guids [n ] = guid
83
+
84
+ if with_winusb :
85
+ if guid is None :
86
+ raise RuntimeError ('Specify guid or guid_discriminator for WinUSB-capable interfaces.' )
87
+
88
+ self .winusb_interfaces .append (n )
81
89
82
90
return n
83
91
@@ -355,7 +363,7 @@ def add_cmsis_dap(self, with_v1 = True, with_v2 = True):
355
363
356
364
if with_v2 :
357
365
# USB interface.
358
- if_num = self .usb_alloc .interface (guid_discriminator = 0x80_43 )
366
+ if_num = self .usb_alloc .interface (guid = 'cdb3b5ad-293b-4663-aa36-1aae46463776' )
359
367
in_ep_num = self .usb_alloc .in_ep ()
360
368
out_ep_num = self .usb_alloc .out_ep ()
361
369
0 commit comments