|
4 | 4 | import sys |
5 | 5 |
|
6 | 6 | # path hacking |
7 | | -sys.path.append("../../tools") |
| 7 | +sys.path.append("../../tools/usb_descriptor") |
8 | 8 |
|
9 | | -from usb_descriptor import core |
10 | | -from usb_descriptor import cdc |
| 9 | +from adafruit_usb_descriptor import cdc, standard, util |
11 | 10 |
|
12 | 11 | parser = argparse.ArgumentParser(description='Generate USB descriptors.') |
13 | 12 | parser.add_argument('--manufacturer', type=str, |
|
24 | 23 |
|
25 | 24 | args = parser.parse_args() |
26 | 25 |
|
27 | | -langid = core.StringDescriptor("\u0409") |
28 | | -manufacturer = core.StringDescriptor(args.manufacturer) |
29 | | -product = core.StringDescriptor(args.product) |
30 | | -serial_number = core.StringDescriptor("serial number. you should fill in a unique serial number here."[:args.serial_number_length]) |
| 26 | +langid = standard.StringDescriptor("\u0409") |
| 27 | +manufacturer = standard.StringDescriptor(args.manufacturer) |
| 28 | +product = standard.StringDescriptor(args.product) |
| 29 | +serial_number = standard.StringDescriptor("serial number. you should fill in a unique serial number here."[:args.serial_number_length]) |
31 | 30 | strings = [langid, manufacturer, product, serial_number] |
32 | 31 |
|
33 | 32 | # vid = 0x239A |
34 | 33 | # pid = 0x8021 |
35 | 34 |
|
36 | | -device = core.DeviceDescriptor( |
| 35 | +device = standard.DeviceDescriptor( |
37 | 36 | idVendor=args.vid, |
38 | 37 | idProduct=args.pid, |
39 | 38 | iManufacturer=strings.index(manufacturer), |
|
43 | 42 | # Interface numbers are interface set local and endpoints are interface local |
44 | 43 | # until core.join_interfaces renumbers them. |
45 | 44 | cdc_interfaces = [ |
46 | | - core.InterfaceDescriptor( |
| 45 | + standard.InterfaceDescriptor( |
47 | 46 | bInterfaceClass=0x2, # Communications Device Class |
48 | 47 | bInterfaceSubClass=0x02, # Abstract control model |
49 | 48 | bInterfaceProtocol=0x01, # Common AT Commands |
|
59 | 58 | cdc.AbstractControlManagement(bmCapabilities=0x02), |
60 | 59 | cdc.Union(bMasterInterface=0x00, |
61 | 60 | bSlaveInterface=[0x01]), |
62 | | - core.EndpointDescriptor( |
63 | | - bEndpointAddress=0x0 | core.EndpointDescriptor.DIRECTION_IN, |
64 | | - bmAttributes=core.EndpointDescriptor.TYPE_INTERRUPT, |
| 61 | + standard.EndpointDescriptor( |
| 62 | + bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN, |
| 63 | + bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT, |
65 | 64 | wMaxPacketSize=0x8, |
66 | 65 | bInterval=10) |
67 | 66 | ] |
68 | 67 | ), |
69 | | - core.InterfaceDescriptor( |
| 68 | + standard.InterfaceDescriptor( |
70 | 69 | bInterfaceClass=0x0a, |
71 | 70 | subdescriptors=[ |
72 | | - core.EndpointDescriptor( |
73 | | - bEndpointAddress=0x0 | core.EndpointDescriptor.DIRECTION_IN, |
74 | | - bmAttributes=core.EndpointDescriptor.TYPE_BULK), |
75 | | - core.EndpointDescriptor( |
76 | | - bEndpointAddress=0x0 | core.EndpointDescriptor.DIRECTION_OUT, |
77 | | - bmAttributes=core.EndpointDescriptor.TYPE_BULK) |
| 71 | + standard.EndpointDescriptor( |
| 72 | + bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN, |
| 73 | + bmAttributes=standard.EndpointDescriptor.TYPE_BULK), |
| 74 | + standard.EndpointDescriptor( |
| 75 | + bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_OUT, |
| 76 | + bmAttributes=standard.EndpointDescriptor.TYPE_BULK) |
78 | 77 | ] |
79 | 78 | ) |
80 | 79 | ] |
81 | 80 |
|
82 | 81 | msc_interfaces = [ |
83 | | - core.InterfaceDescriptor( |
| 82 | + standard.InterfaceDescriptor( |
84 | 83 | bInterfaceClass=0x08, |
85 | 84 | bInterfaceSubClass=0x06, |
86 | 85 | bInterfaceProtocol=0x50, |
87 | 86 | subdescriptors=[ |
88 | | - core.EndpointDescriptor( |
89 | | - bEndpointAddress=0x0 | core.EndpointDescriptor.DIRECTION_IN, |
90 | | - bmAttributes=core.EndpointDescriptor.TYPE_BULK), |
91 | | - core.EndpointDescriptor( |
92 | | - bEndpointAddress=0x1 | core.EndpointDescriptor.DIRECTION_OUT, |
93 | | - bmAttributes=core.EndpointDescriptor.TYPE_BULK) |
| 87 | + standard.EndpointDescriptor( |
| 88 | + bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN, |
| 89 | + bmAttributes=standard.EndpointDescriptor.TYPE_BULK), |
| 90 | + standard.EndpointDescriptor( |
| 91 | + bEndpointAddress=0x1 | standard.EndpointDescriptor.DIRECTION_OUT, |
| 92 | + bmAttributes=standard.EndpointDescriptor.TYPE_BULK) |
94 | 93 | ] |
95 | 94 | ) |
96 | 95 | ] |
97 | 96 |
|
98 | | -interfaces = core.join_interfaces(cdc_interfaces, msc_interfaces) |
| 97 | +interfaces = util.join_interfaces(cdc_interfaces, msc_interfaces) |
99 | 98 |
|
100 | | -cdc_function = core.InterfaceAssociationDescriptor( |
| 99 | +cdc_function = standard.InterfaceAssociationDescriptor( |
101 | 100 | bFirstInterface=interfaces.index(cdc_interfaces[0]), |
102 | 101 | bInterfaceCount=len(cdc_interfaces), |
103 | 102 | bFunctionClass=0x2, # Communications Device Class |
104 | 103 | bFunctionSubClass=0x2, # Abstract control model |
105 | 104 | bFunctionProtocol=0x1) # Common AT Commands |
106 | 105 |
|
107 | | -configuration = core.ConfigurationDescriptor( |
108 | | - wTotalLength=(core.ConfigurationDescriptor.bLength + |
| 106 | +configuration = standard.ConfigurationDescriptor( |
| 107 | + wTotalLength=(standard.ConfigurationDescriptor.bLength + |
109 | 108 | cdc_function.bLength + |
110 | 109 | sum([len(bytes(x)) for x in interfaces])), |
111 | 110 | bNumInterfaces=len(interfaces)) |
|
0 commit comments