Skip to content

Commit 7cf2a6d

Browse files
committed
Fix compatibility with native PyUSB usb.core.Device.ctrl_transfer
1 parent 03bcf90 commit 7cf2a6d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

adafruit_usb_host_descriptors.py

Lines changed: 7 additions & 2 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
@@ -72,13 +73,15 @@ def get_descriptor(device, desc_type, index, buf, language_id=0):
7273
# pylint: disable=invalid-name
7374
wValue = desc_type << 8 | index
7475
wIndex = language_id
75-
device.ctrl_transfer(
76+
result = device.ctrl_transfer(
7677
_REQ_RCPT_DEVICE | _REQ_TYPE_STANDARD | _DIR_IN,
7778
_REQ_GET_DESCRIPTOR,
7879
wValue,
7980
wIndex,
8081
buf,
8182
)
83+
if isinstance(result, array.array):
84+
buf[:] = result.tobytes()
8285

8386

8487
def get_device_descriptor(device):
@@ -114,13 +117,15 @@ def get_report_descriptor(device, interface_num, length):
114117
try:
115118
# 0x81 = Dir: IN | Type: Standard | Recipient: Interface
116119
# wValue = 0x2200 (Report Descriptor)
117-
device.ctrl_transfer(
120+
result = device.ctrl_transfer(
118121
_RECIP_INTERFACE | _REQ_TYPE_STANDARD | _DIR_IN,
119122
_REQ_GET_DESCRIPTOR,
120123
DESC_REPORT << 8,
121124
interface_num,
122125
buf,
123126
)
127+
if isinstance(result, array.array):
128+
buf[:] = result.tobytes()
124129
return buf
125130
except usb.core.USBError as e:
126131
print(f"Failed to read Report Descriptor: {e}")

0 commit comments

Comments
 (0)