Skip to content

Commit 52cb81c

Browse files
authored
Merge pull request #11 from relic-se/blinka
Fix compatibility with native PyUSB `usb.core.Device.ctrl_transfer`
2 parents 03bcf90 + d5fdba9 commit 52cb81c

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

adafruit_usb_host_descriptors.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Author(s): Scott Shawcroft
1111
"""
1212

13+
import array
1314
import struct
1415

1516
import usb
@@ -83,23 +84,23 @@ def get_descriptor(device, desc_type, index, buf, language_id=0):
8384

8485
def get_device_descriptor(device):
8586
"""Fetch the device descriptor and return it."""
86-
buf = bytearray(1)
87+
buf = array.array("B", bytearray(1))
8788
get_descriptor(device, DESC_DEVICE, 0, buf)
88-
full_buf = bytearray(buf[0])
89+
full_buf = array.array("B", bytearray(buf[0]))
8990
get_descriptor(device, DESC_DEVICE, 0, full_buf)
90-
return full_buf
91+
return bytearray(full_buf)
9192

9293

9394
def get_configuration_descriptor(device, index):
9495
"""Fetch the configuration descriptor, its associated descriptors and return it."""
9596
# Allow capitalization that matches the USB spec.
9697
# pylint: disable=invalid-name
97-
buf = bytearray(4)
98+
buf = array.array("B", bytearray(4))
9899
get_descriptor(device, DESC_CONFIGURATION, index, buf)
99100
wTotalLength = struct.unpack("<xxH", buf)[0]
100-
full_buf = bytearray(wTotalLength)
101+
full_buf = array.array("B", bytearray(wTotalLength))
101102
get_descriptor(device, DESC_CONFIGURATION, index, full_buf)
102-
return full_buf
103+
return bytearray(full_buf)
103104

104105

105106
def get_report_descriptor(device, interface_num, length):
@@ -110,7 +111,7 @@ def get_report_descriptor(device, interface_num, length):
110111
if length < 1:
111112
return None
112113

113-
buf = bytearray(length)
114+
buf = array.array("B", bytearray(length))
114115
try:
115116
# 0x81 = Dir: IN | Type: Standard | Recipient: Interface
116117
# wValue = 0x2200 (Report Descriptor)
@@ -121,7 +122,7 @@ def get_report_descriptor(device, interface_num, length):
121122
interface_num,
122123
buf,
123124
)
124-
return buf
125+
return bytearray(buf)
125126
except usb.core.USBError as e:
126127
print(f"Failed to read Report Descriptor: {e}")
127128
return None

0 commit comments

Comments
 (0)