Skip to content

Commit a2c3195

Browse files
committed
usbd: Update to match the latest micropython USBD API.
- No more standalone control_xfer() function, the callback can return a buffer directly. - Combined get_ep_stall() and set_ep_stall() to one function. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 0c6cf7f commit a2c3195

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

micropython/usbd/device.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ class _USBDevice:
5656
def __init__(self):
5757
self._eps = {} # Mapping from endpoint address to interface object
5858
self._ep_cbs = {} # Mapping from endpoint address to Optional[xfer callback]
59-
self._itfs = (
60-
[]
61-
) # List of USBInterfaces (NOTE: each of these may contain >1 USB Interface descriptor)
59+
self._itfs = [] # List of USBInterfaces (NOTE: each of these may contain >1 USB Interface descriptor)
6260
self._desc = Descriptor()
6361
self.include_static = True # Include static devices when enumerating?
6462

@@ -404,15 +402,13 @@ def _control_xfer_cb(self, stage, request):
404402
print(f"Unexpected control request type {request[0]:#x}")
405403
return False
406404

407-
# Accept the following possible replies from handle_NNN_control_xfer():
405+
# Expecting any of the following possible replies from
406+
# handle_NNN_control_xfer():
408407
#
409408
# True - Continue transfer, no data
410409
# False - STALL transfer
411410
# Object with buffer interface - submit this data for the control transfer
412-
if isinstance(result, bool):
413-
return result
414-
415-
return self._usbd.control_xfer(request, result)
411+
return result
416412

417413

418414
class USBInterface:
@@ -609,21 +605,16 @@ def submit_xfer(self, ep_addr, data, done_cb=None):
609605
raise RuntimeError("Not open")
610606
_inst._submit_xfer(ep_addr, data, done_cb)
611607

612-
def set_ep_stall(self, ep_addr, stall):
613-
# Set or clear endpoint STALL state, according to the bool "stall" parameter.
608+
def stall(self, ep_addr, *args):
609+
# Set or get the endpoint STALL state.
614610
#
615-
# Generally endpoint STALL is handled automatically by TinyUSB, but
616-
# there are some device classes that need to explicitly stall or unstall
617-
# an endpoint under certain conditions.
618-
if not self._open or ep_addr not in _inst._eps:
619-
raise RuntimeError
620-
_inst._usbd.set_ep_stall(ep_addr, stall)
621-
622-
def get_ep_stall(self, ep_addr):
623-
# Get the current endpoint STALL state.
611+
# To get endpoint stall stage, call with a single argument.
612+
# To set endpoint stall state, call with an additional boolean
613+
# argument to set or clear.
624614
#
625-
# Endpoint can be stalled/unstalled by host, TinyUSB stack, or calls to
626-
# set_ep_stall().
627-
if not self._open or ep_addr not in get_usbdevice()._eps:
615+
# Generally endpoint STALL is handled automatically, but there are some
616+
# device classes that need to explicitly stall or unstall an endpoint
617+
# under certain conditions.
618+
if not self._open or ep_addr not in _inst._eps:
628619
raise RuntimeError
629-
return _inst._usbd.get_ep_stall(ep_addr)
620+
_inst._usbd.stall(ep_addr, *args)

0 commit comments

Comments
 (0)