Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
usbd: Add USB interface functions for endpoint STALL support.
Necessary for MSC device class, possibly other purposes.
  • Loading branch information
projectgus committed Jul 25, 2023
commit 29e918543952bbadca22270d499ce18bd0ffd8ee
22 changes: 22 additions & 0 deletions micropython/usbd/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ def handle_reset(self):
# reset by the host. This can happen when the USB device is unplugged,
# or if the host triggers a reset for some other reason.
#
# Override this function to cancel any pending operations specific to
# the interface (outstanding USB transfers are already cancelled).
#
# At this point, no USB functionality is available - handle_open() will
# be called later if/when the USB host re-enumerates and configures the
# interface.
Expand Down Expand Up @@ -601,3 +604,22 @@ def submit_xfer(self, ep_addr, data, done_cb=None):
if not self._open:
raise RuntimeError()
return get_usbdevice()._submit_xfer(ep_addr, data, done_cb)

def set_ep_stall(self, ep_addr, stall):
# Set or clear endpoint STALL state, according to the bool "stall" parameter.
#
# Generally endpoint STALL is handled automatically by TinyUSB, but
# there are some device classes that need to explicitly stall or unstall
# an endpoint under certain conditions.
if not self._open or ep_addr not in get_usbdevice()._eps:
raise RuntimeError()
get_usbdevice()._usbd.set_ep_stall(ep_addr, stall)

def get_ep_stall(self, ep_addr):
# Get the current endpoint STALL state.
#
# Endpoint can be stalled/unstalled by host, TinyUSB stack, or calls to
# set_ep_stall().
if not self._open or ep_addr not in get_usbdevice()._eps:
raise RuntimeError()
return get_usbdevice()._usbd.get_ep_stall(ep_addr)