-
Notifications
You must be signed in to change notification settings - Fork 2
Feat cdc python #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
fd786a5
20ccc8b
9244f23
e255093
f63af44
586b054
f55fba4
e28c943
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,13 +44,14 @@ class CDCControlInterface(USBInterface): | |
def __init__(self, interface_str): | ||
super().__init__(_CDC_ITF_CONTROL_CLASS, _CDC_ITF_CONTROL_SUBCLASS, | ||
_CDC_ITF_CONTROL_PROT) | ||
self.ep_in = None | ||
|
||
def get_itf_descriptor(self, num_eps, itf_idx, str_idx): | ||
# CDC needs a Interface Association Descriptor (IAD) | ||
# first interface is zero, two interfaces in total | ||
desc = ustruct.pack("<BBBBBBBB", 8, _ITF_ASSOCIATION_DESC_TYPE, itf_idx, 2, | ||
_CDC_ITF_CONTROL_CLASS, _CDC_ITF_CONTROL_SUBCLASS, | ||
_CDC_ITF_CONTROL_PROT, 0) # "IAD" | ||
_CDC_ITF_CONTROL_PROT, 4) # "IAD" | ||
|
||
itf, strs = super().get_itf_descriptor(num_eps, itf_idx, str_idx) | ||
desc += itf | ||
|
@@ -59,12 +60,13 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx): | |
desc += ustruct.pack("<BBBH", 5, _CS_DESC_TYPE, 0, 0x0120) # "Header" | ||
desc += ustruct.pack("<BBBBB", 5, _CS_DESC_TYPE, 1, 0, 1) # "Call Management" | ||
desc += ustruct.pack("<BBBB", 4, _CS_DESC_TYPE, 2, 2) # "Abstract Control" | ||
desc += ustruct.pack("<BBBH", 5, _CS_DESC_TYPE, 6, itf_idx, 1) # "Union" | ||
desc += ustruct.pack("<BBBBB", 5, _CS_DESC_TYPE, 6, itf_idx, itf_idx+1) # "Union" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, I corrected the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the big problem that fixed most things. It took me a while to realize it as well. |
||
return desc, strs | ||
|
||
def get_endpoint_descriptors(self, ep_addr, str_idx): | ||
self.ep_in = endpoint_descriptor((ep_addr + 1) | EP_IN_FLAG, "interrupt", 8, 16) | ||
return (self.ep_in, [], ((ep_addr+1) | EP_IN_FLAG,)) | ||
self.ep_in = (ep_addr) | EP_IN_FLAG | ||
desc = endpoint_descriptor(self.ep_in, "interrupt", 8, 16) | ||
return (desc, [], (self.ep_in,)) | ||
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that looks good |
||
|
||
|
||
class CDCDataInterface(USBInterface): | ||
|
@@ -78,18 +80,20 @@ def __init__(self, interface_str, timeout=1): | |
self.rx_done = False | ||
self.rx_nbytes = 0 | ||
self.timeout = timeout | ||
self.ep_in = None | ||
self.ep_out = None | ||
|
||
def get_endpoint_descriptors(self, ep_addr, str_idx): | ||
# XXX OUT = 0x00 but is defined as 0x80? | ||
self.ep_in = (ep_addr + 2) | EP_IN_FLAG | ||
self.ep_out = (ep_addr + 2) & ~EP_IN_FLAG | ||
self.ep_in = (ep_addr) | EP_IN_FLAG | ||
self.ep_out = (ep_addr) & ~EP_IN_FLAG | ||
# one IN / OUT Endpoint | ||
e_out = endpoint_descriptor(self.ep_out, "bulk", 64, 0) | ||
e_in = endpoint_descriptor(self.ep_in, "bulk", 64, 0) | ||
return (e_out + e_in, [], (self.ep_out, self.ep_in)) | ||
|
||
def write(self, data): | ||
super().submit_xfer(self.ep_in, data) | ||
self.submit_xfer(self.ep_in, data) | ||
|
||
def read(self, nbytes=0): | ||
# XXX PoC.. When returning, it should probably | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, this is an index to a string descriptor describing the function. Do we have a string descriptor for that? Otherwise this value is 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don't remember why I made it 4, just that it worked.