Skip to content

Commit 29e9185

Browse files
committed
usbd: Add USB interface functions for endpoint STALL support.
Necessary for MSC device class, possibly other purposes.
1 parent 9d4d843 commit 29e9185

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

micropython/usbd/device.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ def handle_reset(self):
508508
# reset by the host. This can happen when the USB device is unplugged,
509509
# or if the host triggers a reset for some other reason.
510510
#
511+
# Override this function to cancel any pending operations specific to
512+
# the interface (outstanding USB transfers are already cancelled).
513+
#
511514
# At this point, no USB functionality is available - handle_open() will
512515
# be called later if/when the USB host re-enumerates and configures the
513516
# interface.
@@ -601,3 +604,22 @@ def submit_xfer(self, ep_addr, data, done_cb=None):
601604
if not self._open:
602605
raise RuntimeError()
603606
return get_usbdevice()._submit_xfer(ep_addr, data, done_cb)
607+
608+
def set_ep_stall(self, ep_addr, stall):
609+
# Set or clear endpoint STALL state, according to the bool "stall" parameter.
610+
#
611+
# Generally endpoint STALL is handled automatically by TinyUSB, but
612+
# there are some device classes that need to explicitly stall or unstall
613+
# an endpoint under certain conditions.
614+
if not self._open or ep_addr not in get_usbdevice()._eps:
615+
raise RuntimeError()
616+
get_usbdevice()._usbd.set_ep_stall(ep_addr, stall)
617+
618+
def get_ep_stall(self, ep_addr):
619+
# Get the current endpoint STALL state.
620+
#
621+
# Endpoint can be stalled/unstalled by host, TinyUSB stack, or calls to
622+
# set_ep_stall().
623+
if not self._open or ep_addr not in get_usbdevice()._eps:
624+
raise RuntimeError()
625+
return get_usbdevice()._usbd.get_ep_stall(ep_addr)

0 commit comments

Comments
 (0)