circuitpython/tools/usb_descriptor/cdc.py
Scott Shawcroft 4aeef100f6 atmel-samd: More USB polish
* Introduce a python script to generate the USB descriptor instead of
  a bunch of C macros. In the future, we can use this dynamically in
  CircuitPython.
* Add support for detecting read-only mass storage mounts.

Fixes #377
2017-10-30 18:29:20 -07:00

53 lines
1.4 KiB
Python

from . import core
import struct
class FunctionalDescriptor(core.Descriptor):
bDescriptorType = 0x24
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fmt = "<BBB" + self.fmt[3:]
def __bytes__(self):
return struct.pack(self.fmt, self.bLength, self.bDescriptorType, self.bDescriptorSubtype, *self.data)
class Header(FunctionalDescriptor):
fields = [('bcdCDC', "H", None)]
bLength = 0x05
bDescriptorSubtype = 0x0
class CallManagement(FunctionalDescriptor):
fields = [('bmCapabilities', "b", None),
('bDataInterface', "b", None)]
bLength = 0x05
bDescriptorSubtype = 0x01
class AbstractControlManagement(FunctionalDescriptor):
fields = [('bmCapabilities', "b", None)]
bLength = 0x04
bDescriptorSubtype = 0x02
class DirectLineManagement(FunctionalDescriptor):
fields = [('bmCapabilities', "b", None)]
bLength = 0x04
bDescriptorSubtype = 0x03
class Union(FunctionalDescriptor):
fields = [('bMasterInterface', "b", None)]
bDescriptorSubtype = 0x06
def __init__(self, *args, **kwargs):
self.bSlaveInterface = kwargs["bSlaveInterface"]
super().__init__(*args, **kwargs)
def __bytes__(self):
return super().__bytes__() + bytes(self.bSlaveInterface)
@property
def bLength(self):
return 0x4 + len(self.bSlaveInterface)