Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: tools/usb_gadget/usb_descriptors.py

Issue 410813002: [usb_gadget p01] Functions for encoding HID descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed copyright text and added specification references. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/usb_gadget/hid_descriptors_test.py ('k') | tools/usb_gadget/usb_descriptors_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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')
OLDNEW
« no previous file with comments | « tools/usb_gadget/hid_descriptors_test.py ('k') | tools/usb_gadget/usb_descriptors_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698