X-Git-Url: http://git.rot13.org//?p=goodfet;a=blobdiff_plain;f=client%2FUSBEndpoint.py;fp=client%2FUSBEndpoint.py;h=a0d1c57440cadfa852d5d6fa7d02f8a3feeb2b0e;hp=0000000000000000000000000000000000000000;hb=96ebf28fac2e03cfee954db85282eac7b8ec8015;hpb=78533a51ab5421601b046a917dd0f6f01a402a49 diff --git a/client/USBEndpoint.py b/client/USBEndpoint.py new file mode 100644 index 0000000..a0d1c57 --- /dev/null +++ b/client/USBEndpoint.py @@ -0,0 +1,53 @@ +# USBEndpoint.py +# +# Contains class definition for USBEndpoint. + +class USBEndpoint: + direction_out = 0x00 + direction_in = 0x01 + + transfer_type_control = 0x00 + transfer_type_isochronous = 0x01 + transfer_type_bulk = 0x02 + transfer_type_interrupt = 0x03 + + sync_type_none = 0x00 + sync_type_async = 0x01 + sync_type_adaptive = 0x02 + sync_type_synchronous = 0x03 + + usage_type_data = 0x00 + usage_type_feedback = 0x01 + usage_type_implicit_feedback = 0x02 + + def __init__(self, number, direction, transfer_type, sync_type, + usage_type, max_packet_size, interval, handler): + + self.number = number + self.direction = direction + self.transfer_type = transfer_type + self.sync_type = sync_type + self.usage_type = usage_type + self.max_packet_size = max_packet_size + self.interval = interval + self.handler = handler + + # see Table 9-13 of USB 2.0 spec (pdf page 297) + def get_descriptor(self): + address = (self.number & 0x0f) | (self.direction << 7) + attributes = (self.transfer_type & 0x03) \ + | ((self.sync_type & 0x03) << 2) \ + | ((self.usage_type & 0x03) << 4) + + d = bytearray([ + 7, # length of descriptor in bytes + 5, # descriptor type 5 == endpoint + address, + attributes, + (self.max_packet_size >> 8) & 0xff, + self.max_packet_size & 0xff, + self.interval + ]) + + return d +