Skip to content

Commit c61ca51

Browse files
committed
usb: Tidy up the description of TinyUSB callbacks.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 01f45c1 commit c61ca51

File tree

1 file changed

+12
-8
lines changed
  • micropython/usb/usb-device/usb/device

1 file changed

+12
-8
lines changed

micropython/usb/usb-device/usb/device/core.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ def active(self, *optional_value):
252252
return self._usbd.active(*optional_value)
253253

254254
def _open_itf_cb(self, desc):
255-
# Singleton callback from TinyUSB custom class driver, when USB host does
256-
# Set Configuration. Called once per interface or IAD.
255+
# Callback from TinyUSB lower layer, when USB host does Set
256+
# Configuration. Called once per interface or IAD.
257257

258258
# Note that even if the configuration descriptor contains an IAD, 'desc'
259259
# starts from the first interface descriptor in the IAD and not the IAD
@@ -291,7 +291,7 @@ def _open_itf_cb(self, desc):
291291
itf.on_open()
292292

293293
def _reset_cb(self):
294-
# Callback when the USB device is reset by the host
294+
# TinyUSB lower layer callback when the USB device is reset by the host
295295

296296
# Allow interfaces to respond to the reset
297297
for itf in self._itfs.values():
@@ -302,7 +302,7 @@ def _reset_cb(self):
302302
self._ep_cbs = {}
303303

304304
def _submit_xfer(self, ep_addr, data, done_cb=None):
305-
# Singleton function to submit a USB transfer (of any type except control).
305+
# Submit a USB transfer (of any type except control) to TinyUSB lower layer.
306306
#
307307
# Generally, drivers should call Interface.submit_xfer() instead. See
308308
# that function for documentation about the possible parameter values.
@@ -319,27 +319,31 @@ def _submit_xfer(self, ep_addr, data, done_cb=None):
319319
return self._usbd.submit_xfer(ep_addr, data)
320320

321321
def _xfer_pending(self, ep_addr):
322-
# Singleton function to return True if transfer is pending on this endpoint.
322+
# Returns True if a transfer is pending on this endpoint.
323323
#
324324
# Generally, drivers should call Interface.xfer_pending() instead. See that
325325
# function for more documentation.
326326
return self._ep_cbs[ep_addr] or (self._cb_ep == ep_addr and self._cb_thread != get_ident())
327327

328328
def _xfer_cb(self, ep_addr, result, xferred_bytes):
329-
# Singleton callback from TinyUSB custom class driver when a transfer completes.
329+
# Callback from TinyUSB lower layer when a transfer completes.
330330
cb = self._ep_cbs.get(ep_addr, None)
331331
self._cb_thread = get_ident()
332332
self._cb_ep = ep_addr # Track while callback is running
333333
self._ep_cbs[ep_addr] = None
334+
335+
# In most cases, 'cb' is a callback function for the transfer. Can also be:
336+
# - True (for a transfer with no callback)
337+
# - None (TinyUSB callback arrived for invalid endpoint, or no transfer.
338+
# Generally unlikely, but may happen in transient states.)
334339
try:
335-
# For a pending xfer, 'cb' should either a callback function or True (if no callback)
336340
if callable(cb):
337341
cb(ep_addr, result, xferred_bytes)
338342
finally:
339343
self._cb_ep = None
340344

341345
def _control_xfer_cb(self, stage, request):
342-
# Singleton callback from TinyUSB custom class driver when a control
346+
# Callback from TinyUSB lower layer when a control
343347
# transfer is in progress.
344348
#
345349
# stage determines appropriate responses (possible values

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy