OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """USB descriptor generation utilities. | 5 """USB descriptor generation utilities. |
6 | 6 |
7 Classes to represent and generate USB descriptors. | 7 Classes to represent and generate USB descriptors. |
8 """ | 8 """ |
9 | 9 |
10 import struct | 10 import struct |
11 | 11 |
| 12 import hid_constants |
12 import usb_constants | 13 import usb_constants |
13 | 14 |
14 | 15 |
15 class Field(object): | 16 class Field(object): |
16 """USB descriptor field information.""" | 17 """USB descriptor field information.""" |
17 | 18 |
18 def __init__(self, name, str_fmt, struct_fmt, required): | 19 def __init__(self, name, str_fmt, struct_fmt, required): |
19 """Define a new USB descriptor field. | 20 """Define a new USB descriptor field. |
20 | 21 |
21 Args: | 22 Args: |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 for typ, length in self._descriptors) | 368 for typ, length in self._descriptors) |
368 return ''.join(bufs) | 369 return ''.join(bufs) |
369 | 370 |
370 def __str__(self): | 371 def __str__(self): |
371 return '{}\n{}'.format( | 372 return '{}\n{}'.format( |
372 super(HidDescriptor, self).__str__(), | 373 super(HidDescriptor, self).__str__(), |
373 '\n'.join(' bDescriptorType: 0x{:02X}\n wDescriptorLength: {}' | 374 '\n'.join(' bDescriptorType: 0x{:02X}\n wDescriptorLength: {}' |
374 .format(typ, length) for typ, length in self._descriptors)) | 375 .format(typ, length) for typ, length in self._descriptors)) |
375 | 376 |
376 HidDescriptor.AddComputedField('bLength', 'B', 'struct_size') | 377 HidDescriptor.AddComputedField('bLength', 'B', 'struct_size') |
377 HidDescriptor.AddFixedField('bDescriptorType', 'B', 33) | 378 HidDescriptor.AddFixedField('bDescriptorType', 'B', |
| 379 hid_constants.DescriptorType.HID) |
378 HidDescriptor.AddField('bcdHID', 'H', default=0x0111, str_fmt='0x{:04X}') | 380 HidDescriptor.AddField('bcdHID', 'H', default=0x0111, str_fmt='0x{:04X}') |
379 HidDescriptor.AddField('bCountryCode', 'B', default=0) | 381 HidDescriptor.AddField('bCountryCode', 'B', default=0) |
380 HidDescriptor.AddComputedField('bNumDescriptors', 'B', 'num_descriptors') | 382 HidDescriptor.AddComputedField('bNumDescriptors', 'B', 'num_descriptors') |
OLD | NEW |