Skip to content

Commit 20fc109

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 f93ce57 commit 20fc109

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

micropython/usbd/device.py

+13-20
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,13 @@ def _control_xfer_cb(self, stage, request):
404404
print(f"Unexpected control request type {request[0]:#x}")
405405
return False
406406

407-
# Accept the following possible replies from handle_NNN_control_xfer():
407+
# Expecting any of the following possible replies from
408+
# handle_NNN_control_xfer():
408409
#
409410
# True - Continue transfer, no data
410411
# False - STALL transfer
411412
# 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)
413+
return result
416414

417415

418416
class USBInterface:
@@ -609,21 +607,16 @@ def submit_xfer(self, ep_addr, data, done_cb=None):
609607
raise RuntimeError("Not open")
610608
_inst._submit_xfer(ep_addr, data, done_cb)
611609

612-
def set_ep_stall(self, ep_addr, stall):
613-
# Set or clear endpoint STALL state, according to the bool "stall" parameter.
610+
def stall(self, ep_addr, *args):
611+
# Set or get the endpoint STALL state.
614612
#
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.
613+
# To get endpoint stall stage, call with a single argument.
614+
# To set endpoint stall state, call with an additional boolean
615+
# argument to set or clear.
624616
#
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:
617+
# Generally endpoint STALL is handled automatically, but there are some
618+
# device classes that need to explicitly stall or unstall an endpoint
619+
# under certain conditions.
620+
if not self._open or ep_addr not in _inst._eps:
628621
raise RuntimeError
629-
return _inst._usbd.get_ep_stall(ep_addr)
622+
_inst._usbd.stall(ep_addr, *args)

0 commit comments

Comments
 (0)